Simplify server temporary mode : now use a JackTemporaryException.
[jack2.git] / common / JackLockedEngine.h
blob941cca9a96cfdaf2cd8cd5a11f6967f2e1b79dc7
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 { \
34 #define CATCH_EXCEPTION_RETURN \
35 } catch(std::bad_alloc& e) { \
36 jack_error("Memory allocation error..."); \
37 return -1; \
38 } catch(JackTemporaryException& e) { \
39 jack_error("JackTemporaryException : now quits..."); \
40 kill(JackTools::GetPID(), SIGINT); \
41 return -1; \
42 } catch (...) { \
43 jack_error("Unknown error..."); \
44 return -1; \
45 } \
47 #define CATCH_ENGINE_EXCEPTION \
48 } catch(std::bad_alloc& e) { \
49 jack_error("Memory allocation error..."); \
50 } catch (...) { \
51 jack_error("Unknown error..."); \
52 } \
54 /*!
55 \brief Locked Engine, access to methods is serialized using a mutex.
58 class SERVER_EXPORT JackLockedEngine : public JackLockAble
60 private:
62 JackEngine fEngine;
64 public:
66 JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler):
67 fEngine(manager, table, controler)
69 ~JackLockedEngine()
72 int Open()
74 // No lock needed
75 TRY_CALL
76 return fEngine.Open();
77 CATCH_EXCEPTION_RETURN
79 int Close()
81 // No lock needed
82 TRY_CALL
83 return fEngine.Close();
84 CATCH_EXCEPTION_RETURN
87 // Client management
88 int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
90 TRY_CALL
91 JackLock lock(this);
92 return fEngine.ClientCheck(name, name_res, protocol, options, status);
93 CATCH_EXCEPTION_RETURN
95 int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
97 TRY_CALL
98 JackLock lock(this);
99 return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
100 CATCH_EXCEPTION_RETURN
102 int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
104 TRY_CALL
105 JackLock lock(this);
106 return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
107 CATCH_EXCEPTION_RETURN
110 int ClientExternalClose(int refnum)
112 TRY_CALL
113 JackLock lock(this);
114 return fEngine.ClientExternalClose(refnum);
115 CATCH_EXCEPTION_RETURN
117 int ClientInternalClose(int refnum, bool wait)
119 TRY_CALL
120 JackLock lock(this);
121 return fEngine.ClientInternalClose(refnum, wait);
122 CATCH_EXCEPTION_RETURN
125 int ClientActivate(int refnum, bool is_real_time)
127 TRY_CALL
128 JackLock lock(this);
129 return fEngine.ClientActivate(refnum, is_real_time);
130 CATCH_EXCEPTION_RETURN
132 int ClientDeactivate(int refnum)
134 TRY_CALL
135 JackLock lock(this);
136 return fEngine.ClientDeactivate(refnum);
137 CATCH_EXCEPTION_RETURN
140 // Internal client management
141 int GetInternalClientName(int int_ref, char* name_res)
143 TRY_CALL
144 JackLock lock(this);
145 return fEngine.GetInternalClientName(int_ref, name_res);
146 CATCH_EXCEPTION_RETURN
148 int InternalClientHandle(const char* client_name, int* status, int* int_ref)
150 TRY_CALL
151 JackLock lock(this);
152 return fEngine.InternalClientHandle(client_name, status, int_ref);
153 CATCH_EXCEPTION_RETURN
155 int InternalClientUnload(int refnum, int* status)
157 TRY_CALL
158 JackLock lock(this);
159 return fEngine.InternalClientUnload(refnum, status);
160 CATCH_EXCEPTION_RETURN
163 // Port management
164 int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
166 TRY_CALL
167 JackLock lock(this);
168 return fEngine.PortRegister(refnum, name, type, flags, buffer_size, port);
169 CATCH_EXCEPTION_RETURN
171 int PortUnRegister(int refnum, jack_port_id_t port)
173 TRY_CALL
174 JackLock lock(this);
175 return fEngine.PortUnRegister(refnum, port);
176 CATCH_EXCEPTION_RETURN
179 int PortConnect(int refnum, const char* src, const char* dst)
181 TRY_CALL
182 JackLock lock(this);
183 return fEngine.PortConnect(refnum, src, dst);
184 CATCH_EXCEPTION_RETURN
186 int PortDisconnect(int refnum, const char* src, const char* dst)
188 TRY_CALL
189 JackLock lock(this);
190 return fEngine.PortDisconnect(refnum, src, dst);
191 CATCH_EXCEPTION_RETURN
194 int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
196 TRY_CALL
197 JackLock lock(this);
198 return fEngine.PortConnect(refnum, src, dst);
199 CATCH_EXCEPTION_RETURN
201 int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
203 TRY_CALL
204 JackLock lock(this);
205 return fEngine.PortDisconnect(refnum, src, dst);
206 CATCH_EXCEPTION_RETURN
209 int PortRename(int refnum, jack_port_id_t port, const char* name)
211 TRY_CALL
212 JackLock lock(this);
213 return fEngine.PortRename(refnum, port, name);
214 CATCH_EXCEPTION_RETURN
217 // Graph
218 bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
220 // RT : no lock
221 return fEngine.Process(cur_cycle_begin, prev_cycle_end);
224 // Notifications
225 void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
227 // RT : no lock
228 fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
231 void NotifyXRun(int refnum)
233 TRY_CALL
234 JackLock lock(this);
235 fEngine.NotifyXRun(refnum);
236 CATCH_ENGINE_EXCEPTION
238 void NotifyGraphReorder()
240 TRY_CALL
241 JackLock lock(this);
242 fEngine.NotifyGraphReorder();
243 CATCH_ENGINE_EXCEPTION
245 void NotifyBufferSize(jack_nframes_t buffer_size)
247 TRY_CALL
248 JackLock lock(this);
249 fEngine.NotifyBufferSize(buffer_size);
250 CATCH_ENGINE_EXCEPTION
252 void NotifySampleRate(jack_nframes_t sample_rate)
254 TRY_CALL
255 JackLock lock(this);
256 fEngine.NotifySampleRate(sample_rate);
257 CATCH_ENGINE_EXCEPTION
259 void NotifyFreewheel(bool onoff)
261 TRY_CALL
262 JackLock lock(this);
263 fEngine.NotifyFreewheel(onoff);
264 CATCH_ENGINE_EXCEPTION
267 void NotifyFailure(int code, const char* reason)
269 TRY_CALL
270 JackLock lock(this);
271 fEngine.NotifyFailure(code, reason);
272 CATCH_ENGINE_EXCEPTION
275 int GetClientPID(const char* name)
277 TRY_CALL
278 JackLock lock(this);
279 return fEngine.GetClientPID(name);
280 CATCH_EXCEPTION_RETURN
283 int GetClientRefNum(const char* name)
285 TRY_CALL
286 JackLock lock(this);
287 return fEngine.GetClientRefNum(name);
288 CATCH_EXCEPTION_RETURN
293 } // end of namespace
295 #endif