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