Jack2  1.9.8
JackLockedEngine.h
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):
00087             fEngine(manager, table, controler)
00088         {}
00089         ~JackLockedEngine()
00090         {}
00091 
00092         int Open()
00093         {
00094             // No lock needed
00095             TRY_CALL
00096             return fEngine.Open();
00097             CATCH_EXCEPTION_RETURN
00098         }
00099         int Close()
00100         {
00101             // No lock needed
00102             TRY_CALL
00103             return fEngine.Close();
00104             CATCH_EXCEPTION_RETURN
00105         }
00106 
00107         // Client management
00108         int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status)
00109         {
00110             TRY_CALL
00111             JackLock lock(&fEngine);
00112             return fEngine.ClientCheck(name, uuid, name_res, protocol, options, status);
00113             CATCH_EXCEPTION_RETURN
00114         }
00115         int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
00116         {
00117             TRY_CALL
00118             JackLock lock(&fEngine);
00119             return fEngine.ClientExternalOpen(name, pid, uuid, ref, shared_engine, shared_client, shared_graph_manager);
00120             CATCH_EXCEPTION_RETURN
00121         }
00122         int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
00123         {
00124             TRY_CALL
00125             JackLock lock(&fEngine);
00126             return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
00127             CATCH_EXCEPTION_RETURN
00128         }
00129 
00130         int ClientExternalClose(int refnum)
00131         {
00132             TRY_CALL
00133             JackLock lock(&fEngine);
00134             return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : -1;
00135             CATCH_CLOSE_EXCEPTION_RETURN
00136         }
00137         int ClientInternalClose(int refnum, bool wait)
00138         {
00139             TRY_CALL
00140             JackLock lock(&fEngine);
00141             return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1;
00142             CATCH_CLOSE_EXCEPTION_RETURN
00143         }
00144 
00145         int ClientActivate(int refnum, bool is_real_time)
00146         {
00147             TRY_CALL
00148             JackLock lock(&fEngine);
00149             return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1;
00150             CATCH_EXCEPTION_RETURN
00151         }
00152         int ClientDeactivate(int refnum)
00153         {
00154             TRY_CALL
00155             JackLock lock(&fEngine);
00156             return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1;
00157             CATCH_EXCEPTION_RETURN
00158         }
00159 
00160         // Internal client management
00161         int GetInternalClientName(int int_ref, char* name_res)
00162         {
00163             TRY_CALL
00164             JackLock lock(&fEngine);
00165             return fEngine.GetInternalClientName(int_ref, name_res);
00166             CATCH_EXCEPTION_RETURN
00167         }
00168         int InternalClientHandle(const char* client_name, int* status, int* int_ref)
00169         {
00170             TRY_CALL
00171             JackLock lock(&fEngine);
00172             return fEngine.InternalClientHandle(client_name, status, int_ref);
00173             CATCH_EXCEPTION_RETURN
00174         }
00175         int InternalClientUnload(int refnum, int* status)
00176         {
00177             TRY_CALL
00178             JackLock lock(&fEngine);
00179             // Client is tested in fEngine.InternalClientUnload
00180             return fEngine.InternalClientUnload(refnum, status);
00181             CATCH_EXCEPTION_RETURN
00182         }
00183 
00184         // Port management
00185         int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
00186         {
00187             TRY_CALL
00188             JackLock lock(&fEngine);
00189             return (fEngine.CheckClient(refnum)) ? fEngine.PortRegister(refnum, name, type, flags, buffer_size, port) : -1;
00190             CATCH_EXCEPTION_RETURN
00191         }
00192         int PortUnRegister(int refnum, jack_port_id_t port)
00193         {
00194             TRY_CALL
00195             JackLock lock(&fEngine);
00196             return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1;
00197             CATCH_EXCEPTION_RETURN
00198         }
00199 
00200         int PortConnect(int refnum, const char* src, const char* dst)
00201         {
00202             TRY_CALL
00203             JackLock lock(&fEngine);
00204             return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
00205             CATCH_EXCEPTION_RETURN
00206         }
00207         int PortDisconnect(int refnum, const char* src, const char* dst)
00208         {
00209             TRY_CALL
00210             JackLock lock(&fEngine);
00211             return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
00212             CATCH_EXCEPTION_RETURN
00213         }
00214 
00215         int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
00216         {
00217             TRY_CALL
00218             JackLock lock(&fEngine);
00219             return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
00220             CATCH_EXCEPTION_RETURN
00221         }
00222         int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
00223         {
00224             TRY_CALL
00225             JackLock lock(&fEngine);
00226             return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
00227             CATCH_EXCEPTION_RETURN
00228         }
00229 
00230         int PortRename(int refnum, jack_port_id_t port, const char* name)
00231         {
00232             TRY_CALL
00233             JackLock lock(&fEngine);
00234             return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1;
00235             CATCH_EXCEPTION_RETURN
00236         }
00237 
00238         int ComputeTotalLatencies()
00239         {
00240             TRY_CALL
00241             JackLock lock(&fEngine);
00242             return fEngine.ComputeTotalLatencies();
00243             CATCH_EXCEPTION_RETURN
00244         }
00245 
00246         // Graph
00247         bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
00248         {
00249             // RT : no lock
00250             return fEngine.Process(cur_cycle_begin, prev_cycle_end);
00251         }
00252 
00253         // Notifications
00254         void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
00255         {
00256             // RT : no lock
00257             fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
00258         }
00259 
00260         void NotifyXRun(int refnum)
00261         {
00262             // RT : no lock
00263             fEngine.NotifyXRun(refnum);
00264         }
00265 
00266         void NotifyGraphReorder()
00267         {
00268             TRY_CALL
00269             JackLock lock(&fEngine);
00270             fEngine.NotifyGraphReorder();
00271             CATCH_EXCEPTION
00272         }
00273 
00274         void NotifyBufferSize(jack_nframes_t buffer_size)
00275         {
00276             TRY_CALL
00277             JackLock lock(&fEngine);
00278             fEngine.NotifyBufferSize(buffer_size);
00279             CATCH_EXCEPTION
00280         }
00281         void NotifySampleRate(jack_nframes_t sample_rate)
00282         {
00283             TRY_CALL
00284             JackLock lock(&fEngine);
00285             fEngine.NotifySampleRate(sample_rate);
00286             CATCH_EXCEPTION
00287         }
00288         void NotifyFreewheel(bool onoff)
00289         {
00290             TRY_CALL
00291             JackLock lock(&fEngine);
00292             fEngine.NotifyFreewheel(onoff);
00293             CATCH_EXCEPTION
00294         }
00295 
00296         void NotifyFailure(int code, const char* reason)
00297         {
00298             TRY_CALL
00299             JackLock lock(&fEngine);
00300             fEngine.NotifyFailure(code, reason);
00301             CATCH_EXCEPTION
00302         }
00303 
00304         int GetClientPID(const char* name)
00305         {
00306             TRY_CALL
00307             JackLock lock(&fEngine);
00308             return fEngine.GetClientPID(name);
00309             CATCH_EXCEPTION_RETURN
00310         }
00311 
00312         int GetClientRefNum(const char* name)
00313         {
00314             TRY_CALL
00315             JackLock lock(&fEngine);
00316             return fEngine.GetClientRefNum(name);
00317             CATCH_EXCEPTION_RETURN
00318         }
00319 
00320         void NotifyQuit()
00321         {
00322             TRY_CALL
00323             JackLock lock(&fEngine);
00324             return fEngine.NotifyQuit();
00325             CATCH_EXCEPTION
00326         }
00327 
00328         void SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket, JackSessionNotifyResult** result)
00329         {
00330             TRY_CALL
00331             JackLock lock(&fEngine);
00332             fEngine.SessionNotify(refnum, target, type, path, socket, result);
00333             CATCH_EXCEPTION
00334         }
00335 
00336         void SessionReply(int refnum)
00337         {
00338             TRY_CALL
00339             JackLock lock(&fEngine);
00340             fEngine.SessionReply(refnum);
00341             CATCH_EXCEPTION
00342         }
00343 
00344         void GetUUIDForClientName(const char *client_name, char *uuid_res, int *result)
00345         {
00346             TRY_CALL
00347             JackLock lock(&fEngine);
00348             fEngine.GetUUIDForClientName(client_name, uuid_res, result);
00349             CATCH_EXCEPTION
00350         }
00351         void GetClientNameForUUID(const char *uuid, char *name_res, int *result)
00352         {
00353             TRY_CALL
00354             JackLock lock(&fEngine);
00355             fEngine.GetClientNameForUUID(uuid, name_res, result);
00356             CATCH_EXCEPTION
00357         }
00358         void ReserveClientName(const char *name, const char *uuid, int *result)
00359         {
00360             TRY_CALL
00361             JackLock lock(&fEngine);
00362             fEngine.ReserveClientName(name, uuid, result);
00363             CATCH_EXCEPTION
00364         }
00365 
00366         void ClientHasSessionCallback(const char *name, int *result)
00367         {
00368             TRY_CALL
00369             JackLock lock(&fEngine);
00370             fEngine.ClientHasSessionCallback(name, result);
00371             CATCH_EXCEPTION
00372         }
00373 };
00374 
00375 } // end of namespace
00376 
00377 #endif
00378