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.

262 lines
7.1KB

  1. /*
  2. Copyright (C) 2004-2006 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 "JackWinNamedPipeClientChannel.h"
  16. #include "JackRequest.h"
  17. #include "JackClient.h"
  18. #include "JackGlobals.h"
  19. namespace Jack
  20. {
  21. JackWinNamedPipeClientChannel::JackWinNamedPipeClientChannel()
  22. {
  23. fThread = JackGlobals::MakeThread(this);
  24. fClient = NULL;
  25. }
  26. JackWinNamedPipeClientChannel::~JackWinNamedPipeClientChannel()
  27. {
  28. delete fThread;
  29. }
  30. int JackWinNamedPipeClientChannel::Open(const char* name, JackClient* obj)
  31. {
  32. JackLog("JackWinNamedPipeClientChannel::Open name = %s\n", name);
  33. if (fNotificationListenPipe.Bind(jack_client_dir, name, 0) < 0) {
  34. jack_error("Cannot bind pipe");
  35. goto error;
  36. }
  37. if (fRequestPipe.Connect(jack_server_dir, 0) < 0) {
  38. jack_error("Cannot connect to server pipe");
  39. goto error;
  40. }
  41. fClient = obj;
  42. return 0;
  43. error:
  44. fRequestPipe.Close();
  45. fNotificationListenPipe.Close();
  46. return -1;
  47. }
  48. void JackWinNamedPipeClientChannel::Close()
  49. {
  50. fRequestPipe.Close();
  51. fNotificationListenPipe.Close();
  52. // Here the thread will correctly stop when the pipe are closed
  53. fThread->Stop();
  54. }
  55. int JackWinNamedPipeClientChannel::Start()
  56. {
  57. JackLog("JackWinNamedPipeClientChannel::Start\n");
  58. if (fThread->Start() != 0) {
  59. jack_error("Cannot start Jack client listener");
  60. return -1;
  61. } else {
  62. return 0;
  63. }
  64. }
  65. void JackWinNamedPipeClientChannel::Stop()
  66. {
  67. JackLog("JackWinNamedPipeClientChannel::Stop\n");
  68. //fThread->Kill(); Unsafe on WIN32...
  69. }
  70. void JackWinNamedPipeClientChannel::ServerSyncCall(JackRequest* req, JackResult* res, int* result)
  71. {
  72. if (req->Write(&fRequestPipe) < 0) {
  73. jack_error("Could not write request type = %ld", req->fType);
  74. *result = -1;
  75. return ;
  76. }
  77. if (res->Read(&fRequestPipe) < 0) {
  78. jack_error("Could not read result type = %ld", req->fType);
  79. *result = -1;
  80. return ;
  81. }
  82. *result = res->fResult;
  83. }
  84. void JackWinNamedPipeClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res, int* result)
  85. {
  86. if (req->Write(&fRequestPipe) < 0) {
  87. jack_error("Could not write request type = %ld", req->fType);
  88. *result = -1;
  89. } else {
  90. *result = 0;
  91. }
  92. }
  93. void JackWinNamedPipeClientChannel::ClientNew(const char* name, int* shared_engine, int* shared_client, int* shared_ports, int* result)
  94. {
  95. JackClientNewRequest req(name);
  96. JackClientNewResult res;
  97. ServerSyncCall(&req, &res, result);
  98. *shared_engine = res.fSharedEngine;
  99. *shared_client = res.fSharedClient;
  100. *shared_ports = res.fSharedPorts;
  101. }
  102. void JackWinNamedPipeClientChannel::ClientClose(int refnum, int* result)
  103. {
  104. JackClientCloseRequest req(refnum);
  105. JackResult res;
  106. ServerAsyncCall(&req, &res, result);
  107. }
  108. void JackWinNamedPipeClientChannel::ClientActivate(int refnum, int* result)
  109. {
  110. JackActivateRequest req(refnum);
  111. JackResult res;
  112. ServerSyncCall(&req, &res, result);
  113. }
  114. void JackWinNamedPipeClientChannel::ClientDeactivate(int refnum, int* result)
  115. {
  116. JackDeactivateRequest req(refnum);
  117. JackResult res;
  118. ServerSyncCall(&req, &res, result);
  119. }
  120. void JackWinNamedPipeClientChannel::PortRegister(int refnum, const char* name, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index, int* result)
  121. {
  122. JackPortRegisterRequest req(refnum, name, "audio", flags, buffer_size);
  123. JackPortRegisterResult res;
  124. ServerSyncCall(&req, &res, result);
  125. *port_index = res.fPortIndex;
  126. }
  127. void JackWinNamedPipeClientChannel::PortUnRegister(int refnum, jack_port_id_t port_index, int* result)
  128. {
  129. JackPortUnRegisterRequest req(refnum, port_index);
  130. JackResult res;
  131. ServerSyncCall(&req, &res, result);
  132. }
  133. void JackWinNamedPipeClientChannel::PortConnect(int refnum, const char* src, const char* dst, int* result)
  134. {
  135. JackPortConnectNameRequest req(refnum, src, dst);
  136. JackResult res;
  137. ServerSyncCall(&req, &res, result);
  138. }
  139. void JackWinNamedPipeClientChannel::PortDisconnect(int refnum, const char* src, const char* dst, int* result)
  140. {
  141. JackPortDisconnectNameRequest req(refnum, src, dst);
  142. JackResult res;
  143. ServerSyncCall(&req, &res, result);
  144. }
  145. void JackWinNamedPipeClientChannel::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
  146. {
  147. JackPortConnectRequest req(refnum, src, dst);
  148. JackResult res;
  149. ServerSyncCall(&req, &res, result);
  150. }
  151. void JackWinNamedPipeClientChannel::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst, int* result)
  152. {
  153. JackPortDisconnectRequest req(refnum, src, dst);
  154. JackResult res;
  155. ServerSyncCall(&req, &res, result);
  156. }
  157. void JackWinNamedPipeClientChannel::SetBufferSize(jack_nframes_t nframes, int* result)
  158. {
  159. JackSetBufferSizeRequest req(nframes);
  160. JackResult res;
  161. ServerSyncCall(&req, &res, result);
  162. }
  163. void JackWinNamedPipeClientChannel::SetFreewheel(int onoff, int* result)
  164. {
  165. JackSetFreeWheelRequest req(onoff);
  166. JackResult res;
  167. ServerSyncCall(&req, &res, result);
  168. }
  169. void JackWinNamedPipeClientChannel::ReleaseTimebase(int refnum, int* result)
  170. {
  171. JackReleaseTimebaseRequest req(refnum);
  172. JackResult res;
  173. ServerSyncCall(&req, &res, result);
  174. }
  175. void JackWinNamedPipeClientChannel::SetTimebaseCallback(int refnum, int conditional, int* result)
  176. {
  177. JackSetTimebaseCallbackRequest req(refnum, conditional);
  178. JackResult res;
  179. ServerSyncCall(&req, &res, result);
  180. }
  181. bool JackWinNamedPipeClientChannel::Init()
  182. {
  183. JackLog("JackWinNamedPipeClientChannel::Init \n");
  184. if (!fNotificationListenPipe.Accept()) {
  185. jack_error("JackWinNamedPipeClientChannel: cannot establish notification pipe");
  186. return false;
  187. } else {
  188. return true;
  189. }
  190. }
  191. bool JackWinNamedPipeClientChannel::Execute()
  192. {
  193. JackClientNotification event;
  194. JackResult res;
  195. //fClient->Init(); // To be checked
  196. if (event.Read(&fNotificationListenPipe) < 0) {
  197. fNotificationListenPipe.Close();
  198. jack_error("JackWinNamedPipeClientChannel read fail");
  199. goto error;
  200. }
  201. res.fResult = fClient->ClientNotify(event.fRefNum, event.fName, event.fNotify, event.fSync, event.fValue);
  202. if (event.fSync) {
  203. if (res.Write(&fNotificationListenPipe) < 0) {
  204. fNotificationListenPipe.Close();
  205. jack_error("JackWinNamedPipeClientChannel write fail");
  206. goto error;
  207. }
  208. }
  209. return true;
  210. error:
  211. //fClient->ShutDown(); needed ??
  212. return false;
  213. }
  214. } // end of namespace