Jack2 1.9.6

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(JackTemporaryException& e) {                       \
00048         jack_error("JackTemporaryException : now quits...");   \
00049         JackTools::KillServer();                     \
00050         return -1;                                  \
00051     } catch (...) {                                 \
00052         jack_error("Unknown error...");             \
00053         throw;                                      \
00054     }                                               \
00055 
00056 #define CATCH_EXCEPTION                      \
00057     } catch(std::bad_alloc& e) {                    \
00058         jack_error("Memory allocation error...");   \
00059     } catch (...) {                                 \
00060         jack_error("Unknown error...");             \
00061         throw;                                      \
00062     }                                               \
00063 
00064 
00069 class SERVER_EXPORT JackLockedEngine 
00070 {
00071     private:
00072 
00073         JackEngine fEngine;
00074 
00075     public:
00076 
00077         JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler):
00078             fEngine(manager, table, controler)
00079         {}
00080         ~JackLockedEngine()
00081         {}
00082 
00083         int Open()
00084         {
00085             // No lock needed
00086             TRY_CALL
00087             return fEngine.Open();
00088             CATCH_EXCEPTION_RETURN
00089         }
00090         int Close()
00091         {
00092             // No lock needed
00093             TRY_CALL
00094             return fEngine.Close();
00095             CATCH_EXCEPTION_RETURN
00096         }
00097     
00098         // Client management
00099         int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
00100         {
00101             TRY_CALL
00102             JackLock lock(&fEngine);
00103             return fEngine.ClientCheck(name, name_res, protocol, options, status);
00104             CATCH_EXCEPTION_RETURN
00105         }
00106         int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
00107         {
00108             TRY_CALL
00109             JackLock lock(&fEngine);
00110             return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
00111             CATCH_EXCEPTION_RETURN
00112         }
00113         int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
00114         {
00115             TRY_CALL
00116             JackLock lock(&fEngine);
00117             return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
00118             CATCH_EXCEPTION_RETURN
00119         }
00120 
00121         int ClientExternalClose(int refnum)
00122         {
00123             TRY_CALL
00124             JackLock lock(&fEngine);
00125             return (fEngine.CheckClient(refnum)) ? fEngine.ClientExternalClose(refnum) : - 1;
00126             CATCH_EXCEPTION_RETURN
00127         }
00128         int ClientInternalClose(int refnum, bool wait)
00129         {
00130             TRY_CALL
00131             JackLock lock(&fEngine);
00132             return (fEngine.CheckClient(refnum)) ? fEngine.ClientInternalClose(refnum, wait) : -1;
00133             CATCH_EXCEPTION_RETURN
00134         }
00135 
00136         int ClientActivate(int refnum, bool is_real_time)
00137         {
00138             TRY_CALL
00139             JackLock lock(&fEngine);
00140             return (fEngine.CheckClient(refnum)) ? fEngine.ClientActivate(refnum, is_real_time) : -1;
00141             CATCH_EXCEPTION_RETURN
00142         }
00143         int ClientDeactivate(int refnum)
00144         {
00145             TRY_CALL
00146             JackLock lock(&fEngine);
00147             return (fEngine.CheckClient(refnum)) ? fEngine.ClientDeactivate(refnum) : -1;
00148             CATCH_EXCEPTION_RETURN
00149         }
00150 
00151         // Internal client management
00152         int GetInternalClientName(int int_ref, char* name_res)
00153         {
00154             TRY_CALL
00155             JackLock lock(&fEngine);
00156             return fEngine.GetInternalClientName(int_ref, name_res);
00157             CATCH_EXCEPTION_RETURN
00158         }
00159         int InternalClientHandle(const char* client_name, int* status, int* int_ref)
00160         {
00161             TRY_CALL
00162             JackLock lock(&fEngine);
00163             return fEngine.InternalClientHandle(client_name, status, int_ref);
00164             CATCH_EXCEPTION_RETURN
00165         }
00166         int InternalClientUnload(int refnum, int* status)
00167         {
00168             TRY_CALL
00169             JackLock lock(&fEngine);
00170             // Client is tested in fEngine.InternalClientUnload
00171             return fEngine.InternalClientUnload(refnum, status);
00172             CATCH_EXCEPTION_RETURN
00173         }
00174 
00175         // Port management
00176         int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
00177         {
00178             TRY_CALL
00179             JackLock lock(&fEngine);
00180             return (fEngine.CheckClient(refnum)) ? fEngine.PortRegister(refnum, name, type, flags, buffer_size, port) : -1;
00181             CATCH_EXCEPTION_RETURN
00182         }
00183         int PortUnRegister(int refnum, jack_port_id_t port)
00184         {
00185             TRY_CALL
00186             JackLock lock(&fEngine);
00187             return (fEngine.CheckClient(refnum)) ? fEngine.PortUnRegister(refnum, port) : -1;
00188             CATCH_EXCEPTION_RETURN
00189         }
00190 
00191         int PortConnect(int refnum, const char* src, const char* dst)
00192         {
00193             TRY_CALL
00194             JackLock lock(&fEngine);
00195             return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
00196             CATCH_EXCEPTION_RETURN
00197         }
00198         int PortDisconnect(int refnum, const char* src, const char* dst)
00199         {
00200             TRY_CALL
00201             JackLock lock(&fEngine);
00202             return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
00203             CATCH_EXCEPTION_RETURN
00204         }
00205 
00206         int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
00207         {
00208             TRY_CALL
00209             JackLock lock(&fEngine);
00210             return (fEngine.CheckClient(refnum)) ? fEngine.PortConnect(refnum, src, dst) : -1;
00211             CATCH_EXCEPTION_RETURN
00212         }
00213         int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
00214         {
00215             TRY_CALL
00216             JackLock lock(&fEngine);
00217             return (fEngine.CheckClient(refnum)) ? fEngine.PortDisconnect(refnum, src, dst) : -1;
00218             CATCH_EXCEPTION_RETURN
00219         }
00220 
00221         int PortRename(int refnum, jack_port_id_t port, const char* name)
00222         {
00223             TRY_CALL
00224             JackLock lock(&fEngine);
00225             return (fEngine.CheckClient(refnum)) ? fEngine.PortRename(refnum, port, name) : -1;
00226             CATCH_EXCEPTION_RETURN
00227         }
00228 
00229         // Graph
00230         bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
00231         {
00232             // RT : no lock
00233             return fEngine.Process(cur_cycle_begin, prev_cycle_end);
00234         }
00235 
00236         // Notifications
00237         void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
00238         {
00239             // RT : no lock
00240             fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
00241         }
00242 
00243         void NotifyXRun(int refnum)
00244         {
00245             // RT : no lock
00246             fEngine.NotifyXRun(refnum);
00247         }
00248         
00249         void NotifyGraphReorder()
00250         {
00251             TRY_CALL
00252             JackLock lock(&fEngine);
00253             fEngine.NotifyGraphReorder();
00254             CATCH_EXCEPTION
00255         }
00256         void NotifyBufferSize(jack_nframes_t buffer_size)
00257         {
00258             TRY_CALL
00259             JackLock lock(&fEngine);
00260             fEngine.NotifyBufferSize(buffer_size);
00261             CATCH_EXCEPTION
00262         }
00263         void NotifySampleRate(jack_nframes_t sample_rate)
00264         {
00265             TRY_CALL
00266             JackLock lock(&fEngine);
00267             fEngine.NotifySampleRate(sample_rate);
00268             CATCH_EXCEPTION
00269         }
00270         void NotifyFreewheel(bool onoff)
00271         {
00272             TRY_CALL
00273             JackLock lock(&fEngine);
00274             fEngine.NotifyFreewheel(onoff);
00275             CATCH_EXCEPTION
00276         }
00277 
00278         void NotifyFailure(int code, const char* reason)
00279         {
00280             TRY_CALL
00281             JackLock lock(&fEngine);
00282             fEngine.NotifyFailure(code, reason);
00283             CATCH_EXCEPTION
00284         }
00285 
00286         int GetClientPID(const char* name)
00287         {
00288             TRY_CALL
00289             JackLock lock(&fEngine);
00290             return fEngine.GetClientPID(name);
00291             CATCH_EXCEPTION_RETURN
00292         }
00293 
00294         int GetClientRefNum(const char* name)
00295         {
00296             TRY_CALL
00297             JackLock lock(&fEngine);
00298             return fEngine.GetClientRefNum(name);
00299             CATCH_EXCEPTION_RETURN
00300         }
00301     
00302         void NotifyQuit()
00303         {
00304             TRY_CALL
00305             JackLock lock(&fEngine);
00306             return fEngine.NotifyQuit();
00307             CATCH_EXCEPTION
00308         }
00309  
00310 };
00311 
00312 } // end of namespace
00313 
00314 #endif
00315