20 #include "JackConnectionManager.h"
21 #include "JackClientControl.h"
22 #include "JackEngineControl.h"
23 #include "JackGlobals.h"
24 #include "JackError.h"
32 JackConnectionManager::JackConnectionManager()
35 jack_log(
"JackConnectionManager::InitConnections size = %ld ",
sizeof(JackConnectionManager));
37 for (i = 0; i < PORT_NUM_MAX; i++) {
38 fConnection[i].Init();
43 jack_log(
"JackConnectionManager::InitClients");
44 for (i = 0; i < CLIENT_NUM; i++) {
49 JackConnectionManager::~JackConnectionManager()
56 bool JackConnectionManager::IsLoopPathAux(
int ref1,
int ref2)
const
58 jack_log(
"JackConnectionManager::IsLoopPathAux ref1 = %ld ref2 = %ld", ref1, ref2);
60 if (ref1 < GetEngineControl()->fDriverNum || ref2 < GetEngineControl()->fDriverNum) {
62 }
else if (ref1 == ref2) {
65 jack_int_t output[CLIENT_NUM];
68 if (fConnectionRef.IsInsideTable(ref2, output)) {
71 for (
int i = 0; i < CLIENT_NUM && output[i] != EMPTY; i++) {
72 if (IsLoopPathAux(output[i], ref2))
89 jack_log(
"JackConnectionManager::Connect port_src = %ld port_dst = %ld", port_src, port_dst);
91 if (fConnection[port_src].AddItem(port_dst)) {
104 jack_log(
"JackConnectionManager::Disconnect port_src = %ld port_dst = %ld", port_src, port_dst);
106 if (fConnection[port_src].RemoveItem(port_dst)) {
119 return fConnection[port_src].CheckItem(port_dst);
127 return fConnection[port_index].GetItems();
139 if (fInputPort[refnum].AddItem(port_index)) {
140 jack_log(
"JackConnectionManager::AddInputPort ref = %ld port = %ld", refnum, port_index);
143 jack_error(
"Maximum number of input ports is reached for application ref = %ld", refnum);
153 if (fOutputPort[refnum].AddItem(port_index)) {
154 jack_log(
"JackConnectionManager::AddOutputPort ref = %ld port = %ld", refnum, port_index);
157 jack_error(
"Maximum number of output ports is reached for application ref = %ld", refnum);
167 jack_log(
"JackConnectionManager::RemoveInputPort ref = %ld port_index = %ld ", refnum, port_index);
169 if (fInputPort[refnum].RemoveItem(port_index)) {
172 jack_error(
"Input port index = %ld not found for application ref = %ld", port_index, refnum);
182 jack_log(
"JackConnectionManager::RemoveOutputPort ref = %ld port_index = %ld ", refnum, port_index);
184 if (fOutputPort[refnum].RemoveItem(port_index)) {
187 jack_error(
"Output port index = %ld not found for application ref = %ld", port_index, refnum);
197 return fInputPort[refnum].GetItems();
205 return fOutputPort[refnum].GetItems();
213 fInputPort[refnum].Init();
214 fOutputPort[refnum].Init();
215 fConnectionRef.Init(refnum);
216 fInputCounter[refnum].SetValue(0);
225 for (
int i = 0; i < CLIENT_NUM; i++) {
226 fInputCounter[i].Reset();
227 timing[i].fStatus = NotTriggered;
237 if ((res = table[control->fRefNum].TimedWait(time_out_usec))) {
238 timing[control->fRefNum].fStatus = Running;
239 timing[control->fRefNum].fAwakeAt = GetMicroSeconds();
241 return (res) ? 0 : -1;
249 jack_time_t current_date = GetMicroSeconds();
250 const jack_int_t* output_ref = fConnectionRef.GetItems(control->fRefNum);
254 timing[control->fRefNum].fStatus = Finished;
255 timing[control->fRefNum].fFinishedAt = current_date;
257 for (
int i = 0; i < CLIENT_NUM; i++) {
260 if (output_ref[i] > 0) {
263 timing[i].fStatus = Triggered;
264 timing[i].fSignaledAt = current_date;
266 if (!fInputCounter[i].Signal(table + i, control)) {
267 jack_log(
"JackConnectionManager::ResumeRefNum error: ref = %ld output = %ld ", control->fRefNum, i);
276 static bool HasNoConnection(jack_int_t* table)
278 for (
int ref = 0; ref < CLIENT_NUM; ref++) {
279 if (table[ref] > 0)
return false;
286 void JackConnectionManager::TopologicalSort(std::vector<jack_int_t>& sorted)
288 JackFixedMatrix<CLIENT_NUM> tmp;
289 std::set<jack_int_t> level;
291 fConnectionRef.Copy(tmp);
294 level.insert(AUDIO_DRIVER_REFNUM);
295 level.insert(FREEWHEEL_DRIVER_REFNUM);
297 while (level.size() > 0) {
298 jack_int_t refnum = *level.begin();
299 sorted.push_back(refnum);
300 level.erase(level.begin());
301 const jack_int_t* output_ref1 = tmp.GetItems(refnum);
302 for (
int dst = 0; dst < CLIENT_NUM; dst++) {
303 if (output_ref1[dst] > 0) {
304 tmp.ClearItem(refnum, dst);
305 jack_int_t output_ref2[CLIENT_NUM];
306 tmp.GetOutputTable1(dst, output_ref2);
307 if (HasNoConnection(output_ref2))
322 assert(ref1 >= 0 && ref2 >= 0);
325 jack_log(
"JackConnectionManager::IncConnectionRef: ref1 = %ld ref2 = %ld", ref1, ref2);
336 assert(ref1 >= 0 && ref2 >= 0);
339 jack_log(
"JackConnectionManager::DecConnectionRef: ref1 = %ld ref2 = %ld", ref1, ref2);
347 assert(ref1 >= 0 && ref2 >= 0);
349 if (fConnectionRef.IncItem(ref1, ref2) == 1) {
350 jack_log(
"JackConnectionManager::DirectConnect first: ref1 = %ld ref2 = %ld", ref1, ref2);
351 fInputCounter[ref2].IncValue();
360 assert(ref1 >= 0 && ref2 >= 0);
362 if (fConnectionRef.DecItem(ref1, ref2) == 0) {
363 jack_log(
"JackConnectionManager::DirectDisconnect last: ref1 = %ld ref2 = %ld", ref1, ref2);
364 fInputCounter[ref2].DecValue();
373 assert(ref1 >= 0 && ref2 >= 0);
374 return (fConnectionRef.GetItemCount(ref1, ref2) > 0);
382 for (
int i = 0; i < CLIENT_NUM; i++) {
383 if (fInputPort[i].CheckItem(port_index))
395 for (
int i = 0; i < CLIENT_NUM; i++) {
396 if (fOutputPort[i].CheckItem(port_index))
411 bool JackConnectionManager::IsFeedbackConnection(jack_port_id_t port_src, jack_port_id_t port_dst)
const
416 bool JackConnectionManager::IncFeedbackConnection(jack_port_id_t port_src, jack_port_id_t port_dst)
422 jack_log(
"JackConnectionManager::IncFeedbackConnection ref1 = %ld ref2 = %ld", ref1, ref2);
423 assert(ref1 >= 0 && ref2 >= 0);
428 return fLoopFeedback.IncConnection(ref1, ref2);
431 bool JackConnectionManager::DecFeedbackConnection(jack_port_id_t port_src, jack_port_id_t port_dst)
437 jack_log(
"JackConnectionManager::DecFeedbackConnection ref1 = %ld ref2 = %ld", ref1, ref2);
438 assert(ref1 >= 0 && ref2 >= 0);
443 return fLoopFeedback.DecConnection(ref1, ref2);
void DirectDisconnect(int ref1, int ref2)
Directly disconnect 2 reference numbers.
bool IsDirectConnection(int ref1, int ref2) const
Returns the connections state between 2 refnum.
bool IsLoopPath(jack_port_id_t port_src, jack_port_id_t port_dst) const
Test is a connection path exists between port_src and port_dst.
int Disconnect(jack_port_id_t port_src, jack_port_id_t port_dst)
Disconnect port_src from port_dst.
Inter process synchronization using using Mach semaphore.
int GetOutputRefNum(jack_port_id_t port_index) const
Get the client refnum of a given ouput port.
void IncDirectConnection(jack_port_id_t port_src, jack_port_id_t port_dst)
Increment the number of ports between 2 clients, if the 2 clients become connected, then the Activation counter is updated.
int SuspendRefNum(JackClientControl *control, JackSynchro *table, JackClientTiming *timing, long time_out_usec)
Wait on the input synchro.
void ResetGraph(JackClientTiming *timing)
Reset all clients activation.
int GetConnectionIndex(int ref1, int ref2) const
Test if a connection between 2 refnum is a feedback connection.
SERVER_EXPORT void jack_error(const char *fmt,...)
int RemoveInputPort(int refnum, jack_port_id_t port_index)
Remove an input port from a client.
int AddOutputPort(int refnum, jack_port_id_t port_index)
Add an output port to a client.
int GetInputRefNum(jack_port_id_t port_index) const
Get the client refnum of a given input port.
void DecDirectConnection(jack_port_id_t port_src, jack_port_id_t port_dst)
Decrement the number of ports between 2 clients, if the 2 clients become disconnected, then the Activation counter is updated.
int Connect(jack_port_id_t port_src, jack_port_id_t port_dst)
Connect port_src to port_dst.
void GetOutputTable(jack_int_t index, jack_int_t *output) const
Get the output indexes of a given index.
const jack_int_t * GetOutputPorts(int refnum)
Get the output port array of a given refnum.
bool IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst) const
Check if port_src and port_dst are connected.
void DirectConnect(int ref1, int ref2)
Directly connect 2 reference numbers.
const jack_int_t * GetConnections(jack_port_id_t port_index) const
Get the connection port array.
int RemoveOutputPort(int refnum, jack_port_id_t port_index)
Remove an output port from a client.
For client timing measurements.
void InitRefNum(int refnum)
Init the refnum.
int AddInputPort(int refnum, jack_port_id_t port_index)
Add an input port to a client.
int ResumeRefNum(JackClientControl *control, JackSynchro *table, JackClientTiming *timing)
Signal clients connected to the given client.
SERVER_EXPORT void jack_log(const char *fmt,...)
const jack_int_t * GetInputPorts(int refnum)
Get the input port array of a given refnum.
Client control possibly in shared memory.