Cleanup
[jack2.git] / common / JackServerAPI.cpp
blobe8931b0ce27c115f274e3a5850ccdb89cdf17af2
1 /*
2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2006 Grame
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.
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.
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.
21 #ifdef WIN32
22 #pragma warning (disable : 4786)
23 #endif
25 #include "JackInternalClient.h"
26 #include "JackGraphManager.h"
27 #include "JackServer.h"
28 #include "JackDebugClient.h"
29 #include "JackServerGlobals.h"
30 #include "JackError.h"
31 #include "varargs.h"
34 TODO:
36 - implement the "jack_client_new", "jack_client_open", "jack_client_close" API so that we can provide a libjackdmp shared library
37 to be used by clients for direct access.
39 - automatic launch of the jack server with the first client open, automatic close when the last client exit. Use of a jackd.rsc configuration file.
43 #ifdef WIN32
44 #define EXPORT __declspec(dllexport)
45 #else
46 #define EXPORT
47 #endif
49 #ifdef __cplusplus
50 extern "C"
52 #endif
54 EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name);
55 EXPORT void my_jack_internal_client_close(jack_client_t* ext_client);
57 EXPORT jack_client_t * jack_client_open (const char *client_name,
58 jack_options_t options,
59 jack_status_t *status, ...);
60 EXPORT jack_client_t * jack_client_new (const char *client_name);
61 EXPORT int jack_client_close (jack_client_t *client);
63 #ifdef __cplusplus
65 #endif
67 using namespace Jack;
69 EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name)
71 JackLog("jack_internal_client_new %s", client_name);
72 if (client_name == NULL) {
73 jack_error("jack_internal_client_new called with a NULL client_name");
74 return NULL;
76 #ifdef __CLIENTDEBUG__
77 JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
78 #else
79 JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
80 #endif
82 int res = client->Open(client_name);
83 if (res < 0) {
84 delete client;
85 return NULL;
86 } else {
87 return (jack_client_t*)client;
91 EXPORT void my_jack_internal_client_close(jack_client_t* ext_client)
93 JackLog("jack_internal_client_close");
94 JackClient* client = (JackClient*)ext_client;
95 if (client == NULL) {
96 jack_error("jack_internal_client_close called with a NULL client");
97 } else {
98 client->Close();
99 delete client;
100 JackLog("jack_internal_client_close OK");
104 EXPORT jack_client_t* jack_client_new(const char* client_name)
106 int options = JackUseExactName;
107 if (getenv("JACK_START_SERVER") == NULL)
108 options |= JackNoStartServer;
110 return jack_client_open(client_name, (jack_options_t)options, NULL);
113 // TO BE IMPLEMENTED PROPERLY
114 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
116 va_list ap; /* variable argument pointer */
117 jack_varargs_t va; /* variable arguments */
118 jack_status_t my_status;
120 if (status == NULL) /* no status from caller? */
121 status = &my_status; /* use local status word */
122 *status = (jack_status_t)0;
124 /* validate parameters */
125 if ((options & ~JackOpenOptions)) {
126 int my_status1 = *status | (JackFailure | JackInvalidOption);
127 *status = (jack_status_t)my_status1;
128 return NULL;
131 /* parse variable arguments */
132 va_start(ap, status);
133 jack_varargs_parse(options, ap, &va);
134 va_end(ap);
136 JackLog("jack_client_open %s\n", client_name);
137 if (client_name == NULL) {
138 jack_error("jack_client_new called with a NULL client_name");
139 return NULL;
142 JackServerGlobals::Init(); // jack server initialisation
144 #ifdef __CLIENTDEBUG__
145 JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
146 #else
147 JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
148 #endif
150 int res = client->Open(client_name);
151 if (res < 0) {
152 delete client;
153 JackServerGlobals::Destroy(); // jack server destruction
154 return NULL;
155 } else {
156 *status = (jack_status_t)0;
157 return (jack_client_t*)client;
159 return NULL;
162 EXPORT int jack_client_close(jack_client_t* ext_client)
164 JackLog("jack_client_close\n");
165 JackClient* client = (JackClient*)ext_client;
166 if (client == NULL) {
167 jack_error("jack_client_close called with a NULL client");
168 return -1;
170 int res = client->Close();
171 delete client;
172 JackLog("jack_client_close OK\n");
173 JackServerGlobals::Destroy(); // jack library destruction
174 return res;