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