jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
9.6KB

  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "JackGenericClientChannel.h"
  16. #include "JackClient.h"
  17. #include "JackGlobals.h"
  18. #include "JackError.h"
  19. namespace Jack
  20. {
  21. JackGenericClientChannel::JackGenericClientChannel()
  22. {}
  23. JackGenericClientChannel::~JackGenericClientChannel()
  24. {}
  25. int JackGenericClientChannel::ServerCheck(const char* server_name)
  26. {
  27. jack_log("JackGenericClientChannel::ServerCheck = %s", server_name);
  28. // Connect to server
  29. if (fRequest->Connect(jack_server_dir, server_name, 0) < 0) {
  30. jack_error("Cannot connect to server request channel");
  31. return -1;
  32. } else {
  33. return 0;
  34. }
  35. }
  36. void JackGenericClientChannel::ServerSyncCall(JackRequest* req, JackResult* res, int* result)
  37. {
  38. // Check call context
  39. if (jack_tls_get(JackGlobals::fNotificationThread)) {
  40. jack_error("Cannot callback the server in notification thread!");
  41. *result = -1;
  42. return;
  43. }
  44. if (!JackGlobals::fServerRunning) {
  45. jack_error("Server is not running");
  46. *result = -1;
  47. return;
  48. }
  49. if (req->Write(fRequest) < 0) {
  50. jack_error("Could not write request type = %ld", req->fType);
  51. *result = -1;
  52. return;
  53. }
  54. if (res->Read(fRequest) < 0) {
  55. jack_error("Could not read result type = %ld", req->fType);
  56. *result = -1;
  57. return;
  58. }
  59. *result = res->fResult;
  60. }
  61. void JackGenericClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res, int* result)
  62. {
  63. // Check call context
  64. if (jack_tls_get(JackGlobals::fNotificationThread)) {
  65. jack_error("Cannot callback the server in notification thread!");
  66. *result = -1;
  67. return;
  68. }
  69. if (!JackGlobals::fServerRunning) {
  70. jack_error("Server is not running");
  71. *result = -1;
  72. return;
  73. }
  74. if (req->Write(fRequest) < 0) {
  75. jack_error("Could not write request type = %ld", req->fType);
  76. *result = -1;
  77. } else {
  78. *result = 0;
  79. }
  80. }
  81. void JackGenericClientChannel::ClientCheck(const char* name, jack_uuid_t uuid, char* name_res, int protocol, int options, int* status, int* result, int open)
  82. {
  83. JackClientCheckRequest req(name, protocol, options, uuid, open);
  84. JackClientCheckResult res;
  85. ServerSyncCall(&req, &res, result);
  86. *status |= res.fStatus;
  87. strcpy(name_res, res.fName);
  88. }
  89. void JackGenericClientChannel::ClientOpen(const char* name, int pid, jack_uuid_t uuid, int* shared_engine, int* shared_client, int* shared_graph, int* result)
  90. {
  91. JackClientOpenRequest req(name, pid, uuid);
  92. JackClientOpenResult res;
  93. ServerSyncCall(&req, &res, result);
  94. *shared_engine = res.fSharedEngine;
  95. *shared_client = res.fSharedClient;
  96. *shared_graph = res.fSharedGraph;
  97. }
  98. void JackGenericClientChannel::ClientClose(int refnum, int* result)
  99. {
  100. JackClientCloseRequest req(refnum);
  101. JackResult res;
  102. ServerSyncCall(&req, &res, result);
  103. }
  104. void JackGenericClientChannel::ClientActivate(int refnum, int is_real_time, int* result)
  105. {
  106. JackActivateRequest req(refnum, is_real_time);
  107. JackResult res;
  108. ServerSyncCall(&req, &res, result);
  109. }
  110. void JackGenericClientChannel::ClientDeactivate(int refnum, int* result)
  111. {
  112. JackDeactivateRequest req(refnum);
  113. JackResult res;
  114. ServerSyncCall(&req, &res, result);
  115. }
  116. void JackGenericClientChannel::PortRegister(int refnum, const char* name, const char* type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index, int* result)
  117. {
  118. JackPortRegisterRequest req(refnum, name, type, flags, buffer_size);
  119. JackPortRegisterResult res;
  120. ServerSyncCall(&req, &res, result);
  121. *port_index = res.fPortIndex;
  122. }
  123. void JackGenericClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
  124. {
  125. JackPortUnRegisterRequest req(refnum, port_index);
  126. JackResult res;
  127. ServerSyncCall(&req, &res, result);
  128. }
  129. void JackGenericClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
  130. {
  131. JackPortConnectNameRequest req(refnum, src, dst);
  132. JackResult res;
  133. ServerSyncCall(&req, &res, result);
  134. }
  135. void JackGenericClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
  136. {
  137. JackPortDisconnectNameRequest req(refnum, src, dst);
  138. JackResult res;
  139. ServerSyncCall(&req, &res, result);
  140. }
  141. void JackGenericClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
  142. {
  143. JackPortConnectRequest req(refnum, src, dst);
  144. JackResult res;
  145. ServerSyncCall(&req, &res, result);
  146. }
  147. void JackGenericClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
  148. {
  149. JackPortDisconnectRequest req(refnum, src, dst);
  150. JackResult res;
  151. ServerSyncCall(&req, &res, result);
  152. }
  153. void JackGenericClientChannel::PortRename(int refnum, jack_port_id_t port, const char* name, int* result)
  154. {
  155. JackPortRenameRequest req(refnum, port, name);
  156. JackResult res;
  157. ServerSyncCall(&req, &res, result);
  158. }
  159. void JackGenericClientChannel::SetBufferSize(jack_nframes_t buffer_size, int* result)
  160. {
  161. JackSetBufferSizeRequest req(buffer_size);
  162. JackResult res;
  163. ServerSyncCall(&req, &res, result);
  164. }
  165. void JackGenericClientChannel::SetFreewheel(int onoff, int* result)
  166. {
  167. JackSetFreeWheelRequest req(onoff);
  168. JackResult res;
  169. ServerSyncCall(&req, &res, result);
  170. }
  171. void JackGenericClientChannel::ComputeTotalLatencies(int* result)
  172. {
  173. JackComputeTotalLatenciesRequest req;
  174. JackResult res;
  175. ServerSyncCall(&req, &res, result);
  176. }
  177. void JackGenericClientChannel::SessionNotify(int refnum, const char* target, jack_session_event_type_t type, const char* path, jack_session_command_t** result)
  178. {
  179. JackSessionNotifyRequest req(refnum, path, type, target);
  180. JackSessionNotifyResult res;
  181. int intresult;
  182. ServerSyncCall(&req, &res, &intresult);
  183. *result = res.GetCommands();
  184. }
  185. void JackGenericClientChannel::SessionReply(int refnum, int* result)
  186. {
  187. JackSessionReplyRequest req(refnum);
  188. JackResult res;
  189. ServerSyncCall(&req, &res, result);
  190. }
  191. void JackGenericClientChannel::GetUUIDForClientName(int refnum, const char* client_name, char* uuid_res, int* result)
  192. {
  193. JackGetUUIDRequest req(client_name);
  194. JackUUIDResult res;
  195. ServerSyncCall(&req, &res, result);
  196. strncpy(uuid_res, res.fUUID, JACK_UUID_SIZE);
  197. }
  198. void JackGenericClientChannel::GetClientNameForUUID(int refnum, const char* uuid, char* name_res, int* result)
  199. {
  200. JackGetClientNameRequest req(uuid);
  201. JackClientNameResult res;
  202. ServerSyncCall(&req, &res, result);
  203. strncpy(name_res, res.fName, JACK_CLIENT_NAME_SIZE);
  204. }
  205. void JackGenericClientChannel::ClientHasSessionCallback(const char* client_name, int* result)
  206. {
  207. JackClientHasSessionCallbackRequest req(client_name);
  208. JackResult res;
  209. ServerSyncCall(&req, &res, result);
  210. }
  211. void JackGenericClientChannel::ReserveClientName(int refnum, const char* client_name, const char* uuid, int* result)
  212. {
  213. JackReserveNameRequest req(refnum, client_name, uuid);
  214. JackResult res;
  215. ServerSyncCall(&req, &res, result);
  216. }
  217. void JackGenericClientChannel::ReleaseTimebase(int refnum, int* result)
  218. {
  219. JackReleaseTimebaseRequest req(refnum);
  220. JackResult res;
  221. ServerSyncCall(&req, &res, result);
  222. }
  223. void JackGenericClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
  224. {
  225. JackSetTimebaseCallbackRequest req(refnum, conditional);
  226. JackResult res;
  227. ServerSyncCall(&req, &res, result);
  228. }
  229. void JackGenericClientChannel::GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
  230. {
  231. JackGetInternalClientNameRequest req(refnum, int_ref);
  232. JackGetInternalClientNameResult res;
  233. ServerSyncCall(&req, &res, result);
  234. strcpy(name_res, res.fName);
  235. }
  236. void JackGenericClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
  237. {
  238. JackInternalClientHandleRequest req(refnum, client_name);
  239. JackInternalClientHandleResult res;
  240. ServerSyncCall(&req, &res, result);
  241. *int_ref = res.fIntRefNum;
  242. *status = res.fStatus;
  243. }
  244. void JackGenericClientChannel::InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, jack_uuid_t uuid, int* result)
  245. {
  246. JackInternalClientLoadRequest req(refnum, client_name, so_name, objet_data, options, uuid);
  247. JackInternalClientLoadResult res;
  248. ServerSyncCall(&req, &res, result);
  249. *int_ref = res.fIntRefNum;
  250. *status = res.fStatus;
  251. }
  252. void JackGenericClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result)
  253. {
  254. JackInternalClientUnloadRequest req(refnum, int_ref);
  255. JackInternalClientUnloadResult res;
  256. ServerSyncCall(&req, &res, result);
  257. *status = res.fStatus;
  258. }
  259. void JackGenericClientChannel::PropertyChangeNotify(jack_uuid_t subject, const char* key, jack_property_change_t change, int* result)
  260. {
  261. JackPropertyChangeNotifyRequest req(subject, key, change);
  262. JackResult res;
  263. ServerAsyncCall(&req, &res, result);
  264. }
  265. } // end of namespace