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 "JackServerLaunch.h"
00027
00028 using namespace Jack;
00029
00030 #ifdef WIN32
00031 #define EXPORT __declspec(dllexport)
00032 #else
00033 #define EXPORT
00034 #endif
00035
00036 #ifdef __cplusplus
00037 extern "C"
00038 {
00039 #endif
00040
00041 EXPORT jack_client_t * jack_client_open (const char *client_name,
00042 jack_options_t options,
00043 jack_status_t *status, ...);
00044 EXPORT jack_client_t * jack_client_new (const char *client_name);
00045 EXPORT int jack_client_close (jack_client_t *client);
00046
00047 #ifdef __cplusplus
00048 }
00049 #endif
00050
00051 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
00052 long JackLibGlobals::fClientCount = 0;
00053
00054 static inline bool CheckPort(jack_port_id_t port_index)
00055 {
00056 return (port_index < PORT_NUM);
00057 }
00058
00059 static jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00060 {
00061 va_list ap;
00062 jack_varargs_t va;
00063 jack_status_t my_status;
00064
00065 if (status == NULL)
00066 status = &my_status;
00067 *status = (jack_status_t)0;
00068
00069
00070 if ((options & ~JackOpenOptions)) {
00071 int my_status1 = *status | (JackFailure | JackInvalidOption);
00072 *status = (jack_status_t)my_status1;
00073 return NULL;
00074 }
00075
00076
00077 va_start(ap, status);
00078 jack_varargs_parse(options, ap, &va);
00079 va_end(ap);
00080
00081 JackLog("jack_client_open %s\n", client_name);
00082 if (client_name == NULL) {
00083 jack_error("jack_client_new called with a NULL client_name");
00084 return NULL;
00085 }
00086
00087 JackLibGlobals::Init();
00088
00089 #ifndef WIN32
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 #endif
00096
00097 #ifdef __CLIENTDEBUG__
00098 JackClient* client = new JackDebugClient(new JackLibClient(GetSynchroTable()));
00099 #else
00100 JackClient* client = new JackLibClient(GetSynchroTable());
00101 #endif
00102
00103 int res = client->Open(client_name, options, status);
00104 if (res < 0) {
00105 delete client;
00106 JackLibGlobals::Destroy();
00107 int my_status1 = (JackFailure|JackServerError);
00108 *status = (jack_status_t)my_status1;
00109 return NULL;
00110 } else {
00111 return (jack_client_t*)client;
00112 }
00113 }
00114
00115 EXPORT jack_client_t* jack_client_new(const char* client_name)
00116 {
00117 int options = JackUseExactName;
00118 if (getenv("JACK_START_SERVER") == NULL)
00119 options |= JackNoStartServer;
00120
00121 return jack_client_open_aux(client_name, (jack_options_t)options, NULL);
00122 }
00123
00124 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00125 {
00126 va_list ap;
00127 va_start(ap, status);
00128 jack_client_t* res = jack_client_open_aux(client_name, options, status, ap);
00129 va_end(ap);
00130 return res;
00131 }
00132
00133 EXPORT int jack_client_close(jack_client_t* ext_client)
00134 {
00135 JackLog("jack_client_close\n");
00136 JackClient* client = (JackClient*)ext_client;
00137 if (client == NULL) {
00138 jack_error("jack_client_close called with a NULL client");
00139 return -1;
00140 } else {
00141 int res = client->Close();
00142 delete client;
00143 JackLog("jack_client_close OK\n");
00144 JackLibGlobals::Destroy();
00145 return res;
00146 }
00147 }
00148
00149