Jack2 1.9.12

JackGraphManager.h
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 */
20
21 #ifndef __JackGraphManager__
22 #define __JackGraphManager__
23
24 #include "JackShmMem.h"
25 #include "JackPort.h"
26 #include "JackConstants.h"
27 #include "JackConnectionManager.h"
28 #include "JackAtomicState.h"
29 #include "JackPlatformPlug.h"
30 #include "JackSystemDeps.h"
31
32 namespace Jack
33 {
34
39 PRE_PACKED_STRUCTURE
40 class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState<JackConnectionManager>
41 {
42
43 private:
44
45 unsigned int fPortMax;
46 JackClientTiming fClientTiming[CLIENT_NUM];
47 JackPort fPortArray[0]; // The actual size depends of port_max, it will be dynamically computed and allocated using "placement" new
48
49 void AssertPort(jack_port_id_t port_index);
50 jack_port_id_t AllocatePortAux(int refnum, const char* port_name, const char* port_type, JackPortFlags flags);
51 void GetConnectionsAux(JackConnectionManager* manager, const char** res, jack_port_id_t port_index);
52 void GetPortsAux(const char** matching_ports, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
53 jack_default_audio_sample_t* GetBuffer(jack_port_id_t port_index);
54 void* GetBufferAux(JackConnectionManager* manager, jack_port_id_t port_index, jack_nframes_t frames);
55 jack_nframes_t ComputeTotalLatencyAux(jack_port_id_t port_index, jack_port_id_t src_port_index, JackConnectionManager* manager, int hop_count);
56 void RecalculateLatencyAux(jack_port_id_t port_index, jack_latency_callback_mode_t mode);
57
58 public:
59
60 JackGraphManager(int port_max);
61 ~JackGraphManager()
62 {}
63
64 void SetBufferSize(jack_nframes_t buffer_size);
65
66 // Ports management
67 jack_port_id_t AllocatePort(int refnum, const char* port_name, const char* port_type, JackPortFlags flags, jack_nframes_t buffer_size);
68 int ReleasePort(int refnum, jack_port_id_t port_index);
69 void GetInputPorts(int refnum, jack_int_t* res);
70 void GetOutputPorts(int refnum, jack_int_t* res);
71 void RemoveAllPorts(int refnum);
72 void DisconnectAllPorts(int refnum);
73
74 JackPort* GetPort(jack_port_id_t index);
75 jack_port_id_t GetPort(const char* name);
76
77 int ComputeTotalLatency(jack_port_id_t port_index);
78 int ComputeTotalLatencies();
79 void RecalculateLatency(jack_port_id_t port_index, jack_latency_callback_mode_t mode);
80
81 int RequestMonitor(jack_port_id_t port_index, bool onoff);
82
83 // Connections management
84 int Connect(jack_port_id_t src_index, jack_port_id_t dst_index);
85 int Disconnect(jack_port_id_t src_index, jack_port_id_t dst_index);
86 int IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst);
87
88 // RT, client
89 int GetConnectionsNum(jack_port_id_t port_index)
90 {
91 JackConnectionManager* manager = ReadCurrentState();
92 return manager->Connections(port_index);
93 }
94
95 const char** GetConnections(jack_port_id_t port_index);
96 void GetConnections(jack_port_id_t port_index, jack_int_t* connections); // TODO
97 const char** GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
98
99 int GetTwoPorts(const char* src, const char* dst, jack_port_id_t* src_index, jack_port_id_t* dst_index);
100 int CheckPorts(jack_port_id_t port_src, jack_port_id_t port_dst);
101
102 void DisconnectAllInput(jack_port_id_t port_index);
103 void DisconnectAllOutput(jack_port_id_t port_index);
104 int DisconnectAll(jack_port_id_t port_index);
105
106 bool IsDirectConnection(int ref1, int ref2);
107 void DirectConnect(int ref1, int ref2);
108 void DirectDisconnect(int ref1, int ref2);
109
110 void Activate(int refnum);
111 void Deactivate(int refnum);
112
113 int GetInputRefNum(jack_port_id_t port_index);
114 int GetOutputRefNum(jack_port_id_t port_index);
115
116 // Buffer management
117 void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames);
118
119 // Activation management
120 void RunCurrentGraph();
121 bool RunNextGraph();
122 bool IsFinishedGraph();
123
124 void InitRefNum(int refnum);
125 int ResumeRefNum(JackClientControl* control, JackSynchro* table);
126 int SuspendRefNum(JackClientControl* control, JackSynchro* table, long usecs);
127 void TopologicalSort(std::vector<jack_int_t>& sorted);
128
129 JackClientTiming* GetClientTiming(int refnum)
130 {
131 return &fClientTiming[refnum];
132 }
133
134 void Save(JackConnectionManager* dst);
135 void Restore(JackConnectionManager* src);
136
137 static JackGraphManager* Allocate(int port_max);
138 static void Destroy(JackGraphManager* manager);
139
140 } POST_PACKED_STRUCTURE;
141
142
143 } // end of namespace
144
145 #endif
146
Jack::JackConnectionManager
Connection manager.
Definition: JackConnectionManager.h:411
Jack::JackPort
Base class for port.
Definition: JackPort.h:39
Jack::JackPosixSemaphore
Inter process synchronization using POSIX semaphore.
Definition: JackPosixSemaphore.h:36
Jack::JackGraphManager
Graph manager: contains the connection manager and the port array.
Definition: JackGraphManager.h:40
Jack::JackConnectionManager::Connections
jack_int_t Connections(jack_port_id_t port_index) const
Get the connection number of a given port.
Definition: JackConnectionManager.h:438
Jack::JackAtomicState
A class to handle two states (switching from one to the other) in a lock-free manner.
Definition: JackAtomicState.h:90
Jack::JackClientTiming
For client timing measurements.
Definition: JackConnectionManager.h:374
Jack::JackShmMem
The base class for shared memory management.
Definition: JackShmMem.h:125
Jack::JackClientControl
Client control possibly in shared memory.
Definition: JackClientControl.h:38