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