20 #include "JackSocketClientChannel.h"
21 #include "JackRequest.h"
22 #include "JackClient.h"
23 #include "JackGlobals.h"
24 #include "JackError.h"
29 JackSocketClientChannel::JackSocketClientChannel()
30 :JackGenericClientChannel(), fThread(this)
32 fRequest =
new JackClientSocket();
33 fNotificationSocket = NULL;
36 JackSocketClientChannel::~JackSocketClientChannel()
39 delete fNotificationSocket;
42 int JackSocketClientChannel::Open(
const char* server_name,
const char* name,
int uuid,
char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status)
45 jack_log(
"JackSocketClientChannel::Open name = %s", name);
47 if (fRequest->Connect(jack_server_dir, server_name, 0) < 0) {
53 ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (
int)options, (
int*)status, &result,
true);
55 int status1 = *status;
56 if (status1 & JackVersionError) {
57 jack_error(
"JACK protocol mismatch %d", JACK_PROTOCOL_VERSION);
59 jack_error(
"Client name = %s conflits with another running client", name);
64 if (fNotificationListenSocket.Bind(jack_client_dir, name_res, 0) < 0) {
74 fNotificationListenSocket.Close();
78 void JackSocketClientChannel::Close()
81 fNotificationListenSocket.Close();
82 if (fNotificationSocket)
83 fNotificationSocket->Close();
86 int JackSocketClientChannel::Start()
88 jack_log(
"JackSocketClientChannel::Start");
92 if (fThread.StartSync() != 0) {
93 jack_error(
"Cannot start Jack client listener");
100 void JackSocketClientChannel::Stop()
102 jack_log(
"JackSocketClientChannel::Stop");
108 jack_log(
"JackSocketClientChannel::Init");
109 fNotificationSocket = fNotificationListenSocket.Accept();
112 fNotificationListenSocket.Close();
115 if (!jack_tls_set(JackGlobals::fNotificationThread,
this)) {
116 jack_error(
"Failed to set thread notification key");
119 if (!fNotificationSocket) {
120 jack_error(
"JackSocketClientChannel: cannot establish notication socket");
127 bool JackSocketClientChannel::Execute()
132 if (event.Read(fNotificationSocket) < 0) {
133 jack_error(
"JackSocketClientChannel read fail");
137 res.fResult = fClient->ClientNotify(event.fRefNum, event.fName, event.fNotify, event.fSync, event.fMessage, event.fValue1, event.fValue2);
140 if (res.Write(fNotificationSocket) < 0) {
141 jack_error(
"JackSocketClientChannel write fail");
148 fNotificationSocket->Close();
SERVER_EXPORT void jack_error(const char *fmt,...)
SERVER_EXPORT void jack_log(const char *fmt,...)