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 Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "JackWinNamedPipeClientChannel.h"
22 #include "JackRequest.h"
23 #include "JackClient.h"
24 #include "JackGlobals.h"
25 #include "JackError.h"
30 JackWinNamedPipeClientChannel::JackWinNamedPipeClientChannel():fThread(this)
35 JackWinNamedPipeClientChannel::~JackWinNamedPipeClientChannel()
38 int JackWinNamedPipeClientChannel::ServerCheck(const char* server_name
)
40 jack_log("JackWinNamedPipeClientChannel::ServerCheck = %s", server_name
);
43 if (fRequestPipe
.Connect(jack_server_dir
, server_name
, 0) < 0) {
44 jack_error("Cannot connect to server pipe");
51 int JackWinNamedPipeClientChannel::Open(const char* server_name
, const char* name
, int uuid
, char* name_res
, JackClient
* obj
, jack_options_t options
, jack_status_t
* status
)
54 jack_log("JackWinNamedPipeClientChannel::Open name = %s", name
);
57 16/08/07: was called before doing "fRequestPipe.Connect" .... still necessary?
58 if (fNotificationListenPipe.Bind(jack_client_dir, name, 0) < 0) {
59 jack_error("Cannot bind pipe");
64 if (fRequestPipe
.Connect(jack_server_dir
, server_name
, 0) < 0) {
65 jack_error("Cannot connect to server pipe");
69 // Check name in server
70 ClientCheck(name
, uuid
, name_res
, JACK_PROTOCOL_VERSION
, (int)options
, (int*)status
, &result
, true);
72 int status1
= *status
;
73 if (status1
& JackVersionError
) {
74 jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION
);
76 jack_error("Client name = %s conflits with another running client", name
);
80 if (fNotificationListenPipe
.Bind(jack_client_dir
, name_res
, 0) < 0) {
81 jack_error("Cannot bind pipe");
90 fNotificationListenPipe
.Close();
94 void JackWinNamedPipeClientChannel::Close()
97 fNotificationListenPipe
.Close();
98 // Here the thread will correctly stop when the pipe are closed
102 int JackWinNamedPipeClientChannel::Start()
104 jack_log("JackWinNamedPipeClientChannel::Start");
106 To be sure notification thread is started before ClientOpen is called.
108 if (fThread
.StartSync() != 0) {
109 jack_error("Cannot start Jack client listener");
116 void JackWinNamedPipeClientChannel::Stop()
118 jack_log("JackWinNamedPipeClientChannel::Stop");
119 fThread
.Kill(); // Unsafe on WIN32... TODO : solve WIN32 thread Kill issue
122 void JackWinNamedPipeClientChannel::ServerSyncCall(JackRequest
* req
, JackResult
* res
, int* result
)
124 if (req
->Write(&fRequestPipe
) < 0) {
125 jack_error("Could not write request type = %ld", req
->fType
);
130 if (res
->Read(&fRequestPipe
) < 0) {
131 jack_error("Could not read result type = %ld", req
->fType
);
136 *result
= res
->fResult
;
139 void JackWinNamedPipeClientChannel::ServerAsyncCall(JackRequest
* req
, JackResult
* res
, int* result
)
141 if (req
->Write(&fRequestPipe
) < 0) {
142 jack_error("Could not write request type = %ld", req
->fType
);
149 void JackWinNamedPipeClientChannel::ClientCheck(const char* name
, int uuid
, char* name_res
, int protocol
, int options
, int* status
, int* result
, int open
)
151 JackClientCheckRequest
req(name
, protocol
, options
, uuid
, open
);
152 JackClientCheckResult res
;
153 ServerSyncCall(&req
, &res
, result
);
154 *status
= res
.fStatus
;
155 strcpy(name_res
, res
.fName
);
158 void JackWinNamedPipeClientChannel::ClientOpen(const char* name
, int pid
, int uuid
, int* shared_engine
, int* shared_client
, int* shared_graph
, int* result
)
160 JackClientOpenRequest
req(name
, pid
, uuid
);
161 JackClientOpenResult res
;
162 ServerSyncCall(&req
, &res
, result
);
163 *shared_engine
= res
.fSharedEngine
;
164 *shared_client
= res
.fSharedClient
;
165 *shared_graph
= res
.fSharedGraph
;
168 void JackWinNamedPipeClientChannel::ClientClose(int refnum
, int* result
)
170 JackClientCloseRequest
req(refnum
);
172 ServerSyncCall(&req
, &res
, result
);
175 void JackWinNamedPipeClientChannel::ClientActivate(int refnum
, int is_real_time
, int* result
)
177 JackActivateRequest
req(refnum
, is_real_time
);
179 ServerSyncCall(&req
, &res
, result
);
182 void JackWinNamedPipeClientChannel::ClientDeactivate(int refnum
, int* result
)
184 JackDeactivateRequest
req(refnum
);
186 ServerSyncCall(&req
, &res
, result
);
189 void JackWinNamedPipeClientChannel::PortRegister(int refnum
, const char* name
, const char* type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port_index
, int* result
)
191 JackPortRegisterRequest
req(refnum
, name
, type
, flags
, buffer_size
);
192 JackPortRegisterResult res
;
193 ServerSyncCall(&req
, &res
, result
);
194 *port_index
= res
.fPortIndex
;
197 void JackWinNamedPipeClientChannel::PortUnRegister(int refnum
, jack_port_id_t port_index
, int* result
)
199 JackPortUnRegisterRequest
req(refnum
, port_index
);
201 ServerSyncCall(&req
, &res
, result
);
204 void JackWinNamedPipeClientChannel::PortConnect(int refnum
, const char* src
, const char* dst
, int* result
)
206 JackPortConnectNameRequest
req(refnum
, src
, dst
);
208 ServerSyncCall(&req
, &res
, result
);
211 void JackWinNamedPipeClientChannel::PortDisconnect(int refnum
, const char* src
, const char* dst
, int* result
)
213 JackPortDisconnectNameRequest
req(refnum
, src
, dst
);
215 ServerSyncCall(&req
, &res
, result
);
218 void JackWinNamedPipeClientChannel::PortConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
, int* result
)
220 JackPortConnectRequest
req(refnum
, src
, dst
);
222 ServerSyncCall(&req
, &res
, result
);
225 void JackWinNamedPipeClientChannel::PortDisconnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
, int* result
)
227 JackPortDisconnectRequest
req(refnum
, src
, dst
);
229 ServerSyncCall(&req
, &res
, result
);
232 void JackWinNamedPipeClientChannel::PortRename(int refnum
, jack_port_id_t port
, const char* name
, int* result
)
234 JackPortRenameRequest
req(refnum
, port
, name
);
236 ServerSyncCall(&req
, &res
, result
);
239 void JackWinNamedPipeClientChannel::SetBufferSize(jack_nframes_t buffer_size
, int* result
)
241 JackSetBufferSizeRequest
req(buffer_size
);
243 ServerSyncCall(&req
, &res
, result
);
246 void JackWinNamedPipeClientChannel::SetFreewheel(int onoff
, int* result
)
248 JackSetFreeWheelRequest
req(onoff
);
250 ServerSyncCall(&req
, &res
, result
);
253 void JackWinNamedPipeClientChannel::ComputeTotalLatencies(int* result
)
255 JackComputeTotalLatenciesRequest req
;
257 ServerSyncCall(&req
, &res
, result
);
260 void JackWinNamedPipeClientChannel::SessionNotify(int refnum
, const char* target
, jack_session_event_type_t type
, const char* path
, jack_session_command_t
** result
)
262 JackSessionNotifyRequest
req(refnum
, path
, type
, target
);
263 JackSessionNotifyResult res
;
265 ServerSyncCall(&req
, &res
, &intresult
);
266 *result
= res
.GetCommands();
269 void JackWinNamedPipeClientChannel::SessionReply(int refnum
, int* result
)
271 JackSessionReplyRequest
req(refnum
);
273 ServerSyncCall(&req
, &res
, result
);
276 void JackWinNamedPipeClientChannel::GetUUIDForClientName(int refnum
, const char* client_name
, char* uuid_res
, int* result
)
278 JackGetUUIDRequest
req(client_name
);
280 ServerSyncCall(&req
, &res
, result
);
281 strncpy(uuid_res
, res
.fUUID
, JACK_UUID_SIZE
);
284 void JackWinNamedPipeClientChannel::GetClientNameForUUID(int refnum
, const char* uuid
, char* name_res
, int* result
)
286 JackGetClientNameRequest
req(uuid
);
287 JackClientNameResult res
;
288 ServerSyncCall(&req
, &res
, result
);
289 strncpy(name_res
, res
.fName
, JACK_CLIENT_NAME_SIZE
);
292 void JackWinNamedPipeClientChannel::ClientHasSessionCallback(const char* client_name
, int* result
)
294 JackClientHasSessionCallbackRequest
req(client_name
);
296 ServerSyncCall(&req
, &res
, result
);
299 void JackWinNamedPipeClientChannel::ReserveClientName(int refnum
, const char* client_name
, const char* uuid
, int* result
)
301 JackReserveNameRequest
req(refnum
, client_name
, uuid
);
303 ServerSyncCall(&req
, &res
, result
);
306 void JackWinNamedPipeClientChannel::ReleaseTimebase(int refnum
, int* result
)
308 JackReleaseTimebaseRequest
req(refnum
);
310 ServerSyncCall(&req
, &res
, result
);
313 void JackWinNamedPipeClientChannel::SetTimebaseCallback(int refnum
, int conditional
, int* result
)
315 JackSetTimebaseCallbackRequest
req(refnum
, conditional
);
317 ServerSyncCall(&req
, &res
, result
);
320 void JackWinNamedPipeClientChannel::GetInternalClientName(int refnum
, int int_ref
, char* name_res
, int* result
)
322 JackGetInternalClientNameRequest
req(refnum
, int_ref
);
323 JackGetInternalClientNameResult res
;
324 ServerSyncCall(&req
, &res
, result
);
325 strcpy(name_res
, res
.fName
);
328 void JackWinNamedPipeClientChannel::InternalClientHandle(int refnum
, const char* client_name
, int* status
, int* int_ref
, int* result
)
330 JackInternalClientHandleRequest
req(refnum
, client_name
);
331 JackInternalClientHandleResult res
;
332 ServerSyncCall(&req
, &res
, result
);
333 *int_ref
= res
.fIntRefNum
;
334 *status
= res
.fStatus
;
337 void JackWinNamedPipeClientChannel::InternalClientLoad(int refnum
, const char* client_name
, const char* so_name
, const char* objet_data
, int options
, int* status
, int* int_ref
, int uuid
, int* result
)
339 JackInternalClientLoadRequest
req(refnum
, client_name
, so_name
, objet_data
, options
, uuid
);
340 JackInternalClientLoadResult res
;
341 ServerSyncCall(&req
, &res
, result
);
342 *int_ref
= res
.fIntRefNum
;
343 *status
= res
.fStatus
;
346 void JackWinNamedPipeClientChannel::InternalClientUnload(int refnum
, int int_ref
, int* status
, int* result
)
348 JackInternalClientUnloadRequest
req(refnum
, int_ref
);
349 JackInternalClientUnloadResult res
;
350 ServerSyncCall(&req
, &res
, result
);
351 *status
= res
.fStatus
;
354 bool JackWinNamedPipeClientChannel::Init()
356 jack_log("JackWinNamedPipeClientChannel::Init");
358 if (!fNotificationListenPipe
.Accept()) {
359 jack_error("JackWinNamedPipeClientChannel: cannot establish notification pipe");
366 bool JackWinNamedPipeClientChannel::Execute()
368 JackClientNotification event
;
371 if (event
.Read(&fNotificationListenPipe
) < 0) {
372 jack_error("JackWinNamedPipeClientChannel read fail");
376 res
.fResult
= fClient
->ClientNotify(event
.fRefNum
, event
.fName
, event
.fNotify
, event
.fSync
, event
.fMessage
, event
.fValue1
, event
.fValue2
);
379 if (res
.Write(&fNotificationListenPipe
) < 0) {
380 jack_error("JackWinNamedPipeClientChannel write fail");
387 // Close the pipes, server wont be able to create them otherwise.
388 fNotificationListenPipe
.Close();
389 fRequestPipe
.Close();
394 } // end of namespace