00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021 #include <fstream>
00022 #include <assert.h>
00023
00024 #include "JackSystemDeps.h"
00025 #include "JackLockedEngine.h"
00026 #include "JackExternalClient.h"
00027 #include "JackInternalClient.h"
00028 #include "JackEngineControl.h"
00029 #include "JackClientControl.h"
00030 #include "JackGlobals.h"
00031 #include "JackChannel.h"
00032 #include "JackError.h"
00033
00034 namespace Jack
00035 {
00036
00037 #define AssertRefnum(ref) assert(ref >= 0 && ref < CLIENT_NUM);
00038
00039 JackEngine::JackEngine(JackGraphManager* manager,
00040 JackSynchro* table,
00041 JackEngineControl* control)
00042 {
00043 fGraphManager = manager;
00044 fSynchroTable = table;
00045 fEngineControl = control;
00046 for (int i = 0; i < CLIENT_NUM; i++)
00047 fClientTable[i] = NULL;
00048 }
00049
00050 JackEngine::~JackEngine()
00051 {
00052 jack_log("JackEngine::~JackEngine");
00053 }
00054
00055 int JackEngine::Open()
00056 {
00057 jack_log("JackEngine::Open");
00058
00059
00060 if (fChannel.Open(fEngineControl->fServerName) < 0) {
00061 jack_error("Cannot connect to server");
00062 return -1;
00063 } else {
00064 return 0;
00065 }
00066 }
00067
00068 int JackEngine::Close()
00069 {
00070 jack_log("JackEngine::Close");
00071 fChannel.Close();
00072
00073
00074 for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) {
00075 if (JackLoadableInternalClient* loadable_client = dynamic_cast<JackLoadableInternalClient*>(fClientTable[i])) {
00076 jack_log("JackEngine::Close loadable client = %s", loadable_client->GetClientControl()->fName);
00077 loadable_client->Close();
00078
00079 fClientTable[i] = NULL;
00080 delete loadable_client;
00081 } else if (JackExternalClient* external_client = dynamic_cast<JackExternalClient*>(fClientTable[i])) {
00082 jack_log("JackEngine::Close external client = %s", external_client->GetClientControl()->fName);
00083 external_client->Close();
00084
00085 fClientTable[i] = NULL;
00086 }
00087 }
00088
00089 fSignal.Destroy();
00090 return 0;
00091 }
00092
00093
00094
00095
00096
00097 int JackEngine::AllocateRefnum()
00098 {
00099 for (int i = 0; i < CLIENT_NUM; i++) {
00100 if (!fClientTable[i]) {
00101 jack_log("JackEngine::AllocateRefNum ref = %ld", i);
00102 return i;
00103 }
00104 }
00105 return -1;
00106 }
00107
00108 void JackEngine::ReleaseRefnum(int ref)
00109 {
00110 fClientTable[ref] = NULL;
00111
00112 if (fEngineControl->fTemporary) {
00113 int i;
00114 for (i = REAL_REFNUM; i < CLIENT_NUM; i++) {
00115 if (fClientTable[i])
00116 break;
00117 }
00118 if (i == CLIENT_NUM) {
00119
00120 jack_log("JackEngine::ReleaseRefnum server quit");
00121 fEngineControl->fTemporary = false;
00122 #ifndef WIN32
00123 exit(0);
00124 #endif
00125 }
00126 }
00127 }
00128
00129
00130
00131
00132
00133 void JackEngine::ProcessNext(jack_time_t cur_cycle_begin)
00134 {
00135 fLastSwitchUsecs = cur_cycle_begin;
00136 if (fGraphManager->RunNextGraph())
00137 fChannel.Notify(ALL_CLIENTS, kGraphOrderCallback, 0);
00138 fSignal.SignalAll();
00139 }
00140
00141 void JackEngine::ProcessCurrent(jack_time_t cur_cycle_begin)
00142 {
00143 if (cur_cycle_begin < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs)
00144 CheckXRun(cur_cycle_begin);
00145 fGraphManager->RunCurrentGraph();
00146 }
00147
00148 bool JackEngine::Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
00149 {
00150 bool res = true;
00151
00152
00153 fEngineControl->CycleBegin(fClientTable, fGraphManager, cur_cycle_begin, prev_cycle_end);
00154
00155
00156 if (fGraphManager->IsFinishedGraph()) {
00157 ProcessNext(cur_cycle_begin);
00158 res = true;
00159 } else {
00160 jack_log("Process: graph not finished!");
00161 if (cur_cycle_begin > fLastSwitchUsecs + fEngineControl->fTimeOutUsecs) {
00162 jack_log("Process: switch to next state delta = %ld", long(cur_cycle_begin - fLastSwitchUsecs));
00163 ProcessNext(cur_cycle_begin);
00164 res = true;
00165 } else {
00166 jack_log("Process: waiting to switch delta = %ld", long(cur_cycle_begin - fLastSwitchUsecs));
00167 ProcessCurrent(cur_cycle_begin);
00168 res = false;
00169 }
00170 }
00171
00172
00173 fEngineControl->CycleEnd(fClientTable);
00174 return res;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183 void JackEngine::CheckXRun(jack_time_t callback_usecs)
00184 {
00185 for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) {
00186 JackClientInterface* client = fClientTable[i];
00187 if (client && client->GetClientControl()->fActive) {
00188 JackClientTiming* timing = fGraphManager->GetClientTiming(i);
00189 jack_client_state_t status = timing->fStatus;
00190 jack_time_t finished_date = timing->fFinishedAt;
00191
00192 if (status != NotTriggered && status != Finished) {
00193 jack_error("JackEngine::XRun: client = %s was not run: state = %ld", client->GetClientControl()->fName, status);
00194 fChannel.Notify(ALL_CLIENTS, kXRunCallback, 0);
00195 }
00196
00197 if (status == Finished && (long)(finished_date - callback_usecs) > 0) {
00198 jack_error("JackEngine::XRun: client %s finished after current callback", client->GetClientControl()->fName);
00199 fChannel.Notify(ALL_CLIENTS, kXRunCallback, 0);
00200 }
00201 }
00202 }
00203 }
00204
00205
00206
00207
00208
00209 void JackEngine::NotifyClient(int refnum, int event, int sync, int value1, int value2)
00210 {
00211 JackClientInterface* client = fClientTable[refnum];
00212
00213
00214 if (!client) {
00215 jack_log("JackEngine::NotifyClient: client not available anymore");
00216 } else if (client->GetClientControl()->fCallback[event]) {
00217 if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, value1, value2) < 0)
00218 jack_error("NotifyClient fails name = %s event = %ld = val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2);
00219 } else {
00220 jack_log("JackEngine::NotifyClient: no callback for event = %ld", event);
00221 }
00222 }
00223
00224 void JackEngine::NotifyClients(int event, int sync, int value1, int value2)
00225 {
00226 for (int i = 0; i < CLIENT_NUM; i++) {
00227 JackClientInterface* client = fClientTable[i];
00228 if (client) {
00229 if (client->GetClientControl()->fCallback[event]) {
00230 if (client->ClientNotify(i, client->GetClientControl()->fName, event, sync, value1, value2) < 0)
00231 jack_error("NotifyClient fails name = %s event = %ld = val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2);
00232 } else {
00233 jack_log("JackEngine::NotifyClients: no callback for event = %ld", event);
00234 }
00235 }
00236 }
00237 }
00238
00239 int JackEngine::NotifyAddClient(JackClientInterface* new_client, const char* name, int refnum)
00240 {
00241
00242 for (int i = 0; i < CLIENT_NUM; i++) {
00243 JackClientInterface* old_client = fClientTable[i];
00244 if (old_client) {
00245 if (old_client->ClientNotify(refnum, name, kAddClient, true, 0, 0) < 0) {
00246 jack_error("NotifyAddClient old_client fails name = %s", old_client->GetClientControl()->fName);
00247 return -1;
00248 }
00249 if (new_client->ClientNotify(i, old_client->GetClientControl()->fName, kAddClient, true, 0, 0) < 0) {
00250 jack_error("NotifyAddClient new_client fails name = %s", name);
00251 return -1;
00252 }
00253 }
00254 }
00255
00256 return 0;
00257 }
00258
00259 void JackEngine::NotifyRemoveClient(const char* name, int refnum)
00260 {
00261
00262 for (int i = 0; i < CLIENT_NUM; i++) {
00263 JackClientInterface* client = fClientTable[i];
00264 if (client) {
00265 client->ClientNotify(refnum, name, kRemoveClient, true, 0, 0);
00266 }
00267 }
00268 }
00269
00270
00271 void JackEngine::NotifyXRun(jack_time_t callback_usecs, float delayed_usecs)
00272 {
00273
00274 fEngineControl->ResetFrameTime(callback_usecs);
00275 fEngineControl->NotifyXRun(delayed_usecs);
00276 fChannel.Notify(ALL_CLIENTS, kXRunCallback, 0);
00277 }
00278
00279 void JackEngine::NotifyXRun(int refnum)
00280 {
00281 if (refnum == ALL_CLIENTS) {
00282 NotifyClients(kXRunCallback, false, 0, 0);
00283 } else {
00284 NotifyClient(refnum, kXRunCallback, false, 0, 0);
00285 }
00286 }
00287
00288 void JackEngine::NotifyGraphReorder()
00289 {
00290 NotifyClients(kGraphOrderCallback, false, 0, 0);
00291 }
00292
00293 void JackEngine::NotifyBufferSize(jack_nframes_t buffer_size)
00294 {
00295 NotifyClients(kBufferSizeCallback, true, buffer_size, 0);
00296 }
00297
00298 void JackEngine::NotifySampleRate(jack_nframes_t sample_rate)
00299 {
00300 NotifyClients(kSampleRateCallback, true, sample_rate, 0);
00301 }
00302
00303 void JackEngine::NotifyFreewheel(bool onoff)
00304 {
00305 fEngineControl->fRealTime = !onoff;
00306 NotifyClients((onoff ? kStartFreewheelCallback : kStopFreewheelCallback), true, 0, 0);
00307 }
00308
00309 void JackEngine::NotifyPortRegistation(jack_port_id_t port_index, bool onoff)
00310 {
00311 NotifyClients((onoff ? kPortRegistrationOnCallback : kPortRegistrationOffCallback), false, port_index, 0);
00312 }
00313
00314 void JackEngine::NotifyPortRename(jack_port_id_t port)
00315 {
00316 NotifyClients(kPortRenameCallback, false, port, 0);
00317 }
00318
00319 void JackEngine::NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff)
00320 {
00321 NotifyClients((onoff ? kPortConnectCallback : kPortDisconnectCallback), false, src, dst);
00322 }
00323
00324 void JackEngine::NotifyActivate(int refnum)
00325 {
00326 NotifyClient(refnum, kActivateClient, true, 0, 0);
00327 }
00328
00329
00330
00331
00332
00333 int JackEngine::GetInternalClientName(int refnum, char* name_res)
00334 {
00335 AssertRefnum(refnum);
00336 JackClientInterface* client = fClientTable[refnum];
00337 if (client) {
00338 strncpy(name_res, client->GetClientControl()->fName, JACK_CLIENT_NAME_SIZE);
00339 return 0;
00340 } else {
00341 return -1;
00342 }
00343 }
00344
00345 int JackEngine::InternalClientHandle(const char* client_name, int* status, int* int_ref)
00346 {
00347
00348 *status = 0;
00349
00350 for (int i = 0; i < CLIENT_NUM; i++) {
00351 JackClientInterface* client = fClientTable[i];
00352 if (client && dynamic_cast<JackLoadableInternalClient*>(client) && (strcmp(client->GetClientControl()->fName, client_name) == 0)) {
00353 jack_log("InternalClientHandle found client name = %s ref = %ld", client_name, i);
00354 *int_ref = i;
00355 return 0;
00356 }
00357 }
00358
00359 *status |= (JackNoSuchClient | JackFailure);
00360 return -1;
00361 }
00362
00363 int JackEngine::InternalClientUnload(int refnum, int* status)
00364 {
00365 AssertRefnum(refnum);
00366 JackClientInterface* client = fClientTable[refnum];
00367 if (client) {
00368 int res = client->Close();
00369 delete client;
00370 *status = 0;
00371 return res;
00372 } else {
00373 *status = (JackNoSuchClient | JackFailure);
00374 return -1;
00375 }
00376 }
00377
00378
00379
00380
00381
00382 int JackEngine::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
00383 {
00384
00385 *status = 0;
00386 strcpy(name_res, name);
00387
00388 jack_log("Check protocol client %ld server = %ld", protocol, JACK_PROTOCOL_VERSION);
00389
00390 if (protocol != JACK_PROTOCOL_VERSION) {
00391 *status |= (JackFailure | JackVersionError);
00392 jack_error("JACK protocol mismatch (%d vs %d)", protocol, JACK_PROTOCOL_VERSION);
00393 return -1;
00394 }
00395
00396 if (ClientCheckName(name)) {
00397
00398 *status |= JackNameNotUnique;
00399
00400 if (options & JackUseExactName) {
00401 jack_error("cannot create new client; %s already exists", name);
00402 *status |= JackFailure;
00403 return -1;
00404 }
00405
00406 if (GenerateUniqueName(name_res)) {
00407 *status |= JackFailure;
00408 return -1;
00409 }
00410 }
00411
00412 return 0;
00413 }
00414
00415 bool JackEngine::GenerateUniqueName(char* name)
00416 {
00417 int tens, ones;
00418 int length = strlen(name);
00419
00420 if (length > JACK_CLIENT_NAME_SIZE - 4) {
00421 jack_error("%s exists and is too long to make unique", name);
00422 return true;
00423 }
00424
00425
00426 name[length++] = '-';
00427 tens = length++;
00428 ones = length++;
00429 name[tens] = '0';
00430 name[ones] = '1';
00431 name[length] = '\0';
00432
00433 while (ClientCheckName(name)) {
00434 if (name[ones] == '9') {
00435 if (name[tens] == '9') {
00436 jack_error("client %s has 99 extra instances already", name);
00437 return true;
00438 }
00439 name[tens]++;
00440 name[ones] = '0';
00441 } else {
00442 name[ones]++;
00443 }
00444 }
00445 return false;
00446 }
00447
00448 bool JackEngine::ClientCheckName(const char* name)
00449 {
00450 for (int i = 0; i < CLIENT_NUM; i++) {
00451 JackClientInterface* client = fClientTable[i];
00452 if (client && (strcmp(client->GetClientControl()->fName, name) == 0))
00453 return true;
00454 }
00455
00456 return false;
00457 }
00458
00459 int JackEngine::GetClientPID(const char* name)
00460 {
00461 for (int i = 0; i < CLIENT_NUM; i++) {
00462 JackClientInterface* client = fClientTable[i];
00463 if (client && (strcmp(client->GetClientControl()->fName, name) == 0))
00464 return client->GetClientControl()->fPID;
00465 }
00466
00467 return 0;
00468 }
00469
00470
00471 int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
00472 {
00473 jack_log("JackEngine::ClientOpen: name = %s ", name);
00474
00475 int refnum = AllocateRefnum();
00476 if (refnum < 0) {
00477 jack_error("No more refnum available");
00478 return -1;
00479 }
00480
00481 JackExternalClient* client = new JackExternalClient();
00482
00483 if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0)) {
00484 jack_error("Cannot allocate synchro");
00485 goto error;
00486 }
00487
00488 if (client->Open(name, pid, refnum, shared_client) < 0) {
00489 jack_error("Cannot open client");
00490 goto error;
00491 }
00492
00493 if (!fSignal.TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
00494
00495 jack_error("Driver is not running");
00496 goto error;
00497 }
00498
00499 fClientTable[refnum] = client;
00500
00501 if (NotifyAddClient(client, name, refnum) < 0) {
00502 jack_error("Cannot notify add client");
00503 goto error;
00504 }
00505
00506 fGraphManager->InitRefNum(refnum);
00507 fEngineControl->ResetRollingUsecs();
00508 *shared_engine = fEngineControl->GetShmIndex();
00509 *shared_graph_manager = fGraphManager->GetShmIndex();
00510 *ref = refnum;
00511 return 0;
00512
00513 error:
00514
00515 fSynchroTable[refnum].Destroy();
00516 fClientTable[refnum] = 0;
00517 client->Close();
00518 delete client;
00519 return -1;
00520 }
00521
00522
00523 int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
00524 {
00525 jack_log("JackEngine::ClientInternalNew: name = %s", name);
00526
00527 int refnum = AllocateRefnum();
00528 if (refnum < 0) {
00529 jack_error("No more refnum available");
00530 goto error;
00531 }
00532
00533 if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0)) {
00534 jack_error("Cannot allocate synchro");
00535 goto error;
00536 }
00537
00538 if (wait && !fSignal.TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
00539
00540 jack_error("Driver is not running");
00541 goto error;
00542 }
00543
00544 fClientTable[refnum] = client;
00545
00546 if (NotifyAddClient(client, name, refnum) < 0) {
00547 jack_error("Cannot notify add client");
00548 goto error;
00549 }
00550
00551 fGraphManager->InitRefNum(refnum);
00552 fEngineControl->ResetRollingUsecs();
00553 *shared_engine = fEngineControl;
00554 *shared_manager = fGraphManager;
00555 *ref = refnum;
00556 return 0;
00557
00558 error:
00559
00560 fSynchroTable[refnum].Destroy();
00561 fClientTable[refnum] = 0;
00562 return -1;
00563 }
00564
00565
00566 int JackEngine::ClientExternalClose(int refnum)
00567 {
00568 AssertRefnum(refnum);
00569 JackClientInterface* client = fClientTable[refnum];
00570
00571 if (client) {
00572 fEngineControl->fTransport.ResetTimebase(refnum);
00573 int res = ClientCloseAux(refnum, client, true);
00574 client->Close();
00575 delete client;
00576 return res;
00577 } else {
00578 return -1;
00579 }
00580 }
00581
00582
00583 int JackEngine::ClientInternalClose(int refnum, bool wait)
00584 {
00585 AssertRefnum(refnum);
00586 JackClientInterface* client = fClientTable[refnum];
00587 return (client) ? ClientCloseAux(refnum, client, wait) : -1;
00588 }
00589
00590 int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wait)
00591 {
00592 jack_log("JackEngine::ClientCloseAux ref = %ld", refnum);
00593
00594
00595 jack_int_t ports[PORT_NUM_FOR_CLIENT];
00596 int i;
00597
00598 fGraphManager->GetInputPorts(refnum, ports);
00599 for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) {
00600 PortUnRegister(refnum, ports[i]);
00601 }
00602
00603 fGraphManager->GetOutputPorts(refnum, ports);
00604 for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) {
00605 PortUnRegister(refnum, ports[i]);
00606 }
00607
00608
00609 ReleaseRefnum(refnum);
00610
00611
00612 fGraphManager->RemoveAllPorts(refnum);
00613
00614
00615 if (wait) {
00616 if (!fSignal.TimedWait(fEngineControl->fTimeOutUsecs * 2)) {
00617 jack_error("JackEngine::ClientCloseAux wait error ref = %ld", refnum);
00618 }
00619 }
00620
00621
00622 NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum);
00623
00624
00625 fSynchroTable[refnum].Destroy();
00626 fEngineControl->ResetRollingUsecs();
00627 return 0;
00628 }
00629
00630 int JackEngine::ClientActivate(int refnum, bool state)
00631 {
00632 AssertRefnum(refnum);
00633 JackClientInterface* client = fClientTable[refnum];
00634 assert(fClientTable[refnum]);
00635
00636 jack_log("JackEngine::ClientActivate ref = %ld name = %s", refnum, client->GetClientControl()->fName);
00637 if (state)
00638 fGraphManager->Activate(refnum);
00639
00640
00641 if (!fSignal.TimedWait(fEngineControl->fTimeOutUsecs * 10)) {
00642 jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName);
00643 return -1;
00644 } else {
00645 NotifyActivate(refnum);
00646 return 0;
00647 }
00648 }
00649
00650
00651 int JackEngine::ClientDeactivate(int refnum)
00652 {
00653 AssertRefnum(refnum);
00654 JackClientInterface* client = fClientTable[refnum];
00655 if (client == NULL)
00656 return -1;
00657
00658 jack_log("JackEngine::ClientDeactivate ref = %ld name = %s", refnum, client->GetClientControl()->fName);
00659
00660
00661 jack_int_t ports[PORT_NUM_FOR_CLIENT];
00662 int i;
00663
00664 fGraphManager->GetInputPorts(refnum, ports);
00665 for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) {
00666 PortDisconnect(refnum, ports[i], ALL_PORTS);
00667 }
00668
00669 fGraphManager->GetOutputPorts(refnum, ports);
00670 for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) {
00671 PortDisconnect(refnum, ports[i], ALL_PORTS);
00672 }
00673
00674 fGraphManager->Deactivate(refnum);
00675 fLastSwitchUsecs = 0;
00676
00677
00678 if (!fSignal.TimedWait(fEngineControl->fTimeOutUsecs * 10)) {
00679 jack_error("JackEngine::ClientDeactivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName);
00680 return -1;
00681 } else {
00682 return 0;
00683 }
00684 }
00685
00686
00687
00688
00689
00690 int JackEngine::PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index)
00691 {
00692 jack_log("JackEngine::PortRegister ref = %ld name = %s type = %s flags = %d buffer_size = %d", refnum, name, type, flags, buffer_size);
00693 AssertRefnum(refnum);
00694 assert(fClientTable[refnum]);
00695
00696
00697 if (fGraphManager->GetPort(name) != NO_PORT) {
00698 jack_error("port_name \"%s\" already exists", name);
00699 return -1;
00700 }
00701
00702 *port_index = fGraphManager->AllocatePort(refnum, name, type, (JackPortFlags)flags, fEngineControl->fBufferSize);
00703 if (*port_index != NO_PORT) {
00704 NotifyPortRegistation(*port_index, true);
00705 return 0;
00706 } else {
00707 return -1;
00708 }
00709 }
00710
00711 int JackEngine::PortUnRegister(int refnum, jack_port_id_t port_index)
00712 {
00713 jack_log("JackEngine::PortUnRegister ref = %ld port_index = %ld", refnum, port_index);
00714 AssertRefnum(refnum);
00715 assert(fClientTable[refnum]);
00716
00717
00718 PortDisconnect(refnum, port_index, ALL_PORTS);
00719
00720 if (fGraphManager->ReleasePort(refnum, port_index) == 0) {
00721 NotifyPortRegistation(port_index, false);
00722 return 0;
00723 } else {
00724 return -1;
00725 }
00726 }
00727
00728 int JackEngine::PortConnect(int refnum, const char* src, const char* dst)
00729 {
00730 jack_log("JackEngine::PortConnect src = %s dst = %s", src, dst);
00731 jack_port_id_t port_src, port_dst;
00732
00733 return (fGraphManager->CheckPorts(src, dst, &port_src, &port_dst) < 0)
00734 ? -1
00735 : PortConnect(refnum, port_src, port_dst);
00736 }
00737
00738 int JackEngine::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
00739 {
00740 jack_log("JackEngine::PortConnect src = %d dst = %d", src, dst);
00741 AssertRefnum(refnum);
00742 JackClientInterface* client;
00743 int ref;
00744
00745 if (fGraphManager->CheckPorts(src, dst) < 0)
00746 return -1;
00747
00748 ref = fGraphManager->GetOutputRefNum(src);
00749 assert(ref >= 0);
00750 client = fClientTable[ref];
00751 assert(client);
00752 if (!client->GetClientControl()->fActive) {
00753 jack_error("Cannot connect ports owned by inactive clients:"
00754 " \"%s\" is not active", client->GetClientControl()->fName);
00755 return -1;
00756 }
00757
00758 ref = fGraphManager->GetInputRefNum(dst);
00759 assert(ref >= 0);
00760 client = fClientTable[ref];
00761 assert(client);
00762 if (!client->GetClientControl()->fActive) {
00763 jack_error("Cannot connect ports owned by inactive clients:"
00764 " \"%s\" is not active", client->GetClientControl()->fName);
00765 return -1;
00766 }
00767
00768 int res = fGraphManager->Connect(src, dst);
00769 if (res == 0)
00770 NotifyPortConnect(src, dst, true);
00771 return res;
00772 }
00773
00774 int JackEngine::PortDisconnect(int refnum, const char* src, const char* dst)
00775 {
00776 jack_log("JackEngine::PortDisconnect src = %s dst = %s", src, dst);
00777 AssertRefnum(refnum);
00778 jack_port_id_t port_src, port_dst;
00779
00780 if (fGraphManager->CheckPorts(src, dst, &port_src, &port_dst) < 0) {
00781 return -1;
00782 } else if (fGraphManager->Disconnect(port_src, port_dst) == 0) {
00783 NotifyPortConnect(port_src, port_dst, false);
00784 return 0;
00785 } else {
00786 return -1;
00787 }
00788 }
00789
00790 int JackEngine::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
00791 {
00792 jack_log("JackEngine::PortDisconnect src = %d dst = %d", src, dst);
00793 AssertRefnum(refnum);
00794
00795 if (dst == ALL_PORTS) {
00796
00797 jack_int_t connections[CONNECTION_NUM_FOR_PORT];
00798 fGraphManager->GetConnections(src, connections);
00799
00800
00801 JackPort* port = fGraphManager->GetPort(src);
00802 if (port->GetFlags() & JackPortIsOutput) {
00803 for (int i = 0; (i < CONNECTION_NUM_FOR_PORT) && (connections[i] != EMPTY); i++) {
00804 jack_log("NotifyPortConnect src = %ld dst = %ld false", src, connections[i]);
00805 NotifyPortConnect(src, connections[i], false);
00806 }
00807 } else {
00808 for (int i = 0; (i < CONNECTION_NUM_FOR_PORT) && (connections[i] != EMPTY); i++) {
00809 jack_log("NotifyPortConnect src = %ld dst = %ld false", connections[i], src);
00810 NotifyPortConnect(connections[i], src, false);
00811 }
00812 }
00813
00814 return fGraphManager->DisconnectAll(src);
00815 } else if (fGraphManager->CheckPorts(src, dst) < 0) {
00816 return -1;
00817 } else if (fGraphManager->Disconnect(src, dst) == 0) {
00818
00819 NotifyPortConnect(src, dst, false);
00820 return 0;
00821 } else {
00822 return -1;
00823 }
00824 }
00825
00826 int JackEngine::PortRename(int refnum, jack_port_id_t port, const char* name)
00827 {
00828 fGraphManager->GetPort(port)->SetName(name);
00829 NotifyPortRename(port);
00830 return 0;
00831 }
00832
00833 }
00834