Correct netjack2 components help.
[jack2.git] / common / JackLockedEngine.h
blob99f1e3598495a23523bda9160a882f16b20d4951
1 /*
2 Copyright (C) 2008 Grame
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.
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.
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.
20 #ifndef __JackLockedEngine__
21 #define __JackLockedEngine__
23 #include "JackEngine.h"
24 #include "JackMutex.h"
25 #include "JackTools.h"
26 #include "JackException.h"
28 namespace Jack
31 #define TRY_CALL \
32 try { \
35 See : http://groups.google.com/group/comp.programming.threads/browse_thread/thread/652bcf186fbbf697/f63757846514e5e5
37 catch (...) {
38 // Assuming thread cancellation, must rethrow
39 throw;
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 } \
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; \
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 } \
74 /*!
75 \brief Locked Engine, access to methods is serialized using a mutex.
78 class SERVER_EXPORT JackLockedEngine
80 private:
82 JackEngine fEngine;
84 public:
86 JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler):
87 fEngine(manager, table, controler)
89 ~JackLockedEngine()
92 int Open()
94 // No lock needed
95 TRY_CALL
96 return fEngine.Open();
97 CATCH_EXCEPTION_RETURN
99 int Close()
101 // No lock needed
102 TRY_CALL
103 return fEngine.Close();
104 CATCH_EXCEPTION_RETURN
107 void ShutDown()
109 // No lock needed
110 TRY_CALL
111 fEngine.ShutDown();
112 CATCH_EXCEPTION
115 // Client management
116 int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status)
118 TRY_CALL
119 JackLock lock(&fEngine);
120 return fEngine.ClientCheck(name, uuid, name_res, protocol, options, status);
121 CATCH_EXCEPTION_RETURN
123 int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
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
130 int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
132 TRY_CALL
133 JackLock lock(&fEngine);
134 return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
135 CATCH_EXCEPTION_RETURN
138 int ClientExternalClose(int refnum)
140 TRY_CALL
141 JackLock lock(&fEngine);
142 return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : -1;
143 CATCH_CLOSE_EXCEPTION_RETURN
145 int ClientInternalClose(int refnum, bool wait)
147 TRY_CALL
148 JackLock lock(&fEngine);
149 return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1;
150 CATCH_CLOSE_EXCEPTION_RETURN
153 int ClientActivate(int refnum, bool is_real_time)
155 TRY_CALL
156 JackLock lock(&fEngine);
157 return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1;
158 CATCH_EXCEPTION_RETURN
160 int ClientDeactivate(int refnum)
162 TRY_CALL
163 JackLock lock(&fEngine);
164 return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1;
165 CATCH_EXCEPTION_RETURN
168 // Internal client management
169 int GetInternalClientName(int int_ref, char* name_res)
171 TRY_CALL
172 JackLock lock(&fEngine);
173 return fEngine.GetInternalClientName(int_ref, name_res);
174 CATCH_EXCEPTION_RETURN
176 int InternalClientHandle(const char* client_name, int* status, int* int_ref)
178 TRY_CALL
179 JackLock lock(&fEngine);
180 return fEngine.InternalClientHandle(client_name, status, int_ref);
181 CATCH_EXCEPTION_RETURN
183 int InternalClientUnload(int refnum, int* status)
185 TRY_CALL
186 JackLock lock(&fEngine);
187 // Client is tested in fEngine.InternalClientUnload
188 return fEngine.InternalClientUnload(refnum, status);
189 CATCH_EXCEPTION_RETURN
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)
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
200 int PortUnRegister(int refnum, jack_port_id_t port)
202 TRY_CALL
203 JackLock lock(&fEngine);
204 return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1;
205 CATCH_EXCEPTION_RETURN
208 int PortConnect(int refnum, const char* src, const char* dst)
210 TRY_CALL
211 JackLock lock(&fEngine);
212 return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
213 CATCH_EXCEPTION_RETURN
215 int PortDisconnect(int refnum, const char* src, const char* dst)
217 TRY_CALL
218 JackLock lock(&fEngine);
219 return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
220 CATCH_EXCEPTION_RETURN
223 int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
225 TRY_CALL
226 JackLock lock(&fEngine);
227 return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
228 CATCH_EXCEPTION_RETURN
230 int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
232 TRY_CALL
233 JackLock lock(&fEngine);
234 return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
235 CATCH_EXCEPTION_RETURN
238 int PortRename(int refnum, jack_port_id_t port, const char* name)
240 TRY_CALL
241 JackLock lock(&fEngine);
242 return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1;
243 CATCH_EXCEPTION_RETURN
246 int ComputeTotalLatencies()
248 TRY_CALL
249 JackLock lock(&fEngine);
250 return fEngine.ComputeTotalLatencies();
251 CATCH_EXCEPTION_RETURN
254 // Graph
255 bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
257 // RT : no lock
258 return fEngine.Process(cur_cycle_begin, prev_cycle_end);
261 // Notifications
262 void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
264 // RT : no lock
265 fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
268 void NotifyXRun(int refnum)
270 // RT : no lock
271 fEngine.NotifyXRun(refnum);
274 void NotifyGraphReorder()
276 TRY_CALL
277 JackLock lock(&fEngine);
278 fEngine.NotifyGraphReorder();
279 CATCH_EXCEPTION
282 void NotifyBufferSize(jack_nframes_t buffer_size)
284 TRY_CALL
285 JackLock lock(&fEngine);
286 fEngine.NotifyBufferSize(buffer_size);
287 CATCH_EXCEPTION
289 void NotifySampleRate(jack_nframes_t sample_rate)
291 TRY_CALL
292 JackLock lock(&fEngine);
293 fEngine.NotifySampleRate(sample_rate);
294 CATCH_EXCEPTION
296 void NotifyFreewheel(bool onoff)
298 TRY_CALL
299 JackLock lock(&fEngine);
300 fEngine.NotifyFreewheel(onoff);
301 CATCH_EXCEPTION
304 void NotifyFailure(int code, const char* reason)
306 TRY_CALL
307 JackLock lock(&fEngine);
308 fEngine.NotifyFailure(code, reason);
309 CATCH_EXCEPTION
312 int GetClientPID(const char* name)
314 TRY_CALL
315 JackLock lock(&fEngine);
316 return fEngine.GetClientPID(name);
317 CATCH_EXCEPTION_RETURN
320 int GetClientRefNum(const char* name)
322 TRY_CALL
323 JackLock lock(&fEngine);
324 return fEngine.GetClientRefNum(name);
325 CATCH_EXCEPTION_RETURN
328 void NotifyQuit()
330 TRY_CALL
331 JackLock lock(&fEngine);
332 return fEngine.NotifyQuit();
333 CATCH_EXCEPTION
336 void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result)
338 TRY_CALL
339 JackLock lock(&fEngine);
340 fEngine.SessionNotify(refnum, target, type, path, socket, result);
341 CATCH_EXCEPTION
344 int SessionReply(int refnum)
346 TRY_CALL
347 JackLock lock(&fEngine);
348 return fEngine.SessionReply(refnum);
349 CATCH_EXCEPTION_RETURN
352 int GetUUIDForClientName(const char *client_name, char *uuid_res)
354 TRY_CALL
355 JackLock lock(&fEngine);
356 return fEngine.GetUUIDForClientName(client_name, uuid_res);
357 CATCH_EXCEPTION_RETURN
359 int GetClientNameForUUID(const char *uuid, char *name_res)
361 TRY_CALL
362 JackLock lock(&fEngine);
363 return fEngine.GetClientNameForUUID(uuid, name_res);
364 CATCH_EXCEPTION_RETURN
366 int ReserveClientName(const char *name, const char *uuid)
368 TRY_CALL
369 JackLock lock(&fEngine);
370 return fEngine.ReserveClientName(name, uuid);
371 CATCH_EXCEPTION_RETURN
374 int ClientHasSessionCallback(const char *name)
376 TRY_CALL
377 JackLock lock(&fEngine);
378 return fEngine.ClientHasSessionCallback(name);
379 CATCH_EXCEPTION_RETURN
383 } // end of namespace
385 #endif