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