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.

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