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* ext_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 char client_name[JACK_CLIENT_NAME_SIZE + 1];
00061
00062 if (ext_client_name == NULL) {
00063 jack_error("jack_client_open called with a NULL client_name");
00064 return NULL;
00065 }
00066
00067 jack_log("jack_client_open %s", ext_client_name);
00068 JackTools::RewriteName(ext_client_name, client_name);
00069
00070 if (status == NULL)
00071 status = &my_status;
00072 *status = (jack_status_t)0;
00073
00074
00075 if ((options & ~JackOpenOptions)) {
00076 int my_status1 = *status | (JackFailure | JackInvalidOption);
00077 *status = (jack_status_t)my_status1;
00078 return NULL;
00079 }
00080
00081
00082 if (ap) {
00083 jack_varargs_parse(options, ap, &va);
00084 } else {
00085 jack_varargs_init(&va);
00086 }
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, 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 EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00115 {
00116 assert(gOpenMutex);
00117 gOpenMutex->Lock();
00118 va_list ap;
00119 va_start(ap, status);
00120 jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
00121 va_end(ap);
00122 gOpenMutex->Unlock();
00123 return res;
00124 }
00125
00126 EXPORT int jack_client_close(jack_client_t* ext_client)
00127 {
00128 assert(gOpenMutex);
00129 gOpenMutex->Lock();
00130 int res = -1;
00131 jack_log("jack_client_close");
00132 JackClient* client = (JackClient*)ext_client;
00133 if (client == NULL) {
00134 jack_error("jack_client_close called with a NULL client");
00135 } else {
00136 res = client->Close();
00137 delete client;
00138 JackLibGlobals::Destroy();
00139 jack_log("jack_client_close res = %d", res);
00140 }
00141 gOpenMutex->Unlock();
00142 return res;
00143 }
00144
00145 EXPORT int jack_get_client_pid(const char *name)
00146 {
00147 jack_error("jack_get_client_pid : not implemented on library side");
00148 return 0;
00149 }
00150