More client debug code: check if the client is still valid in every JackDebugClient...
[jack2.git] / common / JackLibGlobals.h
blobf423a455faced7a7083931481e9dc5ccb4549907
1 /*
2 Copyright (C) 2005 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JackLibGlobals__
21 #define __JackLibGlobals__
23 #include "JackShmMem.h"
24 #include "JackEngineControl.h"
25 #ifdef __APPLE__
26 #include "JackMachPort.h"
27 #include <map>
28 #endif
29 #include "JackGlobals.h"
30 #include "JackTime.h"
31 #include <assert.h>
33 namespace Jack
36 class JackClient;
38 /*!
39 \brief Global library static structure: singleton kind of pattern.
42 struct JackLibGlobals
44 JackShmReadWritePtr<JackGraphManager> fGraphManager; /*! Shared memory Port manager */
45 JackShmReadWritePtr<JackEngineControl> fEngineControl; /*! Shared engine control */ // transport engine has to be writable
46 JackSynchro* fSynchroTable[CLIENT_NUM]; /*! Shared synchro table */
47 #ifdef __APPLE__
48 std::map<mach_port_t, JackClient*> fClientTable; /*! Client table */
49 #endif
51 static long fClientCount;
52 static JackLibGlobals* fGlobals;
54 JackLibGlobals()
56 JackLog("JackLibGlobals\n");
57 for (int i = 0; i < CLIENT_NUM; i++)
58 fSynchroTable[i] = JackGlobals::MakeSynchro();
59 fGraphManager = -1;
60 fEngineControl = -1;
63 virtual ~JackLibGlobals()
65 JackLog("~JackLibGlobals\n");
66 for (int i = 0; i < CLIENT_NUM; i++) {
67 fSynchroTable[i]->Disconnect();
68 delete fSynchroTable[i];
72 static void Init()
74 if (fClientCount++ == 0 && !fGlobals) {
75 JackLog("JackLibGlobals Init %x\n", fGlobals);
76 JackGlobals::InitClient();
77 InitTime();
78 fGlobals = new JackLibGlobals();
82 static void Destroy()
84 if (--fClientCount == 0 && fGlobals) {
85 JackLog("JackLibGlobals Destroy %x\n", fGlobals);
86 delete fGlobals;
87 fGlobals = NULL;
88 JackGlobals::Destroy();
92 static void CheckContext()
94 if (!(fClientCount > 0 && fGlobals))
95 jack_error("Error !!! : client accessing an already desallocated library context");
100 } // end of namespace
102 #endif