Jack2 1.9.12

JackInternalClient.cpp
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "JackSystemDeps.h"
22 #include "JackServerGlobals.h"
23 #include "JackGraphManager.h"
24 #include "JackConstants.h"
25 #include "JackInternalClient.h"
26 #include "JackLockedEngine.h"
27 #include "JackServer.h"
28 #include "JackEngineControl.h"
29 #include "JackClientControl.h"
30 #include "JackInternalClientChannel.h"
31 #include "JackTools.h"
32 #include <assert.h>
33
34 namespace Jack
35 {
36
37 JackGraphManager* JackInternalClient::fGraphManager = NULL;
38 JackEngineControl* JackInternalClient::fEngineControl = NULL;
39
40 // Used for external C API (JackAPI.cpp)
41 SERVER_EXPORT JackGraphManager* GetGraphManager()
42 {
43 return JackServerGlobals::fInstance->GetGraphManager();
44 }
45
46 SERVER_EXPORT JackEngineControl* GetEngineControl()
47 {
48 return JackServerGlobals::fInstance->GetEngineControl();
49 }
50
51 SERVER_EXPORT JackSynchro* GetSynchroTable()
52 {
53 return JackServerGlobals::fInstance->GetSynchroTable();
54 }
55
56 JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table)
57 {
58 fChannel = new JackInternalClientChannel(server);
59 }
60
61 JackInternalClient::~JackInternalClient()
62 {
63 delete fChannel;
64 }
65
66 int JackInternalClient::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
67 {
68 int result;
69 jack_log("JackInternalClient::Open name = %s", name);
70
71 if (strlen(name) >= JACK_CLIENT_NAME_SIZE) {
72 jack_error("\"%s\" is too long to be used as a JACK client name.\n"
73 "Please use %lu characters or less",
74 name,
75 JACK_CLIENT_NAME_SIZE - 1);
76 return -1;
77 }
78
79 strncpy(fServerName, server_name, sizeof(fServerName));
80
81 // Open server/client direct channel
82 char name_res[JACK_CLIENT_NAME_SIZE + 1];
83 fChannel->ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result, false);
84 if (result < 0) {
85 int status1 = *status;
86 if (status1 & JackVersionError) {
87 jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION);
88 } else {
89 jack_error("Client name = %s conflits with another running client", name);
90 }
91 goto error;
92 }
93
94 strcpy(fClientControl.fName, name_res);
95
96 // Require new client
97 fChannel->ClientOpen(name_res, &fClientControl.fRefNum, &fEngineControl, &fGraphManager, this, &result);
98 if (result < 0) {
99 jack_error("Cannot open client name = %s", name_res);
100 goto error;
101 }
102
103 SetupDriverSync(false);
104 JackGlobals::fClientTable[fClientControl.fRefNum] = this;
105 JackGlobals::fServerRunning = true;
106 jack_log("JackInternalClient::Open name = %s refnum = %ld", name_res, fClientControl.fRefNum);
107 return 0;
108
109 error:
110 fChannel->Close();
111 return -1;
112 }
113
114 void JackInternalClient::ShutDown(jack_status_t code, const char* message)
115 {
116 jack_log("JackInternalClient::ShutDown");
117 JackClient::ShutDown(code, message);
118 }
119
120 JackGraphManager* JackInternalClient::GetGraphManager() const
121 {
122 assert(fGraphManager);
123 return fGraphManager;
124 }
125
126 JackEngineControl* JackInternalClient::GetEngineControl() const
127 {
128 assert(fEngineControl);
129 return fEngineControl;
130 }
131
132 JackClientControl* JackInternalClient::GetClientControl() const
133 {
134 return const_cast<JackClientControl*>(&fClientControl);
135 }
136
137 int JackLoadableInternalClient::Init(const char* so_name)
138 {
139 char path_to_so[JACK_PATH_MAX + 1];
140 BuildClientPath(path_to_so, sizeof(path_to_so), so_name);
141
142 fHandle = LoadJackModule(path_to_so);
143 jack_log("JackLoadableInternalClient::JackLoadableInternalClient path_to_so = %s", path_to_so);
144
145 if (fHandle == NULL) {
146 PrintLoadError(so_name);
147 return -1;
148 }
149
150 fFinish = (FinishCallback)GetJackProc(fHandle, "jack_finish");
151 if (fFinish == NULL) {
152 UnloadJackModule(fHandle);
153 jack_error("symbol jack_finish cannot be found in %s", so_name);
154 return -1;
155 }
156
157 fDescriptor = (JackDriverDescFunction)GetJackProc(fHandle, "jack_get_descriptor");
158 if (fDescriptor == NULL) {
159 jack_info("No jack_get_descriptor entry-point for %s", so_name);
160 }
161 return 0;
162 }
163
164 int JackLoadableInternalClient1::Init(const char* so_name)
165 {
166 if (JackLoadableInternalClient::Init(so_name) < 0) {
167 return -1;
168 }
169
170 fInitialize = (InitializeCallback)GetJackProc(fHandle, "jack_initialize");
171 if (fInitialize == NULL) {
172 UnloadJackModule(fHandle);
173 jack_error("symbol jack_initialize cannot be found in %s", so_name);
174 return -1;
175 }
176
177 return 0;
178 }
179
180 int JackLoadableInternalClient2::Init(const char* so_name)
181 {
182 if (JackLoadableInternalClient::Init(so_name) < 0) {
183 return -1;
184 }
185
186 fInitialize = (InternalInitializeCallback)GetJackProc(fHandle, "jack_internal_initialize");
187 if (fInitialize == NULL) {
188 UnloadJackModule(fHandle);
189 jack_error("symbol jack_internal_initialize cannot be found in %s", so_name);
190 return -1;
191 }
192
193 return 0;
194 }
195
196 JackLoadableInternalClient1::JackLoadableInternalClient1(JackServer* server, JackSynchro* table, const char* object_data)
197 : JackLoadableInternalClient(server, table)
198 {
199 strncpy(fObjectData, object_data, JACK_LOAD_INIT_LIMIT);
200 }
201
202 JackLoadableInternalClient2::JackLoadableInternalClient2(JackServer* server, JackSynchro* table, const JSList* parameters)
203 : JackLoadableInternalClient(server, table)
204 {
205 fParameters = parameters;
206 }
207
208 JackLoadableInternalClient::~JackLoadableInternalClient()
209 {
210 if (fFinish != NULL) {
211 fFinish(fProcessArg);
212 }
213 if (fHandle != NULL) {
214 UnloadJackModule(fHandle);
215 }
216 }
217
218 int JackLoadableInternalClient1::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
219 {
220 int res = -1;
221
222 if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) {
223 if (fInitialize((jack_client_t*)this, fObjectData) == 0) {
224 res = 0;
225 } else {
226 JackInternalClient::Close();
227 fFinish = NULL;
228 }
229 }
230
231 return res;
232 }
233
234 int JackLoadableInternalClient2::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
235 {
236 int res = -1;
237
238 if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) {
239 if (fInitialize((jack_client_t*)this, fParameters) == 0) {
240 res = 0;
241 } else {
242 JackInternalClient::Close();
243 fFinish = NULL;
244 }
245 }
246
247 return res;
248 }
249
250 } // end of namespace
251
Jack::JackInternalClientChannel
JackClientChannel for server internal clients.
Definition: JackInternalClientChannel.h:32
Jack::JackPosixSemaphore
Inter process synchronization using POSIX semaphore.
Definition: JackPosixSemaphore.h:36
jack_error
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:92
jack_info
SERVER_EXPORT void jack_info(const char *fmt,...)
Definition: JackError.cpp:100
Jack::JackClient::SetupDriverSync
void SetupDriverSync(bool freewheel)
Definition: JackClient.cpp:138
Jack::JackServer
The Jack server.
Definition: JackServer.h:46
Jack::JackClient::Init
bool Init()
Called once when the thread starts.
Definition: JackClient.cpp:501
Jack::JackInternalClient::JackInternalClient
JackInternalClient(JackServer *server, JackSynchro *table)
Definition: JackInternalClient.cpp:56
Jack::JackClient::fChannel
detail::JackClientChannelInterface * fChannel
Definition: JackClient.h:93
_JSList
Definition: linux/alsa/jslist.h:35
Jack::JackInternalClient::fEngineControl
static JackEngineControl * fEngineControl
Definition: JackInternalClient.h:57
jack_log
SERVER_EXPORT void jack_log(const char *fmt,...)
Definition: JackError.cpp:108
Jack::JackClient
The base class for clients: share part of the implementation for JackInternalClient and JackLibClient...
Definition: JackClient.h:47