00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "JackMachClientChannel.h"
00021 #include "JackRPCEngine.h"
00022 #include "JackRPCClientServer.c"
00023 #include "JackError.h"
00024 #include "JackLibClient.h"
00025 #include "JackLibGlobals.h"
00026 #include "JackMachThread.h"
00027 #include "JackConstants.h"
00028
00029 namespace Jack
00030 {
00031
00032 JackMachClientChannel::JackMachClientChannel()
00033 {
00034 fThread = new JackMachThread(this);
00035 }
00036
00037 JackMachClientChannel::~JackMachClientChannel()
00038 {
00039 delete fThread;
00040 }
00041
00042
00043
00044 int JackMachClientChannel::ServerCheck(const char* server_name)
00045 {
00046 JackLog("JackMachClientChannel::ServerCheck = %s\n", server_name);
00047
00048
00049 if (!fServerPort.ConnectPort(jack_server_entry)) {
00050 jack_error("Cannot connect to server Mach port");
00051 return -1;
00052 } else {
00053 return 0;
00054 }
00055 }
00056
00057 int JackMachClientChannel::Open(const char* name, char* name_res, JackClient* client, jack_options_t options, jack_status_t* status)
00058 {
00059 JackLog("JackMachClientChannel::Open name = %s\n", name);
00060
00061
00062 if (!fServerPort.ConnectPort(jack_server_entry)) {
00063 jack_error("Cannot connect to server Mach port");
00064 return -1;
00065 }
00066
00067
00068 int result = 0;
00069 ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result);
00070 if (result < 0) {
00071 int status1 = *status;
00072 if (status1 & JackVersionError)
00073 jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION);
00074 else
00075 jack_error("Client name = %s conflits with another running client", name);
00076 return -1;
00077 }
00078
00079
00080 char buf[JACK_CLIENT_NAME_SIZE];
00081 snprintf(buf, sizeof(buf) - 1, "%s:%s", jack_client_entry, name_res);
00082
00083 if (!fClientPort.AllocatePort(buf, 16)) {
00084 jack_error("Cannot allocate client Mach port");
00085 return -1;
00086 }
00087
00088 JackLibGlobals::fGlobals->fClientTable[fClientPort.GetPort()] = client;
00089 return 0;
00090 }
00091
00092 void JackMachClientChannel::Close()
00093 {
00094 JackLog("JackMachClientChannel::Close\n");
00095 JackLibGlobals::fGlobals->fClientTable.erase(fClientPort.GetPort());
00096 fServerPort.DisconnectPort();
00097 fClientPort.DestroyPort();
00098
00099
00100 kern_return_t res;
00101 if ((res = mach_port_destroy(mach_task_self(), fPrivatePort)) != KERN_SUCCESS) {
00102 jack_error("JackMachClientChannel::Close err = %s", mach_error_string(res));
00103 }
00104 }
00105
00106 int JackMachClientChannel::Start()
00107 {
00108 JackLog("JackMachClientChannel::Start\n");
00109 if (fThread->Start() != 0) {
00110 jack_error("Cannot start Jack client listener");
00111 return -1;
00112 } else {
00113 return 0;
00114 }
00115 }
00116
00117 void JackMachClientChannel::Stop()
00118 {
00119 JackLog("JackMachClientChannel::Stop\n");
00120 fThread->Kill();
00121 }
00122
00123 void JackMachClientChannel::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result)
00124 {
00125 kern_return_t res = rpc_jack_client_check(fServerPort.GetPort(), (char*)name, name_res, protocol, options, status, result);
00126 if (res != KERN_SUCCESS) {
00127 *result = -1;
00128 jack_error("JackMachClientChannel::ClientCheck err = %s", mach_error_string(res));
00129 }
00130 }
00131
00132 void JackMachClientChannel::ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result)
00133 {
00134 kern_return_t res = rpc_jack_client_open(fServerPort.GetPort(), (char*)name, &fPrivatePort, shared_engine, shared_client, shared_graph, result);
00135 if (res != KERN_SUCCESS) {
00136 *result = -1;
00137 jack_error("JackMachClientChannel::ClientOpen err = %s", mach_error_string(res));
00138 }
00139 }
00140
00141 void JackMachClientChannel::ClientClose(int refnum, int* result)
00142 {
00143 kern_return_t res = rpc_jack_client_close(fPrivatePort, refnum, result);
00144 if (res != KERN_SUCCESS) {
00145 *result = -1;
00146 jack_error("JackMachClientChannel::ClientClose err = %s", mach_error_string(res));
00147 }
00148 }
00149
00150 void JackMachClientChannel::ClientActivate(int refnum, int* result)
00151 {
00152 kern_return_t res = rpc_jack_client_activate(fPrivatePort, refnum, result);
00153 if (res != KERN_SUCCESS) {
00154 *result = -1;
00155 jack_error("JackMachClientChannel::ClientActivate err = %s", mach_error_string(res));
00156 }
00157 }
00158
00159 void JackMachClientChannel::ClientDeactivate(int refnum, int* result)
00160 {
00161 kern_return_t res = rpc_jack_client_deactivate(fPrivatePort, refnum, result);
00162 if (res != KERN_SUCCESS) {
00163 *result = -1;
00164 jack_error("JackMachClientChannel::ClientDeactivate err = %s", mach_error_string(res));
00165 }
00166 }
00167
00168 void JackMachClientChannel::PortRegister(int refnum, const char* name, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index, int* result)
00169 {
00170 kern_return_t res = rpc_jack_port_register(fPrivatePort, refnum, (char*)name, flags, buffer_size, port_index, result);
00171 if (res != KERN_SUCCESS) {
00172 *result = -1;
00173 jack_error("JackMachClientChannel::PortRegister err = %s", mach_error_string(res));
00174 }
00175 }
00176
00177 void JackMachClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
00178 {
00179 kern_return_t res = rpc_jack_port_unregister(fPrivatePort, refnum, port_index, result);
00180 if (res != KERN_SUCCESS) {
00181 *result = -1;
00182 jack_error("JackMachClientChannel::PortUnRegister err = %s", mach_error_string(res));
00183 }
00184 }
00185
00186 void JackMachClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
00187 {
00188 kern_return_t res = rpc_jack_port_connect_name(fPrivatePort, refnum, (char*)src, (char*)dst, result);
00189 if (res != KERN_SUCCESS) {
00190 jack_error("JackMachClientChannel::PortConnect err = %s", mach_error_string(res));
00191 }
00192 }
00193
00194 void JackMachClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
00195 {
00196 kern_return_t res = rpc_jack_port_disconnect_name(fPrivatePort, refnum, (char*)src, (char*)dst, result);
00197 if (res != KERN_SUCCESS) {
00198 *result = -1;
00199 jack_error("JackMachClientChannel::PortDisconnect err = %s", mach_error_string(res));
00200 }
00201 }
00202
00203 void JackMachClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
00204 {
00205 kern_return_t res = rpc_jack_port_connect(fPrivatePort, refnum, src, dst, result);
00206 if (res != KERN_SUCCESS) {
00207 *result = -1;
00208 jack_error("JackMachClientChannel::PortConnect err = %s", mach_error_string(res));
00209 }
00210 }
00211
00212 void JackMachClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
00213 {
00214 kern_return_t res = rpc_jack_port_disconnect(fPrivatePort, refnum, src, dst, result);
00215 if (res != KERN_SUCCESS) {
00216 *result = -1;
00217 jack_error("JackMachClientChannel::PortDisconnect err = %s", mach_error_string(res));
00218 }
00219 }
00220
00221 void JackMachClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
00222 {
00223 kern_return_t res = rpc_jack_set_buffer_size(fPrivatePort, buffer_size, result);
00224 if (res != KERN_SUCCESS) {
00225 *result = -1;
00226 jack_error("JackMachClientChannel::SetBufferSize err = %s", mach_error_string(res));
00227 }
00228 }
00229
00230 void JackMachClientChannel::SetFreewheel(int onoff, int* result)
00231 {
00232 kern_return_t res = rpc_jack_set_freewheel(fPrivatePort, onoff, result);
00233 if (res != KERN_SUCCESS) {
00234 *result = -1;
00235 jack_error("JackMachClientChannel::SetFreewheel err = %s", mach_error_string(res));
00236 }
00237 }
00238
00239 void JackMachClientChannel::ReleaseTimebase(int refnum, int* result)
00240 {
00241 kern_return_t res = rpc_jack_release_timebase(fPrivatePort, refnum, result);
00242 if (res != KERN_SUCCESS) {
00243 *result = -1;
00244 jack_error("JackMachClientChannel::ReleaseTimebase err = %s", mach_error_string(res));
00245 }
00246 }
00247
00248 void JackMachClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
00249 {
00250 kern_return_t res = rpc_jack_set_timebase_callback(fPrivatePort, refnum, conditional, result);
00251 if (res != KERN_SUCCESS) {
00252 *result = -1;
00253 jack_error("JackMachClientChannel::SetTimebaseCallback err = %s", mach_error_string(res));
00254 }
00255 }
00256
00257 void JackMachClientChannel::GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
00258 {
00259 kern_return_t res = rpc_jack_get_internal_clientname(fPrivatePort, refnum, int_ref, name_res, result);
00260 if (res != KERN_SUCCESS) {
00261 *result = -1;
00262 jack_error("JackMachClientChannel::GetInternalClientName err = %s", mach_error_string(res));
00263 }
00264 }
00265
00266 void JackMachClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
00267 {
00268 kern_return_t res = rpc_jack_internal_clienthandle(fPrivatePort, refnum, (char*)client_name, status, int_ref, result);
00269 if (res != KERN_SUCCESS) {
00270 *result = -1;
00271 jack_error("JackMachClientChannel::InternalClientHandle err = %s", mach_error_string(res));
00272 }
00273 }
00274
00275 void JackMachClientChannel::InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result)
00276 {
00277 kern_return_t res = rpc_jack_internal_clientload(fPrivatePort, refnum, (char*)client_name, (char*)so_name, (char*)objet_data, options, status, int_ref, result);
00278 if (res != KERN_SUCCESS) {
00279 *result = -1;
00280 jack_error("JackMachClientChannel::InternalClientLoad err = %s", mach_error_string(res));
00281 }
00282 }
00283
00284 void JackMachClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result)
00285 {
00286 kern_return_t res = rpc_jack_internal_clientunload(fPrivatePort, refnum, int_ref, status, result);
00287 if (res != KERN_SUCCESS) {
00288 *result = -1;
00289 jack_error("JackMachClientChannel::InternalClientUnload err = %s", mach_error_string(res));
00290 }
00291 }
00292
00293 bool JackMachClientChannel::Execute()
00294 {
00295 kern_return_t res;
00296 if ((res = mach_msg_server(JackRPCClient_server, 1024, fClientPort.GetPort(), 0)) != KERN_SUCCESS) {
00297 jack_error("JackMachClientChannel::Execute err = %s", mach_error_string(res));
00298
00299 return false;
00300 } else {
00301 return true;
00302 }
00303 }
00304
00305 }
00306
00307