jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

687 lines
21KB

  1. /*
  2. Copyright (C) 2004-2006 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include <iostream>
  16. #include <fstream>
  17. #include <assert.h>
  18. #include "JackEngine.h"
  19. #include "JackExternalClient.h"
  20. #include "JackEngineControl.h"
  21. #include "JackClientControl.h"
  22. #include "JackEngineTiming.h"
  23. #include "JackGlobals.h"
  24. #include "JackChannel.h"
  25. #include "JackSyncInterface.h"
  26. namespace Jack
  27. {
  28. JackEngine::JackEngine(JackGraphManager* manager,
  29. JackSynchro** table,
  30. JackEngineControl* control,
  31. bool sync,
  32. long time_out_ms,
  33. bool rt,
  34. long priority,
  35. bool ve)
  36. {
  37. fGraphManager = manager;
  38. fSynchroTable = table;
  39. fEngineControl = control;
  40. fEngineControl->fSyncMode = sync;
  41. fEngineControl->fTimeOutUsecs = time_out_ms * 1000;
  42. fEngineControl->fRealTime = rt;
  43. fEngineControl->fPriority = priority;
  44. fEngineControl->fVerbose = ve;
  45. fChannel = JackGlobals::MakeServerNotifyChannel();
  46. fSignal = JackGlobals::MakeInterProcessSync();
  47. fEngineTiming = new JackEngineTiming(fClientTable, fGraphManager, fEngineControl);
  48. for (int i = 0; i < CLIENT_NUM; i++)
  49. fClientTable[i] = NULL;
  50. fEngineTiming->ClearTimeMeasures();
  51. fEngineTiming->ResetRollingUsecs();
  52. }
  53. JackEngine::~JackEngine()
  54. {
  55. delete fChannel;
  56. delete fEngineTiming;
  57. delete fSignal;
  58. }
  59. //-------------------
  60. // Client management
  61. //-------------------
  62. int JackEngine::Open()
  63. {
  64. JackLog("JackEngine::Open\n");
  65. // Open audio thread => request thread communication channel
  66. if (fChannel->Open() < 0) {
  67. jack_error("Cannot connect to server");
  68. return -1;
  69. } else {
  70. return 0;
  71. }
  72. }
  73. int JackEngine::Close()
  74. {
  75. JackLog("JackEngine::Close\n");
  76. fChannel->Close();
  77. // Close (possibly) remaining clients (RT is stopped)
  78. for (int i = 0; i < CLIENT_NUM; i++) {
  79. JackClientInterface* client = fClientTable[i];
  80. if (client) {
  81. JackLog("JackEngine::Close remaining client %ld\n", i);
  82. ClientCloseAux(i, client, false);
  83. client->Close();
  84. delete client;
  85. }
  86. }
  87. fSignal->Destroy();
  88. return 0;
  89. }
  90. int JackEngine::Allocate()
  91. {
  92. for (int i = 0; i < CLIENT_NUM; i++) {
  93. if (!fClientTable[i]) {
  94. JackLog("JackEngine::AllocateRefNum ref = %ld\n", i);
  95. return i;
  96. }
  97. }
  98. return -1;
  99. }
  100. //------------------
  101. // Graph management
  102. //------------------
  103. void JackEngine::ProcessNext(jack_time_t callback_usecs)
  104. {
  105. fLastSwitchUsecs = callback_usecs;
  106. if (fGraphManager->RunNextGraph()) // True if the graph actually switched to a new state
  107. fChannel->ClientNotify(ALL_CLIENTS, JackNotifyChannelInterface::kGraphOrderCallback, 0);
  108. fSignal->SignalAll(); // Signal for threads waiting for next cycle
  109. }
  110. void JackEngine::ProcessCurrent(jack_time_t callback_usecs)
  111. {
  112. if (callback_usecs < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs) // Signal XRun only for the first failling cycle
  113. CheckXRun(callback_usecs);
  114. fGraphManager->RunCurrentGraph();
  115. }
  116. bool JackEngine::Process(jack_time_t callback_usecs)
  117. {
  118. bool res = true;
  119. // Transport begin
  120. fEngineControl->CycleBegin(callback_usecs);
  121. // Timing
  122. fEngineControl->IncFrameTime(callback_usecs);
  123. fEngineTiming->UpdateTiming(callback_usecs);
  124. // Graph
  125. if (fGraphManager->IsFinishedGraph()) {
  126. ProcessNext(callback_usecs);
  127. res = true;
  128. } else {
  129. JackLog("Process: graph not finished!\n");
  130. if (callback_usecs > fLastSwitchUsecs + fEngineControl->fTimeOutUsecs) {
  131. JackLog("Process: switch to next state delta = %ld\n", long(callback_usecs - fLastSwitchUsecs));
  132. //RemoveZombifiedClients(callback_usecs); TODO
  133. ProcessNext(callback_usecs);
  134. res = true;
  135. } else {
  136. JackLog("Process: waiting to switch delta = %ld\n", long(callback_usecs - fLastSwitchUsecs));
  137. ProcessCurrent(callback_usecs);
  138. res = false;
  139. }
  140. }
  141. // Transport end
  142. fEngineControl->CycleEnd(fClientTable);
  143. return res;
  144. }
  145. /*
  146. Client that finish *after* the callback date are considered late even if their output buffers may have been
  147. correctly mixed in the time window: callbackUsecs <==> Read <==> Write.
  148. */
  149. void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions de fin
  150. {
  151. for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) {
  152. JackClientInterface* client = fClientTable[i];
  153. if (client && client->GetClientControl()->fActive) {
  154. JackClientTiming* timing = fGraphManager->GetClientTiming(i);
  155. jack_client_state_t status = timing->fStatus;
  156. jack_time_t finished_date = timing->fFinishedAt;
  157. if (status != NotTriggered && status != Finished) {
  158. jack_error("JackEngine::XRun: client = %s was not run: state = %ld", client->GetClientControl()->fName, status);
  159. //fChannel->ClientNotify(i, kXRunCallback, 0); // Notify the failing client
  160. fChannel->ClientNotify(ALL_CLIENTS, JackNotifyChannelInterface::kXRunCallback, 0); // Notify all clients
  161. }
  162. if (status == Finished && (long)(finished_date - callback_usecs) > 0) {
  163. jack_error("JackEngine::XRun: client %s finished after current callback", client->GetClientControl()->fName);
  164. //fChannel->ClientNotify(i, kXRunCallback, 0); // Notify the failing client
  165. fChannel->ClientNotify(ALL_CLIENTS, JackNotifyChannelInterface::kXRunCallback, 0); // Notify all clients
  166. }
  167. }
  168. }
  169. }
  170. //---------------
  171. // Zombification
  172. //---------------
  173. bool JackEngine::IsZombie(JackClientInterface* client, jack_time_t current_time)
  174. {
  175. return ((current_time - fGraphManager->GetClientTiming(client->GetClientControl()->fRefNum)->fFinishedAt) > 2 * fEngineControl->fTimeOutUsecs); // A VERIFIER
  176. }
  177. // TODO : check what happens with looped sub-graph....
  178. void JackEngine::GetZombifiedClients(bool zombi_clients[CLIENT_NUM], jack_time_t current_time)
  179. {
  180. for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) {
  181. JackClientInterface* client1 = fClientTable[i];
  182. if (client1 && IsZombie(client1, current_time)) {
  183. JackLog("JackEngine::GetZombifiedClients: %s\n", client1->GetClientControl()->fName);
  184. zombi_clients[i] = true; // Assume client is dead
  185. // If another dead client is connected to the scanned one, then the scanned one is not the first of the dead subgraph
  186. for (int j = REAL_REFNUM; j < CLIENT_NUM; j++) {
  187. JackClientInterface* client2 = fClientTable[j];
  188. if (client2 && IsZombie(client2, current_time) && fGraphManager->IsDirectConnection(j, i)) {
  189. zombi_clients[i] = false;
  190. break;
  191. }
  192. }
  193. } else {
  194. zombi_clients[i] = false;
  195. }
  196. }
  197. }
  198. void JackEngine::RemoveZombifiedClients(jack_time_t current_time)
  199. {
  200. bool zombi_clients[CLIENT_NUM];
  201. GetZombifiedClients(zombi_clients, current_time);
  202. for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) {
  203. if (zombi_clients[i] && !fClientTable[i]->GetClientControl()->fZombie) {
  204. fClientTable[i]->GetClientControl()->fZombie = true;
  205. JackLog("RemoveZombifiedCients: name = %s\n", fClientTable[i]->GetClientControl()->fName);
  206. fGraphManager->DirectDisconnect(FREEWHEEL_DRIVER_REFNUM, i);
  207. fGraphManager->DirectDisconnect(i, FREEWHEEL_DRIVER_REFNUM);
  208. fGraphManager->DisconnectAllPorts(i);
  209. fChannel->ClientNotify(i, JackNotifyChannelInterface::kZombifyClient, 0); // Signal engine
  210. }
  211. }
  212. }
  213. void JackEngine::ZombifyClient(int refnum)
  214. {
  215. NotifyClient(refnum, JackNotifyChannelInterface::kZombifyClient, false, 0);
  216. }
  217. //---------------
  218. // Notifications
  219. //---------------
  220. void JackEngine::NotifyClient(int refnum, int event, int sync, int value)
  221. {
  222. JackClientInterface* client = fClientTable[refnum];
  223. // The client may be notified by the RT thread while closing
  224. if (client) {
  225. if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, value) < 0)
  226. jack_error("NotifyClient fails name = %s event = %ld = val = %ld", client->GetClientControl()->fName, event, value);
  227. } else {
  228. JackLog("JackEngine::NotifyClient: client not available anymore\n");
  229. }
  230. }
  231. void JackEngine::NotifyClients(int event, int sync, int value)
  232. {
  233. for (int i = 0; i < CLIENT_NUM; i++) {
  234. JackClientInterface* client = fClientTable[i];
  235. if (client && (client->ClientNotify(i, client->GetClientControl()->fName, event, sync, value) < 0)) {
  236. jack_error("NotifyClient fails name = %s event = %ld = val = %ld", client->GetClientControl()->fName, event, value);
  237. }
  238. }
  239. }
  240. int JackEngine::NotifyAddClient(JackClientInterface* new_client, const char* name, int refnum)
  241. {
  242. // Notify existing clients of the new client and new client of existing clients.
  243. for (int i = 0; i < CLIENT_NUM; i++) {
  244. JackClientInterface* old_client = fClientTable[i];
  245. if (old_client) {
  246. if (old_client->ClientNotify(refnum, name, JackNotifyChannelInterface::kAddClient, true, 0) < 0) {
  247. jack_error("NotifyAddClient old_client fails name = %s", old_client->GetClientControl()->fName);
  248. return -1;
  249. }
  250. if (new_client->ClientNotify(i, old_client->GetClientControl()->fName, JackNotifyChannelInterface::kAddClient, true, 0) < 0) {
  251. jack_error("NotifyAddClient new_client fails name = %s", name);
  252. return -1;
  253. }
  254. }
  255. }
  256. return 0;
  257. }
  258. void JackEngine::NotifyRemoveClient(const char* name, int refnum)
  259. {
  260. // Notify existing clients (including the one beeing suppressed) of the removed client
  261. for (int i = 0; i < CLIENT_NUM; i++) {
  262. JackClientInterface* client = fClientTable[i];
  263. if (client) {
  264. client->ClientNotify(refnum, name, JackNotifyChannelInterface::kRemoveClient, true, 0);
  265. }
  266. }
  267. }
  268. // Coming from the driver
  269. void JackEngine::NotifyXRun(jack_time_t callback_usecs)
  270. {
  271. // Use the audio thread => request thread communication channel
  272. fEngineControl->ResetFrameTime(callback_usecs);
  273. fChannel->ClientNotify(ALL_CLIENTS, JackNotifyChannelInterface::kXRunCallback, 0);
  274. }
  275. void JackEngine::NotifyXRun(int refnum)
  276. {
  277. if (refnum == ALL_CLIENTS) {
  278. NotifyClients(JackNotifyChannelInterface::kXRunCallback, false, 0);
  279. } else {
  280. NotifyClient(refnum, JackNotifyChannelInterface::kXRunCallback, false, 0);
  281. }
  282. }
  283. void JackEngine::NotifyGraphReorder()
  284. {
  285. NotifyClients(JackNotifyChannelInterface::kGraphOrderCallback, false, 0);
  286. }
  287. void JackEngine::NotifyBufferSize(jack_nframes_t nframes)
  288. {
  289. NotifyClients(JackNotifyChannelInterface::kBufferSizeCallback, true, nframes);
  290. }
  291. void JackEngine::NotifyFreewheel(bool onoff)
  292. {
  293. fEngineControl->fRealTime = !onoff;
  294. NotifyClients((onoff ? JackNotifyChannelInterface::kStartFreewheel : JackNotifyChannelInterface::kStopFreewheel), true, 0);
  295. }
  296. void JackEngine::NotifyPortRegistation(jack_port_id_t port_index, bool onoff)
  297. {
  298. NotifyClients((onoff ? JackNotifyChannelInterface::kPortRegistrationOn : JackNotifyChannelInterface::kPortRegistrationOff), false, port_index);
  299. }
  300. void JackEngine::NotifyActivate(int refnum)
  301. {
  302. NotifyClient(refnum, JackNotifyChannelInterface::kActivateClient, true, 0);
  303. }
  304. //-------------------
  305. // Client management
  306. //-------------------
  307. bool JackEngine::ClientCheckName(const char* name)
  308. {
  309. for (int i = 0; i < CLIENT_NUM; i++) {
  310. JackClientInterface* client = fClientTable[i];
  311. if (client && (strcmp(client->GetClientControl()->fName, name) == 0))
  312. return true;
  313. }
  314. return false;
  315. }
  316. // Used for external clients
  317. int JackEngine::ClientNew(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
  318. {
  319. if (ClientCheckName(name)) {
  320. jack_error("client %s already registered", name);
  321. return -1;
  322. }
  323. JackExternalClient* client = new JackExternalClient();
  324. if (ClientExternalNew(name, ref, shared_engine, shared_client, shared_graph_manager, client) < 0) {
  325. delete client;
  326. return -1;
  327. }
  328. return 0;
  329. }
  330. // Used for external clients
  331. int JackEngine::ClientExternalNew(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager, JackExternalClient* client)
  332. {
  333. JackLog("JackEngine::ClientNew: name = %s \n", name);
  334. int refnum = Allocate();
  335. if (refnum < 0) {
  336. jack_error("No more refnum available");
  337. return -1;
  338. }
  339. if (!fSynchroTable[refnum]->Allocate(name, 0)) {
  340. jack_error("Cannot allocate synchro");
  341. goto error;
  342. }
  343. if (client->Open(name, refnum, shared_client) < 0) {
  344. jack_error("Cannot open client");
  345. goto error;
  346. }
  347. if (!fSignal->TimedWait(5 * 1000000)) {
  348. // Failure if RT thread is not running (problem with the driver...)
  349. jack_error("Driver is not running");
  350. goto error;
  351. }
  352. if (NotifyAddClient(client, name, refnum) < 0) {
  353. jack_error("Cannot notify add client");
  354. goto error;
  355. }
  356. fClientTable[refnum] = client;
  357. fGraphManager->InitRefNum(refnum);
  358. fEngineTiming->ResetRollingUsecs();
  359. *shared_engine = fEngineControl->GetShmIndex();
  360. *shared_graph_manager = fGraphManager->GetShmIndex();
  361. *ref = refnum;
  362. return 0;
  363. error:
  364. ClientCloseAux(refnum, client, false);
  365. client->Close();
  366. return -1;
  367. }
  368. // Used for server driver clients
  369. int JackEngine::ClientInternalNew(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client)
  370. {
  371. JackLog("JackEngine::ClientInternalNew: name = %s\n", name);
  372. int refnum = Allocate();
  373. if (refnum < 0) {
  374. jack_error("No more refnum available");
  375. return -1;
  376. }
  377. if (!fSynchroTable[refnum]->Allocate(name, 0)) {
  378. jack_error("Cannot allocate synchro");
  379. return -1;
  380. }
  381. if (NotifyAddClient(client, name, refnum) < 0) {
  382. jack_error("Cannot notify add client");
  383. return -1;
  384. }
  385. fClientTable[refnum] = client;
  386. fGraphManager->InitRefNum(refnum);
  387. fEngineTiming->ResetRollingUsecs();
  388. *shared_engine = fEngineControl;
  389. *shared_manager = fGraphManager;
  390. *ref = refnum;
  391. return 0;
  392. }
  393. // Used for externall clients
  394. int JackEngine::ClientClose(int refnum)
  395. {
  396. JackClientInterface* client = fClientTable[refnum];
  397. if (client) {
  398. fEngineControl->fTransport.ResetTimebase(refnum);
  399. int res = ClientCloseAux(refnum, client, true);
  400. client->Close();
  401. delete client;
  402. return res;
  403. } else {
  404. return -1;
  405. }
  406. }
  407. // Used for server internal clients
  408. int JackEngine::ClientInternalClose(int refnum)
  409. {
  410. JackClientInterface* client = fClientTable[refnum];
  411. return (client) ? ClientCloseAux(refnum, client, true) : -1;
  412. }
  413. // Used for drivers that close when the RT thread is stopped
  414. int JackEngine::ClientInternalCloseIm(int refnum)
  415. {
  416. JackClientInterface* client = fClientTable[refnum];
  417. return (client) ? ClientCloseAux(refnum, client, false) : -1;
  418. }
  419. int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wait)
  420. {
  421. JackLog("JackEngine::ClientCloseAux ref = %ld name = %s\n", refnum, client->GetClientControl()->fName);
  422. // Remove the client from the table
  423. fClientTable[refnum] = NULL;
  424. // Remove ports
  425. fGraphManager->RemoveAllPorts(refnum);
  426. // Wait until next cycle to be sure client is not used anymore
  427. if (wait) {
  428. if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 2)) { // Must wait at least until a switch occurs in Process, even in case of graph end failure
  429. jack_error("JackEngine::ClientCloseAux wait error ref = %ld", refnum);
  430. }
  431. }
  432. // Notify running clients
  433. NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum);
  434. // Cleanup...
  435. fSynchroTable[refnum]->Destroy();
  436. fEngineTiming->ResetRollingUsecs();
  437. return 0;
  438. }
  439. int JackEngine::ClientActivate(int refnum)
  440. {
  441. JackClientInterface* client = fClientTable[refnum];
  442. assert(fClientTable[refnum]);
  443. JackLog("JackEngine::ClientActivate ref = %ld name = %s\n", refnum, client->GetClientControl()->fName);
  444. fGraphManager->Activate(refnum);
  445. // Wait for graph state change to be effective
  446. if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) {
  447. jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName);
  448. return -1;
  449. } else {
  450. NotifyActivate(refnum);
  451. return 0;
  452. }
  453. }
  454. // May be called without client
  455. int JackEngine::ClientDeactivate(int refnum)
  456. {
  457. JackClientInterface* client = fClientTable[refnum];
  458. if (client == NULL)
  459. return -1;
  460. JackLog("JackEngine::ClientDeactivate ref = %ld name = %s\n", refnum, client->GetClientControl()->fName);
  461. fGraphManager->Deactivate(refnum);
  462. fLastSwitchUsecs = 0; // Force switch to occur next cycle, even when called with "dead" clients
  463. // Wait for graph state change to be effective
  464. if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) {
  465. jack_error("JackEngine::ClientDeactivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName);
  466. return -1;
  467. } else {
  468. return 0;
  469. }
  470. }
  471. //-----------------
  472. // Port management
  473. //-----------------
  474. int JackEngine::PortRegister(int refnum, const char* name, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index)
  475. {
  476. JackLog("JackEngine::PortRegister ref = %ld name = %s flags = %d buffer_size = %d\n", refnum, name, flags, buffer_size);
  477. assert(fClientTable[refnum]);
  478. *port_index = fGraphManager->AllocatePort(refnum, name, (JackPortFlags)flags);
  479. if (*port_index != NO_PORT) {
  480. NotifyPortRegistation(*port_index, true);
  481. return 0;
  482. } else {
  483. return -1;
  484. }
  485. }
  486. int JackEngine::PortUnRegister(int refnum, jack_port_id_t port_index)
  487. {
  488. JackLog("JackEngine::PortUnRegister ref = %ld port_index = %ld\n", refnum, port_index);
  489. assert(fClientTable[refnum]);
  490. if (fGraphManager->RemovePort(refnum, port_index) == 0) {
  491. fGraphManager->ReleasePort(port_index);
  492. NotifyPortRegistation(port_index, false);
  493. return 0;
  494. } else {
  495. return -1;
  496. }
  497. }
  498. int JackEngine::PortConnect(int refnum, const char* src, const char* dst)
  499. {
  500. JackLog("JackEngine::PortConnect src = %s dst = %s\n", src, dst);
  501. jack_port_id_t port_src, port_dst;
  502. return (fGraphManager->CheckPorts(src, dst, &port_src, &port_dst) < 0)
  503. ? -1
  504. : PortConnect(refnum, port_src, port_dst);
  505. }
  506. int JackEngine::PortDisconnect(int refnum, const char* src, const char* dst)
  507. {
  508. JackLog("JackEngine::PortDisconnect src = %s dst = %s\n", src, dst);
  509. jack_port_id_t port_src, port_dst;
  510. return (fGraphManager->CheckPorts(src, dst, &port_src, &port_dst) < 0)
  511. ? -1
  512. : fGraphManager->Disconnect(port_src, port_dst);
  513. }
  514. int JackEngine::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
  515. {
  516. JackLog("JackEngine::PortConnect src = %d dst = %d\n", src, dst);
  517. JackClientInterface* client;
  518. int ref;
  519. if (fGraphManager->CheckPorts(src, dst) < 0)
  520. return -1;
  521. ref = fGraphManager->GetOutputRefNum(src);
  522. assert(ref >= 0);
  523. client = fClientTable[ref];
  524. assert(client);
  525. if (!client->GetClientControl()->fActive) {
  526. jack_error("Cannot connect ports owned by inactive clients:"
  527. " \"%s\" is not active", client->GetClientControl()->fName);
  528. return -1;
  529. }
  530. ref = fGraphManager->GetInputRefNum(dst);
  531. assert(ref >= 0);
  532. client = fClientTable[ref];
  533. assert(client);
  534. if (!client->GetClientControl()->fActive) {
  535. jack_error("Cannot connect ports owned by inactive clients:"
  536. " \"%s\" is not active", client->GetClientControl()->fName);
  537. return -1;
  538. }
  539. return fGraphManager->Connect(src, dst);
  540. }
  541. int JackEngine::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
  542. {
  543. JackLog("JackEngine::PortDisconnect src = %d dst = %d\n", src, dst);
  544. if (dst == ALL_PORTS) {
  545. return (fGraphManager->CheckPort(src) < 0)
  546. ? -1
  547. : fGraphManager->DisconnectAll(src);
  548. } else {
  549. return (fGraphManager->CheckPorts(src, dst) < 0)
  550. ? -1
  551. : fGraphManager->Disconnect(src, dst);
  552. }
  553. }
  554. //----------------------
  555. // Transport management
  556. //----------------------
  557. int JackEngine::ReleaseTimebase(int refnum)
  558. {
  559. return fEngineControl->fTransport.ResetTimebase(refnum);
  560. }
  561. int JackEngine::SetTimebaseCallback(int refnum, int conditional)
  562. {
  563. return fEngineControl->fTransport.SetTimebase(refnum, conditional);
  564. }
  565. //-----------
  566. // Debugging
  567. //-----------
  568. void JackEngine::PrintState()
  569. {
  570. std::cout << "Engine State" << std::endl;
  571. for (int i = 0; i < CLIENT_NUM; i++) {
  572. JackClientInterface* client = fClientTable[i];
  573. if (client)
  574. std::cout << "Client : " << client->GetClientControl()->fName << " : " << i << std::endl;
  575. }
  576. //fGraphManager->PrintState();
  577. fEngineTiming->PrintState();
  578. }
  579. } // end of namespace