2 Copyright (C) 2004-2006 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 #include "JackLibClient.h"
22 #include "JackLibGlobals.h"
23 #include "JackGlobals.h"
24 #include "JackChannel.h"
29 // Used for external C API (JackAPI.cpp)
30 JackGraphManager
* GetGraphManager()
32 assert(JackLibGlobals::fGlobals
->fGraphManager
);
33 return JackLibGlobals::fGlobals
->fGraphManager
;
36 JackEngineControl
* GetEngineControl()
38 assert(JackLibGlobals::fGlobals
->fEngineControl
);
39 return JackLibGlobals::fGlobals
->fEngineControl
;
42 JackSynchro
** GetSynchroTable()
44 assert(JackLibGlobals::fGlobals
);
45 return JackLibGlobals::fGlobals
->fSynchroTable
;
52 JackLibClient::JackLibClient(JackSynchro
** table
): JackClient(table
)
54 JackLog("JackLibClient::JackLibClient table = %x\n", table
);
55 fChannel
= JackGlobals::MakeClientChannel();
58 JackLibClient::~JackLibClient()
60 JackLog("JackLibClient::~JackLibClient\n");
64 int JackLibClient::Open(const char* name
)
66 int shared_engine
, shared_client
, shared_graph
, result
;
67 JackLog("JackLibClient::Open %s\n", name
);
69 // Open server/client channel
70 if (fChannel
->Open(name
, this) < 0) {
71 jack_error("Cannot connect to the server");
75 // Start receiving notifications
76 if (fChannel
->Start() < 0) {
77 jack_error("Cannot start channel");
82 fChannel
->ClientOpen(name
, &shared_engine
, &shared_client
, &shared_graph
, &result
);
84 jack_error("Cannot open %s client", name
);
89 // Map shared memory segments
90 JackLibGlobals::fGlobals
->fEngineControl
= shared_engine
;
91 JackLibGlobals::fGlobals
->fGraphManager
= shared_graph
;
92 fClientControl
= shared_client
;
93 jack_verbose
= GetEngineControl()->fVerbose
;
95 jack_error("Map shared memory segments exception %d", n
);
99 SetupDriverSync(false);
101 /* TODO : solve WIN32 thread Kill issue
103 // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process
104 if (!fSynchroTable[fClientControl->fRefNum]->Connect(name)) {
105 jack_error("Cannot ConnectSemaphore %s client", name);
110 // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process
111 if (!fSynchroTable
[fClientControl
->fRefNum
]->Connect(name
)) {
112 jack_error("Cannot ConnectSemaphore %s client", name
);
116 JackLog("JackLibClient::Open name = %s refnum = %ld\n", name
, fClientControl
->fRefNum
);
126 // Notifications received from the server
127 // TODO this should be done once for all clients in the process, when a shared notification channel
128 // will be shared by all clients...
129 int JackLibClient::ClientNotifyImp(int refnum
, const char* name
, int notify
, int sync
, int value
)
136 case JackNotifyChannelInterface::kAddClient
:
137 JackLog("JackClient::AddClient name = %s, ref = %ld \n", name
, refnum
);
138 // the synchro must be usable in I/O mode when several clients live in the same process
139 res
= fSynchroTable
[refnum
]->Connect(name
) ? 0 : -1;
142 case JackNotifyChannelInterface::kRemoveClient
:
143 JackLog("JackClient::RemoveClient name = %s, ref = %ld \n", name
, refnum
);
144 if (strcmp(GetClientControl()->fName
, name
) != 0)
145 res
= fSynchroTable
[refnum
]->Disconnect() ? 0 : -1;
152 JackGraphManager
* JackLibClient::GetGraphManager() const
154 assert(JackLibGlobals::fGlobals
->fGraphManager
);
155 return JackLibGlobals::fGlobals
->fGraphManager
;
158 JackEngineControl
* JackLibClient::GetEngineControl() const
160 assert(JackLibGlobals::fGlobals
->fEngineControl
);
161 return JackLibGlobals::fGlobals
->fEngineControl
;
164 JackClientControl
* JackLibClient::GetClientControl() const
166 return fClientControl
;
169 } // end of namespace