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 "JackClient.h"
00031 #include "JackError.h"
00032 #include <assert.h>
00033 #include <signal.h>
00034
00035 #ifdef WIN32
00036 #ifdef __MINGW32__
00037 #include <sys/types.h>
00038 typedef _sigset_t sigset_t;
00039 #else
00040 typedef HANDLE sigset_t;
00041 #endif
00042 #endif
00043
00044 namespace Jack
00045 {
00046
00047 class JackClient;
00048
00053 struct LIB_EXPORT JackLibGlobals
00054 {
00055 JackShmReadWritePtr<JackGraphManager> fGraphManager;
00056 JackShmReadWritePtr<JackEngineControl> fEngineControl;
00057 JackSynchro fSynchroTable[CLIENT_NUM];
00058 sigset_t fProcessSignals;
00059
00060 static int fClientCount;
00061 static JackLibGlobals* fGlobals;
00062
00063 JackLibGlobals()
00064 {
00065 jack_log("JackLibGlobals");
00066 JackMessageBuffer::Create();
00067 fGraphManager = -1;
00068 fEngineControl = -1;
00069
00070
00071 #ifdef WIN32
00072
00073 #else
00074 sigset_t signals;
00075 sigemptyset(&signals);
00076 sigaddset(&signals, SIGPIPE);
00077 sigprocmask(SIG_BLOCK, &signals, &fProcessSignals);
00078 #endif
00079 }
00080
00081 ~JackLibGlobals()
00082 {
00083 jack_log("~JackLibGlobals");
00084 for (int i = 0; i < CLIENT_NUM; i++) {
00085 fSynchroTable[i].Disconnect();
00086 }
00087 JackMessageBuffer::Destroy();
00088
00089
00090 #ifdef WIN32
00091
00092 #else
00093 sigprocmask(SIG_BLOCK, &fProcessSignals, 0);
00094 #endif
00095 }
00096
00097 static void Init()
00098 {
00099 if (!JackGlobals::fServerRunning && fClientCount > 0) {
00100
00101
00102 jack_error("Jack server was closed but clients are still allocated, cleanup...");
00103 for (int i = 0; i < CLIENT_NUM; i++) {
00104 JackClient* client = JackGlobals::fClientTable[i];
00105 if (client) {
00106 jack_error("Cleanup client ref = %d", i);
00107 client->Close();
00108 delete client;
00109 JackGlobals::fClientTable[CLIENT_NUM] = NULL;
00110 }
00111 }
00112
00113
00114 fClientCount = 0;
00115 delete fGlobals;
00116 fGlobals = NULL;
00117 }
00118
00119 if (fClientCount++ == 0 && !fGlobals) {
00120 jack_log("JackLibGlobals Init %x", fGlobals);
00121 InitTime();
00122 fGlobals = new JackLibGlobals();
00123 }
00124 }
00125
00126 static void Destroy()
00127 {
00128 if (--fClientCount == 0 && fGlobals) {
00129 jack_log("JackLibGlobals Destroy %x", fGlobals);
00130 delete fGlobals;
00131 fGlobals = NULL;
00132 }
00133 }
00134
00135 };
00136
00137 }
00138
00139 #endif
00140