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) {
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);
64 if (fRequestPipe.Connect(jack_server_dir, server_name, 0) < 0) {
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) {
90 fNotificationListenPipe.Close();
94 void JackWinNamedPipeClientChannel::Close()
97 fNotificationListenPipe.Close();
102 int JackWinNamedPipeClientChannel::Start()
104 jack_log(
"JackWinNamedPipeClientChannel::Start");
108 if (fThread.StartSync() != 0) {
109 jack_error(
"Cannot start Jack client listener");
116 void JackWinNamedPipeClientChannel::Stop()
118 jack_log(
"JackWinNamedPipeClientChannel::Stop");
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;
356 jack_log(
"JackWinNamedPipeClientChannel::Init");
358 if (!fNotificationListenPipe.Accept()) {
359 jack_error(
"JackWinNamedPipeClientChannel: cannot establish notification pipe");
366 bool JackWinNamedPipeClientChannel::Execute()
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");
388 fNotificationListenPipe.Close();
389 fRequestPipe.Close();