1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/*
Copyright (C) 2008 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackLockedEngine__
#define __JackLockedEngine__
#include "JackEngine.h"
#include "JackMutex.h"
#include "JackTools.h"
#include "JackException.h"
namespace Jack
{
#define TRY_CALL \
try { \
/*
See : http://groups.google.com/group/comp.programming.threads/browse_thread/thread/652bcf186fbbf697/f63757846514e5e5
catch (...) {
// Assuming thread cancellation, must rethrow
throw;
}
*/
#define CATCH_EXCEPTION_RETURN \
} catch(std::bad_alloc& e) { \
jack_error("Memory allocation error..."); \
return -1; \
} catch(JackTemporaryException& e) { \
jack_error("JackTemporaryException : now quits..."); \
JackTools::KillServer(); \
return -1; \
} catch (...) { \
jack_error("Unknown error..."); \
throw; \
} \
#define CATCH_EXCEPTION \
} catch(std::bad_alloc& e) { \
jack_error("Memory allocation error..."); \
} catch (...) { \
jack_error("Unknown error..."); \
throw; \
} \
/*!
\brief Locked Engine, access to methods is serialized using a mutex.
*/
class SERVER_EXPORT JackLockedEngine
{
private:
JackEngine fEngine;
public:
JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler):
fEngine(manager, table, controler)
{}
~JackLockedEngine()
{}
int Open()
{
// No lock needed
TRY_CALL
return fEngine.Open();
CATCH_EXCEPTION_RETURN
}
int Close()
{
// No lock needed
TRY_CALL
return fEngine.Close();
CATCH_EXCEPTION_RETURN
}
// Client management
int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.ClientCheck(name, name_res, protocol, options, status);
CATCH_EXCEPTION_RETURN
}
int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
CATCH_EXCEPTION_RETURN
}
int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
CATCH_EXCEPTION_RETURN
}
int ClientExternalClose(int refnum)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : - 1;
CATCH_EXCEPTION_RETURN
}
int ClientInternalClose(int refnum, bool wait)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1;
CATCH_EXCEPTION_RETURN
}
int ClientActivate(int refnum, bool is_real_time)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1;
CATCH_EXCEPTION_RETURN
}
int ClientDeactivate(int refnum)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1;
CATCH_EXCEPTION_RETURN
}
// Internal client management
int GetInternalClientName(int int_ref, char* name_res)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.GetInternalClientName(int_ref, name_res);
CATCH_EXCEPTION_RETURN
}
int InternalClientHandle(const char* client_name, int* status, int* int_ref)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.InternalClientHandle(client_name, status, int_ref);
CATCH_EXCEPTION_RETURN
}
int InternalClientUnload(int refnum, int* status)
{
TRY_CALL
JackLock lock(&fEngine);
// Client is tested in fEngine.InternalClientUnload
return fEngine.InternalClientUnload(refnum, status);
CATCH_EXCEPTION_RETURN
}
// Port management
int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortRegister(refnum, name, type, flags, buffer_size, port) : -1;
CATCH_EXCEPTION_RETURN
}
int PortUnRegister(int refnum, jack_port_id_t port)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1;
CATCH_EXCEPTION_RETURN
}
int PortConnect(int refnum, const char* src, const char* dst)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
CATCH_EXCEPTION_RETURN
}
int PortDisconnect(int refnum, const char* src, const char* dst)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
CATCH_EXCEPTION_RETURN
}
int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
CATCH_EXCEPTION_RETURN
}
int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
CATCH_EXCEPTION_RETURN
}
int PortRename(int refnum, jack_port_id_t port, const char* name)
{
TRY_CALL
JackLock lock(&fEngine);
return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1;
CATCH_EXCEPTION_RETURN
}
// Graph
bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
{
// RT : no lock
return fEngine.Process(cur_cycle_begin, prev_cycle_end);
}
// Notifications
void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
{
// RT : no lock
fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
}
void NotifyXRun(int refnum)
{
// RT : no lock
fEngine.NotifyXRun(refnum);
}
void NotifyGraphReorder()
{
TRY_CALL
JackLock lock(&fEngine);
fEngine.NotifyGraphReorder();
CATCH_EXCEPTION
}
void NotifyBufferSize(jack_nframes_t buffer_size)
{
TRY_CALL
JackLock lock(&fEngine);
fEngine.NotifyBufferSize(buffer_size);
CATCH_EXCEPTION
}
void NotifySampleRate(jack_nframes_t sample_rate)
{
TRY_CALL
JackLock lock(&fEngine);
fEngine.NotifySampleRate(sample_rate);
CATCH_EXCEPTION
}
void NotifyFreewheel(bool onoff)
{
TRY_CALL
JackLock lock(&fEngine);
fEngine.NotifyFreewheel(onoff);
CATCH_EXCEPTION
}
void NotifyFailure(int code, const char* reason)
{
TRY_CALL
JackLock lock(&fEngine);
fEngine.NotifyFailure(code, reason);
CATCH_EXCEPTION
}
int GetClientPID(const char* name)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.GetClientPID(name);
CATCH_EXCEPTION_RETURN
}
int GetClientRefNum(const char* name)
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.GetClientRefNum(name);
CATCH_EXCEPTION_RETURN
}
void NotifyQuit()
{
TRY_CALL
JackLock lock(&fEngine);
return fEngine.NotifyQuit();
CATCH_EXCEPTION
}
};
} // end of namespace
#endif
|