Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / common / JackGenericClientChannel.cpp
blob2cf2a26c934dfc31e52b6068c1e2d8c6ae9254b5
1 /*
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.
20 #include "JackGenericClientChannel.h"
21 #include "JackClient.h"
22 #include "JackGlobals.h"
23 #include "JackError.h"
25 namespace Jack
28 JackGenericClientChannel::JackGenericClientChannel()
31 JackGenericClientChannel::~JackGenericClientChannel()
34 int JackGenericClientChannel::ServerCheck(const char* server_name)
36 jack_log("JackGenericClientChannel::ServerCheck = %s", server_name);
38 // Connect to server
39 if (fRequest->Connect(jack_server_dir, server_name, 0) < 0) {
40 jack_error("Cannot connect to server request channel");
41 return -1;
42 } else {
43 return 0;
47 void JackGenericClientChannel::ServerSyncCall(JackRequest* req, JackResult* res, int* result)
49 // Check call context
50 if (jack_tls_get(JackGlobals::fNotificationThread)) {
51 jack_error("Cannot callback the server in notification thread!");
52 *result = -1;
53 return;
56 if (req->Write(fRequest) < 0) {
57 jack_error("Could not write request type = %ld", req->fType);
58 *result = -1;
59 return;
62 if (res->Read(fRequest) < 0) {
63 jack_error("Could not read result type = %ld", req->fType);
64 *result = -1;
65 return;
68 *result = res->fResult;
71 void JackGenericClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res, int* result)
73 // Check call context
74 if (jack_tls_get(JackGlobals::fNotificationThread)) {
75 jack_error("Cannot callback the server in notification thread!");
76 *result = -1;
77 return;
80 if (req->Write(fRequest) < 0) {
81 jack_error("Could not write request type = %ld", req->fType);
82 *result = -1;
83 } else {
84 *result = 0;
88 void JackGenericClientChannel::ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status, int* result, int open)
90 JackClientCheckRequest req(name, protocol, options, uuid, open);
91 JackClientCheckResult res;
92 ServerSyncCall(&req, &res, result);
93 *status = res.fStatus;
94 strcpy(name_res, res.fName);
97 void JackGenericClientChannel::ClientOpen(const char* name, int pid, int uuid, int* shared_engine, int* shared_client, int* shared_graph, int* result)
99 JackClientOpenRequest req(name, pid, uuid);
100 JackClientOpenResult res;
101 ServerSyncCall(&req, &res, result);
102 *shared_engine = res.fSharedEngine;
103 *shared_client = res.fSharedClient;
104 *shared_graph = res.fSharedGraph;
107 void JackGenericClientChannel::ClientClose(int refnum, int* result)
109 JackClientCloseRequest req(refnum);
110 JackResult res;
111 ServerSyncCall(&req, &res, result);
114 void JackGenericClientChannel::ClientActivate(int refnum, int is_real_time, int* result)
116 JackActivateRequest req(refnum, is_real_time);
117 JackResult res;
118 ServerSyncCall(&req, &res, result);
121 void JackGenericClientChannel::ClientDeactivate(int refnum, int* result)
123 JackDeactivateRequest req(refnum);
124 JackResult res;
125 ServerSyncCall(&req, &res, result);
128 void JackGenericClientChannel::PortRegister(int refnum, const char* name, const char* type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index, int* result)
130 JackPortRegisterRequest req(refnum, name, type, flags, buffer_size);
131 JackPortRegisterResult res;
132 ServerSyncCall(&req, &res, result);
133 *port_index = res.fPortIndex;
136 void JackGenericClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
138 JackPortUnRegisterRequest req(refnum, port_index);
139 JackResult res;
140 ServerSyncCall(&req, &res, result);
143 void JackGenericClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
145 JackPortConnectNameRequest req(refnum, src, dst);
146 JackResult res;
147 ServerSyncCall(&req, &res, result);
150 void JackGenericClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
152 JackPortDisconnectNameRequest req(refnum, src, dst);
153 JackResult res;
154 ServerSyncCall(&req, &res, result);
157 void JackGenericClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
159 JackPortConnectRequest req(refnum, src, dst);
160 JackResult res;
161 ServerSyncCall(&req, &res, result);
164 void JackGenericClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
166 JackPortDisconnectRequest req(refnum, src, dst);
167 JackResult res;
168 ServerSyncCall(&req, &res, result);
171 void JackGenericClientChannel::PortRename(int refnum, jack_port_id_t port, const char* name, int* result)
173 JackPortRenameRequest req(refnum, port, name);
174 JackResult res;
175 ServerSyncCall(&req, &res, result);
178 void JackGenericClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
180 JackSetBufferSizeRequest req(buffer_size);
181 JackResult res;
182 ServerSyncCall(&req, &res, result);
185 void JackGenericClientChannel::SetFreewheel(int onoff, int* result)
187 JackSetFreeWheelRequest req(onoff);
188 JackResult res;
189 ServerSyncCall(&req, &res, result);
192 void JackGenericClientChannel::ComputeTotalLatencies(int* result)
194 JackComputeTotalLatenciesRequest req;
195 JackResult res;
196 ServerSyncCall(&req, &res, result);
199 void JackGenericClientChannel::SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char* path, jack_session_command_t** result)
201 JackSessionNotifyRequest req(refnum, path, type, target);
202 JackSessionNotifyResult res;
203 int intresult;
204 ServerSyncCall(&req, &res, &intresult);
205 *result = res.GetCommands();
208 void JackGenericClientChannel::SessionReply(int refnum, int* result)
210 JackSessionReplyRequest req(refnum);
211 JackResult res;
212 ServerSyncCall(&req, &res, result);
215 void JackGenericClientChannel::GetUUIDForClientName(int refnum, const char* client_name, char* uuid_res, int* result)
217 JackGetUUIDRequest req(client_name);
218 JackUUIDResult res;
219 ServerSyncCall(&req, &res, result);
220 strncpy(uuid_res, res.fUUID, JACK_UUID_SIZE);
223 void JackGenericClientChannel::GetClientNameForUUID(int refnum, const char* uuid, char* name_res, int* result)
225 JackGetClientNameRequest req(uuid);
226 JackClientNameResult res;
227 ServerSyncCall(&req, &res, result);
228 strncpy(name_res, res.fName, JACK_CLIENT_NAME_SIZE);
231 void JackGenericClientChannel::ClientHasSessionCallback(const char* client_name, int* result)
233 JackClientHasSessionCallbackRequest req(client_name);
234 JackResult res;
235 ServerSyncCall(&req, &res, result);
238 void JackGenericClientChannel::ReserveClientName(int refnum, const char* client_name, const char* uuid, int* result)
240 JackReserveNameRequest req(refnum, client_name, uuid);
241 JackResult res;
242 ServerSyncCall(&req, &res, result);
245 void JackGenericClientChannel::ReleaseTimebase(int refnum, int* result)
247 JackReleaseTimebaseRequest req(refnum);
248 JackResult res;
249 ServerSyncCall(&req, &res, result);
252 void JackGenericClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
254 JackSetTimebaseCallbackRequest req(refnum, conditional);
255 JackResult res;
256 ServerSyncCall(&req, &res, result);
259 void JackGenericClientChannel::GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
261 JackGetInternalClientNameRequest req(refnum, int_ref);
262 JackGetInternalClientNameResult res;
263 ServerSyncCall(&req, &res, result);
264 strcpy(name_res, res.fName);
267 void JackGenericClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
269 JackInternalClientHandleRequest req(refnum, client_name);
270 JackInternalClientHandleResult res;
271 ServerSyncCall(&req, &res, result);
272 *int_ref = res.fIntRefNum;
273 *status = res.fStatus;
276 void JackGenericClientChannel::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)
278 JackInternalClientLoadRequest req(refnum, client_name, so_name, objet_data, options, uuid);
279 JackInternalClientLoadResult res;
280 ServerSyncCall(&req, &res, result);
281 *int_ref = res.fIntRefNum;
282 *status = res.fStatus;
285 void JackGenericClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result)
287 JackInternalClientUnloadRequest req(refnum, int_ref);
288 JackInternalClientUnloadResult res;
289 ServerSyncCall(&req, &res, result);
290 *status = res.fStatus;
293 } // end of namespace