00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "JackDebugClient.h"
00022 #include "JackLibClient.h"
00023 #include "JackChannel.h"
00024 #include "JackLibGlobals.h"
00025 #include "JackGlobals.h"
00026 #include "JackCompilerDeps.h"
00027 #include "JackTools.h"
00028 #include "JackSystemDeps.h"
00029 #include "JackServerLaunch.h"
00030 #include <assert.h>
00031
00032 using namespace Jack;
00033
00034 #ifdef __cplusplus
00035 extern "C"
00036 {
00037 #endif
00038
00039 jack_client_t * jack_client_new_aux (const char *client_name,
00040 jack_options_t options,
00041 jack_status_t *status);
00042
00043 LIB_EXPORT jack_client_t * jack_client_open (const char *client_name,
00044 jack_options_t options,
00045 jack_status_t *status, ...);
00046 LIB_EXPORT int jack_client_close (jack_client_t *client);
00047 LIB_EXPORT int jack_get_client_pid (const char *name);
00048
00049
00050 #ifdef __cplusplus
00051 }
00052 #endif
00053
00054 static jack_client_t * jack_client_open_aux (const char *client_name,
00055 jack_options_t options,
00056 jack_status_t *status, va_list ap);
00057
00058 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
00059 int JackLibGlobals::fClientCount = 0;
00060
00061 jack_client_t* jack_client_new_aux(const char* client_name, jack_options_t options, jack_status_t* status)
00062 {
00063 jack_varargs_t va;
00064 jack_status_t my_status;
00065 JackClient* client;
00066
00067 if (client_name == NULL) {
00068 jack_error("jack_client_new called with a NULL client_name");
00069 return NULL;
00070 }
00071
00072 jack_log("jack_client_new %s", client_name);
00073
00074 if (status == NULL)
00075 status = &my_status;
00076 *status = (jack_status_t)0;
00077
00078
00079 if ((options & ~JackOpenOptions)) {
00080 int my_status1 = *status | (JackFailure | JackInvalidOption);
00081 *status = (jack_status_t)my_status1;
00082 return NULL;
00083 }
00084
00085
00086 jack_varargs_init(&va);
00087
00088 JackLibGlobals::Init();
00089
00090 if (try_start_server(&va, options, status)) {
00091 jack_error("jack server is not running or cannot be started");
00092 JackLibGlobals::Destroy();
00093 return 0;
00094 }
00095
00096 if (JACK_DEBUG) {
00097 client = new JackDebugClient(new JackLibClient(GetSynchroTable()));
00098 } else {
00099 client = new JackLibClient(GetSynchroTable());
00100 }
00101
00102 int res = client->Open(va.server_name, client_name, va.session_id, options, status);
00103 if (res < 0) {
00104 delete client;
00105 JackLibGlobals::Destroy();
00106 int my_status1 = (JackFailure | JackServerError);
00107 *status = (jack_status_t)my_status1;
00108 return NULL;
00109 } else {
00110 return (jack_client_t*)client;
00111 }
00112 }
00113
00114 static jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
00115 {
00116 jack_varargs_t va;
00117 jack_status_t my_status;
00118 JackClient* client;
00119
00120 if (client_name == NULL) {
00121 jack_error("jack_client_open called with a NULL client_name");
00122 return NULL;
00123 }
00124
00125 jack_log("jack_client_open %s", client_name);
00126
00127 if (status == NULL)
00128 status = &my_status;
00129 *status = (jack_status_t)0;
00130
00131
00132 if ((options & ~JackOpenOptions)) {
00133 int my_status1 = *status | (JackFailure | JackInvalidOption);
00134 *status = (jack_status_t)my_status1;
00135 return NULL;
00136 }
00137
00138
00139 jack_varargs_parse(options, ap, &va);
00140
00141 JackLibGlobals::Init();
00142
00143 if (try_start_server(&va, options, status)) {
00144 jack_error("jack server is not running or cannot be started");
00145 JackLibGlobals::Destroy();
00146 return 0;
00147 }
00148
00149 if (JACK_DEBUG) {
00150 client = new JackDebugClient(new JackLibClient(GetSynchroTable()));
00151 } else {
00152 client = new JackLibClient(GetSynchroTable());
00153 }
00154
00155 int res = client->Open(va.server_name, client_name, va.session_id, options, status);
00156 if (res < 0) {
00157 delete client;
00158 JackLibGlobals::Destroy();
00159 int my_status1 = (JackFailure | JackServerError);
00160 *status = (jack_status_t)my_status1;
00161 return NULL;
00162 } else {
00163 return (jack_client_t*)client;
00164 }
00165 }
00166
00167 LIB_EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00168 {
00169 JackGlobals::CheckContext("jack_client_open");
00170
00171 try {
00172 assert(JackGlobals::fOpenMutex);
00173 JackGlobals::fOpenMutex->Lock();
00174 va_list ap;
00175 va_start(ap, status);
00176 jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
00177 va_end(ap);
00178 JackGlobals::fOpenMutex->Unlock();
00179 return res;
00180 } catch (std::bad_alloc& e) {
00181 jack_error("Memory allocation error...");
00182 return NULL;
00183 } catch (...) {
00184 jack_error("Unknown error...");
00185 return NULL;
00186 }
00187 }
00188
00189 LIB_EXPORT int jack_client_close(jack_client_t* ext_client)
00190 {
00191 JackGlobals::CheckContext("jack_client_close");
00192
00193 assert(JackGlobals::fOpenMutex);
00194 JackGlobals::fOpenMutex->Lock();
00195 int res = -1;
00196 jack_log("jack_client_close");
00197 JackClient* client = (JackClient*)ext_client;
00198 if (client == NULL) {
00199 jack_error("jack_client_close called with a NULL client");
00200 } else {
00201 res = client->Close();
00202 delete client;
00203 JackLibGlobals::Destroy();
00204 jack_log("jack_client_close res = %d", res);
00205 }
00206 JackGlobals::fOpenMutex->Unlock();
00207 return res;
00208 }
00209
00210 LIB_EXPORT int jack_get_client_pid(const char *name)
00211 {
00212 jack_error("jack_get_client_pid : not implemented on library side");
00213 return 0;
00214 }
00215