Unused variable.
[jack2.git] / common / JackLibGlobals.h
blobf109b6658047ae0ba1e318cc3e597a3f04101a06
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 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"
29 #include "JackTime.h"
30 #include "JackClient.h"
31 #include "JackError.h"
32 #include <assert.h>
33 #include <signal.h>
35 namespace Jack
38 class JackClient;
40 /*!
41 \brief Global library static structure: singleton kind of pattern.
44 struct JackLibGlobals
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;
54 JackLibGlobals()
56 jack_log("JackLibGlobals");
57 JackMessageBuffer::Create();
58 fGraphManager = -1;
59 fEngineControl = -1;
61 // Filter SIGPIPE to avoid having client get a SIGPIPE when trying to access a died server.
62 #ifdef WIN32
63 // TODO
64 #else
65 sigset_t signals;
66 sigemptyset(&signals);
67 sigaddset(&signals, SIGPIPE);
68 sigprocmask(SIG_BLOCK, &signals, &fProcessSignals);
69 #endif
72 ~JackLibGlobals()
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
81 #ifdef WIN32
82 // TODO
83 #else
84 sigprocmask(SIG_BLOCK, &fProcessSignals, 0);
85 #endif
88 static void Init()
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];
96 if (client) {
97 jack_error("Cleanup client ref = %d", i);
98 client->Close();
99 delete client;
100 JackGlobals::fClientTable[CLIENT_NUM] = NULL;
104 // Cleanup global context
105 fClientCount = 0;
106 delete fGlobals;
107 fGlobals = NULL;
110 if (fClientCount++ == 0 && !fGlobals) {
111 jack_log("JackLibGlobals Init %x", fGlobals);
112 InitTime();
113 fGlobals = new JackLibGlobals();
117 static void Destroy()
119 if (--fClientCount == 0 && fGlobals) {
120 jack_log("JackLibGlobals Destroy %x", fGlobals);
121 delete fGlobals;
122 fGlobals = NULL;
126 static void CheckContext()
128 if (!(fClientCount > 0 && fGlobals)) {
129 jack_error("Error !!! : client accessing an already desallocated library context");
135 } // end of namespace
137 #endif