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::Open(const char* name, JackClient* client)
00045 {
00046 JackLog("JackMachClientChannel::Open name = %s\n", name);
00047
00048
00049 if (!fServerPort.ConnectPort(jack_server_entry)) {
00050 jack_error("Cannot connect to server Mach port");
00051 return -1;
00052 }
00053
00054
00055 char buf[256];
00056 snprintf(buf, sizeof(buf) - 1, "%s:%s", jack_client_entry, name);
00057
00058 if (!fClientPort.AllocatePort(buf, 16)) {
00059 jack_error("Cannot allocate client Mach port");
00060 return -1;
00061 }
00062
00063 JackLibGlobals::fGlobals->fClientTable[fClientPort.GetPort()] = client;
00064 return 0;
00065 }
00066
00067 void JackMachClientChannel::Close()
00068 {
00069 JackLog("JackMachClientChannel::Close\n");
00070 JackLibGlobals::fGlobals->fClientTable.erase(fClientPort.GetPort());
00071 fServerPort.DisconnectPort();
00072 fClientPort.DestroyPort();
00073
00074
00075 kern_return_t res;
00076 if ((res = mach_port_destroy(mach_task_self(), fPrivatePort)) != KERN_SUCCESS) {
00077 jack_error("JackMachClientChannel::Close err = %s", mach_error_string(res));
00078 }
00079 }
00080
00081 int JackMachClientChannel::Start()
00082 {
00083 JackLog("JackMachClientChannel::Start\n");
00084 if (fThread->Start() != 0) {
00085 jack_error("Cannot start Jack client listener");
00086 return -1;
00087 } else {
00088 return 0;
00089 }
00090 }
00091
00092 void JackMachClientChannel::Stop()
00093 {
00094 JackLog("JackMachClientChannel::Stop\n");
00095 fThread->Kill();
00096 }
00097
00098 void JackMachClientChannel::ClientNew(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result)
00099 {
00100 kern_return_t res = rpc_jack_client_new(fServerPort.GetPort(), (char*)name, &fPrivatePort, shared_engine, shared_client, shared_graph, result);
00101 if (res != KERN_SUCCESS) {
00102 *result = -1;
00103 jack_error("JackMachClientChannel::ClientNew err = %s", mach_error_string(res));
00104 }
00105 }
00106
00107 void JackMachClientChannel::ClientClose(int refnum, int* result)
00108 {
00109 kern_return_t res = rpc_jack_client_close(fPrivatePort, refnum, result);
00110 if (res != KERN_SUCCESS) {
00111 *result = -1;
00112 jack_error("JackMachClientChannel::ClientClose err = %s", mach_error_string(res));
00113 }
00114 }
00115
00116 void JackMachClientChannel::ClientActivate(int refnum, int* result)
00117 {
00118 kern_return_t res = rpc_jack_client_activate(fPrivatePort, refnum, result);
00119 if (res != KERN_SUCCESS) {
00120 *result = -1;
00121 jack_error("JackMachClientChannel::ClientActivate err = %s", mach_error_string(res));
00122 }
00123 }
00124
00125 void JackMachClientChannel::ClientDeactivate(int refnum, int* result)
00126 {
00127 kern_return_t res = rpc_jack_client_deactivate(fPrivatePort, refnum, result);
00128 if (res != KERN_SUCCESS) {
00129 *result = -1;
00130 jack_error("JackMachClientChannel::ClientDeactivate err = %s", mach_error_string(res));
00131 }
00132 }
00133
00134 void JackMachClientChannel::PortRegister(int refnum, const char* name, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index, int* result)
00135 {
00136 kern_return_t res = rpc_jack_port_register(fPrivatePort, refnum, (char*)name, flags, buffer_size, port_index, result);
00137 if (res != KERN_SUCCESS) {
00138 *result = -1;
00139 jack_error("JackMachClientChannel::PortRegister err = %s", mach_error_string(res));
00140 }
00141 }
00142
00143 void JackMachClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
00144 {
00145 kern_return_t res = rpc_jack_port_unregister(fPrivatePort, refnum, port_index, result);
00146 if (res != KERN_SUCCESS) {
00147 *result = -1;
00148 jack_error("JackMachClientChannel::PortUnRegister err = %s", mach_error_string(res));
00149 }
00150 }
00151
00152 void JackMachClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
00153 {
00154 kern_return_t res = rpc_jack_port_connect_name(fPrivatePort, refnum, (char*)src, (char*)dst, result);
00155 if (res != KERN_SUCCESS) {
00156 jack_error("JackMachClientChannel::PortConnect err = %s", mach_error_string(res));
00157 }
00158 }
00159
00160 void JackMachClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
00161 {
00162 kern_return_t res = rpc_jack_port_disconnect_name(fPrivatePort, refnum, (char*)src, (char*)dst, result);
00163 if (res != KERN_SUCCESS) {
00164 *result = -1;
00165 jack_error("JackMachClientChannel::PortDisconnect err = %s", mach_error_string(res));
00166 }
00167 }
00168
00169 void JackMachClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
00170 {
00171 kern_return_t res = rpc_jack_port_connect(fPrivatePort, refnum, src, dst, result);
00172 if (res != KERN_SUCCESS) {
00173 *result = -1;
00174 jack_error("JackMachClientChannel::PortConnect err = %s", mach_error_string(res));
00175 }
00176 }
00177
00178 void JackMachClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
00179 {
00180 kern_return_t res = rpc_jack_port_disconnect(fPrivatePort, refnum, src, dst, result);
00181 if (res != KERN_SUCCESS) {
00182 *result = -1;
00183 jack_error("JackMachClientChannel::PortDisconnect err = %s", mach_error_string(res));
00184 }
00185 }
00186
00187 void JackMachClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
00188 {
00189 kern_return_t res = rpc_jack_set_buffer_size(fPrivatePort, buffer_size, result);
00190 if (res != KERN_SUCCESS) {
00191 *result = -1;
00192 jack_error("JackMachClientChannel::SetBufferSize err = %s", mach_error_string(res));
00193 }
00194 }
00195
00196 void JackMachClientChannel::SetFreewheel(int onoff, int* result)
00197 {
00198 kern_return_t res = rpc_jack_set_freewheel(fPrivatePort, onoff, result);
00199 if (res != KERN_SUCCESS) {
00200 *result = -1;
00201 jack_error("JackMachClientChannel::SetFreewheel err = %s", mach_error_string(res));
00202 }
00203 }
00204
00205 void JackMachClientChannel::ReleaseTimebase(int refnum, int* result)
00206 {
00207 kern_return_t res = rpc_jack_release_timebase(fPrivatePort, refnum, result);
00208 if (res != KERN_SUCCESS) {
00209 *result = -1;
00210 jack_error("JackMachClientChannel::ReleaseTimebase err = %s", mach_error_string(res));
00211 }
00212 }
00213
00214 void JackMachClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
00215 {
00216 kern_return_t res = rpc_jack_set_timebase_callback(fPrivatePort, refnum, conditional, result);
00217 if (res != KERN_SUCCESS) {
00218 *result = -1;
00219 jack_error("JackMachClientChannel::SetTimebaseCallback err = %s", mach_error_string(res));
00220 }
00221 }
00222
00223 bool JackMachClientChannel::Execute()
00224 {
00225 kern_return_t res;
00226 if ((res = mach_msg_server(JackRPCClient_server, 1024, fClientPort.GetPort(), 0)) != KERN_SUCCESS) {
00227 jack_error("JackMachClientChannel::Execute err = %s", mach_error_string(res));
00228
00229 return false;
00230 } else {
00231 return true;
00232 }
00233 }
00234
00235 }
00236
00237