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