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 EXPORT jack_client_t * jack_client_open_aux (const char *client_name,
00040 jack_options_t options,
00041 jack_status_t *status, va_list ap);
00042 EXPORT jack_client_t * jack_client_open (const char *client_name,
00043 jack_options_t options,
00044 jack_status_t *status, ...);
00045 EXPORT int jack_client_close (jack_client_t *client);
00046 EXPORT int jack_get_client_pid (const char *name);
00047
00048 #ifdef __cplusplus
00049 }
00050 #endif
00051
00052 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
00053 int JackLibGlobals::fClientCount = 0;
00054
00055 EXPORT jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
00056 {
00057 jack_varargs_t va;
00058 jack_status_t my_status;
00059 JackClient* client;
00060
00061 if (client_name == NULL) {
00062 jack_error("jack_client_open called with a NULL client_name");
00063 return NULL;
00064 }
00065
00066 jack_log("jack_client_open %s", client_name);
00067
00068 if (status == NULL)
00069 status = &my_status;
00070 *status = (jack_status_t)0;
00071
00072
00073 if ((options & ~JackOpenOptions)) {
00074 int my_status1 = *status | (JackFailure | JackInvalidOption);
00075 *status = (jack_status_t)my_status1;
00076 return NULL;
00077 }
00078
00079
00080 if (ap) {
00081 jack_varargs_parse(options, ap, &va);
00082 } else {
00083 jack_varargs_init(&va);
00084 }
00085
00086 JackLibGlobals::Init();
00087
00088 if (try_start_server(&va, options, status)) {
00089 jack_error("jack server is not running or cannot be started");
00090 JackLibGlobals::Destroy();
00091 return 0;
00092 }
00093
00094 if (JACK_DEBUG) {
00095 client = new JackDebugClient(new JackLibClient(GetSynchroTable()));
00096 } else {
00097 client = new JackLibClient(GetSynchroTable());
00098 }
00099
00100 int res = client->Open(va.server_name, client_name, options, status);
00101 if (res < 0) {
00102 delete client;
00103 JackLibGlobals::Destroy();
00104 int my_status1 = (JackFailure | JackServerError);
00105 *status = (jack_status_t)my_status1;
00106 return NULL;
00107 } else {
00108 return (jack_client_t*)client;
00109 }
00110 }
00111
00112 EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00113 {
00114 try {
00115 #ifdef __CLIENTDEBUG__
00116 JackGlobals::CheckContext("jack_client_open");
00117 #endif
00118 assert(JackGlobals::fOpenMutex);
00119 JackGlobals::fOpenMutex->Lock();
00120 va_list ap;
00121 va_start(ap, status);
00122 jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
00123 va_end(ap);
00124 JackGlobals::fOpenMutex->Unlock();
00125 return res;
00126 } catch(std::bad_alloc& e) {
00127 jack_error("Memory allocation error...");
00128 return NULL;
00129 } catch (...) {
00130 jack_error("Unknown error...");
00131 return NULL;
00132 }
00133 }
00134
00135 EXPORT int jack_client_close(jack_client_t* ext_client)
00136 {
00137 #ifdef __CLIENTDEBUG__
00138 JackGlobals::CheckContext("jack_client_close");
00139 #endif
00140 assert(JackGlobals::fOpenMutex);
00141 JackGlobals::fOpenMutex->Lock();
00142 int res = -1;
00143 jack_log("jack_client_close");
00144 JackClient* client = (JackClient*)ext_client;
00145 if (client == NULL) {
00146 jack_error("jack_client_close called with a NULL client");
00147 } else {
00148 res = client->Close();
00149 delete client;
00150 JackLibGlobals::Destroy();
00151 jack_log("jack_client_close res = %d", res);
00152 }
00153 JackGlobals::fOpenMutex->Unlock();
00154 return res;
00155 }
00156
00157 EXPORT int jack_get_client_pid(const char *name)
00158 {
00159 jack_error("jack_get_client_pid : not implemented on library side");
00160 return 0;
00161 }
00162