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);