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"
37 #include <sys/types.h>
38 typedef _sigset_t sigset_t
;
40 typedef HANDLE sigset_t
;
50 \brief Global library static structure: singleton kind of pattern.
55 JackShmReadWritePtr
<JackGraphManager
> fGraphManager
; /*! Shared memory Port manager */
56 JackShmReadWritePtr
<JackEngineControl
> fEngineControl
; /*! Shared engine control */ // transport engine has to be writable
57 JackSynchro fSynchroTable
[CLIENT_NUM
]; /*! Shared synchro table */
58 sigset_t fProcessSignals
;
60 static int fClientCount
;
61 static JackLibGlobals
* fGlobals
;
65 jack_log("JackLibGlobals");
66 if (!JackMessageBuffer::Create()) {
67 jack_error("Cannot create message buffer");
72 // Filter SIGPIPE to avoid having client get a SIGPIPE when trying to access a died server.
77 sigemptyset(&signals
);
78 sigaddset(&signals
, SIGPIPE
);
79 sigprocmask(SIG_BLOCK
, &signals
, &fProcessSignals
);
85 jack_log("~JackLibGlobals");
86 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
87 fSynchroTable
[i
].Disconnect();
89 JackMessageBuffer::Destroy();
91 // Restore old signal mask
95 sigprocmask(SIG_BLOCK
, &fProcessSignals
, 0);
101 if (!JackGlobals::fServerRunning
&& fClientCount
> 0) {
103 // Cleanup remaining clients
104 jack_error("Jack server was closed but clients are still allocated, cleanup...");
105 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
106 JackClient
* client
= JackGlobals::fClientTable
[i
];
108 jack_error("Cleanup client ref = %d", i
);
111 JackGlobals::fClientTable
[CLIENT_NUM
] = NULL
;
115 // Cleanup global context
121 if (fClientCount
++ == 0 && !fGlobals
) {
122 jack_log("JackLibGlobals Init %x", fGlobals
);
124 fGlobals
= new JackLibGlobals();
128 static void Destroy()
130 if (--fClientCount
== 0 && fGlobals
) {
131 jack_log("JackLibGlobals Destroy %x", fGlobals
);
140 } // end of namespace