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
, char self_connect_mode
):
87 fEngine(manager
, table
, controler
, self_connect_mode
)
92 bool Lock() { return fEngine
.Lock(); }
93 bool Unlock() { return fEngine
.Unlock(); }
94 bool Trylock() { return fEngine
.Trylock(); }
100 return fEngine
.Open();
101 CATCH_EXCEPTION_RETURN
107 return fEngine
.Close();
108 CATCH_EXCEPTION_RETURN
112 int ClientCheck(const char* name
, jack_uuid_t uuid
, char* name_res
, int protocol
, int options
, int* status
)
115 JackLock
lock(&fEngine
);
116 return fEngine
.ClientCheck(name
, uuid
, name_res
, protocol
, options
, status
);
117 CATCH_EXCEPTION_RETURN
119 int ClientExternalOpen(const char* name
, int pid
, jack_uuid_t uuid
, int* ref
, int* shared_engine
, int* shared_client
, int* shared_graph_manager
)
122 JackLock
lock(&fEngine
);
123 return fEngine
.ClientExternalOpen(name
, pid
, uuid
, ref
, shared_engine
, shared_client
, shared_graph_manager
);
124 CATCH_EXCEPTION_RETURN
126 int ClientInternalOpen(const char* name
, int* ref
, JackEngineControl
** shared_engine
, JackGraphManager
** shared_manager
, JackClientInterface
* client
, bool wait
)
129 JackLock
lock(&fEngine
);
130 return fEngine
.ClientInternalOpen(name
, ref
, shared_engine
, shared_manager
, client
, wait
);
131 CATCH_EXCEPTION_RETURN
134 int ClientExternalClose(int refnum
)
137 JackLock
lock(&fEngine
);
138 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientExternalClose(refnum
) : -1;
139 CATCH_CLOSE_EXCEPTION_RETURN
141 int ClientInternalClose(int refnum
, bool wait
)
144 JackLock
lock(&fEngine
);
145 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientInternalClose(refnum
, wait
) : -1;
146 CATCH_CLOSE_EXCEPTION_RETURN
149 int ClientActivate(int refnum
, bool is_real_time
)
152 JackLock
lock(&fEngine
);
153 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientActivate(refnum
, is_real_time
) : -1;
154 CATCH_EXCEPTION_RETURN
156 int ClientDeactivate(int refnum
)
159 JackLock
lock(&fEngine
);
160 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientDeactivate(refnum
) : -1;
161 CATCH_EXCEPTION_RETURN
163 void ClientKill(int refnum
)
166 JackLock
lock(&fEngine
);
167 fEngine
.ClientKill(refnum
);
171 // Internal client management
172 int GetInternalClientName(int int_ref
, char* name_res
)
175 JackLock
lock(&fEngine
);
176 return fEngine
.GetInternalClientName(int_ref
, name_res
);
177 CATCH_EXCEPTION_RETURN
179 int InternalClientHandle(const char* client_name
, int* status
, int* int_ref
)
182 JackLock
lock(&fEngine
);
183 return fEngine
.InternalClientHandle(client_name
, status
, int_ref
);
184 CATCH_EXCEPTION_RETURN
186 int InternalClientUnload(int refnum
, int* status
)
189 JackLock
lock(&fEngine
);
190 // Client is tested in fEngine.InternalClientUnload
191 return fEngine
.InternalClientUnload(refnum
, status
);
192 CATCH_EXCEPTION_RETURN
196 int PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port
)
199 JackLock
lock(&fEngine
);
200 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortRegister(refnum
, name
, type
, flags
, buffer_size
, port
) : -1;
201 CATCH_EXCEPTION_RETURN
203 int PortUnRegister(int refnum
, jack_port_id_t port
)
206 JackLock
lock(&fEngine
);
207 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortUnRegister(refnum
, port
) : -1;
208 CATCH_EXCEPTION_RETURN
211 int PortConnect(int refnum
, const char* src
, const char* dst
)
214 JackLock
lock(&fEngine
);
215 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortConnect(refnum
, src
, dst
) : -1;
216 CATCH_EXCEPTION_RETURN
218 int PortDisconnect(int refnum
, const char* src
, const char* dst
)
221 JackLock
lock(&fEngine
);
222 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortDisconnect(refnum
, src
, dst
) : -1;
223 CATCH_EXCEPTION_RETURN
226 int PortConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
229 JackLock
lock(&fEngine
);
230 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortConnect(refnum
, src
, dst
) : -1;
231 CATCH_EXCEPTION_RETURN
233 int PortDisconnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
236 JackLock
lock(&fEngine
);
237 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortDisconnect(refnum
, src
, dst
) : -1;
238 CATCH_EXCEPTION_RETURN
241 int PortRename(int refnum
, jack_port_id_t port
, const char* name
)
244 JackLock
lock(&fEngine
);
245 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortRename(refnum
, port
, name
) : -1;
246 CATCH_EXCEPTION_RETURN
249 int PortSetDeviceMetadata(int refnum
, jack_port_id_t port
, const char* pretty_name
)
252 JackLock
lock(&fEngine
);
253 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortSetDeviceMetadata(port
, pretty_name
) : -1;
254 CATCH_EXCEPTION_RETURN
257 int ComputeTotalLatencies()
260 JackLock
lock(&fEngine
);
261 return fEngine
.ComputeTotalLatencies();
262 CATCH_EXCEPTION_RETURN
266 bool Process(jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
)
269 return fEngine
.Process(cur_cycle_begin
, prev_cycle_end
);
273 void NotifyDriverXRun()
275 // Coming from the driver in RT : no lock
276 fEngine
.NotifyDriverXRun();
279 void NotifyClientXRun(int refnum
)
282 JackLock
lock(&fEngine
);
283 fEngine
.NotifyClientXRun(refnum
);
287 void NotifyGraphReorder()
290 JackLock
lock(&fEngine
);
291 fEngine
.NotifyGraphReorder();
295 void NotifyBufferSize(jack_nframes_t buffer_size
)
298 JackLock
lock(&fEngine
);
299 fEngine
.NotifyBufferSize(buffer_size
);
302 void NotifySampleRate(jack_nframes_t sample_rate
)
305 JackLock
lock(&fEngine
);
306 fEngine
.NotifySampleRate(sample_rate
);
309 void NotifyFreewheel(bool onoff
)
312 JackLock
lock(&fEngine
);
313 fEngine
.NotifyFreewheel(onoff
);
317 void NotifyFailure(int code
, const char* reason
)
320 JackLock
lock(&fEngine
);
321 fEngine
.NotifyFailure(code
, reason
);
325 int GetClientPID(const char* name
)
328 JackLock
lock(&fEngine
);
329 return fEngine
.GetClientPID(name
);
330 CATCH_EXCEPTION_RETURN
333 int GetClientRefNum(const char* name
)
336 JackLock
lock(&fEngine
);
337 return fEngine
.GetClientRefNum(name
);
338 CATCH_EXCEPTION_RETURN
345 return fEngine
.NotifyQuit();
349 void SessionNotify(int refnum
, const char* target
, jack_session_event_type_t type
, const char *path
, detail::JackChannelTransactionInterface
*socket
, JackSessionNotifyResult
** result
)
352 JackLock
lock(&fEngine
);
353 fEngine
.SessionNotify(refnum
, target
, type
, path
, socket
, result
);
357 int SessionReply(int refnum
)
360 JackLock
lock(&fEngine
);
361 return fEngine
.SessionReply(refnum
);
362 CATCH_EXCEPTION_RETURN
365 int GetUUIDForClientName(const char *client_name
, char *uuid_res
)
368 JackLock
lock(&fEngine
);
369 return fEngine
.GetUUIDForClientName(client_name
, uuid_res
);
370 CATCH_EXCEPTION_RETURN
373 int GetClientNameForUUID(const char *uuid
, char *name_res
)
376 JackLock
lock(&fEngine
);
377 return fEngine
.GetClientNameForUUID(uuid
, name_res
);
378 CATCH_EXCEPTION_RETURN
380 int ReserveClientName(const char *name
, const char *uuid
)
383 JackLock
lock(&fEngine
);
384 return fEngine
.ReserveClientName(name
, uuid
);
385 CATCH_EXCEPTION_RETURN
388 int ClientHasSessionCallback(const char *name
)
391 JackLock
lock(&fEngine
);
392 return fEngine
.ClientHasSessionCallback(name
);
393 CATCH_EXCEPTION_RETURN
396 int PropertyChangeNotify(jack_uuid_t subject
, const char* key
, jack_property_change_t change
)
399 JackLock
lock(&fEngine
);
400 return fEngine
.PropertyChangeNotify(subject
, key
, change
);
401 CATCH_EXCEPTION_RETURN
405 } // end of namespace