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 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 if (!JackMessageBuffer::Create()) {
00067 jack_error("Cannot create message buffer");
00068 }
00069 fGraphManager = -1;
00070 fEngineControl = -1;
00071
00072
00073 #ifdef WIN32
00074
00075 #else
00076 sigset_t signals;
00077 sigemptyset(&signals);
00078 sigaddset(&signals, SIGPIPE);
00079 sigprocmask(SIG_BLOCK, &signals, &fProcessSignals);
00080 #endif
00081 }
00082
00083 ~JackLibGlobals()
00084 {
00085 jack_log("~JackLibGlobals");
00086 for (int i = 0; i < CLIENT_NUM; i++) {
00087 fSynchroTable[i].Disconnect();
00088 }
00089 JackMessageBuffer::Destroy();
00090
00091
00092 #ifdef WIN32
00093
00094 #else
00095 sigprocmask(SIG_BLOCK, &fProcessSignals, 0);
00096 #endif
00097 }
00098
00099 static void Init()
00100 {
00101 if (!JackGlobals::fServerRunning && fClientCount > 0) {
00102
00103
00104 jack_error("Jack server was closed but clients are still allocated, cleanup...");
00105 for (int i = 0; i < CLIENT_NUM; i++) {
00106 JackClient* client = JackGlobals::fClientTable[i];
00107 if (client) {
00108 jack_error("Cleanup client ref = %d", i);
00109 client->Close();
00110 delete client;
00111 }
00112 }
00113
00114
00115 fClientCount = 0;
00116 delete fGlobals;
00117 fGlobals = NULL;
00118 }
00119
00120 if (fClientCount++ == 0 && !fGlobals) {
00121 jack_log("JackLibGlobals Init %x", fGlobals);
00122 InitTime();
00123 fGlobals = new JackLibGlobals();
00124 }
00125 }
00126
00127 static void Destroy()
00128 {
00129 if (--fClientCount == 0 && fGlobals) {
00130 jack_log("JackLibGlobals Destroy %x", fGlobals);
00131 EndTime();
00132 delete fGlobals;
00133 fGlobals = NULL;
00134 }
00135 }
00136
00137 };
00138
00139 }
00140
00141 #endif
00142