00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "JackWinNamedPipeClientChannel.h"
00021 #include "JackRequest.h"
00022 #include "JackClient.h"
00023 #include "JackGlobals.h"
00024 #include "JackError.h"
00025
00026 namespace Jack
00027 {
00028
00029 JackWinNamedPipeClientChannel::JackWinNamedPipeClientChannel():fThread(this)
00030 {
00031 fClient = NULL;
00032 }
00033
00034 JackWinNamedPipeClientChannel::~JackWinNamedPipeClientChannel()
00035 {}
00036
00037 int JackWinNamedPipeClientChannel::ServerCheck(const char* server_name)
00038 {
00039 jack_log("JackWinNamedPipeClientChannel::ServerCheck = %s", server_name);
00040
00041
00042 if (fRequestPipe.Connect(jack_server_dir, server_name, 0) < 0) {
00043 jack_error("Cannot connect to server pipe");
00044 return -1;
00045 } else {
00046 return 0;
00047 }
00048 }
00049
00050 int JackWinNamedPipeClientChannel::Open(const char* server_name, const char* name, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status)
00051 {
00052 int result = 0;
00053 jack_log("JackWinNamedPipeClientChannel::Open name = %s", name);
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 if (fRequestPipe.Connect(jack_server_dir, server_name, 0) < 0) {
00064 jack_error("Cannot connect to server pipe");
00065 goto error;
00066 }
00067
00068
00069 ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result);
00070 if (result < 0) {
00071 jack_error("Client name = %s conflits with another running client", name);
00072 goto error;
00073 }
00074
00075 if (fNotificationListenPipe.Bind(jack_client_dir, name_res, 0) < 0) {
00076 jack_error("Cannot bind pipe");
00077 goto error;
00078 }
00079
00080 fClient = obj;
00081 return 0;
00082
00083 error:
00084 fRequestPipe.Close();
00085 fNotificationListenPipe.Close();
00086 return -1;
00087 }
00088
00089 void JackWinNamedPipeClientChannel::Close()
00090 {
00091 fRequestPipe.Close();
00092 fNotificationListenPipe.Close();
00093
00094 fThread.Stop();
00095 }
00096
00097 int JackWinNamedPipeClientChannel::Start()
00098 {
00099 jack_log("JackWinNamedPipeClientChannel::Start");
00100
00101
00102
00103 if (fThread.StartSync() != 0) {
00104 jack_error("Cannot start Jack client listener");
00105 return -1;
00106 } else {
00107 return 0;
00108 }
00109 }
00110
00111 void JackWinNamedPipeClientChannel::Stop()
00112 {
00113 jack_log("JackWinNamedPipeClientChannel::Stop");
00114 fThread.Kill();
00115 }
00116
00117 void JackWinNamedPipeClientChannel::ServerSyncCall(JackRequest* req, JackResult* res, int* result)
00118 {
00119 if (req->Write(&fRequestPipe) < 0) {
00120 jack_error("Could not write request type = %ld", req->fType);
00121 *result = -1;
00122 return ;
00123 }
00124
00125 if (res->Read(&fRequestPipe) < 0) {
00126 jack_error("Could not read result type = %ld", req->fType);
00127 *result = -1;
00128 return ;
00129 }
00130
00131 *result = res->fResult;
00132 }
00133
00134 void JackWinNamedPipeClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res, int* result)
00135 {
00136 if (req->Write(&fRequestPipe) < 0) {
00137 jack_error("Could not write request type = %ld", req->fType);
00138 *result = -1;
00139 } else {
00140 *result = 0;
00141 }
00142 }
00143
00144 void JackWinNamedPipeClientChannel::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result)
00145 {
00146 JackClientCheckRequest req(name, protocol, options);
00147 JackClientCheckResult res;
00148 ServerSyncCall(&req, &res, result);
00149 *status = res.fStatus;
00150 strcpy(name_res, res.fName);
00151 }
00152
00153 void JackWinNamedPipeClientChannel::ClientOpen(const char* name, int pid, int* shared_engine, int* shared_client, int* shared_graph, int* result)
00154 {
00155 JackClientOpenRequest req(name, pid);
00156 JackClientOpenResult res;
00157 ServerSyncCall(&req, &res, result);
00158 *shared_engine = res.fSharedEngine;
00159 *shared_client = res.fSharedClient;
00160 *shared_graph = res.fSharedGraph;
00161 }
00162
00163 void JackWinNamedPipeClientChannel::ClientClose(int refnum, int* result)
00164 {
00165 JackClientCloseRequest req(refnum);
00166 JackResult res;
00167 ServerSyncCall(&req, &res, result);
00168 }
00169
00170 void JackWinNamedPipeClientChannel::ClientActivate(int refnum, int is_real_time, int* result)
00171 {
00172 JackActivateRequest req(refnum, is_real_time);
00173 JackResult res;
00174 ServerSyncCall(&req, &res, result);
00175 }
00176
00177 void JackWinNamedPipeClientChannel::ClientDeactivate(int refnum, int* result)
00178 {
00179 JackDeactivateRequest req(refnum);
00180 JackResult res;
00181 ServerSyncCall(&req, &res, result);
00182 }
00183
00184 void JackWinNamedPipeClientChannel::PortRegister(int refnum, const char* name, const char* type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index, int* result)
00185 {
00186 JackPortRegisterRequest req(refnum, name, type, flags, buffer_size);
00187 JackPortRegisterResult res;
00188 ServerSyncCall(&req, &res, result);
00189 *port_index = res.fPortIndex;
00190 }
00191
00192 void JackWinNamedPipeClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
00193 {
00194 JackPortUnRegisterRequest req(refnum, port_index);
00195 JackResult res;
00196 ServerSyncCall(&req, &res, result);
00197 }
00198
00199 void JackWinNamedPipeClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
00200 {
00201 JackPortConnectNameRequest req(refnum, src, dst);
00202 JackResult res;
00203 ServerSyncCall(&req, &res, result);
00204 }
00205
00206 void JackWinNamedPipeClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
00207 {
00208 JackPortDisconnectNameRequest req(refnum, src, dst);
00209 JackResult res;
00210 ServerSyncCall(&req, &res, result);
00211 }
00212
00213 void JackWinNamedPipeClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
00214 {
00215 JackPortConnectRequest req(refnum, src, dst);
00216 JackResult res;
00217 ServerSyncCall(&req, &res, result);
00218 }
00219
00220 void JackWinNamedPipeClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
00221 {
00222 JackPortDisconnectRequest req(refnum, src, dst);
00223 JackResult res;
00224 ServerSyncCall(&req, &res, result);
00225 }
00226
00227 void JackWinNamedPipeClientChannel::PortRename(int refnum, jack_port_id_t port, const char* name, int* result)
00228 {
00229 JackPortRenameRequest req(refnum, port, name);
00230 JackResult res;
00231 ServerSyncCall(&req, &res, result);
00232 }
00233
00234 void JackWinNamedPipeClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
00235 {
00236 JackSetBufferSizeRequest req(buffer_size);
00237 JackResult res;
00238 ServerSyncCall(&req, &res, result);
00239 }
00240
00241 void JackWinNamedPipeClientChannel::SetFreewheel(int onoff, int* result)
00242 {
00243 JackSetFreeWheelRequest req(onoff);
00244 JackResult res;
00245 ServerSyncCall(&req, &res, result);
00246 }
00247
00248 void JackWinNamedPipeClientChannel::ReleaseTimebase(int refnum, int* result)
00249 {
00250 JackReleaseTimebaseRequest req(refnum);
00251 JackResult res;
00252 ServerSyncCall(&req, &res, result);
00253 }
00254
00255 void JackWinNamedPipeClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
00256 {
00257 JackSetTimebaseCallbackRequest req(refnum, conditional);
00258 JackResult res;
00259 ServerSyncCall(&req, &res, result);
00260 }
00261
00262 void JackWinNamedPipeClientChannel::GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
00263 {
00264 JackGetInternalClientNameRequest req(refnum, int_ref);
00265 JackGetInternalClientNameResult res;
00266 ServerSyncCall(&req, &res, result);
00267 strcpy(name_res, res.fName);
00268 }
00269
00270 void JackWinNamedPipeClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
00271 {
00272 JackInternalClientHandleRequest req(refnum, client_name);
00273 JackInternalClientHandleResult res;
00274 ServerSyncCall(&req, &res, result);
00275 *int_ref = res.fIntRefNum;
00276 *status = res.fStatus;
00277 }
00278
00279 void JackWinNamedPipeClientChannel::InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result)
00280 {
00281 JackInternalClientLoadRequest req(refnum, client_name, so_name, objet_data, options);
00282 JackInternalClientLoadResult res;
00283 ServerSyncCall(&req, &res, result);
00284 *int_ref = res.fIntRefNum;
00285 *status = res.fStatus;
00286 }
00287
00288 void JackWinNamedPipeClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result)
00289 {
00290 JackInternalClientUnloadRequest req(refnum, int_ref);
00291 JackInternalClientUnloadResult res;
00292 ServerSyncCall(&req, &res, result);
00293 *status = res.fStatus;
00294 }
00295
00296 bool JackWinNamedPipeClientChannel::Init()
00297 {
00298 jack_log("JackWinNamedPipeClientChannel::Init");
00299
00300 if (!fNotificationListenPipe.Accept()) {
00301 jack_error("JackWinNamedPipeClientChannel: cannot establish notification pipe");
00302 return false;
00303 } else {
00304 return fClient->Init();
00305 }
00306 }
00307
00308 bool JackWinNamedPipeClientChannel::Execute()
00309 {
00310 JackClientNotification event;
00311 JackResult res;
00312
00313 if (event.Read(&fNotificationListenPipe) < 0) {
00314 jack_error("JackWinNamedPipeClientChannel read fail");
00315 goto error;
00316 }
00317
00318 res.fResult = fClient->ClientNotify(event.fRefNum, event.fName, event.fNotify, event.fSync, event.fMessage, event.fValue1, event.fValue2);
00319
00320 if (event.fSync) {
00321 if (res.Write(&fNotificationListenPipe) < 0) {
00322 jack_error("JackWinNamedPipeClientChannel write fail");
00323 goto error;
00324 }
00325 }
00326 return true;
00327
00328 error:
00329
00330 fNotificationListenPipe.Close();
00331 fRequestPipe.Close();
00332 fClient->ShutDown();
00333 return false;
00334 }
00335
00336 }
00337
00338