00001 /* 00002 Copyright (C) 2005 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #ifndef __JackLibGlobals__ 00021 #define __JackLibGlobals__ 00022 00023 #include "JackShmMem.h" 00024 #include "JackEngineControl.h" 00025 #ifdef __APPLE__ 00026 #include "JackMachPort.h" 00027 #include <map> 00028 #endif 00029 #include "JackGlobals.h" 00030 #include "JackGraphManager.h" 00031 #include "JackTime.h" 00032 #include <assert.h> 00033 00034 namespace Jack 00035 { 00036 00037 class JackClient; 00038 00043 struct JackLibGlobals 00044 { 00045 JackShmReadWritePtr<JackGraphManager> fGraphManager; 00046 JackShmReadWritePtr<JackEngineControl> fEngineControl; // transport engine has to be writable 00047 JackSynchro* fSynchroTable[CLIENT_NUM]; 00048 #ifdef __APPLE__ 00049 std::map<mach_port_t, JackClient*> fClientTable; 00050 #endif 00051 00052 static int fClientCount; 00053 static JackLibGlobals* fGlobals; 00054 00055 JackLibGlobals() 00056 { 00057 JackLog("JackLibGlobals\n"); 00058 for (int i = 0; i < CLIENT_NUM; i++) 00059 fSynchroTable[i] = JackGlobals::MakeSynchro(); 00060 fGraphManager = -1; 00061 fEngineControl = -1; 00062 } 00063 00064 virtual ~JackLibGlobals() 00065 { 00066 JackLog("~JackLibGlobals\n"); 00067 for (int i = 0; i < CLIENT_NUM; i++) { 00068 fSynchroTable[i]->Disconnect(); 00069 delete fSynchroTable[i]; 00070 } 00071 } 00072 00073 static void Init() 00074 { 00075 if (fClientCount++ == 0 && !fGlobals) { 00076 JackLog("JackLibGlobals Init %x\n", fGlobals); 00077 JackGlobals::InitClient(); 00078 InitTime(); 00079 fGlobals = new JackLibGlobals(); 00080 } 00081 } 00082 00083 static void Destroy() 00084 { 00085 if (--fClientCount == 0 && fGlobals) { 00086 JackLog("JackLibGlobals Destroy %x\n", fGlobals); 00087 delete fGlobals; 00088 fGlobals = NULL; 00089 JackGlobals::Destroy(); 00090 } 00091 } 00092 00093 static void CheckContext() 00094 { 00095 if (!(fClientCount > 0 && fGlobals)) { 00096 jack_error("Error !!! : client accessing an already desallocated library context"); 00097 } 00098 } 00099 00100 }; 00101 00102 } // end of namespace 00103 00104 #endif 00105