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 JackServerGlobals::fKilled
= true;
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
)
308 fEngineControl
->fRealTime
= !onoff
;
309 NotifyClients((onoff
? kStartFreewheelCallback
: kStopFreewheelCallback
), true, "", 0, 0);
312 void JackEngine::NotifyPortRegistation(jack_port_id_t port_index
, bool onoff
)
314 NotifyClients((onoff
? kPortRegistrationOnCallback
: kPortRegistrationOffCallback
), false, "", port_index
, 0);
317 void JackEngine::NotifyPortRename(jack_port_id_t port
)
319 NotifyClients(kPortRenameCallback
, false, "", port
, 0);
322 void JackEngine::NotifyPortConnect(jack_port_id_t src
, jack_port_id_t dst
, bool onoff
)
324 NotifyClients((onoff
? kPortConnectCallback
: kPortDisconnectCallback
), false, "", src
, dst
);
327 void JackEngine::NotifyActivate(int refnum
)
329 NotifyClient(refnum
, kActivateClient
, true, "", 0, 0);
332 //----------------------------
333 // Loadable client management
334 //----------------------------
336 int JackEngine::GetInternalClientName(int refnum
, char* name_res
)
338 AssertRefnum(refnum
);
339 JackClientInterface
* client
= fClientTable
[refnum
];
341 strncpy(name_res
, client
->GetClientControl()->fName
, JACK_CLIENT_NAME_SIZE
);
348 int JackEngine::InternalClientHandle(const char* client_name
, int* status
, int* int_ref
)
353 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
354 JackClientInterface
* client
= fClientTable
[i
];
355 if (client
&& dynamic_cast<JackLoadableInternalClient
*>(client
) && (strcmp(client
->GetClientControl()->fName
, client_name
) == 0)) {
356 jack_log("InternalClientHandle found client name = %s ref = %ld", client_name
, i
);
362 *status
|= (JackNoSuchClient
| JackFailure
);
366 int JackEngine::InternalClientUnload(int refnum
, int* status
)
368 AssertRefnum(refnum
);
369 JackClientInterface
* client
= fClientTable
[refnum
];
371 int res
= client
->Close();
376 *status
= (JackNoSuchClient
| JackFailure
);
381 //-------------------
383 //-------------------
385 int JackEngine::ClientCheck(const char* name
, char* name_res
, int protocol
, int options
, int* status
)
389 strcpy(name_res
, name
);
391 jack_log("Check protocol client %ld server = %ld", protocol
, JACK_PROTOCOL_VERSION
);
393 if (protocol
!= JACK_PROTOCOL_VERSION
) {
394 *status
|= (JackFailure
| JackVersionError
);
395 jack_error("JACK protocol mismatch (%d vs %d)", protocol
, JACK_PROTOCOL_VERSION
);
399 if (ClientCheckName(name
)) {
401 *status
|= JackNameNotUnique
;
403 if (options
& JackUseExactName
) {
404 jack_error("cannot create new client; %s already exists", name
);
405 *status
|= JackFailure
;
409 if (GenerateUniqueName(name_res
)) {
410 *status
|= JackFailure
;
418 bool JackEngine::GenerateUniqueName(char* name
)
421 int length
= strlen(name
);
423 if (length
> JACK_CLIENT_NAME_SIZE
- 4) {
424 jack_error("%s exists and is too long to make unique", name
);
425 return true; /* failure */
428 /* generate a unique name by appending "-01".."-99" */
429 name
[length
++] = '-';
436 while (ClientCheckName(name
)) {
437 if (name
[ones
] == '9') {
438 if (name
[tens
] == '9') {
439 jack_error("client %s has 99 extra instances already", name
);
440 return true; /* give up */
451 bool JackEngine::ClientCheckName(const char* name
)
453 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
454 JackClientInterface
* client
= fClientTable
[i
];
455 if (client
&& (strcmp(client
->GetClientControl()->fName
, name
) == 0))
462 int JackEngine::GetClientPID(const char* name
)
464 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
465 JackClientInterface
* client
= fClientTable
[i
];
466 if (client
&& (strcmp(client
->GetClientControl()->fName
, name
) == 0))
467 return client
->GetClientControl()->fPID
;
473 int JackEngine::GetClientRefNum(const char* name
)
475 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
476 JackClientInterface
* client
= fClientTable
[i
];
477 if (client
&& (strcmp(client
->GetClientControl()->fName
, name
) == 0))
478 return client
->GetClientControl()->fRefNum
;
484 // Used for external clients
485 int JackEngine::ClientExternalOpen(const char* name
, int pid
, int* ref
, int* shared_engine
, int* shared_client
, int* shared_graph_manager
)
487 jack_log("JackEngine::ClientOpen: name = %s ", name
);
489 int refnum
= AllocateRefnum();
491 jack_error("No more refnum available");
495 JackExternalClient
* client
= new JackExternalClient();
497 if (!fSynchroTable
[refnum
].Allocate(name
, fEngineControl
->fServerName
, 0)) {
498 jack_error("Cannot allocate synchro");
502 if (client
->Open(name
, pid
, refnum
, shared_client
) < 0) {
503 jack_error("Cannot open client");
507 if (!fSignal
.LockedTimedWait(DRIVER_OPEN_TIMEOUT
* 1000000)) {
508 // Failure if RT thread is not running (problem with the driver...)
509 jack_error("Driver is not running");
513 fClientTable
[refnum
] = client
;
515 if (NotifyAddClient(client
, name
, refnum
) < 0) {
516 jack_error("Cannot notify add client");
520 fGraphManager
->InitRefNum(refnum
);
521 fEngineControl
->ResetRollingUsecs();
522 *shared_engine
= fEngineControl
->GetShmIndex();
523 *shared_graph_manager
= fGraphManager
->GetShmIndex();
529 fSynchroTable
[refnum
].Destroy();
530 fClientTable
[refnum
] = 0;
536 // Used for server driver clients
537 int JackEngine::ClientInternalOpen(const char* name
, int* ref
, JackEngineControl
** shared_engine
, JackGraphManager
** shared_manager
, JackClientInterface
* client
, bool wait
)
539 jack_log("JackEngine::ClientInternalNew: name = %s", name
);
541 int refnum
= AllocateRefnum();
543 jack_error("No more refnum available");
547 if (!fSynchroTable
[refnum
].Allocate(name
, fEngineControl
->fServerName
, 0)) {
548 jack_error("Cannot allocate synchro");
552 if (wait
&& !fSignal
.LockedTimedWait(DRIVER_OPEN_TIMEOUT
* 1000000)) {
553 // Failure if RT thread is not running (problem with the driver...)
554 jack_error("Driver is not running");
558 fClientTable
[refnum
] = client
;
560 if (NotifyAddClient(client
, name
, refnum
) < 0) {
561 jack_error("Cannot notify add client");
565 fGraphManager
->InitRefNum(refnum
);
566 fEngineControl
->ResetRollingUsecs();
567 *shared_engine
= fEngineControl
;
568 *shared_manager
= fGraphManager
;
574 fSynchroTable
[refnum
].Destroy();
575 fClientTable
[refnum
] = 0;
579 // Used for external clients
580 int JackEngine::ClientExternalClose(int refnum
)
582 AssertRefnum(refnum
);
583 JackClientInterface
* client
= fClientTable
[refnum
];
586 fEngineControl
->fTransport
.ResetTimebase(refnum
);
587 int res
= ClientCloseAux(refnum
, client
, true);
596 // Used for server internal clients or drivers when the RT thread is stopped
597 int JackEngine::ClientInternalClose(int refnum
, bool wait
)
599 AssertRefnum(refnum
);
600 JackClientInterface
* client
= fClientTable
[refnum
];
601 return (client
) ? ClientCloseAux(refnum
, client
, wait
) : -1;
604 int JackEngine::ClientCloseAux(int refnum
, JackClientInterface
* client
, bool wait
)
606 jack_log("JackEngine::ClientCloseAux ref = %ld", refnum
);
608 // Unregister all ports ==> notifications are sent
609 jack_int_t ports
[PORT_NUM_FOR_CLIENT
];
612 fGraphManager
->GetInputPorts(refnum
, ports
);
613 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
614 PortUnRegister(refnum
, ports
[i
]);
617 fGraphManager
->GetOutputPorts(refnum
, ports
);
618 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
619 PortUnRegister(refnum
, ports
[i
]);
622 // Remove the client from the table
623 ReleaseRefnum(refnum
);
626 fGraphManager
->RemoveAllPorts(refnum
);
628 // Wait until next cycle to be sure client is not used anymore
630 if (!fSignal
.LockedTimedWait(fEngineControl
->fTimeOutUsecs
* 2)) { // Must wait at least until a switch occurs in Process, even in case of graph end failure
631 jack_error("JackEngine::ClientCloseAux wait error ref = %ld", refnum
);
635 // Notify running clients
636 NotifyRemoveClient(client
->GetClientControl()->fName
, client
->GetClientControl()->fRefNum
);
639 fSynchroTable
[refnum
].Destroy();
640 fEngineControl
->ResetRollingUsecs();
644 int JackEngine::ClientActivate(int refnum
, bool is_real_time
)
646 AssertRefnum(refnum
);
647 JackClientInterface
* client
= fClientTable
[refnum
];
648 assert(fClientTable
[refnum
]);
650 jack_log("JackEngine::ClientActivate ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
652 fGraphManager
->Activate(refnum
);
654 // Wait for graph state change to be effective
655 if (!fSignal
.LockedTimedWait(fEngineControl
->fTimeOutUsecs
* 10)) {
656 jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
659 NotifyActivate(refnum
);
664 // May be called without client
665 int JackEngine::ClientDeactivate(int refnum
)
667 AssertRefnum(refnum
);
668 JackClientInterface
* client
= fClientTable
[refnum
];
672 jack_log("JackEngine::ClientDeactivate ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
674 // Disconnect all ports ==> notifications are sent
675 jack_int_t ports
[PORT_NUM_FOR_CLIENT
];
678 fGraphManager
->GetInputPorts(refnum
, ports
);
679 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
680 PortDisconnect(refnum
, ports
[i
], ALL_PORTS
);
683 fGraphManager
->GetOutputPorts(refnum
, ports
);
684 for (i
= 0; (i
< PORT_NUM_FOR_CLIENT
) && (ports
[i
] != EMPTY
) ; i
++) {
685 PortDisconnect(refnum
, ports
[i
], ALL_PORTS
);
688 fGraphManager
->Deactivate(refnum
);
689 fLastSwitchUsecs
= 0; // Force switch to occur next cycle, even when called with "dead" clients
691 // Wait for graph state change to be effective
692 if (!fSignal
.LockedTimedWait(fEngineControl
->fTimeOutUsecs
* 10)) {
693 jack_error("JackEngine::ClientDeactivate wait error ref = %ld name = %s", refnum
, client
->GetClientControl()->fName
);
704 int JackEngine::PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port_index
)
706 jack_log("JackEngine::PortRegister ref = %ld name = %s type = %s flags = %d buffer_size = %d", refnum
, name
, type
, flags
, buffer_size
);
707 AssertRefnum(refnum
);
708 assert(fClientTable
[refnum
]);
710 // Check if port name already exists
711 if (fGraphManager
->GetPort(name
) != NO_PORT
) {
712 jack_error("port_name \"%s\" already exists", name
);
716 *port_index
= fGraphManager
->AllocatePort(refnum
, name
, type
, (JackPortFlags
)flags
, fEngineControl
->fBufferSize
);
717 if (*port_index
!= NO_PORT
) {
718 NotifyPortRegistation(*port_index
, true);
725 int JackEngine::PortUnRegister(int refnum
, jack_port_id_t port_index
)
727 jack_log("JackEngine::PortUnRegister ref = %ld port_index = %ld", refnum
, port_index
);
728 AssertRefnum(refnum
);
729 assert(fClientTable
[refnum
]);
731 // Disconnect port ==> notification is sent
732 PortDisconnect(refnum
, port_index
, ALL_PORTS
);
734 if (fGraphManager
->ReleasePort(refnum
, port_index
) == 0) {
735 NotifyPortRegistation(port_index
, false);
742 int JackEngine::PortConnect(int refnum
, const char* src
, const char* dst
)
744 jack_log("JackEngine::PortConnect src = %s dst = %s", src
, dst
);
745 AssertRefnum(refnum
);
746 jack_port_id_t port_src
, port_dst
;
748 return (fGraphManager
->GetTwoPorts(src
, dst
, &port_src
, &port_dst
) < 0)
750 : PortConnect(refnum
, port_src
, port_dst
);
753 int JackEngine::PortConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
755 jack_log("JackEngine::PortConnect src = %d dst = %d", src
, dst
);
756 AssertRefnum(refnum
);
757 JackClientInterface
* client
;
760 if (fGraphManager
->CheckPorts(src
, dst
) < 0)
763 ref
= fGraphManager
->GetOutputRefNum(src
);
765 client
= fClientTable
[ref
];
767 if (!client
->GetClientControl()->fActive
) {
768 jack_error("Cannot connect ports owned by inactive clients:"
769 " \"%s\" is not active", client
->GetClientControl()->fName
);
773 ref
= fGraphManager
->GetInputRefNum(dst
);
775 client
= fClientTable
[ref
];
777 if (!client
->GetClientControl()->fActive
) {
778 jack_error("Cannot connect ports owned by inactive clients:"
779 " \"%s\" is not active", client
->GetClientControl()->fName
);
783 int res
= fGraphManager
->Connect(src
, dst
);
785 NotifyPortConnect(src
, dst
, true);
789 int JackEngine::PortDisconnect(int refnum
, const char* src
, const char* dst
)
791 jack_log("JackEngine::PortDisconnect src = %s dst = %s", src
, dst
);
792 AssertRefnum(refnum
);
793 jack_port_id_t port_src
, port_dst
;
795 return (fGraphManager
->GetTwoPorts(src
, dst
, &port_src
, &port_dst
) < 0)
797 : PortDisconnect(refnum
, port_src
, port_dst
);
800 int JackEngine::PortDisconnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
802 jack_log("JackEngine::PortDisconnect src = %d dst = %d", src
, dst
);
803 AssertRefnum(refnum
);
805 if (dst
== ALL_PORTS
) {
807 jack_int_t connections
[CONNECTION_NUM_FOR_PORT
];
808 fGraphManager
->GetConnections(src
, connections
);
810 JackPort
* port
= fGraphManager
->GetPort(src
);
812 if (port
->GetFlags() & JackPortIsOutput
) {
813 for (int i
= 0; (i
< CONNECTION_NUM_FOR_PORT
) && (connections
[i
] != EMPTY
); i
++) {
814 if (PortDisconnect(refnum
, src
, connections
[i
]) != 0) {
819 for (int i
= 0; (i
< CONNECTION_NUM_FOR_PORT
) && (connections
[i
] != EMPTY
); i
++) {
820 if (PortDisconnect(refnum
, connections
[i
], src
) != 0) {
827 } else if (fGraphManager
->CheckPorts(src
, dst
) < 0) {
829 } else if (fGraphManager
->Disconnect(src
, dst
) == 0) {
831 NotifyPortConnect(src
, dst
, false);
838 int JackEngine::PortRename(int refnum
, jack_port_id_t port
, const char* name
)
840 AssertRefnum(refnum
);
841 fGraphManager
->GetPort(port
)->SetName(name
);
842 NotifyPortRename(port
);
846 } // end of namespace