00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "JackSystemDeps.h"
00022 #include "JackGraphManager.h"
00023 #include "JackInternalClient.h"
00024 #include "JackServer.h"
00025 #include "JackDebugClient.h"
00026 #include "JackServerGlobals.h"
00027 #include "JackTools.h"
00028 #include "JackCompilerDeps.h"
00029 #include "JackLockedEngine.h"
00030
00031 #ifdef __cplusplus
00032 extern "C"
00033 {
00034 #endif
00035
00036 EXPORT jack_client_t * jack_client_open_aux (const char *client_name,
00037 jack_options_t options,
00038 jack_status_t *status, va_list ap);
00039 EXPORT jack_client_t * jack_client_open (const char *client_name,
00040 jack_options_t options,
00041 jack_status_t *status, ...);
00042 EXPORT int jack_client_close (jack_client_t *client);
00043 EXPORT int jack_get_client_pid (const char *name);
00044
00045 #ifdef __cplusplus
00046 }
00047 #endif
00048
00049 using namespace Jack;
00050
00051
00052 static bool g_nostart;
00053
00054 EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_options_t options, jack_status_t* status, va_list ap)
00055 {
00056 jack_varargs_t va;
00057 jack_status_t my_status;
00058 JackClient* client;
00059 char client_name[JACK_CLIENT_NAME_SIZE + 1];
00060
00061 if (ext_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", ext_client_name);
00067 JackTools::RewriteName(ext_client_name, client_name);
00068
00069 if (status == NULL)
00070 status = &my_status;
00071 *status = (jack_status_t)0;
00072
00073
00074 if ((options & ~JackOpenOptions)) {
00075 int my_status1 = *status | (JackFailure | JackInvalidOption);
00076 *status = (jack_status_t)my_status1;
00077 return NULL;
00078 }
00079
00080
00081 if (ap) {
00082 jack_varargs_parse(options, ap, &va);
00083 } else {
00084 jack_varargs_init(&va);
00085 }
00086
00087 g_nostart = (options & JackNoStartServer) != 0;
00088 if (!g_nostart) {
00089 if (!JackServerGlobals::Init()) {
00090 int my_status1 = (JackFailure | JackServerError);
00091 *status = (jack_status_t)my_status1;
00092 return NULL;
00093 }
00094 }
00095
00096 if (JACK_DEBUG) {
00097 client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable()));
00098 } else {
00099 client = new JackInternalClient(JackServer::fInstance, GetSynchroTable());
00100 }
00101
00102 int res = client->Open(va.server_name, client_name, options, status);
00103 if (res < 0) {
00104 delete client;
00105 if (!g_nostart) {
00106 JackServerGlobals::Destroy();
00107 }
00108 int my_status1 = (JackFailure | JackServerError);
00109 *status = (jack_status_t)my_status1;
00110 return NULL;
00111 } else {
00112 return (jack_client_t*)client;
00113 }
00114 }
00115
00116 EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00117 {
00118 assert(gOpenMutex);
00119 gOpenMutex->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 gOpenMutex->Unlock();
00125 return res;
00126 }
00127
00128 EXPORT int jack_client_close(jack_client_t* ext_client)
00129 {
00130 assert(gOpenMutex);
00131 gOpenMutex->Lock();
00132 int res = -1;
00133 jack_log("jack_client_close");
00134 JackClient* client = (JackClient*)ext_client;
00135 if (client == NULL) {
00136 jack_error("jack_client_close called with a NULL client");
00137 } else {
00138 res = client->Close();
00139 delete client;
00140 if (!g_nostart) {
00141 JackServerGlobals::Destroy();
00142 }
00143 jack_log("jack_client_close res = %d", res);
00144 }
00145 gOpenMutex->Unlock();
00146 return res;
00147 }
00148
00149 EXPORT int jack_get_client_pid(const char *name)
00150 {
00151 return (JackServer::fInstance != NULL)
00152 ? JackServer::fInstance->GetEngine()->GetClientPID(name)
00153 : 0;
00154 }
00155