2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "JackSystemDeps.h"
25 #include "JackLockedEngine.h"
26 #include "JackExternalClient.h"
27 #include "JackInternalClient.h"
28 #include "JackEngineControl.h"
29 #include "JackClientControl.h"
30 #include "JackServerGlobals.h"
31 #include "JackGlobals.h"
32 #include "JackChannel.h"
33 #include "JackError.h"
38 #define AssertRefnum(ref) assert(ref >= 0 && ref < CLIENT_NUM);
40 JackEngine::JackEngine(JackGraphManager
* manager
,
42 JackEngineControl
* control
)
44 fGraphManager
= manager
;
45 fSynchroTable
= table
;
46 fEngineControl
= control
;
47 for (int i
= 0; i
< CLIENT_NUM
; i
++)
48 fClientTable
[i
] = NULL
;
51 JackEngine::~JackEngine()
53 jack_log("JackEngine::~JackEngine");
56 int JackEngine::Open()
58 jack_log("JackEngine::Open");
60 // Open audio thread => request thread communication channel
61 if (fChannel
.Open(fEngineControl
->fServerName
) < 0) {
62 jack_error("Cannot connect to server");
69 int JackEngine::Close()
71 jack_log("JackEngine::Close");
74 // Close remaining clients (RT is stopped)
75 for (int i
= fEngineControl
->fDriverNum
; i
< CLIENT_NUM
; i
++) {
76 if (JackLoadableInternalClient
* loadable_client
= dynamic_cast<JackLoadableInternalClient
*>(fClientTable
[i
])) {
77 jack_log("JackEngine::Close loadable client = %s", loadable_client
->GetClientControl()->fName
);
78 loadable_client
->Close();
79 // Close does not delete the pointer for internal clients
80 fClientTable
[i
] = NULL
;
81 delete loadable_client
;
82 } else if (JackExternalClient
* external_client
= dynamic_cast<JackExternalClient
*>(fClientTable
[i
])) {
83 jack_log("JackEngine::Close external client = %s", external_client
->GetClientControl()->fName
);
84 external_client
->Close();
85 // Close deletes the pointer for external clients
86 fClientTable
[i
] = NULL
;
93 //-----------------------------
94 // Client ressource management
95 //-----------------------------
97 int JackEngine::AllocateRefnum()
99 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
100 if (!fClientTable
[i
]) {
101 jack_log("JackEngine::AllocateRefNum ref = %ld", i
);
108 void JackEngine::ReleaseRefnum(int ref
)
110 fClientTable
[ref
] = NULL
;
112 if (fEngineControl
->fTemporary
) {
114 for (i
= fEngineControl
->fDriverNum
; i
< CLIENT_NUM
; i
++) {
118 if (i
== CLIENT_NUM
) {
119 // last client and temporay case: quit the server
120 jack_log("JackEngine::ReleaseRefnum server quit");
121 fEngineControl
->fTemporary
= false;
122 throw JackTemporaryException();
131 void JackEngine::ProcessNext(jack_time_t cur_cycle_begin
)
133 fLastSwitchUsecs
= cur_cycle_begin
;
134 if (fGraphManager
->RunNextGraph()) // True if the graph actually switched to a new state
135 fChannel
.Notify(ALL_CLIENTS
, kGraphOrderCallback
, 0);
136 fSignal
.Signal(); // Signal for threads waiting for next cycle
139 void JackEngine::ProcessCurrent(jack_time_t cur_cycle_begin
)
141 if (cur_cycle_begin
< fLastSwitchUsecs
+ 2 * fEngineControl
->fPeriodUsecs
) // Signal XRun only for the first failing cycle
142 CheckXRun(cur_cycle_begin
);
143 fGraphManager
->RunCurrentGraph();
146 bool JackEngine::Process(jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
)
151 fEngineControl
->CycleBegin(fClientTable
, fGraphManager
, cur_cycle_begin
, prev_cycle_end
);
154 if (fGraphManager
->IsFinishedGraph()) {
155 ProcessNext(cur_cycle_begin
);
158 jack_log("Process: graph not finished!");
159 if (cur_cycle_begin
> fLastSwitchUsecs
+ fEngineControl
->fTimeOutUsecs
) {
160 jack_log("Process: switch to next state delta = %ld", long(cur_cycle_begin
- fLastSwitchUsecs
));
161 ProcessNext(cur_cycle_begin
);
164 jack_log("Process: waiting to switch delta = %ld", long(cur_cycle_begin
- fLastSwitchUsecs
));
165 ProcessCurrent(cur_cycle_begin
);
171 fEngineControl
->CycleEnd(fClientTable
);
176 Client that finish *after* the callback date are considered late even if their output buffers may have been
177 correctly mixed in the time window: callbackUsecs <==> Read <==> Write.
180 void JackEngine::CheckXRun(jack_time_t callback_usecs
) // REVOIR les conditions de fin
182 for (int i
= fEngineControl
->fDriverNum
; i
< CLIENT_NUM
; i
++) {
183 JackClientInterface
* client
= fClientTable
[i
];
184 if (client
&& client
->GetClientControl()->fActive
) {
185 JackClientTiming
* timing
= fGraphManager
->GetClientTiming(i
);
186 jack_client_state_t status
= timing
->fStatus
;
187 jack_time_t finished_date
= timing
->fFinishedAt
;
189 if (status
!= NotTriggered
&& status
!= Finished
) {
190 jack_error("JackEngine::XRun: client = %s was not run: state = %ld", client
->GetClientControl()->fName
, status
);
191 fChannel
.Notify(ALL_CLIENTS
, kXRunCallback
, 0); // Notify all clients
194 if (status
== Finished
&& (long)(finished_date
- callback_usecs
) > 0) {
195 jack_error("JackEngine::XRun: client %s finished after current callback", client
->GetClientControl()->fName
);
196 fChannel
.Notify(ALL_CLIENTS
, kXRunCallback
, 0); // Notify all clients
206 void JackEngine::NotifyClient(int refnum
, int event
, int sync
, const char* message
, int value1
, int value2
)
208 JackClientInterface
* client
= fClientTable
[refnum
];
210 // The client may be notified by the RT thread while closing
212 jack_log("JackEngine::NotifyClient: client not available anymore");
213 } else if (client
->GetClientControl()->fCallback
[event
]) {
214 if (client
->ClientNotify(refnum
, client
->GetClientControl()->fName
, event
, sync
, message
, value1
, value2
) < 0)
215 jack_error("NotifyClient fails name = %s event = %ld val1 = %ld val2 = %ld", client
->GetClientControl()->fName
, event
, value1
, value2
);
217 jack_log("JackEngine::NotifyClient: no callback for event = %ld", event
);
221 void JackEngine::NotifyClients(int event
, int sync
, const char* message
, int value1
, int value2
)
223 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
224 JackClientInterface
* client
= fClientTable
[i
];
226 if (client
->GetClientControl()->fCallback
[event
]) {
227 if (client
->ClientNotify(i
, client
->GetClientControl()->fName
, event
, sync
, message
, value1
, value2
) < 0)
228 jack_error("NotifyClient fails name = %s event = %ld val1 = %ld val2 = %ld", client
->GetClientControl()->fName
, event
, value1
, value2
);
230 jack_log("JackEngine::NotifyClients: no callback for event = %ld", event
);
236 int JackEngine::NotifyAddClient(JackClientInterface
* new_client
, const char* name
, int refnum
)
238 jack_log("JackEngine::NotifyAddClient: name = %s", name
);
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
];
243 if (old_client
->ClientNotify(refnum
, name
, kAddClient
, true, "", 0, 0) < 0) {
244 jack_error("NotifyAddClient old_client fails name = %s", old_client
->GetClientControl()->fName
);
247 if (new_client
->ClientNotify(i
, old_client
->GetClientControl()->fName
, kAddClient
, true, "", 0, 0) < 0) {
248 jack_error("NotifyAddClient new_client fails name = %s", name
);
257 void JackEngine::NotifyRemoveClient(const char* name
, int refnum
)
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
];
263 client
->ClientNotify(refnum
, name
, kRemoveClient
, true, "",0, 0);
268 // Coming from the driver
269 void JackEngine::NotifyXRun(jack_time_t callback_usecs
, float delayed_usecs
)
271 // Use the audio thread => request thread communication channel
272 fEngineControl
->ResetFrameTime(callback_usecs
);
273 fEngineControl
->NotifyXRun(delayed_usecs
);
274 fChannel
.Notify(ALL_CLIENTS
, kXRunCallback
, 0);
277 void JackEngine::NotifyXRun(int refnum
)
279 if (refnum
== ALL_CLIENTS
) {
280 NotifyClients(kXRunCallback
, false, "", 0, 0);
282 NotifyClient(refnum
, kXRunCallback
, false, "", 0, 0);
286 void JackEngine::NotifyGraphReorder()
288 NotifyClients(kGraphOrderCallback
, false, "", 0, 0);
291 void JackEngine::NotifyBufferSize(jack_nframes_t buffer_size
)
293 NotifyClients(kBufferSizeCallback
, true, "", buffer_size
, 0);
296 void JackEngine::NotifySampleRate(jack_nframes_t sample_rate
)
298 NotifyClients(kSampleRateCallback
, true, "", sample_rate
, 0);
301 void JackEngine::NotifyFailure(int code
, const char* reason
)
303 NotifyClients(kShutDownCallback
, false, reason
, code
, 0);
306 void JackEngine::NotifyFreewheel(bool onoff
)
310 fEngineControl
->fSavedRealTime
= fEngineControl
->fRealTime
;
311 fEngineControl
->fRealTime
= false;
314 fEngineControl
->fRealTime
= fEngineControl
->fSavedRealTime
;
315 fEngineControl
->fSavedRealTime
= false;
317 NotifyClients((onoff
? kStartFreewheelCallback
: kStopFreewheelCallback
), true, "", 0, 0);
320 void JackEngine::NotifyPortRegistation(jack_port_id_t port_index
, bool onoff
)
322 NotifyClients((onoff
? kPortRegistrationOnCallback
: kPortRegistrationOffCallback
), false, "", port_index
, 0);
325 void JackEngine::NotifyPortRename(jack_port_id_t port
)
327 NotifyClients(kPortRenameCallback
, false, "", port
, 0);
330 void JackEngine::NotifyPortConnect(jack_port_id_t src
, jack_port_id_t dst
, bool onoff
)
332 NotifyClients((onoff
? kPortConnectCallback
: kPortDisconnectCallback
), false, "", src
, dst
);
335 void JackEngine::NotifyActivate(int refnum
)
337 NotifyClient(refnum
, kActivateClient
, true, "", 0, 0);
340 //----------------------------
341 // Loadable client management
342 //----------------------------
344 int JackEngine::GetInternalClientName(int refnum
, char* name_res
)
346 AssertRefnum(refnum
);
347 JackClientInterface
* client
= fClientTable
[refnum
];
349 strncpy(name_res
, client
->GetClientControl()->fName
, JACK_CLIENT_NAME_SIZE
);
356 int JackEngine::InternalClientHandle(const char* client_name
, int* status
, int* int_ref
)
361 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
362 JackClientInterface
* client
= fClientTable
[i
];
363 if (client
&& dynamic_cast<JackLoadableInternalClient
*>(client
) && (strcmp(client
->GetClientControl()->fName
, client_name
) == 0)) {
364 jack_log("InternalClientHandle found client name = %s ref = %ld", client_name
, i
);
370 *status
|= (JackNoSuchClient
| JackFailure
);
374 int JackEngine::InternalClientUnload(int refnum
, int* status
)
376 AssertRefnum(refnum
);
377 JackClientInterface
* client
= fClientTable
[refnum
];
379 int res
= client
->Close();
384 *status
= (JackNoSuchClient
| JackFailure
);
389 //-------------------
391 //-------------------
393 int JackEngine::ClientCheck(const char* name
, char* name_res
, int protocol
, int options
, int* status
)
397 strcpy(name_res
, name
);
399 jack_log("Check protocol client %ld server = %ld", protocol
, JACK_PROTOCOL_VERSION
);
401 if (protocol
!= JACK_PROTOCOL_VERSION
) {
402 *status
|= (JackFailure
| JackVersionError
);
403 jack_error("JACK protocol mismatch (%d vs %d)", protocol
, JACK_PROTOCOL_VERSION
);
407 if (ClientCheckName(name
)) {
409 *status
|= JackNameNotUnique
;
411 if (options
& JackUseExactName
) {
412 jack_error("cannot create new client; %s already exists", name
);
413 *status
|= JackFailure
;
417 if (GenerateUniqueName(name_res
)) {
418 *status
|= JackFailure
;
426 bool JackEngine::GenerateUniqueName(char* name
)
429 int length
= strlen(name
);
431 if (length
> JACK_CLIENT_NAME_SIZE
- 4) {
432 jack_error("%s exists and is too long to make unique", name
);
433 return true; /* failure */
436 /* generate a unique name by appending "-01".."-99" */
437 name
[length
++] = '-';
444 while (ClientCheckName(name
)) {
445 if (name
[ones
] == '9') {
446 if (name
[tens
] == '9') {
447 jack_error("client %s has 99 extra instances already", name
);
448 return true; /* give up */
459 bool JackEngine::ClientCheckName(const char* name
)
461 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
462 JackClientInterface
* client
= fClientTable
[i
];
463 if (client
&& (strcmp(client
->GetClientControl()->fName
, name
) == 0))
470 int JackEngine::GetClientPID(const char* name
)
472 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
473 JackClientInterface
* client
= fClientTable
[i
];
474 if (client
&& (strcmp(client
->GetClientControl()->fName
, name
) == 0))
475 return client
->GetClientControl()->fPID
;
481 int JackEngine::GetClientRefNum(const char* name
)
483 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
484 JackClientInterface
* client
= fClientTable
[i
];
485 if (client
&& (strcmp(client
->GetClientControl()->fName
, name
) == 0))
486 return client
->GetClientControl()->fRefNum
;
492 // Used for external clients
493 int JackEngine::ClientExternalOpen(const char* name
, int pid
, int* ref
, int* shared_engine
, int* shared_client
, int* shared_graph_manager
)
495 jack_log("JackEngine::ClientExternalOpen: name = %s ", name
);
497 int refnum
= AllocateRefnum();
499 jack_error("No more refnum available");
503 JackExternalClient
* client
= new JackExternalClient();
505 if (!fSynchroTable
[refnum
].Allocate(name
, fEngineControl
->fServerName
, 0)) {
506 jack_error("Cannot allocate synchro");
510 if (client
->Open(name
, pid
, refnum
, shared_client
) < 0) {
511 jack_error("Cannot open client");
515 if (!fSignal
.LockedTimedWait(DRIVER_OPEN_TIMEOUT
* 1000000)) {
516 // Failure if RT thread is not running (problem with the driver...)
517 jack_error("Driver is not running");
521 fClientTable
[refnum
] = client
;
523 if (NotifyAddClient(client
, name
, refnum
) < 0) {
524 jack_error("Cannot notify add client");
528 fGraphManager
->InitRefNum(refnum
);
529 fEngineControl
->ResetRollingUsecs();
530 *shared_engine
= fEngineControl
->GetShmIndex();
531 *shared_graph_manager
= fGraphManager
->GetShmIndex();
537 fSynchroTable
[refnum
].Destroy();
538 fClientTable
[refnum
] = 0;
544 // Used for server driver clients
545 int JackEngine::ClientInternalOpen(const char* name
, int* ref
, JackEngineControl
** shared_engine
, JackGraphManager
** shared_manager
, JackClientInterface
* client
, bool wait
)
547 jack_log("JackEngine::ClientInternalOpen: name = %s", name
);
549 int refnum
= AllocateRefnum();
551 jack_error("No more refnum available");
555 if (!fSynchroTable
[refnum
].Allocate(name
, fEngineControl
->fServerName
, 0)) {
556 jack_error("Cannot allocate synchro");
560 if (wait
&& !fSignal
.LockedTimedWait(DRIVER_OPEN_TIMEOUT
* 1000000)) {
561 // Failure if RT thread is not running (problem with the driver...)
562 jack_error("Driver is not running");
566 fClientTable
[refnum
] = client
;
568 if (NotifyAddClient(client
, name
, refnum
) < 0) {
569 jack_error("Cannot notify add client");
573 fGraphManager
->InitRefNum(refnum
);
574 fEngineControl
->ResetRollingUsecs();
575 *shared_engine
= fEngineControl
;
576 *shared_manager
= fGraphManager
;
582 fSynchroTable
[refnum
].Destroy();
583 fClientTable
[refnum
] = 0;
587 // Used for external clients
588 int JackEngine::ClientExternalClose(int refnum
)
590 AssertRefnum(refnum
);
591 JackClientInterface
* client
= fClientTable
[refnum
];
594 fEngineControl
->fTransport
.ResetTimebase(refnum
);
595 int res
= ClientCloseAux(refnum
, client
, true);
604 // Used for server internal clients or drivers when the RT thread is stopped
605 int JackEngine::ClientInternalClose(int refnum
, bool wait
)
607 AssertRefnum(refnum
);
608 JackClientInterface
* client
= fClientTable
[refnum
];
609 return (client
) ? ClientCloseAux(refnum
, client
, wait
) : -1;
612 int JackEngine::ClientCloseAux(int refnum
, JackClientInterface
* client
, bool wait
)
614 jack_log("JackEngine::ClientCloseAux ref = %ld", refnum
);
616 // Unregister all ports ==> notifications are sent
617 jack_int_t ports
[PORT_NUM_FOR_CLIENT
];
620 fGraphManager
->GetInputPorts(refnum
, ports
);
621 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
622 PortUnRegister(refnum
, ports
[i
]);
625 fGraphManager
->GetOutputPorts(refnum
, ports
);
626 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
627 PortUnRegister(refnum
, ports
[i
]);
630 // Remove the client from the table
631 ReleaseRefnum(refnum
);
634 fGraphManager
->RemoveAllPorts(refnum
);
636 // Wait until next cycle to be sure client is not used anymore
638 if (!fSignal
.LockedTimedWait(fEngineControl
->fTimeOutUsecs
* 2)) { // Must wait at least until a switch occurs in Process, even in case of graph end failure
639 jack_error("JackEngine::ClientCloseAux wait error ref = %ld", refnum
);
643 // Notify running clients
644 NotifyRemoveClient(client
->GetClientControl()->fName
, client
->GetClientControl()->fRefNum
);
647 fSynchroTable
[refnum
].Destroy();
648 fEngineControl
->ResetRollingUsecs();
652 int JackEngine::ClientActivate(int refnum
, bool is_real_time
)
654 AssertRefnum(refnum
);
655 JackClientInterface
* client
= fClientTable
[refnum
];
656 assert(fClientTable
[refnum
]);
658 jack_log("JackEngine::ClientActivate ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
660 fGraphManager
->Activate(refnum
);
662 // Wait for graph state change to be effective
663 if (!fSignal
.LockedTimedWait(fEngineControl
->fTimeOutUsecs
* 10)) {
664 jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
667 NotifyActivate(refnum
);
672 // May be called without client
673 int JackEngine::ClientDeactivate(int refnum
)
675 AssertRefnum(refnum
);
676 JackClientInterface
* client
= fClientTable
[refnum
];
680 jack_log("JackEngine::ClientDeactivate ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
682 // Disconnect all ports ==> notifications are sent
683 jack_int_t ports
[PORT_NUM_FOR_CLIENT
];
686 fGraphManager
->GetInputPorts(refnum
, ports
);
687 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
688 PortDisconnect(refnum
, ports
[i
], ALL_PORTS
);
691 fGraphManager
->GetOutputPorts(refnum
, ports
);
692 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
693 PortDisconnect(refnum
, ports
[i
], ALL_PORTS
);
696 fGraphManager
->Deactivate(refnum
);
697 fLastSwitchUsecs
= 0; // Force switch to occur next cycle, even when called with "dead" clients
699 // Wait for graph state change to be effective
700 if (!fSignal
.LockedTimedWait(fEngineControl
->fTimeOutUsecs
* 10)) {
701 jack_error("JackEngine::ClientDeactivate wait error ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
712 int JackEngine::PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port_index
)
714 jack_log("JackEngine::PortRegister ref = %ld name = %s type = %s flags = %d buffer_size = %d", refnum
, name
, type
, flags
, buffer_size
);
715 AssertRefnum(refnum
);
716 assert(fClientTable
[refnum
]);
718 // Check if port name already exists
719 if (fGraphManager
->GetPort(name
) != NO_PORT
) {
720 jack_error("port_name \"%s\" already exists", name
);
724 *port_index
= fGraphManager
->AllocatePort(refnum
, name
, type
, (JackPortFlags
)flags
, fEngineControl
->fBufferSize
);
725 if (*port_index
!= NO_PORT
) {
726 NotifyPortRegistation(*port_index
, true);
733 int JackEngine::PortUnRegister(int refnum
, jack_port_id_t port_index
)
735 jack_log("JackEngine::PortUnRegister ref = %ld port_index = %ld", refnum
, port_index
);
736 AssertRefnum(refnum
);
737 assert(fClientTable
[refnum
]);
739 // Disconnect port ==> notification is sent
740 PortDisconnect(refnum
, port_index
, ALL_PORTS
);
742 if (fGraphManager
->ReleasePort(refnum
, port_index
) == 0) {
743 NotifyPortRegistation(port_index
, false);
750 int JackEngine::PortConnect(int refnum
, const char* src
, const char* dst
)
752 jack_log("JackEngine::PortConnect src = %s dst = %s", src
, dst
);
753 AssertRefnum(refnum
);
754 jack_port_id_t port_src
, port_dst
;
756 return (fGraphManager
->GetTwoPorts(src
, dst
, &port_src
, &port_dst
) < 0)
758 : PortConnect(refnum
, port_src
, port_dst
);
761 int JackEngine::PortConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
763 jack_log("JackEngine::PortConnect src = %d dst = %d", src
, dst
);
764 AssertRefnum(refnum
);
765 JackClientInterface
* client
;
768 if (fGraphManager
->CheckPorts(src
, dst
) < 0)
771 ref
= fGraphManager
->GetOutputRefNum(src
);
773 client
= fClientTable
[ref
];
775 if (!client
->GetClientControl()->fActive
) {
776 jack_error("Cannot connect ports owned by inactive clients:"
777 " \"%s\" is not active", client
->GetClientControl()->fName
);
781 ref
= fGraphManager
->GetInputRefNum(dst
);
783 client
= fClientTable
[ref
];
785 if (!client
->GetClientControl()->fActive
) {
786 jack_error("Cannot connect ports owned by inactive clients:"
787 " \"%s\" is not active", client
->GetClientControl()->fName
);
791 int res
= fGraphManager
->Connect(src
, dst
);
793 NotifyPortConnect(src
, dst
, true);
797 int JackEngine::PortDisconnect(int refnum
, const char* src
, const char* dst
)
799 jack_log("JackEngine::PortDisconnect src = %s dst = %s", src
, dst
);
800 AssertRefnum(refnum
);
801 jack_port_id_t port_src
, port_dst
;
803 return (fGraphManager
->GetTwoPorts(src
, dst
, &port_src
, &port_dst
) < 0)
805 : PortDisconnect(refnum
, port_src
, port_dst
);
808 int JackEngine::PortDisconnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
810 jack_log("JackEngine::PortDisconnect src = %d dst = %d", src
, dst
);
811 AssertRefnum(refnum
);
813 if (dst
== ALL_PORTS
) {
815 jack_int_t connections
[CONNECTION_NUM_FOR_PORT
];
816 fGraphManager
->GetConnections(src
, connections
);
818 JackPort
* port
= fGraphManager
->GetPort(src
);
820 if (port
->GetFlags() & JackPortIsOutput
) {
821 for (int i
= 0; (i
< CONNECTION_NUM_FOR_PORT
) && (connections
[i
] != EMPTY
); i
++) {
822 if (PortDisconnect(refnum
, src
, connections
[i
]) != 0) {
827 for (int i
= 0; (i
< CONNECTION_NUM_FOR_PORT
) && (connections
[i
] != EMPTY
); i
++) {
828 if (PortDisconnect(refnum
, connections
[i
], src
) != 0) {
835 } else if (fGraphManager
->CheckPorts(src
, dst
) < 0) {
837 } else if (fGraphManager
->Disconnect(src
, dst
) == 0) {
839 NotifyPortConnect(src
, dst
, false);
846 int JackEngine::PortRename(int refnum
, jack_port_id_t port
, const char* name
)
848 AssertRefnum(refnum
);
849 fGraphManager
->GetPort(port
)->SetName(name
);
850 NotifyPortRename(port
);
854 } // end of namespace