20 #include "JackSocketClientChannel.h"
21 #include "JackRequest.h"
22 #include "JackClient.h"
23 #include "JackGlobals.h"
28 JackSocketClientChannel::JackSocketClientChannel():
31 fNotificationSocket = NULL;
35 JackSocketClientChannel::~JackSocketClientChannel()
37 delete fNotificationSocket;
40 int JackSocketClientChannel::ServerCheck(
const char* server_name)
42 jack_log(
"JackSocketClientChannel::ServerCheck = %s", server_name);
45 if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) {
47 fRequestSocket.Close();
54 int JackSocketClientChannel::Open(
const char* server_name,
const char* name,
int uuid,
char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status)
57 jack_log(
"JackSocketClientChannel::Open name = %s", name);
59 if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) {
65 ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (
int)options, (
int*)status, &result,
true);
67 int status1 = *status;
68 if (status1 & JackVersionError) {
69 jack_error(
"JACK protocol mismatch %d", JACK_PROTOCOL_VERSION);
71 jack_error(
"Client name = %s conflits with another running client", name);
76 if (fNotificationListenSocket.Bind(jack_client_dir, name_res, 0) < 0) {
85 fRequestSocket.Close();
86 fNotificationListenSocket.Close();
90 void JackSocketClientChannel::Close()
92 fRequestSocket.Close();
93 fNotificationListenSocket.Close();
94 if (fNotificationSocket)
95 fNotificationSocket->Close();
98 int JackSocketClientChannel::Start()
100 jack_log(
"JackSocketClientChannel::Start");
104 if (fThread.StartSync() != 0) {
105 jack_error(
"Cannot start Jack client listener");
112 void JackSocketClientChannel::Stop()
114 jack_log(
"JackSocketClientChannel::Stop");
118 void JackSocketClientChannel::ServerSyncCall(JackRequest* req, JackResult* res,
int* result)
120 if (req->Write(&fRequestSocket) < 0) {
121 jack_error(
"Could not write request type = %ld", req->fType);
126 if (res->Read(&fRequestSocket) < 0) {
127 jack_error(
"Could not read result type = %ld", req->fType);
132 *result = res->fResult;
135 void JackSocketClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res,
int* result)
137 if (req->Write(&fRequestSocket) < 0) {
138 jack_error(
"Could not write request type = %ld", req->fType);
145 void JackSocketClientChannel::ClientCheck(
const char* name,
int uuid,
char* name_res,
int protocol,
int options,
int* status,
int* result,
int open)
147 JackClientCheckRequest req(name, protocol, options, uuid, open);
148 JackClientCheckResult res;
149 ServerSyncCall(&req, &res, result);
150 *status = res.fStatus;
151 strcpy(name_res, res.fName);
154 void JackSocketClientChannel::ClientOpen(
const char* name,
int pid,
int uuid,
int* shared_engine,
int* shared_client,
int* shared_graph,
int* result)
156 JackClientOpenRequest req(name, pid, uuid);
157 JackClientOpenResult res;
158 ServerSyncCall(&req, &res, result);
159 *shared_engine = res.fSharedEngine;
160 *shared_client = res.fSharedClient;
161 *shared_graph = res.fSharedGraph;
164 void JackSocketClientChannel::ClientClose(
int refnum,
int* result)
166 JackClientCloseRequest req(refnum);
168 ServerSyncCall(&req, &res, result);
171 void JackSocketClientChannel::ClientActivate(
int refnum,
int is_real_time,
int* result)
173 JackActivateRequest req(refnum, is_real_time);
175 ServerSyncCall(&req, &res, result);
178 void JackSocketClientChannel::ClientDeactivate(
int refnum,
int* result)
180 JackDeactivateRequest req(refnum);
182 ServerSyncCall(&req, &res, result);
185 void JackSocketClientChannel::PortRegister(
int refnum,
const char* name,
const char* type,
unsigned int flags,
unsigned int buffer_size, jack_port_id_t* port_index,
int* result)
187 JackPortRegisterRequest req(refnum, name, type, flags, buffer_size);
188 JackPortRegisterResult res;
189 ServerSyncCall(&req, &res, result);
190 *port_index = res.fPortIndex;
193 void JackSocketClientChannel::PortUnRegister(
int refnum, jack_port_id_t port_index,
int* result)
195 JackPortUnRegisterRequest req(refnum, port_index);
197 ServerSyncCall(&req, &res, result);
200 void JackSocketClientChannel::PortConnect(
int refnum,
const char* src,
const char* dst,
int* result)
202 JackPortConnectNameRequest req(refnum, src, dst);
204 ServerSyncCall(&req, &res, result);
207 void JackSocketClientChannel::PortDisconnect(
int refnum,
const char* src,
const char* dst,
int* result)
209 JackPortDisconnectNameRequest req(refnum, src, dst);
211 ServerSyncCall(&req, &res, result);
214 void JackSocketClientChannel::PortConnect(
int refnum, jack_port_id_t src, jack_port_id_t dst,
int* result)
216 JackPortConnectRequest req(refnum, src, dst);
218 ServerSyncCall(&req, &res, result);
221 void JackSocketClientChannel::PortDisconnect(
int refnum, jack_port_id_t src, jack_port_id_t dst,
int* result)
223 JackPortDisconnectRequest req(refnum, src, dst);
225 ServerSyncCall(&req, &res, result);
228 void JackSocketClientChannel::PortRename(
int refnum, jack_port_id_t port,
const char* name,
int* result)
230 JackPortRenameRequest req(refnum, port, name);
232 ServerSyncCall(&req, &res, result);
235 void JackSocketClientChannel::SetBufferSize(jack_nframes_t buffer_size,
int* result)
237 JackSetBufferSizeRequest req(buffer_size);
239 ServerSyncCall(&req, &res, result);
242 void JackSocketClientChannel::SetFreewheel(
int onoff,
int* result)
244 JackSetFreeWheelRequest req(onoff);
246 ServerSyncCall(&req, &res, result);
249 void JackSocketClientChannel::ComputeTotalLatencies(
int* result)
251 JackComputeTotalLatenciesRequest req;
253 ServerSyncCall(&req, &res, result);
256 void JackSocketClientChannel::SessionNotify(
int refnum,
const char* target, jack_session_event_type_t type,
const char* path,
jack_session_command_t** result)
258 JackSessionNotifyRequest req(refnum, path, type, target);
259 JackSessionNotifyResult res;
261 ServerSyncCall(&req, &res, &intresult);
262 *result = res.GetCommands();
265 void JackSocketClientChannel::SessionReply(
int refnum,
int* result)
267 JackSessionReplyRequest req(refnum);
269 ServerSyncCall(&req, &res, result);
272 void JackSocketClientChannel::GetUUIDForClientName(
int refnum,
const char* client_name,
char* uuid_res,
int* result)
274 JackGetUUIDRequest req(client_name);
276 ServerSyncCall(&req, &res, result);
277 strncpy(uuid_res, res.fUUID, JACK_UUID_SIZE);
280 void JackSocketClientChannel::GetClientNameForUUID(
int refnum,
const char* uuid,
char* name_res,
int* result)
282 JackGetClientNameRequest req(uuid);
283 JackClientNameResult res;
284 ServerSyncCall(&req, &res, result);
285 strncpy(name_res, res.fName, JACK_CLIENT_NAME_SIZE);
288 void JackSocketClientChannel::ClientHasSessionCallback(
const char* client_name,
int* result)
290 JackClientHasSessionCallbackRequest req(client_name);
292 ServerSyncCall(&req, &res, result);
295 void JackSocketClientChannel::ReserveClientName(
int refnum,
const char* client_name,
const char* uuid,
int* result)
297 JackReserveNameRequest req(refnum, client_name, uuid);
299 ServerSyncCall(&req, &res, result);
302 void JackSocketClientChannel::ReleaseTimebase(
int refnum,
int* result)
304 JackReleaseTimebaseRequest req(refnum);
306 ServerSyncCall(&req, &res, result);
309 void JackSocketClientChannel::SetTimebaseCallback(
int refnum,
int conditional,
int* result)
311 JackSetTimebaseCallbackRequest req(refnum, conditional);
313 ServerSyncCall(&req, &res, result);
316 void JackSocketClientChannel::GetInternalClientName(
int refnum,
int int_ref,
char* name_res,
int* result)
318 JackGetInternalClientNameRequest req(refnum, int_ref);
319 JackGetInternalClientNameResult res;
320 ServerSyncCall(&req, &res, result);
321 strcpy(name_res, res.fName);
324 void JackSocketClientChannel::InternalClientHandle(
int refnum,
const char* client_name,
int* status,
int* int_ref,
int* result)
326 JackInternalClientHandleRequest req(refnum, client_name);
327 JackInternalClientHandleResult res;
328 ServerSyncCall(&req, &res, result);
329 *int_ref = res.fIntRefNum;
330 *status = res.fStatus;
333 void JackSocketClientChannel::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)
335 JackInternalClientLoadRequest req(refnum, client_name, so_name, objet_data, options, uuid);
336 JackInternalClientLoadResult res;
337 ServerSyncCall(&req, &res, result);
338 *int_ref = res.fIntRefNum;
339 *status = res.fStatus;
342 void JackSocketClientChannel::InternalClientUnload(
int refnum,
int int_ref,
int* status,
int* result)
344 JackInternalClientUnloadRequest req(refnum, int_ref);
345 JackInternalClientUnloadResult res;
346 ServerSyncCall(&req, &res, result);
347 *status = res.fStatus;
352 jack_log(
"JackSocketClientChannel::Init");
353 fNotificationSocket = fNotificationListenSocket.Accept();
355 fNotificationListenSocket.Close();
357 if (!fNotificationSocket) {
358 jack_error(
"JackSocketClientChannel: cannot establish notication socket");
365 bool JackSocketClientChannel::Execute()
370 if (event.Read(fNotificationSocket) < 0) {
371 jack_error(
"JackSocketClientChannel read fail");
375 res.fResult = fClient->ClientNotify(event.fRefNum, event.fName, event.fNotify, event.fSync, event.fMessage, event.fValue1, event.fValue2);
378 if (res.Write(fNotificationSocket) < 0) {
379 jack_error(
"JackSocketClientChannel write fail");
386 fNotificationSocket->Close();