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"
26 #include "JackMachPort.h"
29 #include "JackGlobals.h"
39 \brief Global library static structure: singleton kind of pattern.
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 */
48 std::map
<mach_port_t
, JackClient
*> fClientTable
; /*! Client table */
51 static long fClientCount
;
52 static JackLibGlobals
* fGlobals
;
56 JackLog("JackLibGlobals\n");
57 for (int i
= 0; i
< CLIENT_NUM
; i
++)
58 fSynchroTable
[i
] = JackGlobals::MakeSynchro();
63 virtual ~JackLibGlobals()
65 JackLog("~JackLibGlobals\n");
66 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
67 fSynchroTable
[i
]->Disconnect();
68 delete fSynchroTable
[i
];
74 if (fClientCount
++ == 0 && !fGlobals
) {
75 JackLog("JackLibGlobals Init %x\n", fGlobals
);
76 JackGlobals::InitClient();
78 fGlobals
= new JackLibGlobals();
84 if (--fClientCount
== 0 && fGlobals
) {
85 JackLog("JackLibGlobals Destroy %x\n", fGlobals
);
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