00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackLibGlobals__
00021 #define __JackLibGlobals__
00022
00023 #include "JackShmMem.h"
00024 #include "JackEngineControl.h"
00025 #include "JackGlobals.h"
00026 #include "JackPlatformPlug.h"
00027 #include "JackGraphManager.h"
00028 #include "JackMessageBuffer.h"
00029 #include "JackTime.h"
00030 #include "JackError.h"
00031 #include <assert.h>
00032 #include <signal.h>
00033
00034 namespace Jack
00035 {
00036
00037 class JackClient;
00038
00043 struct JackLibGlobals
00044 {
00045 JackShmReadWritePtr<JackGraphManager> fGraphManager;
00046 JackShmReadWritePtr<JackEngineControl> fEngineControl;
00047 JackSynchro fSynchroTable[CLIENT_NUM];
00048 sigset_t fProcessSignals;
00049
00050 static int fClientCount;
00051 static JackLibGlobals* fGlobals;
00052
00053 JackLibGlobals()
00054 {
00055 jack_log("JackLibGlobals");
00056 JackMessageBuffer::Create();
00057 fGraphManager = -1;
00058 fEngineControl = -1;
00059
00060
00061 #ifdef WIN32
00062
00063 #else
00064 sigset_t signals;
00065 sigemptyset(&signals);
00066 sigaddset(&signals, SIGPIPE);
00067 sigprocmask(SIG_BLOCK, &signals, &fProcessSignals);
00068 #endif
00069 }
00070
00071 ~JackLibGlobals()
00072 {
00073 jack_log("~JackLibGlobals");
00074 for (int i = 0; i < CLIENT_NUM; i++) {
00075 fSynchroTable[i].Disconnect();
00076 }
00077 JackMessageBuffer::Destroy();
00078
00079
00080 #ifdef WIN32
00081
00082 #else
00083 sigprocmask(SIG_BLOCK, &fProcessSignals, 0);
00084 #endif
00085 }
00086
00087 static void Init()
00088 {
00089 if (fClientCount++ == 0 && !fGlobals) {
00090 jack_log("JackLibGlobals Init %x", fGlobals);
00091 InitTime();
00092 fGlobals = new JackLibGlobals();
00093 }
00094 }
00095
00096 static void Destroy()
00097 {
00098 if (--fClientCount == 0 && fGlobals) {
00099 jack_log("JackLibGlobals Destroy %x", fGlobals);
00100 delete fGlobals;
00101 fGlobals = NULL;
00102 }
00103 }
00104
00105 static void CheckContext()
00106 {
00107 if (!(fClientCount > 0 && fGlobals)) {
00108 jack_error("Error !!! : client accessing an already desallocated library context");
00109 }
00110 }
00111
00112 };
00113
00114 }
00115
00116 #endif
00117