2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "JackDebugClient.h"
22 #include "JackLibClient.h"
23 #include "JackChannel.h"
24 #include "JackLibGlobals.h"
25 #include "JackGlobals.h"
26 #include "JackCompilerDeps.h"
27 #include "JackTools.h"
28 #include "JackSystemDeps.h"
29 #include "JackServerLaunch.h"
39 jack_client_t
* jack_client_new_aux (const char *client_name
,
40 jack_options_t options
,
41 jack_status_t
*status
);
43 LIB_EXPORT jack_client_t
* jack_client_open (const char *client_name
,
44 jack_options_t options
,
45 jack_status_t
*status
, ...);
46 LIB_EXPORT
int jack_client_close (jack_client_t
*client
);
47 LIB_EXPORT
int jack_get_client_pid (const char *name
);
54 static jack_client_t
* jack_client_open_aux (const char *client_name
,
55 jack_options_t options
,
56 jack_status_t
*status
, va_list ap
);
58 JackLibGlobals
* JackLibGlobals::fGlobals
= NULL
;
59 int JackLibGlobals::fClientCount
= 0;
61 jack_client_t
* jack_client_new_aux(const char* client_name
, jack_options_t options
, jack_status_t
* status
)
63 jack_varargs_t va
; /* variable arguments */
64 jack_status_t my_status
;
67 if (client_name
== NULL
) {
68 jack_error("jack_client_new called with a NULL client_name");
72 jack_log("jack_client_new %s", client_name
);
74 if (status
== NULL
) /* no status from caller? */
75 status
= &my_status
; /* use local status word */
76 *status
= (jack_status_t
)0;
78 /* validate parameters */
79 if ((options
& ~JackOpenOptions
)) {
80 int my_status1
= *status
| (JackFailure
| JackInvalidOption
);
81 *status
= (jack_status_t
)my_status1
;
85 /* parse variable arguments */
86 jack_varargs_init(&va
);
88 JackLibGlobals::Init(); // jack library initialisation
90 if (try_start_server(&va
, options
, status
)) {
91 jack_error("jack server is not running or cannot be started");
92 JackLibGlobals::Destroy(); // jack library destruction
97 client
= new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
99 client
= new JackLibClient(GetSynchroTable());
102 int res
= client
->Open(va
.server_name
, client_name
, va
.session_id
, options
, status
);
105 JackLibGlobals::Destroy(); // jack library destruction
106 int my_status1
= (JackFailure
| JackServerError
);
107 *status
= (jack_status_t
)my_status1
;
110 return (jack_client_t
*)client
;
114 static jack_client_t
* jack_client_open_aux(const char* client_name
, jack_options_t options
, jack_status_t
* status
, va_list ap
)
116 jack_varargs_t va
; /* variable arguments */
117 jack_status_t my_status
;
120 if (client_name
== NULL
) {
121 jack_error("jack_client_open called with a NULL client_name");
125 jack_log("jack_client_open %s", client_name
);
127 if (status
== NULL
) /* no status from caller? */
128 status
= &my_status
; /* use local status word */
129 *status
= (jack_status_t
)0;
131 /* validate parameters */
132 if ((options
& ~JackOpenOptions
)) {
133 int my_status1
= *status
| (JackFailure
| JackInvalidOption
);
134 *status
= (jack_status_t
)my_status1
;
138 /* parse variable arguments */
139 jack_varargs_parse(options
, ap
, &va
);
141 JackLibGlobals::Init(); // jack library initialisation
143 if (try_start_server(&va
, options
, status
)) {
144 jack_error("jack server is not running or cannot be started");
145 JackLibGlobals::Destroy(); // jack library destruction
150 client
= new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
152 client
= new JackLibClient(GetSynchroTable());
155 int res
= client
->Open(va
.server_name
, client_name
, va
.session_id
, options
, status
);
158 JackLibGlobals::Destroy(); // jack library destruction
159 int my_status1
= (JackFailure
| JackServerError
);
160 *status
= (jack_status_t
)my_status1
;
163 return (jack_client_t
*)client
;
167 LIB_EXPORT jack_client_t
* jack_client_open(const char* ext_client_name
, jack_options_t options
, jack_status_t
* status
, ...)
169 JackGlobals::CheckContext("jack_client_open");
172 assert(JackGlobals::fOpenMutex
);
173 JackGlobals::fOpenMutex
->Lock();
175 va_start(ap
, status
);
176 jack_client_t
* res
= jack_client_open_aux(ext_client_name
, options
, status
, ap
);
178 JackGlobals::fOpenMutex
->Unlock();
180 } catch (std::bad_alloc
& e
) {
181 jack_error("Memory allocation error...");
184 jack_error("Unknown error...");
189 LIB_EXPORT
int jack_client_close(jack_client_t
* ext_client
)
191 JackGlobals::CheckContext("jack_client_close");
193 assert(JackGlobals::fOpenMutex
);
194 JackGlobals::fOpenMutex
->Lock();
196 jack_log("jack_client_close");
197 JackClient
* client
= (JackClient
*)ext_client
;
198 if (client
== NULL
) {
199 jack_error("jack_client_close called with a NULL client");
201 res
= client
->Close();
203 JackLibGlobals::Destroy(); // jack library destruction
204 jack_log("jack_client_close res = %d", res
);
206 JackGlobals::fOpenMutex
->Unlock();
210 LIB_EXPORT
int jack_get_client_pid(const char *name
)
212 jack_error("jack_get_client_pid : not implemented on library side");