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.

729 lines
22KB

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