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 Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __JackLibGlobals__
21 #define __JackLibGlobals__
23 #include "JackShmMem.h"
24 #include "JackEngineControl.h"
25 #include "JackGlobals.h"
26 #include "JackPlatformPlug.h"
27 #include "JackGraphManager.h"
28 #include "JackMessageBuffer.h"
30 #include "JackClient.h"
31 #include "JackError.h"
41 \brief Global library static structure: singleton kind of pattern.
46 JackShmReadWritePtr
<JackGraphManager
> fGraphManager
; /*! Shared memory Port manager */
47 JackShmReadWritePtr
<JackEngineControl
> fEngineControl
; /*! Shared engine control */ // transport engine has to be writable
48 JackSynchro fSynchroTable
[CLIENT_NUM
]; /*! Shared synchro table */
49 sigset_t fProcessSignals
;
51 static int fClientCount
;
52 static JackLibGlobals
* fGlobals
;
56 jack_log("JackLibGlobals");
57 JackMessageBuffer::Create();
61 // Filter SIGPIPE to avoid having client get a SIGPIPE when trying to access a died server.
66 sigemptyset(&signals
);
67 sigaddset(&signals
, SIGPIPE
);
68 sigprocmask(SIG_BLOCK
, &signals
, &fProcessSignals
);
74 jack_log("~JackLibGlobals");
75 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
76 fSynchroTable
[i
].Disconnect();
78 JackMessageBuffer::Destroy();
80 // Restore old signal mask
84 sigprocmask(SIG_BLOCK
, &fProcessSignals
, 0);
90 if (!JackGlobals::fServerRunning
&& fClientCount
> 0) {
92 // Cleanup remaining clients
93 jack_error("Jack server was closed but clients are still allocated, cleanup...");
94 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
95 JackClient
* client
= JackGlobals::fClientTable
[i
];
97 jack_error("Cleanup client ref = %d", i
);
100 JackGlobals::fClientTable
[CLIENT_NUM
] = NULL
;
104 // Cleanup global context
110 if (fClientCount
++ == 0 && !fGlobals
) {
111 jack_log("JackLibGlobals Init %x", fGlobals
);
113 fGlobals
= new JackLibGlobals();
117 static void Destroy()
119 if (--fClientCount
== 0 && fGlobals
) {
120 jack_log("JackLibGlobals Destroy %x", fGlobals
);
126 static void CheckContext()
128 if (!(fClientCount
> 0 && fGlobals
)) {
129 jack_error("Error !!! : client accessing an already desallocated library context");
135 } // end of namespace