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"
34 #define CATCH_EXCEPTION_RETURN \
35 } catch(std::bad_alloc& e) { \
36 jack_error("Memory allocation error..."); \
38 } catch(JackTemporaryException& e) { \
39 jack_error("JackTemporaryException : now quits..."); \
40 kill(JackTools::GetPID(), SIGINT); \
43 jack_error("Unknown error..."); \
47 #define CATCH_ENGINE_EXCEPTION \
48 } catch(std::bad_alloc& e) { \
49 jack_error("Memory allocation error..."); \
51 jack_error("Unknown error..."); \
55 \brief Locked Engine, access to methods is serialized using a mutex.
58 class SERVER_EXPORT JackLockedEngine
: public JackLockAble
66 JackLockedEngine(JackGraphManager
* manager
, JackSynchro
* table
, JackEngineControl
* controler
):
67 fEngine(manager
, table
, controler
)
76 return fEngine
.Open();
77 CATCH_EXCEPTION_RETURN
83 return fEngine
.Close();
84 CATCH_EXCEPTION_RETURN
88 int ClientCheck(const char* name
, char* name_res
, int protocol
, int options
, int* status
)
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
)
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
)
106 return fEngine
.ClientInternalOpen(name
, ref
, shared_engine
, shared_manager
, client
, wait
);
107 CATCH_EXCEPTION_RETURN
110 int ClientExternalClose(int refnum
)
114 return fEngine
.ClientExternalClose(refnum
);
115 CATCH_EXCEPTION_RETURN
117 int ClientInternalClose(int refnum
, bool wait
)
121 return fEngine
.ClientInternalClose(refnum
, wait
);
122 CATCH_EXCEPTION_RETURN
125 int ClientActivate(int refnum
, bool is_real_time
)
129 return fEngine
.ClientActivate(refnum
, is_real_time
);
130 CATCH_EXCEPTION_RETURN
132 int ClientDeactivate(int refnum
)
136 return fEngine
.ClientDeactivate(refnum
);
137 CATCH_EXCEPTION_RETURN
140 // Internal client management
141 int GetInternalClientName(int int_ref
, char* name_res
)
145 return fEngine
.GetInternalClientName(int_ref
, name_res
);
146 CATCH_EXCEPTION_RETURN
148 int InternalClientHandle(const char* client_name
, int* status
, int* int_ref
)
152 return fEngine
.InternalClientHandle(client_name
, status
, int_ref
);
153 CATCH_EXCEPTION_RETURN
155 int InternalClientUnload(int refnum
, int* status
)
159 return fEngine
.InternalClientUnload(refnum
, status
);
160 CATCH_EXCEPTION_RETURN
164 int PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port
)
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
)
175 return fEngine
.PortUnRegister(refnum
, port
);
176 CATCH_EXCEPTION_RETURN
179 int PortConnect(int refnum
, const char* src
, const char* dst
)
183 return fEngine
.PortConnect(refnum
, src
, dst
);
184 CATCH_EXCEPTION_RETURN
186 int PortDisconnect(int refnum
, const char* src
, const char* dst
)
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
)
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
)
205 return fEngine
.PortDisconnect(refnum
, src
, dst
);
206 CATCH_EXCEPTION_RETURN
209 int PortRename(int refnum
, jack_port_id_t port
, const char* name
)
213 return fEngine
.PortRename(refnum
, port
, name
);
214 CATCH_EXCEPTION_RETURN
218 bool Process(jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
)
221 return fEngine
.Process(cur_cycle_begin
, prev_cycle_end
);
225 void NotifyXRun(jack_time_t cur_cycle_begin
, float delayed_usecs
)
228 fEngine
.NotifyXRun(cur_cycle_begin
, delayed_usecs
);
231 void NotifyXRun(int refnum
)
235 fEngine
.NotifyXRun(refnum
);
236 CATCH_ENGINE_EXCEPTION
238 void NotifyGraphReorder()
242 fEngine
.NotifyGraphReorder();
243 CATCH_ENGINE_EXCEPTION
245 void NotifyBufferSize(jack_nframes_t buffer_size
)
249 fEngine
.NotifyBufferSize(buffer_size
);
250 CATCH_ENGINE_EXCEPTION
252 void NotifySampleRate(jack_nframes_t sample_rate
)
256 fEngine
.NotifySampleRate(sample_rate
);
257 CATCH_ENGINE_EXCEPTION
259 void NotifyFreewheel(bool onoff
)
263 fEngine
.NotifyFreewheel(onoff
);
264 CATCH_ENGINE_EXCEPTION
267 void NotifyFailure(int code
, const char* reason
)
271 fEngine
.NotifyFailure(code
, reason
);
272 CATCH_ENGINE_EXCEPTION
275 int GetClientPID(const char* name
)
279 return fEngine
.GetClientPID(name
);
280 CATCH_EXCEPTION_RETURN
283 int GetClientRefNum(const char* name
)
287 return fEngine
.GetClientRefNum(name
);
288 CATCH_EXCEPTION_RETURN
293 } // end of namespace