Jack2 1.9.12

JackLockedEngine.h
1 /*
2 Copyright (C) 2008 Grame
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __JackLockedEngine__
21 #define __JackLockedEngine__
22
23 #include "JackEngine.h"
24 #include "JackMutex.h"
25 #include "JackTools.h"
26 #include "JackException.h"
27
28 namespace Jack
29 {
30
31 #define TRY_CALL \
32 try { \
33
34 /*
35 See : http://groups.google.com/group/comp.programming.threads/browse_thread/thread/652bcf186fbbf697/f63757846514e5e5
36
37 catch (...) {
38 // Assuming thread cancellation, must rethrow
39 throw;
40 }
41 */
42
43 #define CATCH_EXCEPTION_RETURN \
44 } catch (std::bad_alloc& e) { \
45 jack_error("Memory allocation error..."); \
46 return -1; \
47 } catch (...) { \
48 jack_error("Unknown error..."); \
49 throw; \
50 } \
51
52 #define CATCH_CLOSE_EXCEPTION_RETURN \
53 } catch (std::bad_alloc& e) { \
54 jack_error("Memory allocation error..."); \
55 return -1; \
56 } catch (JackTemporaryException& e) { \
57 jack_error("JackTemporaryException : now quits..."); \
58 JackTools::KillServer(); \
59 return 0; \
60 } catch (...) { \
61 jack_error("Unknown error..."); \
62 throw; \
63 }
64
65 #define CATCH_EXCEPTION \
66 } catch (std::bad_alloc& e) { \
67 jack_error("Memory allocation error..."); \
68 } catch (...) { \
69 jack_error("Unknown error..."); \
70 throw; \
71 } \
72
73
78 class SERVER_EXPORT JackLockedEngine
79 {
80 private:
81
82 JackEngine fEngine;
83
84 public:
85
86 JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode):
87 fEngine(manager, table, controler, self_connect_mode)
88 {}
89 ~JackLockedEngine()
90 {}
91
92 bool Lock() { return fEngine.Lock(); }
93 bool Unlock() { return fEngine.Unlock(); }
94 bool Trylock() { return fEngine.Trylock(); }
95
96 int Open()
97 {
98 // No lock needed
99 TRY_CALL
100 return fEngine.Open();
101 CATCH_EXCEPTION_RETURN
102 }
103 int Close()
104 {
105 // No lock needed
106 TRY_CALL
107 return fEngine.Close();
108 CATCH_EXCEPTION_RETURN
109 }
110
111 // Client management
112 int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status)
113 {
114 TRY_CALL
115 JackLock lock(&fEngine);
116 return fEngine.ClientCheck(name, uuid, name_res, protocol, options, status);
117 CATCH_EXCEPTION_RETURN
118 }
119 int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
120 {
121 TRY_CALL
122 JackLock lock(&fEngine);
123 return fEngine.ClientExternalOpen(name, pid, uuid, ref, shared_engine, shared_client, shared_graph_manager);
124 CATCH_EXCEPTION_RETURN
125 }
126 int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
127 {
128 TRY_CALL
129 JackLock lock(&fEngine);
130 return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
131 CATCH_EXCEPTION_RETURN
132 }
133
134 int ClientExternalClose(int refnum)
135 {
136 TRY_CALL
137 JackLock lock(&fEngine);
138 return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : -1;
139 CATCH_CLOSE_EXCEPTION_RETURN
140 }
141 int ClientInternalClose(int refnum, bool wait)
142 {
143 TRY_CALL
144 JackLock lock(&fEngine);
145 return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1;
146 CATCH_CLOSE_EXCEPTION_RETURN
147 }
148
149 int ClientActivate(int refnum, bool is_real_time)
150 {
151 TRY_CALL
152 JackLock lock(&fEngine);
153 return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1;
154 CATCH_EXCEPTION_RETURN
155 }
156 int ClientDeactivate(int refnum)
157 {
158 TRY_CALL
159 JackLock lock(&fEngine);
160 return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1;
161 CATCH_EXCEPTION_RETURN
162 }
163 void ClientKill(int refnum)
164 {
165 TRY_CALL
166 JackLock lock(&fEngine);
167 fEngine.ClientKill(refnum);
168 CATCH_EXCEPTION
169 }
170
171 // Internal client management
172 int GetInternalClientName(int int_ref, char* name_res)
173 {
174 TRY_CALL
175 JackLock lock(&fEngine);
176 return fEngine.GetInternalClientName(int_ref, name_res);
177 CATCH_EXCEPTION_RETURN
178 }
179 int InternalClientHandle(const char* client_name, int* status, int* int_ref)
180 {
181 TRY_CALL
182 JackLock lock(&fEngine);
183 return fEngine.InternalClientHandle(client_name, status, int_ref);
184 CATCH_EXCEPTION_RETURN
185 }
186 int InternalClientUnload(int refnum, int* status)
187 {
188 TRY_CALL
189 JackLock lock(&fEngine);
190 // Client is tested in fEngine.InternalClientUnload
191 return fEngine.InternalClientUnload(refnum, status);
192 CATCH_EXCEPTION_RETURN
193 }
194
195 // Port management
196 int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
197 {
198 TRY_CALL
199 JackLock lock(&fEngine);
200 return (fEngine.CheckClient(refnum)) ? fEngine.PortRegister(refnum, name, type, flags, buffer_size, port) : -1;
201 CATCH_EXCEPTION_RETURN
202 }
203 int PortUnRegister(int refnum, jack_port_id_t port)
204 {
205 TRY_CALL
206 JackLock lock(&fEngine);
207 return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1;
208 CATCH_EXCEPTION_RETURN
209 }
210
211 int PortConnect(int refnum, const char* src, const char* dst)
212 {
213 TRY_CALL
214 JackLock lock(&fEngine);
215 return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
216 CATCH_EXCEPTION_RETURN
217 }
218 int PortDisconnect(int refnum, const char* src, const char* dst)
219 {
220 TRY_CALL
221 JackLock lock(&fEngine);
222 return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
223 CATCH_EXCEPTION_RETURN
224 }
225
226 int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
227 {
228 TRY_CALL
229 JackLock lock(&fEngine);
230 return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
231 CATCH_EXCEPTION_RETURN
232 }
233 int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
234 {
235 TRY_CALL
236 JackLock lock(&fEngine);
237 return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
238 CATCH_EXCEPTION_RETURN
239 }
240
241 int PortRename(int refnum, jack_port_id_t port, const char* name)
242 {
243 TRY_CALL
244 JackLock lock(&fEngine);
245 return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1;
246 CATCH_EXCEPTION_RETURN
247 }
248
249 int ComputeTotalLatencies()
250 {
251 TRY_CALL
252 JackLock lock(&fEngine);
253 return fEngine.ComputeTotalLatencies();
254 CATCH_EXCEPTION_RETURN
255 }
256
257 // Graph
258 bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
259 {
260 // RT : no lock
261 return fEngine.Process(cur_cycle_begin, prev_cycle_end);
262 }
263
264 // Notifications
265 void NotifyDriverXRun()
266 {
267 // Coming from the driver in RT : no lock
268 fEngine.NotifyDriverXRun();
269 }
270
271 void NotifyClientXRun(int refnum)
272 {
273 TRY_CALL
274 JackLock lock(&fEngine);
275 fEngine.NotifyClientXRun(refnum);
276 CATCH_EXCEPTION
277 }
278
279 void NotifyGraphReorder()
280 {
281 TRY_CALL
282 JackLock lock(&fEngine);
283 fEngine.NotifyGraphReorder();
284 CATCH_EXCEPTION
285 }
286
287 void NotifyBufferSize(jack_nframes_t buffer_size)
288 {
289 TRY_CALL
290 JackLock lock(&fEngine);
291 fEngine.NotifyBufferSize(buffer_size);
292 CATCH_EXCEPTION
293 }
294 void NotifySampleRate(jack_nframes_t sample_rate)
295 {
296 TRY_CALL
297 JackLock lock(&fEngine);
298 fEngine.NotifySampleRate(sample_rate);
299 CATCH_EXCEPTION
300 }
301 void NotifyFreewheel(bool onoff)
302 {
303 TRY_CALL
304 JackLock lock(&fEngine);
305 fEngine.NotifyFreewheel(onoff);
306 CATCH_EXCEPTION
307 }
308
309 void NotifyFailure(int code, const char* reason)
310 {
311 TRY_CALL
312 JackLock lock(&fEngine);
313 fEngine.NotifyFailure(code, reason);
314 CATCH_EXCEPTION
315 }
316
317 int GetClientPID(const char* name)
318 {
319 TRY_CALL
320 JackLock lock(&fEngine);
321 return fEngine.GetClientPID(name);
322 CATCH_EXCEPTION_RETURN
323 }
324
325 int GetClientRefNum(const char* name)
326 {
327 TRY_CALL
328 JackLock lock(&fEngine);
329 return fEngine.GetClientRefNum(name);
330 CATCH_EXCEPTION_RETURN
331 }
332
333 void NotifyQuit()
334 {
335 // No lock needed
336 TRY_CALL
337 return fEngine.NotifyQuit();
338 CATCH_EXCEPTION
339 }
340
341 void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result)
342 {
343 TRY_CALL
344 JackLock lock(&fEngine);
345 fEngine.SessionNotify(refnum, target, type, path, socket, result);
346 CATCH_EXCEPTION
347 }
348
349 int SessionReply(int refnum)
350 {
351 TRY_CALL
352 JackLock lock(&fEngine);
353 return fEngine.SessionReply(refnum);
354 CATCH_EXCEPTION_RETURN
355 }
356
357 int GetUUIDForClientName(const char *client_name, char *uuid_res)
358 {
359 TRY_CALL
360 JackLock lock(&fEngine);
361 return fEngine.GetUUIDForClientName(client_name, uuid_res);
362 CATCH_EXCEPTION_RETURN
363 }
364 int GetClientNameForUUID(const char *uuid, char *name_res)
365 {
366 TRY_CALL
367 JackLock lock(&fEngine);
368 return fEngine.GetClientNameForUUID(uuid, name_res);
369 CATCH_EXCEPTION_RETURN
370 }
371 int ReserveClientName(const char *name, const char *uuid)
372 {
373 TRY_CALL
374 JackLock lock(&fEngine);
375 return fEngine.ReserveClientName(name, uuid);
376 CATCH_EXCEPTION_RETURN
377 }
378
379 int ClientHasSessionCallback(const char *name)
380 {
381 TRY_CALL
382 JackLock lock(&fEngine);
383 return fEngine.ClientHasSessionCallback(name);
384 CATCH_EXCEPTION_RETURN
385 }
386 };
387
388 } // end of namespace
389
390 #endif
391
Jack::JackEngine
Engine description.
Definition: JackEngine.h:44
Jack::JackLockedEngine
Locked Engine, access to methods is serialized using a mutex.
Definition: JackLockedEngine.h:78
Jack::JackPosixSemaphore
Inter process synchronization using POSIX semaphore.
Definition: JackPosixSemaphore.h:36
Jack::JackLock
Definition: JackMutex.h:68
Jack::JackGraphManager
Graph manager: contains the connection manager and the port array.
Definition: JackGraphManager.h:40
Jack::JackClientInterface
Client interface.
Definition: JackClientInterface.h:35
Jack::JackEngineControl
Engine control in shared memory.
Definition: JackEngineControl.h:49
Jack::detail::JackChannelTransactionInterface
Definition: JackChannel.h:38
Jack::JackSessionNotifyResult
Definition: JackRequest.h:1258