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 EXPORT jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
00052 {
00053 jack_varargs_t va;
00054 jack_status_t my_status;
00055 JackClient* client;
00056
00057 if (client_name == NULL) {
00058 jack_error("jack_client_open called with a NULL client_name");
00059 return NULL;
00060 }
00061
00062 jack_log("jack_client_open %s", client_name);
00063
00064 if (status == NULL)
00065 status = &my_status;
00066 *status = (jack_status_t)0;
00067
00068
00069 if ((options & ~JackOpenOptions)) {
00070 int my_status1 = *status | (JackFailure | JackInvalidOption);
00071 *status = (jack_status_t)my_status1;
00072 return NULL;
00073 }
00074
00075
00076 if (ap) {
00077 jack_varargs_parse(options, ap, &va);
00078 } else {
00079 jack_varargs_init(&va);
00080 }
00081
00082 if (!JackServerGlobals::Init()) {
00083 int my_status1 = (JackFailure | JackServerError);
00084 *status = (jack_status_t)my_status1;
00085 return NULL;
00086 }
00087
00088 if (JACK_DEBUG) {
00089 client = new JackDebugClient(new JackInternalClient(JackServerGlobals::fInstance, GetSynchroTable()));
00090 } else {
00091 client = new JackInternalClient(JackServerGlobals::fInstance, GetSynchroTable());
00092 }
00093
00094 int res = client->Open(va.server_name, client_name, options, status);
00095 if (res < 0) {
00096 delete client;
00097 JackServerGlobals::Destroy();
00098 int my_status1 = (JackFailure | JackServerError);
00099 *status = (jack_status_t)my_status1;
00100 return NULL;
00101 } else {
00102 return (jack_client_t*)client;
00103 }
00104 }
00105
00106 EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00107 {
00108 try {
00109 assert(JackGlobals::fOpenMutex);
00110 JackGlobals::fOpenMutex->Lock();
00111 va_list ap;
00112 va_start(ap, status);
00113 jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
00114 va_end(ap);
00115 JackGlobals::fOpenMutex->Unlock();
00116 return res;
00117 } catch(std::bad_alloc& e) {
00118 jack_error("Memory allocation error...");
00119 return NULL;
00120 } catch (...) {
00121 jack_error("Unknown error...");
00122 return NULL;
00123 }
00124 }
00125
00126 EXPORT int jack_client_close(jack_client_t* ext_client)
00127 {
00128 assert(JackGlobals::fOpenMutex);
00129 JackGlobals::fOpenMutex->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 JackServerGlobals::Destroy();
00139 jack_log("jack_client_close res = %d", res);
00140 }
00141 JackGlobals::fOpenMutex->Unlock();
00142 return res;
00143 }
00144
00145 EXPORT int jack_get_client_pid(const char *name)
00146 {
00147 return (JackServerGlobals::fInstance != NULL)
00148 ? JackServerGlobals::fInstance->GetEngine()->GetClientPID(name)
00149 : 0;
00150 }
00151