Jack2  1.9.9
JackGenericClientChannel.cpp
1 /*
2 Copyright (C) 2004-2008 Grame
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include "JackGenericClientChannel.h"
21 #include "JackClient.h"
22 #include "JackGlobals.h"
23 #include "JackError.h"
24 
25 namespace Jack
26 {
27 
28 JackGenericClientChannel::JackGenericClientChannel()
29 {}
30 
31 JackGenericClientChannel::~JackGenericClientChannel()
32 {}
33 
34 int JackGenericClientChannel::ServerCheck(const char* server_name)
35 {
36  jack_log("JackGenericClientChannel::ServerCheck = %s", server_name);
37 
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;
44  }
45 }
46 
47 void JackGenericClientChannel::ServerSyncCall(JackRequest* req, JackResult* res, int* result)
48 {
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;
54  }
55 
56  if (req->Write(fRequest) < 0) {
57  jack_error("Could not write request type = %ld", req->fType);
58  *result = -1;
59  return;
60  }
61 
62  if (res->Read(fRequest) < 0) {
63  jack_error("Could not read result type = %ld", req->fType);
64  *result = -1;
65  return;
66  }
67 
68  *result = res->fResult;
69 }
70 
71 void JackGenericClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res, int* result)
72 {
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;
78  }
79 
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;
85  }
86 }
87 
88 void JackGenericClientChannel::ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status, int* result, int open)
89 {
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);
95 }
96 
97 void JackGenericClientChannel::ClientOpen(const char* name, int pid, int uuid, int* shared_engine, int* shared_client, int* shared_graph, int* result)
98 {
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;
105 }
106 
107 void JackGenericClientChannel::ClientClose(int refnum, int* result)
108 {
109  JackClientCloseRequest req(refnum);
110  JackResult res;
111  ServerSyncCall(&req, &res, result);
112 }
113 
114 void JackGenericClientChannel::ClientActivate(int refnum, int is_real_time, int* result)
115 {
116  JackActivateRequest req(refnum, is_real_time);
117  JackResult res;
118  ServerSyncCall(&req, &res, result);
119 }
120 
121 void JackGenericClientChannel::ClientDeactivate(int refnum, int* result)
122 {
123  JackDeactivateRequest req(refnum);
124  JackResult res;
125  ServerSyncCall(&req, &res, result);
126 }
127 
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)
129 {
130  JackPortRegisterRequest req(refnum, name, type, flags, buffer_size);
131  JackPortRegisterResult res;
132  ServerSyncCall(&req, &res, result);
133  *port_index = res.fPortIndex;
134 }
135 
136 void JackGenericClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
137 {
138  JackPortUnRegisterRequest req(refnum, port_index);
139  JackResult res;
140  ServerSyncCall(&req, &res, result);
141 }
142 
143 void JackGenericClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
144 {
145  JackPortConnectNameRequest req(refnum, src, dst);
146  JackResult res;
147  ServerSyncCall(&req, &res, result);
148 }
149 
150 void JackGenericClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
151 {
152  JackPortDisconnectNameRequest req(refnum, src, dst);
153  JackResult res;
154  ServerSyncCall(&req, &res, result);
155 }
156 
157 void JackGenericClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
158 {
159  JackPortConnectRequest req(refnum, src, dst);
160  JackResult res;
161  ServerSyncCall(&req, &res, result);
162 }
163 
164 void JackGenericClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
165 {
166  JackPortDisconnectRequest req(refnum, src, dst);
167  JackResult res;
168  ServerSyncCall(&req, &res, result);
169 }
170 
171 void JackGenericClientChannel::PortRename(int refnum, jack_port_id_t port, const char* name, int* result)
172 {
173  JackPortRenameRequest req(refnum, port, name);
174  JackResult res;
175  ServerSyncCall(&req, &res, result);
176 }
177 
178 void JackGenericClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
179 {
180  JackSetBufferSizeRequest req(buffer_size);
181  JackResult res;
182  ServerSyncCall(&req, &res, result);
183 }
184 
185 void JackGenericClientChannel::SetFreewheel(int onoff, int* result)
186 {
187  JackSetFreeWheelRequest req(onoff);
188  JackResult res;
189  ServerSyncCall(&req, &res, result);
190 }
191 
192 void JackGenericClientChannel::ComputeTotalLatencies(int* result)
193 {
194  JackComputeTotalLatenciesRequest req;
195  JackResult res;
196  ServerSyncCall(&req, &res, result);
197 }
198 
199 void JackGenericClientChannel::SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char* path, jack_session_command_t** result)
200 {
201  JackSessionNotifyRequest req(refnum, path, type, target);
202  JackSessionNotifyResult res;
203  int intresult;
204  ServerSyncCall(&req, &res, &intresult);
205  *result = res.GetCommands();
206 }
207 
208 void JackGenericClientChannel::SessionReply(int refnum, int* result)
209 {
210  JackSessionReplyRequest req(refnum);
211  JackResult res;
212  ServerSyncCall(&req, &res, result);
213 }
214 
215 void JackGenericClientChannel::GetUUIDForClientName(int refnum, const char* client_name, char* uuid_res, int* result)
216 {
217  JackGetUUIDRequest req(client_name);
218  JackUUIDResult res;
219  ServerSyncCall(&req, &res, result);
220  strncpy(uuid_res, res.fUUID, JACK_UUID_SIZE);
221 }
222 
223 void JackGenericClientChannel::GetClientNameForUUID(int refnum, const char* uuid, char* name_res, int* result)
224 {
225  JackGetClientNameRequest req(uuid);
226  JackClientNameResult res;
227  ServerSyncCall(&req, &res, result);
228  strncpy(name_res, res.fName, JACK_CLIENT_NAME_SIZE);
229 }
230 
231 void JackGenericClientChannel::ClientHasSessionCallback(const char* client_name, int* result)
232 {
233  JackClientHasSessionCallbackRequest req(client_name);
234  JackResult res;
235  ServerSyncCall(&req, &res, result);
236 }
237 
238 void JackGenericClientChannel::ReserveClientName(int refnum, const char* client_name, const char* uuid, int* result)
239 {
240  JackReserveNameRequest req(refnum, client_name, uuid);
241  JackResult res;
242  ServerSyncCall(&req, &res, result);
243 }
244 
245 void JackGenericClientChannel::ReleaseTimebase(int refnum, int* result)
246 {
247  JackReleaseTimebaseRequest req(refnum);
248  JackResult res;
249  ServerSyncCall(&req, &res, result);
250 }
251 
252 void JackGenericClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
253 {
254  JackSetTimebaseCallbackRequest req(refnum, conditional);
255  JackResult res;
256  ServerSyncCall(&req, &res, result);
257 }
258 
259 void JackGenericClientChannel::GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
260 {
261  JackGetInternalClientNameRequest req(refnum, int_ref);
262  JackGetInternalClientNameResult res;
263  ServerSyncCall(&req, &res, result);
264  strcpy(name_res, res.fName);
265 }
266 
267 void JackGenericClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
268 {
269  JackInternalClientHandleRequest req(refnum, client_name);
270  JackInternalClientHandleResult res;
271  ServerSyncCall(&req, &res, result);
272  *int_ref = res.fIntRefNum;
273  *status = res.fStatus;
274 }
275 
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)
277 {
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;
283 }
284 
285 void JackGenericClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result)
286 {
287  JackInternalClientUnloadRequest req(refnum, int_ref);
288  JackInternalClientUnloadResult res;
289  ServerSyncCall(&req, &res, result);
290  *status = res.fStatus;
291 }
292 
293 } // end of namespace
294 
295 
296 
297 
298 
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:91
SERVER_EXPORT void jack_log(const char *fmt,...)
Definition: JackError.cpp:107