Jack2  1.9.9
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):
87  fEngine(manager, table, controler)
88  {}
90  {}
91 
92  int Open()
93  {
94  // No lock needed
95  TRY_CALL
96  return fEngine.Open();
97  CATCH_EXCEPTION_RETURN
98  }
99  int Close()
100  {
101  // No lock needed
102  TRY_CALL
103  return fEngine.Close();
104  CATCH_EXCEPTION_RETURN
105  }
106 
107  void ShutDown()
108  {
109  // No lock needed
110  TRY_CALL
111  fEngine.ShutDown();
112  CATCH_EXCEPTION
113  }
114 
115  // Client management
116  int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status)
117  {
118  TRY_CALL
119  JackLock lock(&fEngine);
120  return fEngine.ClientCheck(name, uuid, name_res, protocol, options, status);
121  CATCH_EXCEPTION_RETURN
122  }
123  int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
124  {
125  TRY_CALL
126  JackLock lock(&fEngine);
127  return fEngine.ClientExternalOpen(name, pid, uuid, ref, shared_engine, shared_client, shared_graph_manager);
128  CATCH_EXCEPTION_RETURN
129  }
130  int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
131  {
132  TRY_CALL
133  JackLock lock(&fEngine);
134  return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
135  CATCH_EXCEPTION_RETURN
136  }
137 
138  int ClientExternalClose(int refnum)
139  {
140  TRY_CALL
141  JackLock lock(&fEngine);
142  return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : -1;
143  CATCH_CLOSE_EXCEPTION_RETURN
144  }
145  int ClientInternalClose(int refnum, bool wait)
146  {
147  TRY_CALL
148  JackLock lock(&fEngine);
149  return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1;
150  CATCH_CLOSE_EXCEPTION_RETURN
151  }
152 
153  int ClientActivate(int refnum, bool is_real_time)
154  {
155  TRY_CALL
156  JackLock lock(&fEngine);
157  return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1;
158  CATCH_EXCEPTION_RETURN
159  }
160  int ClientDeactivate(int refnum)
161  {
162  TRY_CALL
163  JackLock lock(&fEngine);
164  return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1;
165  CATCH_EXCEPTION_RETURN
166  }
167 
168  // Internal client management
169  int GetInternalClientName(int int_ref, char* name_res)
170  {
171  TRY_CALL
172  JackLock lock(&fEngine);
173  return fEngine.GetInternalClientName(int_ref, name_res);
174  CATCH_EXCEPTION_RETURN
175  }
176  int InternalClientHandle(const char* client_name, int* status, int* int_ref)
177  {
178  TRY_CALL
179  JackLock lock(&fEngine);
180  return fEngine.InternalClientHandle(client_name, status, int_ref);
181  CATCH_EXCEPTION_RETURN
182  }
183  int InternalClientUnload(int refnum, int* status)
184  {
185  TRY_CALL
186  JackLock lock(&fEngine);
187  // Client is tested in fEngine.InternalClientUnload
188  return fEngine.InternalClientUnload(refnum, status);
189  CATCH_EXCEPTION_RETURN
190  }
191 
192  // Port management
193  int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
194  {
195  TRY_CALL
196  JackLock lock(&fEngine);
197  return (fEngine.CheckClient(refnum)) ? fEngine.PortRegister(refnum, name, type, flags, buffer_size, port) : -1;
198  CATCH_EXCEPTION_RETURN
199  }
200  int PortUnRegister(int refnum, jack_port_id_t port)
201  {
202  TRY_CALL
203  JackLock lock(&fEngine);
204  return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1;
205  CATCH_EXCEPTION_RETURN
206  }
207 
208  int PortConnect(int refnum, const char* src, const char* dst)
209  {
210  TRY_CALL
211  JackLock lock(&fEngine);
212  return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
213  CATCH_EXCEPTION_RETURN
214  }
215  int PortDisconnect(int refnum, const char* src, const char* dst)
216  {
217  TRY_CALL
218  JackLock lock(&fEngine);
219  return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
220  CATCH_EXCEPTION_RETURN
221  }
222 
223  int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
224  {
225  TRY_CALL
226  JackLock lock(&fEngine);
227  return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
228  CATCH_EXCEPTION_RETURN
229  }
230  int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
231  {
232  TRY_CALL
233  JackLock lock(&fEngine);
234  return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
235  CATCH_EXCEPTION_RETURN
236  }
237 
238  int PortRename(int refnum, jack_port_id_t port, const char* name)
239  {
240  TRY_CALL
241  JackLock lock(&fEngine);
242  return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1;
243  CATCH_EXCEPTION_RETURN
244  }
245 
246  int ComputeTotalLatencies()
247  {
248  TRY_CALL
249  JackLock lock(&fEngine);
250  return fEngine.ComputeTotalLatencies();
251  CATCH_EXCEPTION_RETURN
252  }
253 
254  // Graph
255  bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
256  {
257  // RT : no lock
258  return fEngine.Process(cur_cycle_begin, prev_cycle_end);
259  }
260 
261  // Notifications
262  void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
263  {
264  // RT : no lock
265  fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
266  }
267 
268  void NotifyXRun(int refnum)
269  {
270  // RT : no lock
271  fEngine.NotifyXRun(refnum);
272  }
273 
274  void NotifyGraphReorder()
275  {
276  TRY_CALL
277  JackLock lock(&fEngine);
278  fEngine.NotifyGraphReorder();
279  CATCH_EXCEPTION
280  }
281 
282  void NotifyBufferSize(jack_nframes_t buffer_size)
283  {
284  TRY_CALL
285  JackLock lock(&fEngine);
286  fEngine.NotifyBufferSize(buffer_size);
287  CATCH_EXCEPTION
288  }
289  void NotifySampleRate(jack_nframes_t sample_rate)
290  {
291  TRY_CALL
292  JackLock lock(&fEngine);
293  fEngine.NotifySampleRate(sample_rate);
294  CATCH_EXCEPTION
295  }
296  void NotifyFreewheel(bool onoff)
297  {
298  TRY_CALL
299  JackLock lock(&fEngine);
300  fEngine.NotifyFreewheel(onoff);
301  CATCH_EXCEPTION
302  }
303 
304  void NotifyFailure(int code, const char* reason)
305  {
306  TRY_CALL
307  JackLock lock(&fEngine);
308  fEngine.NotifyFailure(code, reason);
309  CATCH_EXCEPTION
310  }
311 
312  int GetClientPID(const char* name)
313  {
314  TRY_CALL
315  JackLock lock(&fEngine);
316  return fEngine.GetClientPID(name);
317  CATCH_EXCEPTION_RETURN
318  }
319 
320  int GetClientRefNum(const char* name)
321  {
322  TRY_CALL
323  JackLock lock(&fEngine);
324  return fEngine.GetClientRefNum(name);
325  CATCH_EXCEPTION_RETURN
326  }
327 
328  void NotifyQuit()
329  {
330  // No lock needed
331  TRY_CALL
332  return fEngine.NotifyQuit();
333  CATCH_EXCEPTION
334  }
335 
336  void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result)
337  {
338  TRY_CALL
339  JackLock lock(&fEngine);
340  fEngine.SessionNotify(refnum, target, type, path, socket, result);
341  CATCH_EXCEPTION
342  }
343 
344  int SessionReply(int refnum)
345  {
346  TRY_CALL
347  JackLock lock(&fEngine);
348  return fEngine.SessionReply(refnum);
349  CATCH_EXCEPTION_RETURN
350  }
351 
352  int GetUUIDForClientName(const char *client_name, char *uuid_res)
353  {
354  TRY_CALL
355  JackLock lock(&fEngine);
356  return fEngine.GetUUIDForClientName(client_name, uuid_res);
357  CATCH_EXCEPTION_RETURN
358  }
359  int GetClientNameForUUID(const char *uuid, char *name_res)
360  {
361  TRY_CALL
362  JackLock lock(&fEngine);
363  return fEngine.GetClientNameForUUID(uuid, name_res);
364  CATCH_EXCEPTION_RETURN
365  }
366  int ReserveClientName(const char *name, const char *uuid)
367  {
368  TRY_CALL
369  JackLock lock(&fEngine);
370  return fEngine.ReserveClientName(name, uuid);
371  CATCH_EXCEPTION_RETURN
372  }
373 
374  int ClientHasSessionCallback(const char *name)
375  {
376  TRY_CALL
377  JackLock lock(&fEngine);
378  return fEngine.ClientHasSessionCallback(name);
379  CATCH_EXCEPTION_RETURN
380  }
381 };
382 
383 } // end of namespace
384 
385 #endif
386 
Engine description.
Definition: JackEngine.h:44
Inter process synchronization using using Mach semaphore.
Locked Engine, access to methods is serialized using a mutex.
Graph manager: contains the connection manager and the port array.
Engine control in shared memory.