JackLibGlobals.h

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 "JackTime.h"
00031 #include <assert.h>
00032 
00033 namespace Jack
00034 {
00035 
00036 class JackClient;
00037 
00042 struct JackLibGlobals
00043 {
00044     JackShmReadWritePtr<JackGraphManager> fGraphManager;        
00045     JackShmReadWritePtr<JackEngineControl> fEngineControl;        // transport engine has to be writable
00046     JackSynchro* fSynchroTable[CLIENT_NUM];                                     
00047 #ifdef __APPLE__
00048     std::map<mach_port_t, JackClient*> fClientTable;        
00049 #endif
00050 
00051     static long fClientCount;
00052     static JackLibGlobals* fGlobals;
00053 
00054     JackLibGlobals()
00055     {
00056         JackLog("JackLibGlobals\n");
00057         for (int i = 0; i < CLIENT_NUM; i++)
00058             fSynchroTable[i] = JackGlobals::MakeSynchro();
00059         fGraphManager = -1;
00060         fEngineControl = -1;
00061     }
00062 
00063     virtual ~JackLibGlobals()
00064     {
00065         JackLog("~JackLibGlobals\n");
00066         for (int i = 0; i < CLIENT_NUM; i++) {
00067             fSynchroTable[i]->Disconnect();
00068             delete fSynchroTable[i];
00069         }
00070     }
00071 
00072     static void Init()
00073     {
00074         if (fClientCount++ == 0 && !fGlobals) {
00075             JackLog("JackLibGlobals Init %x\n", fGlobals);
00076             JackGlobals::InitClient();
00077             InitTime();
00078             fGlobals = new JackLibGlobals();
00079            }
00080     }
00081 
00082     static void Destroy()
00083     {
00084         if (--fClientCount == 0 && fGlobals) {
00085             JackLog("JackLibGlobals Destroy %x\n", fGlobals);
00086             delete fGlobals;
00087             fGlobals = NULL;
00088             JackGlobals::Destroy();
00089         }
00090     }
00091 
00092 };
00093 
00094 } // end of namespace
00095 
00096 #endif
00097 

Generated on Wed Jan 10 11:42:45 2007 for Jackdmp by  doxygen 1.4.5