Jack2
1.9.10
|
00001 /* 00002 Copyright (C) 2008 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #ifndef __JackLockedEngine__ 00021 #define __JackLockedEngine__ 00022 00023 #include "JackEngine.h" 00024 #include "JackMutex.h" 00025 #include "JackTools.h" 00026 #include "JackException.h" 00027 00028 namespace Jack 00029 { 00030 00031 #define TRY_CALL \ 00032 try { \ 00033 00034 /* 00035 See : http://groups.google.com/group/comp.programming.threads/browse_thread/thread/652bcf186fbbf697/f63757846514e5e5 00036 00037 catch (...) { 00038 // Assuming thread cancellation, must rethrow 00039 throw; 00040 } 00041 */ 00042 00043 #define CATCH_EXCEPTION_RETURN \ 00044 } catch (std::bad_alloc& e) { \ 00045 jack_error("Memory allocation error..."); \ 00046 return -1; \ 00047 } catch (...) { \ 00048 jack_error("Unknown error..."); \ 00049 throw; \ 00050 } \ 00051 00052 #define CATCH_CLOSE_EXCEPTION_RETURN \ 00053 } catch (std::bad_alloc& e) { \ 00054 jack_error("Memory allocation error..."); \ 00055 return -1; \ 00056 } catch (JackTemporaryException& e) { \ 00057 jack_error("JackTemporaryException : now quits..."); \ 00058 JackTools::KillServer(); \ 00059 return 0; \ 00060 } catch (...) { \ 00061 jack_error("Unknown error..."); \ 00062 throw; \ 00063 } 00064 00065 #define CATCH_EXCEPTION \ 00066 } catch (std::bad_alloc& e) { \ 00067 jack_error("Memory allocation error..."); \ 00068 } catch (...) { \ 00069 jack_error("Unknown error..."); \ 00070 throw; \ 00071 } \ 00072 00073 00078 class SERVER_EXPORT JackLockedEngine 00079 { 00080 private: 00081 00082 JackEngine fEngine; 00083 00084 public: 00085 00086 JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode): 00087 fEngine(manager, table, controler, self_connect_mode) 00088 {} 00089 ~JackLockedEngine() 00090 {} 00091 00092 bool Lock() { return fEngine.Lock(); } 00093 bool Unlock() { return fEngine.Unlock(); } 00094 bool Trylock() { return fEngine.Trylock(); } 00095 00096 int Open() 00097 { 00098 // No lock needed 00099 TRY_CALL 00100 return fEngine.Open(); 00101 CATCH_EXCEPTION_RETURN 00102 } 00103 int Close() 00104 { 00105 // No lock needed 00106 TRY_CALL 00107 return fEngine.Close(); 00108 CATCH_EXCEPTION_RETURN 00109 } 00110 00111 // Client management 00112 int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status) 00113 { 00114 TRY_CALL 00115 JackLock lock(&fEngine); 00116 return fEngine.ClientCheck(name, uuid, name_res, protocol, options, status); 00117 CATCH_EXCEPTION_RETURN 00118 } 00119 int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) 00120 { 00121 TRY_CALL 00122 JackLock lock(&fEngine); 00123 return fEngine.ClientExternalOpen(name, pid, uuid, ref, shared_engine, shared_client, shared_graph_manager); 00124 CATCH_EXCEPTION_RETURN 00125 } 00126 int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait) 00127 { 00128 TRY_CALL 00129 JackLock lock(&fEngine); 00130 return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait); 00131 CATCH_EXCEPTION_RETURN 00132 } 00133 00134 int ClientExternalClose(int refnum) 00135 { 00136 TRY_CALL 00137 JackLock lock(&fEngine); 00138 return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : -1; 00139 CATCH_CLOSE_EXCEPTION_RETURN 00140 } 00141 int ClientInternalClose(int refnum, bool wait) 00142 { 00143 TRY_CALL 00144 JackLock lock(&fEngine); 00145 return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1; 00146 CATCH_CLOSE_EXCEPTION_RETURN 00147 } 00148 00149 int ClientActivate(int refnum, bool is_real_time) 00150 { 00151 TRY_CALL 00152 JackLock lock(&fEngine); 00153 return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1; 00154 CATCH_EXCEPTION_RETURN 00155 } 00156 int ClientDeactivate(int refnum) 00157 { 00158 TRY_CALL 00159 JackLock lock(&fEngine); 00160 return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1; 00161 CATCH_EXCEPTION_RETURN 00162 } 00163 void ClientKill(int refnum) 00164 { 00165 TRY_CALL 00166 JackLock lock(&fEngine); 00167 fEngine.ClientKill(refnum); 00168 CATCH_EXCEPTION 00169 } 00170 00171 // Internal client management 00172 int GetInternalClientName(int int_ref, char* name_res) 00173 { 00174 TRY_CALL 00175 JackLock lock(&fEngine); 00176 return fEngine.GetInternalClientName(int_ref, name_res); 00177 CATCH_EXCEPTION_RETURN 00178 } 00179 int InternalClientHandle(const char* client_name, int* status, int* int_ref) 00180 { 00181 TRY_CALL 00182 JackLock lock(&fEngine); 00183 return fEngine.InternalClientHandle(client_name, status, int_ref); 00184 CATCH_EXCEPTION_RETURN 00185 } 00186 int InternalClientUnload(int refnum, int* status) 00187 { 00188 TRY_CALL 00189 JackLock lock(&fEngine); 00190 // Client is tested in fEngine.InternalClientUnload 00191 return fEngine.InternalClientUnload(refnum, status); 00192 CATCH_EXCEPTION_RETURN 00193 } 00194 00195 // Port management 00196 int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port) 00197 { 00198 TRY_CALL 00199 JackLock lock(&fEngine); 00200 return (fEngine.CheckClient(refnum)) ? fEngine.PortRegister(refnum, name, type, flags, buffer_size, port) : -1; 00201 CATCH_EXCEPTION_RETURN 00202 } 00203 int PortUnRegister(int refnum, jack_port_id_t port) 00204 { 00205 TRY_CALL 00206 JackLock lock(&fEngine); 00207 return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1; 00208 CATCH_EXCEPTION_RETURN 00209 } 00210 00211 int PortConnect(int refnum, const char* src, const char* dst) 00212 { 00213 TRY_CALL 00214 JackLock lock(&fEngine); 00215 return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1; 00216 CATCH_EXCEPTION_RETURN 00217 } 00218 int PortDisconnect(int refnum, const char* src, const char* dst) 00219 { 00220 TRY_CALL 00221 JackLock lock(&fEngine); 00222 return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1; 00223 CATCH_EXCEPTION_RETURN 00224 } 00225 00226 int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst) 00227 { 00228 TRY_CALL 00229 JackLock lock(&fEngine); 00230 return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1; 00231 CATCH_EXCEPTION_RETURN 00232 } 00233 int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst) 00234 { 00235 TRY_CALL 00236 JackLock lock(&fEngine); 00237 return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1; 00238 CATCH_EXCEPTION_RETURN 00239 } 00240 00241 int PortRename(int refnum, jack_port_id_t port, const char* name) 00242 { 00243 TRY_CALL 00244 JackLock lock(&fEngine); 00245 return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1; 00246 CATCH_EXCEPTION_RETURN 00247 } 00248 00249 int ComputeTotalLatencies() 00250 { 00251 TRY_CALL 00252 JackLock lock(&fEngine); 00253 return fEngine.ComputeTotalLatencies(); 00254 CATCH_EXCEPTION_RETURN 00255 } 00256 00257 // Graph 00258 bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end) 00259 { 00260 // RT : no lock 00261 return fEngine.Process(cur_cycle_begin, prev_cycle_end); 00262 } 00263 00264 // Notifications 00265 void NotifyDriverXRun() 00266 { 00267 // Coming from the driver in RT : no lock 00268 fEngine.NotifyDriverXRun(); 00269 } 00270 00271 void NotifyClientXRun(int refnum) 00272 { 00273 TRY_CALL 00274 JackLock lock(&fEngine); 00275 fEngine.NotifyClientXRun(refnum); 00276 CATCH_EXCEPTION 00277 } 00278 00279 void NotifyGraphReorder() 00280 { 00281 TRY_CALL 00282 JackLock lock(&fEngine); 00283 fEngine.NotifyGraphReorder(); 00284 CATCH_EXCEPTION 00285 } 00286 00287 void NotifyBufferSize(jack_nframes_t buffer_size) 00288 { 00289 TRY_CALL 00290 JackLock lock(&fEngine); 00291 fEngine.NotifyBufferSize(buffer_size); 00292 CATCH_EXCEPTION 00293 } 00294 void NotifySampleRate(jack_nframes_t sample_rate) 00295 { 00296 TRY_CALL 00297 JackLock lock(&fEngine); 00298 fEngine.NotifySampleRate(sample_rate); 00299 CATCH_EXCEPTION 00300 } 00301 void NotifyFreewheel(bool onoff) 00302 { 00303 TRY_CALL 00304 JackLock lock(&fEngine); 00305 fEngine.NotifyFreewheel(onoff); 00306 CATCH_EXCEPTION 00307 } 00308 00309 void NotifyFailure(int code, const char* reason) 00310 { 00311 TRY_CALL 00312 JackLock lock(&fEngine); 00313 fEngine.NotifyFailure(code, reason); 00314 CATCH_EXCEPTION 00315 } 00316 00317 int GetClientPID(const char* name) 00318 { 00319 TRY_CALL 00320 JackLock lock(&fEngine); 00321 return fEngine.GetClientPID(name); 00322 CATCH_EXCEPTION_RETURN 00323 } 00324 00325 int GetClientRefNum(const char* name) 00326 { 00327 TRY_CALL 00328 JackLock lock(&fEngine); 00329 return fEngine.GetClientRefNum(name); 00330 CATCH_EXCEPTION_RETURN 00331 } 00332 00333 void NotifyQuit() 00334 { 00335 // No lock needed 00336 TRY_CALL 00337 return fEngine.NotifyQuit(); 00338 CATCH_EXCEPTION 00339 } 00340 00341 void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result) 00342 { 00343 TRY_CALL 00344 JackLock lock(&fEngine); 00345 fEngine.SessionNotify(refnum, target, type, path, socket, result); 00346 CATCH_EXCEPTION 00347 } 00348 00349 int SessionReply(int refnum) 00350 { 00351 TRY_CALL 00352 JackLock lock(&fEngine); 00353 return fEngine.SessionReply(refnum); 00354 CATCH_EXCEPTION_RETURN 00355 } 00356 00357 int GetUUIDForClientName(const char *client_name, char *uuid_res) 00358 { 00359 TRY_CALL 00360 JackLock lock(&fEngine); 00361 return fEngine.GetUUIDForClientName(client_name, uuid_res); 00362 CATCH_EXCEPTION_RETURN 00363 } 00364 int GetClientNameForUUID(const char *uuid, char *name_res) 00365 { 00366 TRY_CALL 00367 JackLock lock(&fEngine); 00368 return fEngine.GetClientNameForUUID(uuid, name_res); 00369 CATCH_EXCEPTION_RETURN 00370 } 00371 int ReserveClientName(const char *name, const char *uuid) 00372 { 00373 TRY_CALL 00374 JackLock lock(&fEngine); 00375 return fEngine.ReserveClientName(name, uuid); 00376 CATCH_EXCEPTION_RETURN 00377 } 00378 00379 int ClientHasSessionCallback(const char *name) 00380 { 00381 TRY_CALL 00382 JackLock lock(&fEngine); 00383 return fEngine.ClientHasSessionCallback(name); 00384 CATCH_EXCEPTION_RETURN 00385 } 00386 }; 00387 00388 } // end of namespace 00389 00390 #endif 00391