Cleanup
[jack2.git] / common / JackLibAPI.cpp
blob101a508e3da942875b59e689f4b0062a12292f07
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 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 "JackGraphManager.h"
25 #include "JackLibGlobals.h"
26 #include "JackGlobals.h"
27 #include "varargs.h"
29 using namespace Jack;
31 #ifdef WIN32
32 #define EXPORT __declspec(dllexport)
33 #else
34 #define EXPORT
35 #endif
37 #ifdef __cplusplus
38 extern "C"
40 #endif
42 EXPORT jack_client_t * jack_client_open (const char *client_name,
43 jack_options_t options,
44 jack_status_t *status, ...);
45 EXPORT jack_client_t * jack_client_new (const char *client_name);
46 EXPORT int jack_client_close (jack_client_t *client);
48 #ifdef __cplusplus
50 #endif
52 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
53 long JackLibGlobals::fClientCount = 0;
55 static inline bool CheckPort(jack_port_id_t port_index)
57 return (port_index < PORT_NUM);
60 static jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, ...)
62 va_list ap; /* variable argument pointer */
63 jack_varargs_t va; /* variable arguments */
64 jack_status_t my_status;
66 if (status == NULL) /* no status from caller? */
67 status = &my_status; /* use local status word */
68 *status = (jack_status_t)0;
70 /* validate parameters */
71 if ((options & ~JackOpenOptions)) {
72 int my_status1 = *status | (JackFailure | JackInvalidOption);
73 *status = (jack_status_t)my_status1;
74 return NULL;
77 /* parse variable arguments */
78 va_start(ap, status);
79 jack_varargs_parse(options, ap, &va);
80 va_end(ap);
82 JackLog("jack_client_open %s\n", client_name);
83 if (client_name == NULL) {
84 jack_error("jack_client_new called with a NULL client_name");
85 return NULL;
88 JackLibGlobals::Init(); // jack library initialisation
90 #ifdef __CLIENTDEBUG__
91 JackClient* client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
92 #else
93 JackClient* client = new JackLibClient(GetSynchroTable());
94 #endif
96 int res = client->Open(client_name);
97 if (res < 0) {
98 delete client;
99 JackLibGlobals::Destroy(); // jack library destruction
100 return NULL;
101 } else {
102 *status = (jack_status_t)0;
103 return (jack_client_t*)client;
107 EXPORT jack_client_t* jack_client_new(const char* client_name)
109 int options = JackUseExactName;
110 if (getenv("JACK_START_SERVER") == NULL)
111 options |= JackNoStartServer;
113 return jack_client_open_aux(client_name, (jack_options_t)options, NULL);
116 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
118 va_list ap;
119 va_start(ap, status);
120 jack_client_t* res = jack_client_open_aux(client_name, options, status, ap);
121 va_end(ap);
122 return res;
125 EXPORT int jack_client_close(jack_client_t* ext_client)
127 JackLog("jack_client_close\n");
128 JackClient* client = (JackClient*)ext_client;
129 if (client == NULL) {
130 jack_error("jack_client_close called with a NULL client");
131 return -1;
132 } else {
133 int res = client->Close();
134 delete client;
135 JackLog("jack_client_close OK\n");
136 JackLibGlobals::Destroy(); // jack library destruction
137 return res;