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"
35 See : http://groups.google.com/group/comp.programming.threads/browse_thread/thread/652bcf186fbbf697/f63757846514e5e5
38 // Assuming thread cancellation, must rethrow
43 #define CATCH_EXCEPTION_RETURN \
44 } catch(std::bad_alloc& e) { \
45 jack_error("Memory allocation error..."); \
48 jack_error("Unknown error..."); \
52 #define CATCH_CLOSE_EXCEPTION_RETURN \
53 } catch(std::bad_alloc& e) { \
54 jack_error("Memory allocation error..."); \
56 } catch(JackTemporaryException& e) { \
57 jack_error("JackTemporaryException : now quits..."); \
58 JackTools::KillServer(); \
61 jack_error("Unknown error..."); \
65 #define CATCH_EXCEPTION \
66 } catch(std::bad_alloc& e) { \
67 jack_error("Memory allocation error..."); \
69 jack_error("Unknown error..."); \
75 \brief Locked Engine, access to methods is serialized using a mutex.
78 class SERVER_EXPORT JackLockedEngine
86 JackLockedEngine(JackGraphManager
* manager
, JackSynchro
* table
, JackEngineControl
* controler
):
87 fEngine(manager
, table
, controler
)
96 return fEngine
.Open();
97 CATCH_EXCEPTION_RETURN
103 return fEngine
.Close();
104 CATCH_EXCEPTION_RETURN
116 int ClientCheck(const char* name
, int uuid
, char* name_res
, int protocol
, int options
, int* status
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
179 JackLock
lock(&fEngine
);
180 return fEngine
.InternalClientHandle(client_name
, status
, int_ref
);
181 CATCH_EXCEPTION_RETURN
183 int InternalClientUnload(int refnum
, int* status
)
186 JackLock
lock(&fEngine
);
187 // Client is tested in fEngine.InternalClientUnload
188 return fEngine
.InternalClientUnload(refnum
, status
);
189 CATCH_EXCEPTION_RETURN
193 int PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port
)
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
)
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
)
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
)
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
)
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
)
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
)
241 JackLock
lock(&fEngine
);
242 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortRename(refnum
, port
, name
) : -1;
243 CATCH_EXCEPTION_RETURN
246 int ComputeTotalLatencies()
249 JackLock
lock(&fEngine
);
250 return fEngine
.ComputeTotalLatencies();
251 CATCH_EXCEPTION_RETURN
255 bool Process(jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
)
258 return fEngine
.Process(cur_cycle_begin
, prev_cycle_end
);
262 void NotifyXRun(jack_time_t cur_cycle_begin
, float delayed_usecs
)
265 fEngine
.NotifyXRun(cur_cycle_begin
, delayed_usecs
);
268 void NotifyXRun(int refnum
)
271 fEngine
.NotifyXRun(refnum
);
274 void NotifyGraphReorder()
277 JackLock
lock(&fEngine
);
278 fEngine
.NotifyGraphReorder();
282 void NotifyBufferSize(jack_nframes_t buffer_size
)
285 JackLock
lock(&fEngine
);
286 fEngine
.NotifyBufferSize(buffer_size
);
289 void NotifySampleRate(jack_nframes_t sample_rate
)
292 JackLock
lock(&fEngine
);
293 fEngine
.NotifySampleRate(sample_rate
);
296 void NotifyFreewheel(bool onoff
)
299 JackLock
lock(&fEngine
);
300 fEngine
.NotifyFreewheel(onoff
);
304 void NotifyFailure(int code
, const char* reason
)
307 JackLock
lock(&fEngine
);
308 fEngine
.NotifyFailure(code
, reason
);
312 int GetClientPID(const char* name
)
315 JackLock
lock(&fEngine
);
316 return fEngine
.GetClientPID(name
);
317 CATCH_EXCEPTION_RETURN
320 int GetClientRefNum(const char* name
)
323 JackLock
lock(&fEngine
);
324 return fEngine
.GetClientRefNum(name
);
325 CATCH_EXCEPTION_RETURN
331 JackLock
lock(&fEngine
);
332 return fEngine
.NotifyQuit();
336 void SessionNotify(int refnum
, const char* target
, jack_session_event_type_t type
, const char *path
, detail::JackChannelTransactionInterface
*socket
, JackSessionNotifyResult
** result
)
339 JackLock
lock(&fEngine
);
340 fEngine
.SessionNotify(refnum
, target
, type
, path
, socket
, result
);
344 int SessionReply(int refnum
)
347 JackLock
lock(&fEngine
);
348 return fEngine
.SessionReply(refnum
);
349 CATCH_EXCEPTION_RETURN
352 int GetUUIDForClientName(const char *client_name
, char *uuid_res
)
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
)
362 JackLock
lock(&fEngine
);
363 return fEngine
.GetClientNameForUUID(uuid
, name_res
);
364 CATCH_EXCEPTION_RETURN
366 int ReserveClientName(const char *name
, const char *uuid
)
369 JackLock
lock(&fEngine
);
370 return fEngine
.ReserveClientName(name
, uuid
);
371 CATCH_EXCEPTION_RETURN
374 int ClientHasSessionCallback(const char *name
)
377 JackLock
lock(&fEngine
);
378 return fEngine
.ClientHasSessionCallback(name
);
379 CATCH_EXCEPTION_RETURN
383 } // end of namespace