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..."); \
47 } catch(JackTemporaryException& e) { \
48 jack_error("JackTemporaryException : now quits..."); \
49 JackTools::KillServer(); \
52 jack_error("Unknown error..."); \
56 #define CATCH_EXCEPTION \
57 } catch(std::bad_alloc& e) { \
58 jack_error("Memory allocation error..."); \
60 jack_error("Unknown error..."); \
66 \brief Locked Engine, access to methods is serialized using a mutex.
69 class SERVER_EXPORT JackLockedEngine
77 JackLockedEngine(JackGraphManager
* manager
, JackSynchro
* table
, JackEngineControl
* controler
):
78 fEngine(manager
, table
, controler
)
87 return fEngine
.Open();
88 CATCH_EXCEPTION_RETURN
94 return fEngine
.Close();
95 CATCH_EXCEPTION_RETURN
99 int ClientCheck(const char* name
, char* name_res
, int protocol
, int options
, int* status
)
102 JackLock
lock(&fEngine
);
103 return fEngine
.ClientCheck(name
, name_res
, protocol
, options
, status
);
104 CATCH_EXCEPTION_RETURN
106 int ClientExternalOpen(const char* name
, int pid
, int* ref
, int* shared_engine
, int* shared_client
, int* shared_graph_manager
)
109 JackLock
lock(&fEngine
);
110 return fEngine
.ClientExternalOpen(name
, pid
, ref
, shared_engine
, shared_client
, shared_graph_manager
);
111 CATCH_EXCEPTION_RETURN
113 int ClientInternalOpen(const char* name
, int* ref
, JackEngineControl
** shared_engine
, JackGraphManager
** shared_manager
, JackClientInterface
* client
, bool wait
)
116 JackLock
lock(&fEngine
);
117 return fEngine
.ClientInternalOpen(name
, ref
, shared_engine
, shared_manager
, client
, wait
);
118 CATCH_EXCEPTION_RETURN
121 int ClientExternalClose(int refnum
)
124 JackLock
lock(&fEngine
);
125 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientExternalClose(refnum
) : - 1;
126 CATCH_EXCEPTION_RETURN
128 int ClientInternalClose(int refnum
, bool wait
)
131 JackLock
lock(&fEngine
);
132 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientInternalClose(refnum
, wait
) : -1;
133 CATCH_EXCEPTION_RETURN
136 int ClientActivate(int refnum
, bool is_real_time
)
139 JackLock
lock(&fEngine
);
140 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientActivate(refnum
, is_real_time
) : -1;
141 CATCH_EXCEPTION_RETURN
143 int ClientDeactivate(int refnum
)
146 JackLock
lock(&fEngine
);
147 return (fEngine
.CheckClient(refnum
)) ? fEngine
.ClientDeactivate(refnum
) : -1;
148 CATCH_EXCEPTION_RETURN
151 // Internal client management
152 int GetInternalClientName(int int_ref
, char* name_res
)
155 JackLock
lock(&fEngine
);
156 return fEngine
.GetInternalClientName(int_ref
, name_res
);
157 CATCH_EXCEPTION_RETURN
159 int InternalClientHandle(const char* client_name
, int* status
, int* int_ref
)
162 JackLock
lock(&fEngine
);
163 return fEngine
.InternalClientHandle(client_name
, status
, int_ref
);
164 CATCH_EXCEPTION_RETURN
166 int InternalClientUnload(int refnum
, int* status
)
169 JackLock
lock(&fEngine
);
170 return (fEngine
.CheckClient(refnum
)) ? fEngine
.InternalClientUnload(refnum
, status
) : -1;
171 CATCH_EXCEPTION_RETURN
175 int PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port
)
178 JackLock
lock(&fEngine
);
179 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortRegister(refnum
, name
, type
, flags
, buffer_size
, port
) : -1;
180 CATCH_EXCEPTION_RETURN
182 int PortUnRegister(int refnum
, jack_port_id_t port
)
185 JackLock
lock(&fEngine
);
186 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortUnRegister(refnum
, port
) : -1;
187 CATCH_EXCEPTION_RETURN
190 int PortConnect(int refnum
, const char* src
, const char* dst
)
193 JackLock
lock(&fEngine
);
194 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortConnect(refnum
, src
, dst
) : -1;
195 CATCH_EXCEPTION_RETURN
197 int PortDisconnect(int refnum
, const char* src
, const char* dst
)
200 JackLock
lock(&fEngine
);
201 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortDisconnect(refnum
, src
, dst
) : -1;
202 CATCH_EXCEPTION_RETURN
205 int PortConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
208 JackLock
lock(&fEngine
);
209 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortConnect(refnum
, src
, dst
) : -1;
210 CATCH_EXCEPTION_RETURN
212 int PortDisconnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
)
215 JackLock
lock(&fEngine
);
216 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortDisconnect(refnum
, src
, dst
) : -1;
217 CATCH_EXCEPTION_RETURN
220 int PortRename(int refnum
, jack_port_id_t port
, const char* name
)
223 JackLock
lock(&fEngine
);
224 return (fEngine
.CheckClient(refnum
)) ? fEngine
.PortRename(refnum
, port
, name
) : -1;
225 CATCH_EXCEPTION_RETURN
229 bool Process(jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
)
232 return fEngine
.Process(cur_cycle_begin
, prev_cycle_end
);
236 void NotifyXRun(jack_time_t cur_cycle_begin
, float delayed_usecs
)
239 fEngine
.NotifyXRun(cur_cycle_begin
, delayed_usecs
);
242 void NotifyXRun(int refnum
)
245 fEngine
.NotifyXRun(refnum
);
248 void NotifyGraphReorder()
251 JackLock
lock(&fEngine
);
252 fEngine
.NotifyGraphReorder();
255 void NotifyBufferSize(jack_nframes_t buffer_size
)
258 JackLock
lock(&fEngine
);
259 fEngine
.NotifyBufferSize(buffer_size
);
262 void NotifySampleRate(jack_nframes_t sample_rate
)
265 JackLock
lock(&fEngine
);
266 fEngine
.NotifySampleRate(sample_rate
);
269 void NotifyFreewheel(bool onoff
)
272 JackLock
lock(&fEngine
);
273 fEngine
.NotifyFreewheel(onoff
);
277 void NotifyFailure(int code
, const char* reason
)
280 JackLock
lock(&fEngine
);
281 fEngine
.NotifyFailure(code
, reason
);
285 int GetClientPID(const char* name
)
288 JackLock
lock(&fEngine
);
289 return fEngine
.GetClientPID(name
);
290 CATCH_EXCEPTION_RETURN
293 int GetClientRefNum(const char* name
)
296 JackLock
lock(&fEngine
);
297 return fEngine
.GetClientRefNum(name
);
298 CATCH_EXCEPTION_RETURN
304 JackLock
lock(&fEngine
);
305 return fEngine
.NotifyQuit();
311 } // end of namespace