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.

1742 lines
47KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackRequest__
  17. #define __JackRequest__
  18. #include "JackConstants.h"
  19. #include "JackError.h"
  20. #include "JackPlatformPlug.h"
  21. #include "JackChannel.h"
  22. #include "JackTime.h"
  23. #include "types.h"
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <list>
  28. namespace Jack
  29. {
  30. #define CheckRes(exp) { if ((exp) < 0) { jack_error("CheckRes error"); return -1; } }
  31. #define CheckSize() { CheckRes(trans->Read(&fSize, sizeof(int))); if (fSize != Size()) { jack_error("CheckSize error size = %d Size() = %d", fSize, Size()); return -1; } }
  32. /*!
  33. \brief Session API constants.
  34. */
  35. enum JackSessionReply {
  36. kImmediateSessionReply = 1,
  37. kPendingSessionReply = 2
  38. };
  39. /*!
  40. \brief Request from client to server.
  41. */
  42. struct JackRequest
  43. {
  44. enum RequestType {
  45. kRegisterPort = 1,
  46. kUnRegisterPort = 2,
  47. kConnectPorts = 3,
  48. kDisconnectPorts = 4,
  49. kSetTimeBaseClient = 5,
  50. kActivateClient = 6,
  51. kDeactivateClient = 7,
  52. kDisconnectPort = 8,
  53. kSetClientCapabilities = 9,
  54. kGetPortConnections = 10,
  55. kGetPortNConnections = 11,
  56. kReleaseTimebase = 12,
  57. kSetTimebaseCallback = 13,
  58. kSetBufferSize = 20,
  59. kSetFreeWheel = 21,
  60. kClientCheck = 22,
  61. kClientOpen = 23,
  62. kClientClose = 24,
  63. kConnectNamePorts = 25,
  64. kDisconnectNamePorts = 26,
  65. kGetInternalClientName = 27,
  66. kInternalClientHandle = 28,
  67. kInternalClientLoad = 29,
  68. kInternalClientUnload = 30,
  69. kPortRename = 31,
  70. kNotification = 32,
  71. kSessionNotify = 33,
  72. kSessionReply = 34,
  73. kGetClientByUUID = 35,
  74. kReserveClientName = 36,
  75. kGetUUIDByClient = 37,
  76. kClientHasSessionCallback = 38,
  77. kComputeTotalLatencies = 39,
  78. kPropertyChangeNotify = 40
  79. };
  80. RequestType fType;
  81. int fSize;
  82. JackRequest(): fType((RequestType)0), fSize(0)
  83. {}
  84. JackRequest(RequestType type): fType(type), fSize(0)
  85. {}
  86. virtual ~JackRequest()
  87. {}
  88. virtual int Read(detail::JackChannelTransactionInterface* trans)
  89. {
  90. return trans->Read(&fType, sizeof(RequestType));
  91. }
  92. virtual int Write(detail::JackChannelTransactionInterface* trans) { return -1; }
  93. virtual int Write(detail::JackChannelTransactionInterface* trans, int size)
  94. {
  95. fSize = size;
  96. CheckRes(trans->Write(&fType, sizeof(RequestType)));
  97. return trans->Write(&fSize, sizeof(int));
  98. }
  99. virtual int Size() { return 0; }
  100. };
  101. /*!
  102. \brief Result from the server.
  103. */
  104. struct JackResult
  105. {
  106. int fResult;
  107. JackResult(): fResult( -1)
  108. {}
  109. JackResult(int result): fResult(result)
  110. {}
  111. virtual ~JackResult()
  112. {}
  113. virtual int Read(detail::JackChannelTransactionInterface* trans)
  114. {
  115. return trans->Read(&fResult, sizeof(int));
  116. }
  117. virtual int Write(detail::JackChannelTransactionInterface* trans)
  118. {
  119. return trans->Write(&fResult, sizeof(int));
  120. }
  121. };
  122. /*!
  123. \brief CheckClient request.
  124. */
  125. struct JackClientCheckRequest : public JackRequest
  126. {
  127. char fName[JACK_CLIENT_NAME_SIZE+1];
  128. int fProtocol;
  129. int fOptions;
  130. int fOpen;
  131. jack_uuid_t fUUID;
  132. JackClientCheckRequest() : fProtocol(0), fOptions(0), fOpen(0), fUUID(JACK_UUID_EMPTY_INITIALIZER)
  133. {
  134. memset(fName, 0, sizeof(fName));
  135. }
  136. JackClientCheckRequest(const char* name, int protocol, int options, jack_uuid_t uuid, int open = false)
  137. : JackRequest(JackRequest::kClientCheck), fProtocol(protocol), fOptions(options), fOpen(open), fUUID(uuid)
  138. {
  139. memset(fName, 0, sizeof(fName));
  140. snprintf(fName, sizeof(fName), "%s", name);
  141. }
  142. int Read(detail::JackChannelTransactionInterface* trans)
  143. {
  144. CheckSize();
  145. CheckRes(trans->Read(&fName, sizeof(fName)));
  146. CheckRes(trans->Read(&fProtocol, sizeof(int)));
  147. CheckRes(trans->Read(&fOptions, sizeof(int)));
  148. CheckRes(trans->Read(&fUUID, sizeof(jack_uuid_t)));
  149. return trans->Read(&fOpen, sizeof(int));
  150. }
  151. int Write(detail::JackChannelTransactionInterface* trans)
  152. {
  153. CheckRes(JackRequest::Write(trans, Size()));
  154. CheckRes(trans->Write(&fName, sizeof(fName)));
  155. CheckRes(trans->Write(&fProtocol, sizeof(int)));
  156. CheckRes(trans->Write(&fOptions, sizeof(int)));
  157. CheckRes(trans->Write(&fUUID, sizeof(jack_uuid_t)));
  158. return trans->Write(&fOpen, sizeof(int));
  159. }
  160. int Size() { return sizeof(fName) + 3 * sizeof(int) + sizeof(jack_uuid_t); }
  161. };
  162. /*!
  163. \brief CheckClient result.
  164. */
  165. struct JackClientCheckResult : public JackResult
  166. {
  167. char fName[JACK_CLIENT_NAME_SIZE+1];
  168. int fStatus;
  169. JackClientCheckResult(): JackResult(), fStatus(0)
  170. {
  171. memset(fName, 0, sizeof(fName));
  172. }
  173. JackClientCheckResult(int32_t result, const char* name, int status)
  174. : JackResult(result), fStatus(status)
  175. {
  176. memset(fName, 0, sizeof(fName));
  177. snprintf(fName, sizeof(fName), "%s", name);
  178. }
  179. int Read(detail::JackChannelTransactionInterface* trans)
  180. {
  181. CheckRes(JackResult::Read(trans));
  182. CheckRes(trans->Read(&fName, sizeof(fName)));
  183. CheckRes(trans->Read(&fStatus, sizeof(int)));
  184. return 0;
  185. }
  186. int Write(detail::JackChannelTransactionInterface* trans)
  187. {
  188. CheckRes(JackResult::Write(trans));
  189. CheckRes(trans->Write(&fName, sizeof(fName)));
  190. CheckRes(trans->Write(&fStatus, sizeof(int)));
  191. return 0;
  192. }
  193. };
  194. /*!
  195. \brief NewClient request.
  196. */
  197. struct JackClientOpenRequest : public JackRequest
  198. {
  199. int fPID;
  200. jack_uuid_t fUUID;
  201. char fName[JACK_CLIENT_NAME_SIZE+1];
  202. JackClientOpenRequest() : fPID(0), fUUID(JACK_UUID_EMPTY_INITIALIZER)
  203. {
  204. memset(fName, 0, sizeof(fName));
  205. }
  206. JackClientOpenRequest(const char* name, int pid, jack_uuid_t uuid): JackRequest(JackRequest::kClientOpen)
  207. {
  208. memset(fName, 0, sizeof(fName));
  209. snprintf(fName, sizeof(fName), "%s", name);
  210. fPID = pid;
  211. fUUID = uuid;
  212. }
  213. int Read(detail::JackChannelTransactionInterface* trans)
  214. {
  215. CheckSize();
  216. CheckRes(trans->Read(&fPID, sizeof(int)));
  217. CheckRes(trans->Read(&fUUID, sizeof(jack_uuid_t)));
  218. return trans->Read(&fName, sizeof(fName));
  219. }
  220. int Write(detail::JackChannelTransactionInterface* trans)
  221. {
  222. CheckRes(JackRequest::Write(trans, Size()));
  223. CheckRes(trans->Write(&fPID, sizeof(int)));
  224. CheckRes(trans->Write(&fUUID, sizeof(jack_uuid_t)));
  225. return trans->Write(&fName, sizeof(fName));
  226. }
  227. int Size() { return sizeof(int) + sizeof(jack_uuid_t) + sizeof(fName); }
  228. };
  229. /*!
  230. \brief NewClient result.
  231. */
  232. struct JackClientOpenResult : public JackResult
  233. {
  234. int fSharedEngine;
  235. int fSharedClient;
  236. int fSharedGraph;
  237. JackClientOpenResult()
  238. : JackResult(), fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1)
  239. {}
  240. JackClientOpenResult(int32_t result, int index1, int index2, int index3)
  241. : JackResult(result), fSharedEngine(index1), fSharedClient(index2), fSharedGraph(index3)
  242. {}
  243. int Read(detail::JackChannelTransactionInterface* trans)
  244. {
  245. CheckRes(JackResult::Read(trans));
  246. CheckRes(trans->Read(&fSharedEngine, sizeof(int)));
  247. CheckRes(trans->Read(&fSharedClient, sizeof(int)));
  248. CheckRes(trans->Read(&fSharedGraph, sizeof(int)));
  249. return 0;
  250. }
  251. int Write(detail::JackChannelTransactionInterface* trans)
  252. {
  253. CheckRes(JackResult::Write(trans));
  254. CheckRes(trans->Write(&fSharedEngine, sizeof(int)));
  255. CheckRes(trans->Write(&fSharedClient, sizeof(int)));
  256. CheckRes(trans->Write(&fSharedGraph, sizeof(int)));
  257. return 0;
  258. }
  259. };
  260. /*!
  261. \brief CloseClient request.
  262. */
  263. struct JackClientCloseRequest : public JackRequest
  264. {
  265. int fRefNum;
  266. JackClientCloseRequest() : fRefNum(0)
  267. {}
  268. JackClientCloseRequest(int refnum): JackRequest(JackRequest::kClientClose), fRefNum(refnum)
  269. {}
  270. int Read(detail::JackChannelTransactionInterface* trans)
  271. {
  272. CheckSize();
  273. return trans->Read(&fRefNum, sizeof(int));
  274. }
  275. int Write(detail::JackChannelTransactionInterface* trans)
  276. {
  277. CheckRes(JackRequest::Write(trans, Size()));
  278. return trans->Write(&fRefNum, sizeof(int));
  279. }
  280. int Size() { return sizeof(int); }
  281. };
  282. /*!
  283. \brief Activate request.
  284. */
  285. struct JackActivateRequest : public JackRequest
  286. {
  287. int fRefNum;
  288. int fIsRealTime;
  289. JackActivateRequest() : fRefNum(0), fIsRealTime(0)
  290. {}
  291. JackActivateRequest(int refnum, int is_real_time)
  292. : JackRequest(JackRequest::kActivateClient), fRefNum(refnum), fIsRealTime(is_real_time)
  293. {}
  294. int Read(detail::JackChannelTransactionInterface* trans)
  295. {
  296. CheckSize();
  297. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  298. return trans->Read(&fIsRealTime, sizeof(int));
  299. }
  300. int Write(detail::JackChannelTransactionInterface* trans)
  301. {
  302. CheckRes(JackRequest::Write(trans, Size()));
  303. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  304. return trans->Write(&fIsRealTime, sizeof(int));
  305. }
  306. int Size() { return 2 * sizeof(int); }
  307. };
  308. /*!
  309. \brief Deactivate request.
  310. */
  311. struct JackDeactivateRequest : public JackRequest
  312. {
  313. int fRefNum;
  314. JackDeactivateRequest() : fRefNum(0)
  315. {}
  316. JackDeactivateRequest(int refnum): JackRequest(JackRequest::kDeactivateClient), fRefNum(refnum)
  317. {}
  318. int Read(detail::JackChannelTransactionInterface* trans)
  319. {
  320. CheckSize();
  321. return trans->Read(&fRefNum, sizeof(int));
  322. }
  323. int Write(detail::JackChannelTransactionInterface* trans)
  324. {
  325. CheckRes(JackRequest::Write(trans, Size()));
  326. return trans->Write(&fRefNum, sizeof(int));
  327. }
  328. int Size() { return sizeof(int); }
  329. };
  330. /*!
  331. \brief PortRegister request.
  332. */
  333. struct JackPortRegisterRequest : public JackRequest
  334. {
  335. int fRefNum;
  336. char fName[JACK_PORT_NAME_SIZE + 1]; // port short name
  337. char fPortType[JACK_PORT_TYPE_SIZE + 1];
  338. unsigned int fFlags;
  339. unsigned int fBufferSize;
  340. JackPortRegisterRequest() : fRefNum(0), fFlags(0), fBufferSize(0)
  341. {
  342. memset(fName, 0, sizeof(fName));
  343. memset(fPortType, 0, sizeof(fPortType));
  344. }
  345. JackPortRegisterRequest(int refnum, const char* name, const char* port_type, unsigned int flags, unsigned int buffer_size)
  346. : JackRequest(JackRequest::kRegisterPort), fRefNum(refnum), fFlags(flags), fBufferSize(buffer_size)
  347. {
  348. memset(fName, 0, sizeof(fName));
  349. memset(fPortType, 0, sizeof(fPortType));
  350. strncpy(fName, name, sizeof(fName)-1);
  351. strncpy(fPortType, port_type, sizeof(fPortType)-1);
  352. }
  353. int Read(detail::JackChannelTransactionInterface* trans)
  354. {
  355. CheckSize();
  356. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  357. CheckRes(trans->Read(&fName, sizeof(fName)));
  358. CheckRes(trans->Read(&fPortType, sizeof(fPortType)));
  359. CheckRes(trans->Read(&fFlags, sizeof(unsigned int)));
  360. CheckRes(trans->Read(&fBufferSize, sizeof(unsigned int)));
  361. return 0;
  362. }
  363. int Write(detail::JackChannelTransactionInterface* trans)
  364. {
  365. CheckRes(JackRequest::Write(trans, Size()));
  366. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  367. CheckRes(trans->Write(&fName, sizeof(fName)));
  368. CheckRes(trans->Write(&fPortType, sizeof(fPortType)));
  369. CheckRes(trans->Write(&fFlags, sizeof(unsigned int)));
  370. CheckRes(trans->Write(&fBufferSize, sizeof(unsigned int)));
  371. return 0;
  372. }
  373. int Size() { return sizeof(int) + sizeof(fName) + sizeof(fPortType) + 2 * sizeof(unsigned int); }
  374. };
  375. /*!
  376. \brief PortRegister result.
  377. */
  378. struct JackPortRegisterResult : public JackResult
  379. {
  380. jack_port_id_t fPortIndex;
  381. JackPortRegisterResult(): JackResult(), fPortIndex(NO_PORT)
  382. {}
  383. int Read(detail::JackChannelTransactionInterface* trans)
  384. {
  385. CheckRes(JackResult::Read(trans));
  386. return trans->Read(&fPortIndex, sizeof(jack_port_id_t));
  387. }
  388. int Write(detail::JackChannelTransactionInterface* trans)
  389. {
  390. CheckRes(JackResult::Write(trans));
  391. return trans->Write(&fPortIndex, sizeof(jack_port_id_t));
  392. }
  393. };
  394. /*!
  395. \brief PortUnregister request.
  396. */
  397. struct JackPortUnRegisterRequest : public JackRequest
  398. {
  399. int fRefNum;
  400. jack_port_id_t fPortIndex;
  401. JackPortUnRegisterRequest() : fRefNum(0), fPortIndex(0)
  402. {}
  403. JackPortUnRegisterRequest(int refnum, jack_port_id_t index)
  404. : JackRequest(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
  405. {}
  406. int Read(detail::JackChannelTransactionInterface* trans)
  407. {
  408. CheckSize();
  409. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  410. CheckRes(trans->Read(&fPortIndex, sizeof(jack_port_id_t)));
  411. return 0;
  412. }
  413. int Write(detail::JackChannelTransactionInterface* trans)
  414. {
  415. CheckRes(JackRequest::Write(trans, Size()));
  416. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  417. CheckRes(trans->Write(&fPortIndex, sizeof(jack_port_id_t)));
  418. return 0;
  419. }
  420. int Size() { return sizeof(int) + sizeof(jack_port_id_t); }
  421. };
  422. /*!
  423. \brief PortConnectName request.
  424. */
  425. struct JackPortConnectNameRequest : public JackRequest
  426. {
  427. int fRefNum;
  428. char fSrc[REAL_JACK_PORT_NAME_SIZE+1]; // port full name
  429. char fDst[REAL_JACK_PORT_NAME_SIZE+1]; // port full name
  430. JackPortConnectNameRequest() : fRefNum(0)
  431. {
  432. memset(fSrc, 0, sizeof(fSrc));
  433. memset(fDst, 0, sizeof(fDst));
  434. }
  435. JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name)
  436. : JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
  437. {
  438. memset(fSrc, 0, sizeof(fSrc));
  439. memset(fDst, 0, sizeof(fDst));
  440. strncpy(fSrc, src_name, sizeof(fSrc)-1);
  441. strncpy(fDst, dst_name, sizeof(fDst)-1);
  442. }
  443. int Read(detail::JackChannelTransactionInterface* trans)
  444. {
  445. CheckSize();
  446. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  447. CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
  448. CheckRes(trans->Read(&fDst, sizeof(fDst)));
  449. return 0;
  450. }
  451. int Write(detail::JackChannelTransactionInterface* trans)
  452. {
  453. CheckRes(JackRequest::Write(trans, Size()));
  454. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  455. CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
  456. CheckRes(trans->Write(&fDst, sizeof(fDst)));
  457. return 0;
  458. }
  459. int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
  460. };
  461. /*!
  462. \brief PortDisconnectName request.
  463. */
  464. struct JackPortDisconnectNameRequest : public JackRequest
  465. {
  466. int fRefNum;
  467. char fSrc[REAL_JACK_PORT_NAME_SIZE+1]; // port full name
  468. char fDst[REAL_JACK_PORT_NAME_SIZE+1]; // port full name
  469. JackPortDisconnectNameRequest() : fRefNum(0)
  470. {
  471. memset(fSrc, 0, sizeof(fSrc));
  472. memset(fDst, 0, sizeof(fDst));
  473. }
  474. JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name)
  475. : JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
  476. {
  477. memset(fSrc, 0, sizeof(fSrc));
  478. memset(fDst, 0, sizeof(fDst));
  479. strncpy(fSrc, src_name, sizeof(fSrc)-1);
  480. strncpy(fDst, dst_name, sizeof(fDst)-1);
  481. }
  482. int Read(detail::JackChannelTransactionInterface* trans)
  483. {
  484. CheckSize();
  485. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  486. CheckRes(trans->Read(&fSrc, sizeof(fSrc)));
  487. CheckRes(trans->Read(&fDst, sizeof(fDst)));
  488. return 0;
  489. }
  490. int Write(detail::JackChannelTransactionInterface* trans)
  491. {
  492. CheckRes(JackRequest::Write(trans, Size()));
  493. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  494. CheckRes(trans->Write(&fSrc, sizeof(fSrc)));
  495. CheckRes(trans->Write(&fDst, sizeof(fDst)));
  496. return 0;
  497. }
  498. int Size() { return sizeof(int) + sizeof(fSrc) + sizeof(fDst); }
  499. };
  500. /*!
  501. \brief PortConnect request.
  502. */
  503. struct JackPortConnectRequest : public JackRequest
  504. {
  505. int fRefNum;
  506. jack_port_id_t fSrc;
  507. jack_port_id_t fDst;
  508. JackPortConnectRequest() : fRefNum(0), fSrc(0), fDst(0)
  509. {}
  510. JackPortConnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst)
  511. : JackRequest(JackRequest::kConnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
  512. {}
  513. int Read(detail::JackChannelTransactionInterface* trans)
  514. {
  515. CheckSize();
  516. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  517. CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t)));
  518. CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t)));
  519. return 0;
  520. }
  521. int Write(detail::JackChannelTransactionInterface* trans)
  522. {
  523. CheckRes(JackRequest::Write(trans, Size()));
  524. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  525. CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t)));
  526. CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t)));
  527. return 0;
  528. }
  529. int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
  530. };
  531. /*!
  532. \brief PortDisconnect request.
  533. */
  534. struct JackPortDisconnectRequest : public JackRequest
  535. {
  536. int fRefNum;
  537. jack_port_id_t fSrc;
  538. jack_port_id_t fDst;
  539. JackPortDisconnectRequest() : fRefNum(0), fSrc(0), fDst(0)
  540. {}
  541. JackPortDisconnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst)
  542. : JackRequest(JackRequest::kDisconnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
  543. {}
  544. int Read(detail::JackChannelTransactionInterface* trans)
  545. {
  546. CheckSize();
  547. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  548. CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t)));
  549. CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t)));
  550. return 0;
  551. }
  552. int Write(detail::JackChannelTransactionInterface* trans)
  553. {
  554. CheckRes(JackRequest::Write(trans, Size()));
  555. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  556. CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t)));
  557. CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t)));
  558. return 0;
  559. }
  560. int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(jack_port_id_t); }
  561. };
  562. /*!
  563. \brief PortRename request.
  564. */
  565. struct JackPortRenameRequest : public JackRequest
  566. {
  567. int fRefNum;
  568. jack_port_id_t fPort;
  569. char fName[JACK_PORT_NAME_SIZE + 1]; // port short name
  570. JackPortRenameRequest() : fRefNum(0), fPort(0)
  571. {
  572. memset(fName, 0, sizeof(fName));
  573. }
  574. JackPortRenameRequest(int refnum, jack_port_id_t port, const char* name)
  575. : JackRequest(JackRequest::kPortRename), fRefNum(refnum), fPort(port)
  576. {
  577. memset(fName, 0, sizeof(fName));
  578. strncpy(fName, name, sizeof(fName)-1);
  579. }
  580. int Read(detail::JackChannelTransactionInterface* trans)
  581. {
  582. CheckSize();
  583. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  584. CheckRes(trans->Read(&fPort, sizeof(jack_port_id_t)));
  585. CheckRes(trans->Read(&fName, sizeof(fName)));
  586. return 0;
  587. }
  588. int Write(detail::JackChannelTransactionInterface* trans)
  589. {
  590. CheckRes(JackRequest::Write(trans, Size()));
  591. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  592. CheckRes(trans->Write(&fPort, sizeof(jack_port_id_t)));
  593. CheckRes(trans->Write(&fName, sizeof(fName)));
  594. return 0;
  595. }
  596. int Size() { return sizeof(int) + sizeof(jack_port_id_t) + sizeof(fName); }
  597. };
  598. /*!
  599. \brief SetBufferSize request.
  600. */
  601. struct JackSetBufferSizeRequest : public JackRequest
  602. {
  603. jack_nframes_t fBufferSize;
  604. JackSetBufferSizeRequest() : fBufferSize(0)
  605. {}
  606. JackSetBufferSizeRequest(jack_nframes_t buffer_size)
  607. : JackRequest(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
  608. {}
  609. int Read(detail::JackChannelTransactionInterface* trans)
  610. {
  611. CheckSize();
  612. return trans->Read(&fBufferSize, sizeof(jack_nframes_t));
  613. }
  614. int Write(detail::JackChannelTransactionInterface* trans)
  615. {
  616. CheckRes(JackRequest::Write(trans, Size()));
  617. return trans->Write(&fBufferSize, sizeof(jack_nframes_t));
  618. }
  619. int Size() { return sizeof(jack_nframes_t); }
  620. };
  621. /*!
  622. \brief SetFreeWheel request.
  623. */
  624. struct JackSetFreeWheelRequest : public JackRequest
  625. {
  626. int fOnOff;
  627. JackSetFreeWheelRequest() : fOnOff(0)
  628. {}
  629. JackSetFreeWheelRequest(int onoff)
  630. : JackRequest(JackRequest::kSetFreeWheel), fOnOff(onoff)
  631. {}
  632. int Read(detail::JackChannelTransactionInterface* trans)
  633. {
  634. CheckSize();
  635. return trans->Read(&fOnOff, sizeof(int));
  636. }
  637. int Write(detail::JackChannelTransactionInterface* trans)
  638. {
  639. CheckRes(JackRequest::Write(trans, Size()));
  640. return trans->Write(&fOnOff, sizeof(int));
  641. }
  642. int Size() { return sizeof(int); }
  643. };
  644. /*!
  645. \brief ComputeTotalLatencies request.
  646. */
  647. struct JackComputeTotalLatenciesRequest : public JackRequest
  648. {
  649. JackComputeTotalLatenciesRequest()
  650. : JackRequest(JackRequest::kComputeTotalLatencies)
  651. {}
  652. int Read(detail::JackChannelTransactionInterface* trans)
  653. {
  654. CheckSize();
  655. return 0;
  656. }
  657. int Write(detail::JackChannelTransactionInterface* trans)
  658. {
  659. CheckRes(JackRequest::Write(trans, Size()));
  660. return 0;
  661. }
  662. int Size() { return 0; }
  663. };
  664. /*!
  665. \brief ReleaseTimebase request.
  666. */
  667. struct JackReleaseTimebaseRequest : public JackRequest
  668. {
  669. int fRefNum;
  670. JackReleaseTimebaseRequest() : fRefNum(0)
  671. {}
  672. JackReleaseTimebaseRequest(int refnum)
  673. : JackRequest(JackRequest::kReleaseTimebase), fRefNum(refnum)
  674. {}
  675. int Read(detail::JackChannelTransactionInterface* trans)
  676. {
  677. CheckSize();
  678. return trans->Read(&fRefNum, sizeof(int));
  679. }
  680. int Write(detail::JackChannelTransactionInterface* trans)
  681. {
  682. CheckRes(JackRequest::Write(trans, Size()));
  683. return trans->Write(&fRefNum, sizeof(int));
  684. }
  685. int Size() { return sizeof(int); }
  686. };
  687. /*!
  688. \brief SetTimebaseCallback request.
  689. */
  690. struct JackSetTimebaseCallbackRequest : public JackRequest
  691. {
  692. int fRefNum;
  693. int fConditionnal;
  694. JackSetTimebaseCallbackRequest() : fRefNum(0), fConditionnal(0)
  695. {}
  696. JackSetTimebaseCallbackRequest(int refnum, int conditional)
  697. : JackRequest(JackRequest::kSetTimebaseCallback), fRefNum(refnum), fConditionnal(conditional)
  698. {}
  699. int Read(detail::JackChannelTransactionInterface* trans)
  700. {
  701. CheckSize();
  702. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  703. return trans->Read(&fConditionnal, sizeof(int));
  704. }
  705. int Write(detail::JackChannelTransactionInterface* trans)
  706. {
  707. CheckRes(JackRequest::Write(trans, Size()));
  708. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  709. return trans->Write(&fConditionnal, sizeof(int));
  710. }
  711. int Size() { return sizeof(int) + sizeof(int); }
  712. };
  713. /*!
  714. \brief GetInternalClientName request.
  715. */
  716. struct JackGetInternalClientNameRequest : public JackRequest
  717. {
  718. int fRefNum;
  719. int fIntRefNum;
  720. JackGetInternalClientNameRequest() : fRefNum(0), fIntRefNum(0)
  721. {}
  722. JackGetInternalClientNameRequest(int refnum, int int_ref)
  723. : JackRequest(JackRequest::kGetInternalClientName), fRefNum(refnum), fIntRefNum(int_ref)
  724. {}
  725. int Read(detail::JackChannelTransactionInterface* trans)
  726. {
  727. CheckSize();
  728. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  729. return trans->Read(&fIntRefNum, sizeof(int));
  730. }
  731. int Write(detail::JackChannelTransactionInterface* trans)
  732. {
  733. CheckRes(JackRequest::Write(trans, Size()));
  734. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  735. return trans->Write(&fIntRefNum, sizeof(int));
  736. }
  737. int Size() { return sizeof(int) + sizeof(int); }
  738. };
  739. /*!
  740. \brief GetInternalClient result.
  741. */
  742. struct JackGetInternalClientNameResult : public JackResult
  743. {
  744. char fName[JACK_CLIENT_NAME_SIZE+1];
  745. JackGetInternalClientNameResult(): JackResult()
  746. {
  747. memset(fName, 0, sizeof(fName));
  748. }
  749. JackGetInternalClientNameResult(int32_t result, const char* name)
  750. : JackResult(result)
  751. {
  752. memset(fName, 0, sizeof(fName));
  753. snprintf(fName, sizeof(fName), "%s", name);
  754. }
  755. int Read(detail::JackChannelTransactionInterface* trans)
  756. {
  757. CheckRes(JackResult::Read(trans));
  758. CheckRes(trans->Read(&fName, sizeof(fName)));
  759. return 0;
  760. }
  761. int Write(detail::JackChannelTransactionInterface* trans)
  762. {
  763. CheckRes(JackResult::Write(trans));
  764. CheckRes(trans->Write(&fName, sizeof(fName)));
  765. return 0;
  766. }
  767. int Size() { return sizeof(fName); }
  768. };
  769. /*!
  770. \brief InternalClientHandle request.
  771. */
  772. struct JackInternalClientHandleRequest : public JackRequest
  773. {
  774. int fRefNum;
  775. char fName[JACK_CLIENT_NAME_SIZE+1];
  776. JackInternalClientHandleRequest() : fRefNum(0)
  777. {
  778. memset(fName, 0, sizeof(fName));
  779. }
  780. JackInternalClientHandleRequest(int refnum, const char* client_name)
  781. : JackRequest(JackRequest::kInternalClientHandle), fRefNum(refnum)
  782. {
  783. memset(fName, 0, sizeof(fName));
  784. snprintf(fName, sizeof(fName), "%s", client_name);
  785. }
  786. int Read(detail::JackChannelTransactionInterface* trans)
  787. {
  788. CheckSize();
  789. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  790. return trans->Read(&fName, sizeof(fName));
  791. }
  792. int Write(detail::JackChannelTransactionInterface* trans)
  793. {
  794. CheckRes(JackRequest::Write(trans, Size()));
  795. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  796. return trans->Write(&fName, sizeof(fName));
  797. }
  798. int Size() { return sizeof(int) + sizeof(fName); }
  799. };
  800. /*!
  801. \brief InternalClientHandle result.
  802. */
  803. struct JackInternalClientHandleResult : public JackResult
  804. {
  805. int fStatus;
  806. int fIntRefNum;
  807. JackInternalClientHandleResult(): JackResult(), fStatus(0), fIntRefNum(0)
  808. {}
  809. JackInternalClientHandleResult(int32_t result, int status, int int_ref)
  810. : JackResult(result), fStatus(status), fIntRefNum(int_ref)
  811. {}
  812. int Read(detail::JackChannelTransactionInterface* trans)
  813. {
  814. CheckRes(JackResult::Read(trans));
  815. CheckRes(trans->Read(&fStatus, sizeof(int)));
  816. CheckRes(trans->Read(&fIntRefNum, sizeof(int)));
  817. return 0;
  818. }
  819. int Write(detail::JackChannelTransactionInterface* trans)
  820. {
  821. CheckRes(JackResult::Write(trans));
  822. CheckRes(trans->Write(&fStatus, sizeof(int)));
  823. CheckRes(trans->Write(&fIntRefNum, sizeof(int)));
  824. return 0;
  825. }
  826. int Size() { return sizeof(int) + sizeof(int); }
  827. };
  828. /*!
  829. \brief InternalClientLoad request.
  830. */
  831. struct JackInternalClientLoadRequest : public JackRequest
  832. {
  833. #ifndef MAX_PATH
  834. #define MAX_PATH 256
  835. #endif
  836. int fRefNum;
  837. char fName[JACK_CLIENT_NAME_SIZE+1];
  838. char fDllName[MAX_PATH+1];
  839. char fLoadInitName[JACK_LOAD_INIT_LIMIT+1];
  840. int fOptions;
  841. jack_uuid_t fUUID;
  842. JackInternalClientLoadRequest() : fRefNum(0), fOptions(0), fUUID(JACK_UUID_EMPTY_INITIALIZER)
  843. {
  844. memset(fName, 0, sizeof(fName));
  845. memset(fDllName, 0, sizeof(fDllName));
  846. memset(fLoadInitName, 0, sizeof(fLoadInitName));
  847. }
  848. JackInternalClientLoadRequest(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, jack_uuid_t uuid )
  849. : JackRequest(JackRequest::kInternalClientLoad), fRefNum(refnum), fOptions(options), fUUID(uuid)
  850. {
  851. memset(fName, 0, sizeof(fName));
  852. memset(fDllName, 0, sizeof(fDllName));
  853. memset(fLoadInitName, 0, sizeof(fLoadInitName));
  854. strncpy(fName, client_name, sizeof(fName)-1);
  855. if (so_name) {
  856. strncpy(fDllName, so_name, sizeof(fDllName)-1);
  857. }
  858. if (objet_data) {
  859. strncpy(fLoadInitName, objet_data, sizeof(fLoadInitName)-1);
  860. }
  861. }
  862. int Read(detail::JackChannelTransactionInterface* trans)
  863. {
  864. CheckSize();
  865. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  866. CheckRes(trans->Read(&fName, sizeof(fName)));
  867. CheckRes(trans->Read(&fDllName, sizeof(fDllName)));
  868. CheckRes(trans->Read(&fLoadInitName, sizeof(fLoadInitName)));
  869. CheckRes(trans->Read(&fUUID, sizeof(jack_uuid_t)));
  870. return trans->Read(&fOptions, sizeof(int));
  871. }
  872. int Write(detail::JackChannelTransactionInterface* trans)
  873. {
  874. CheckRes(JackRequest::Write(trans, Size()));
  875. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  876. CheckRes(trans->Write(&fName, sizeof(fName)));
  877. CheckRes(trans->Write(&fDllName, sizeof(fDllName)));
  878. CheckRes(trans->Write(&fLoadInitName, sizeof(fLoadInitName)));
  879. CheckRes(trans->Write(&fUUID, sizeof(jack_uuid_t)));
  880. return trans->Write(&fOptions, sizeof(int));
  881. }
  882. int Size() { return sizeof(int) + sizeof(fName) + sizeof(fDllName) + sizeof(fLoadInitName) + sizeof(int) + sizeof(jack_uuid_t); }
  883. };
  884. /*!
  885. \brief InternalClientLoad result.
  886. */
  887. struct JackInternalClientLoadResult : public JackResult
  888. {
  889. int fStatus;
  890. int fIntRefNum;
  891. JackInternalClientLoadResult(): JackResult(), fStatus(0), fIntRefNum(0)
  892. {}
  893. JackInternalClientLoadResult(int32_t result, int status, int int_ref)
  894. : JackResult(result), fStatus(status), fIntRefNum(int_ref)
  895. {}
  896. int Read(detail::JackChannelTransactionInterface* trans)
  897. {
  898. CheckRes(JackResult::Read(trans));
  899. CheckRes(trans->Read(&fStatus, sizeof(int)));
  900. CheckRes(trans->Read(&fIntRefNum, sizeof(int)));
  901. return 0;
  902. }
  903. int Write(detail::JackChannelTransactionInterface* trans)
  904. {
  905. CheckRes(JackResult::Write(trans));
  906. CheckRes(trans->Write(&fStatus, sizeof(int)));
  907. CheckRes(trans->Write(&fIntRefNum, sizeof(int)));
  908. return 0;
  909. }
  910. int Size() { return sizeof(int) + sizeof(int); }
  911. };
  912. /*!
  913. \brief InternalClientUnload request.
  914. */
  915. struct JackInternalClientUnloadRequest : public JackRequest
  916. {
  917. int fRefNum;
  918. int fIntRefNum;
  919. JackInternalClientUnloadRequest() : fRefNum(0), fIntRefNum(0)
  920. {}
  921. JackInternalClientUnloadRequest(int refnum, int int_ref)
  922. : JackRequest(JackRequest::kInternalClientUnload), fRefNum(refnum), fIntRefNum(int_ref)
  923. {}
  924. int Read(detail::JackChannelTransactionInterface* trans)
  925. {
  926. CheckSize();
  927. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  928. return trans->Read(&fIntRefNum, sizeof(int));
  929. }
  930. int Write(detail::JackChannelTransactionInterface* trans)
  931. {
  932. CheckRes(JackRequest::Write(trans, Size()));
  933. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  934. return trans->Write(&fIntRefNum, sizeof(int));
  935. }
  936. int Size() { return sizeof(int) + sizeof(int); }
  937. };
  938. /*!
  939. \brief InternalClientLoad result.
  940. */
  941. struct JackInternalClientUnloadResult : public JackResult
  942. {
  943. int fStatus;
  944. JackInternalClientUnloadResult(): JackResult(), fStatus(0)
  945. {}
  946. JackInternalClientUnloadResult(int32_t result, int status)
  947. : JackResult(result), fStatus(status)
  948. {}
  949. int Read(detail::JackChannelTransactionInterface* trans)
  950. {
  951. CheckRes(JackResult::Read(trans));
  952. CheckRes(trans->Read(&fStatus, sizeof(int)));
  953. return 0;
  954. }
  955. int Write(detail::JackChannelTransactionInterface* trans)
  956. {
  957. CheckRes(JackResult::Write(trans));
  958. CheckRes(trans->Write(&fStatus, sizeof(int)));
  959. return 0;
  960. }
  961. int Size() { return sizeof(int); }
  962. };
  963. /*!
  964. \brief ClientNotification request.
  965. */
  966. struct JackClientNotificationRequest : public JackRequest
  967. {
  968. int fRefNum;
  969. int fNotify;
  970. int fValue;
  971. JackClientNotificationRequest() : fRefNum(0), fNotify(0), fValue(0)
  972. {}
  973. JackClientNotificationRequest(int refnum, int notify, int value)
  974. : JackRequest(JackRequest::kNotification), fRefNum(refnum), fNotify(notify), fValue(value)
  975. {}
  976. int Read(detail::JackChannelTransactionInterface* trans)
  977. {
  978. CheckSize();
  979. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  980. CheckRes(trans->Read(&fNotify, sizeof(int)));
  981. CheckRes(trans->Read(&fValue, sizeof(int)));
  982. return 0;
  983. }
  984. int Write(detail::JackChannelTransactionInterface* trans)
  985. {
  986. CheckRes(JackRequest::Write(trans, Size()));
  987. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  988. CheckRes(trans->Write(&fNotify, sizeof(int)));
  989. CheckRes(trans->Write(&fValue, sizeof(int)));
  990. return 0;
  991. }
  992. int Size() { return 3 * sizeof(int); }
  993. };
  994. struct JackSessionCommand
  995. {
  996. char fUUID[JACK_UUID_STRING_SIZE];
  997. char fClientName[JACK_CLIENT_NAME_SIZE+1];
  998. char fCommand[JACK_SESSION_COMMAND_SIZE+1];
  999. jack_session_flags_t fFlags;
  1000. JackSessionCommand() : fFlags(JackSessionSaveError)
  1001. {
  1002. memset(fUUID, 0, sizeof(fUUID));
  1003. memset(fClientName, 0, sizeof(fClientName));
  1004. memset(fCommand, 0, sizeof(fCommand));
  1005. }
  1006. JackSessionCommand(const char *uuid, const char *clientname, const char *command, jack_session_flags_t flags)
  1007. {
  1008. memset(fUUID, 0, sizeof(fUUID));
  1009. memset(fClientName, 0, sizeof(fClientName));
  1010. memset(fCommand, 0, sizeof(fCommand));
  1011. strncpy(fUUID, uuid, sizeof(fUUID)-1);
  1012. strncpy(fClientName, clientname, sizeof(fClientName)-1);
  1013. strncpy(fCommand, command, sizeof(fCommand)-1);
  1014. fFlags = flags;
  1015. }
  1016. };
  1017. struct JackSessionNotifyResult : public JackResult
  1018. {
  1019. std::list<JackSessionCommand> fCommandList;
  1020. bool fDone;
  1021. JackSessionNotifyResult(): JackResult(), fDone(false)
  1022. {}
  1023. JackSessionNotifyResult(int32_t result)
  1024. : JackResult(result), fDone(false)
  1025. {}
  1026. int Read(detail::JackChannelTransactionInterface* trans)
  1027. {
  1028. if (trans == NULL)
  1029. {
  1030. return 0;
  1031. }
  1032. CheckRes(JackResult::Read(trans));
  1033. while (true) {
  1034. JackSessionCommand buffer;
  1035. CheckRes(trans->Read(buffer.fUUID, sizeof(buffer.fUUID)));
  1036. if (buffer.fUUID[0] == '\0')
  1037. break;
  1038. CheckRes(trans->Read(buffer.fClientName, sizeof(buffer.fClientName)));
  1039. CheckRes(trans->Read(buffer.fCommand, sizeof(buffer.fCommand)));
  1040. CheckRes(trans->Read(&(buffer.fFlags), sizeof(buffer.fFlags)));
  1041. fCommandList.push_back(buffer);
  1042. }
  1043. fDone = true;
  1044. return 0;
  1045. }
  1046. int Write(detail::JackChannelTransactionInterface* trans)
  1047. {
  1048. if (trans == NULL)
  1049. {
  1050. fDone = true;
  1051. return 0;
  1052. }
  1053. char terminator[JACK_UUID_STRING_SIZE];
  1054. memset(terminator, 0, sizeof(terminator));
  1055. CheckRes(JackResult::Write(trans));
  1056. for (std::list<JackSessionCommand>::iterator i = fCommandList.begin(); i != fCommandList.end(); i++) {
  1057. CheckRes(trans->Write(i->fUUID, sizeof(i->fUUID)));
  1058. CheckRes(trans->Write(i->fClientName, sizeof(i->fClientName)));
  1059. CheckRes(trans->Write(i->fCommand, sizeof(i->fCommand)));
  1060. CheckRes(trans->Write(&(i->fFlags), sizeof(i->fFlags)));
  1061. }
  1062. CheckRes(trans->Write(terminator, sizeof(terminator)));
  1063. return 0;
  1064. }
  1065. jack_session_command_t* GetCommands()
  1066. {
  1067. /* TODO: some kind of signal should be used instead */
  1068. while (!fDone)
  1069. {
  1070. JackSleep(50000); /* 50 ms */
  1071. }
  1072. jack_session_command_t* session_command = (jack_session_command_t *)malloc(sizeof(jack_session_command_t) * (fCommandList.size() + 1));
  1073. int i = 0;
  1074. for (std::list<JackSessionCommand>::iterator ci = fCommandList.begin(); ci != fCommandList.end(); ci++) {
  1075. session_command[i].uuid = strdup(ci->fUUID);
  1076. session_command[i].client_name = strdup(ci->fClientName);
  1077. session_command[i].command = strdup(ci->fCommand);
  1078. session_command[i].flags = ci->fFlags;
  1079. i += 1;
  1080. }
  1081. session_command[i].uuid = NULL;
  1082. session_command[i].client_name = NULL;
  1083. session_command[i].command = NULL;
  1084. session_command[i].flags = (jack_session_flags_t)0;
  1085. return session_command;
  1086. }
  1087. };
  1088. /*!
  1089. \brief SessionNotify request.
  1090. */
  1091. struct JackSessionNotifyRequest : public JackRequest
  1092. {
  1093. char fPath[JACK_MESSAGE_SIZE+1];
  1094. char fDst[JACK_CLIENT_NAME_SIZE+1];
  1095. jack_session_event_type_t fEventType;
  1096. int fRefNum;
  1097. JackSessionNotifyRequest() : fEventType(JackSessionSave), fRefNum(0)
  1098. {}
  1099. JackSessionNotifyRequest(int refnum, const char* path, jack_session_event_type_t type, const char* dst)
  1100. : JackRequest(JackRequest::kSessionNotify), fEventType(type), fRefNum(refnum)
  1101. {
  1102. memset(fPath, 0, sizeof(fPath));
  1103. memset(fDst, 0, sizeof(fDst));
  1104. strncpy(fPath, path, sizeof(fPath)-1);
  1105. if (dst) {
  1106. strncpy(fDst, dst, sizeof(fDst)-1);
  1107. }
  1108. }
  1109. int Read(detail::JackChannelTransactionInterface* trans)
  1110. {
  1111. CheckSize();
  1112. CheckRes(trans->Read(&fRefNum, sizeof(fRefNum)));
  1113. CheckRes(trans->Read(&fPath, sizeof(fPath)));
  1114. CheckRes(trans->Read(&fDst, sizeof(fDst)));
  1115. CheckRes(trans->Read(&fEventType, sizeof(fEventType)));
  1116. return 0;
  1117. }
  1118. int Write(detail::JackChannelTransactionInterface* trans)
  1119. {
  1120. CheckRes(JackRequest::Write(trans, Size()));
  1121. CheckRes(trans->Write(&fRefNum, sizeof(fRefNum)));
  1122. CheckRes(trans->Write(&fPath, sizeof(fPath)));
  1123. CheckRes(trans->Write(&fDst, sizeof(fDst)));
  1124. CheckRes(trans->Write(&fEventType, sizeof(fEventType)));
  1125. return 0;
  1126. }
  1127. int Size() { return sizeof(fRefNum) + sizeof(fPath) + sizeof(fDst) + sizeof(fEventType); }
  1128. };
  1129. struct JackSessionReplyRequest : public JackRequest
  1130. {
  1131. int fRefNum;
  1132. JackSessionReplyRequest() : fRefNum(0)
  1133. {}
  1134. JackSessionReplyRequest(int refnum)
  1135. : JackRequest(JackRequest::kSessionReply), fRefNum(refnum)
  1136. {}
  1137. int Read(detail::JackChannelTransactionInterface* trans)
  1138. {
  1139. CheckSize();
  1140. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  1141. return 0;
  1142. }
  1143. int Write(detail::JackChannelTransactionInterface* trans)
  1144. {
  1145. CheckRes(JackRequest::Write(trans, Size()));
  1146. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  1147. return 0;
  1148. }
  1149. int Size() { return sizeof(int); }
  1150. };
  1151. struct JackClientNameResult : public JackResult
  1152. {
  1153. char fName[JACK_CLIENT_NAME_SIZE+1];
  1154. JackClientNameResult(): JackResult()
  1155. {
  1156. memset(fName, 0, sizeof(fName));
  1157. }
  1158. JackClientNameResult(int32_t result, const char* name)
  1159. : JackResult(result)
  1160. {
  1161. memset(fName, 0, sizeof(fName));
  1162. strncpy(fName, name, sizeof(fName)-1);
  1163. }
  1164. int Read(detail::JackChannelTransactionInterface* trans)
  1165. {
  1166. CheckRes(JackResult::Read(trans));
  1167. CheckRes(trans->Read(&fName, sizeof(fName)));
  1168. return 0;
  1169. }
  1170. int Write(detail::JackChannelTransactionInterface* trans)
  1171. {
  1172. CheckRes(JackResult::Write(trans));
  1173. CheckRes(trans->Write(&fName, sizeof(fName)));
  1174. return 0;
  1175. }
  1176. };
  1177. struct JackUUIDResult : public JackResult
  1178. {
  1179. char fUUID[JACK_UUID_STRING_SIZE];
  1180. JackUUIDResult(): JackResult()
  1181. {
  1182. memset(fUUID, 0, sizeof(fUUID));
  1183. }
  1184. JackUUIDResult(int32_t result, const char* uuid)
  1185. : JackResult(result)
  1186. {
  1187. memset(fUUID, 0, sizeof(fUUID));
  1188. strncpy(fUUID, uuid, sizeof(fUUID)-1);
  1189. }
  1190. int Read(detail::JackChannelTransactionInterface* trans)
  1191. {
  1192. CheckRes(JackResult::Read(trans));
  1193. CheckRes(trans->Read(&fUUID, sizeof(fUUID)));
  1194. return 0;
  1195. }
  1196. int Write(detail::JackChannelTransactionInterface* trans)
  1197. {
  1198. CheckRes(JackResult::Write(trans));
  1199. CheckRes(trans->Write(&fUUID, sizeof(fUUID)));
  1200. return 0;
  1201. }
  1202. };
  1203. struct JackGetUUIDRequest : public JackRequest
  1204. {
  1205. char fName[JACK_CLIENT_NAME_SIZE+1];
  1206. JackGetUUIDRequest()
  1207. {
  1208. memset(fName, 0, sizeof(fName));
  1209. }
  1210. JackGetUUIDRequest(const char* client_name)
  1211. : JackRequest(JackRequest::kGetUUIDByClient)
  1212. {
  1213. memset(fName, 0, sizeof(fName));
  1214. strncpy(fName, client_name, sizeof(fName)-1);
  1215. }
  1216. int Read(detail::JackChannelTransactionInterface* trans)
  1217. {
  1218. CheckSize();
  1219. CheckRes(trans->Read(&fName, sizeof(fName)));
  1220. return 0;
  1221. }
  1222. int Write(detail::JackChannelTransactionInterface* trans)
  1223. {
  1224. CheckRes(JackRequest::Write(trans, Size()));
  1225. CheckRes(trans->Write(&fName, sizeof(fName)));
  1226. return 0;
  1227. }
  1228. int Size() { return sizeof(fName); }
  1229. };
  1230. struct JackGetClientNameRequest : public JackRequest
  1231. {
  1232. char fUUID[JACK_UUID_STRING_SIZE];
  1233. JackGetClientNameRequest()
  1234. {
  1235. memset(fUUID, 0, sizeof(fUUID));
  1236. }
  1237. JackGetClientNameRequest(const char* uuid)
  1238. : JackRequest(JackRequest::kGetClientByUUID)
  1239. {
  1240. memset(fUUID, 0, sizeof(fUUID));
  1241. strncpy(fUUID, uuid, sizeof(fUUID)-1);
  1242. }
  1243. int Read(detail::JackChannelTransactionInterface* trans)
  1244. {
  1245. CheckSize();
  1246. CheckRes(trans->Read(&fUUID, sizeof(fUUID)));
  1247. return 0;
  1248. }
  1249. int Write(detail::JackChannelTransactionInterface* trans)
  1250. {
  1251. CheckRes(JackRequest::Write(trans, Size()));
  1252. CheckRes(trans->Write(&fUUID, sizeof(fUUID)));
  1253. return 0;
  1254. }
  1255. int Size() { return sizeof(fUUID); }
  1256. };
  1257. struct JackReserveNameRequest : public JackRequest
  1258. {
  1259. int fRefNum;
  1260. char fName[JACK_CLIENT_NAME_SIZE+1];
  1261. char fUUID[JACK_UUID_STRING_SIZE];
  1262. JackReserveNameRequest() : fRefNum(0)
  1263. {
  1264. memset(fName, 0, sizeof(fName));
  1265. memset(fUUID, 0, sizeof(fUUID));
  1266. }
  1267. JackReserveNameRequest(int refnum, const char *name, const char* uuid)
  1268. : JackRequest(JackRequest::kReserveClientName), fRefNum(refnum)
  1269. {
  1270. memset(fName, 0, sizeof(fName));
  1271. memset(fUUID, 0, sizeof(fUUID));
  1272. strncpy(fName, name, sizeof(fName)-1);
  1273. strncpy(fUUID, uuid, sizeof(fUUID)-1);
  1274. }
  1275. int Read(detail::JackChannelTransactionInterface* trans)
  1276. {
  1277. CheckSize();
  1278. CheckRes(trans->Read(&fUUID, sizeof(fUUID)));
  1279. CheckRes(trans->Read(&fName, sizeof(fName)));
  1280. CheckRes(trans->Read(&fRefNum, sizeof(fRefNum)));
  1281. return 0;
  1282. }
  1283. int Write(detail::JackChannelTransactionInterface* trans)
  1284. {
  1285. CheckRes(JackRequest::Write(trans, Size()));
  1286. CheckRes(trans->Write(&fUUID, sizeof(fUUID)));
  1287. CheckRes(trans->Write(&fName, sizeof(fName)));
  1288. CheckRes(trans->Write(&fRefNum, sizeof(fRefNum)));
  1289. return 0;
  1290. }
  1291. int Size() { return sizeof(fUUID) + sizeof(fName) + sizeof(fRefNum); }
  1292. };
  1293. struct JackClientHasSessionCallbackRequest : public JackRequest
  1294. {
  1295. char fName[JACK_CLIENT_NAME_SIZE+1];
  1296. JackClientHasSessionCallbackRequest()
  1297. {
  1298. memset(fName, 0, sizeof(fName));
  1299. }
  1300. JackClientHasSessionCallbackRequest(const char *name)
  1301. : JackRequest(JackRequest::kClientHasSessionCallback)
  1302. {
  1303. memset(fName, 0, sizeof(fName));
  1304. strncpy(fName, name, sizeof(fName)-1);
  1305. }
  1306. int Read(detail::JackChannelTransactionInterface* trans)
  1307. {
  1308. CheckSize();
  1309. CheckRes(trans->Read(&fName, sizeof(fName)));
  1310. return 0;
  1311. }
  1312. int Write(detail::JackChannelTransactionInterface* trans)
  1313. {
  1314. CheckRes(JackRequest::Write(trans, Size()));
  1315. CheckRes(trans->Write(&fName, sizeof(fName)));
  1316. return 0;
  1317. }
  1318. int Size() { return sizeof(fName); }
  1319. };
  1320. struct JackPropertyChangeNotifyRequest : public JackRequest
  1321. {
  1322. jack_uuid_t fSubject;
  1323. char fKey[MAX_PATH+1];
  1324. jack_property_change_t fChange;
  1325. JackPropertyChangeNotifyRequest() : fChange((jack_property_change_t)0)
  1326. {
  1327. jack_uuid_clear(&fSubject);
  1328. memset(fKey, 0, sizeof(fKey));
  1329. }
  1330. JackPropertyChangeNotifyRequest(jack_uuid_t subject, const char* key, jack_property_change_t change)
  1331. : JackRequest(JackRequest::kPropertyChangeNotify), fChange(change)
  1332. {
  1333. jack_uuid_copy(&fSubject, subject);
  1334. memset(fKey, 0, sizeof(fKey));
  1335. if (key)
  1336. strncpy(fKey, key, sizeof(fKey)-1);
  1337. }
  1338. int Read(detail::JackChannelTransactionInterface* trans)
  1339. {
  1340. CheckSize();
  1341. CheckRes(trans->Read(&fSubject, sizeof(fSubject)));
  1342. CheckRes(trans->Read(&fKey, sizeof(fKey)));
  1343. CheckRes(trans->Read(&fChange, sizeof(fChange)));
  1344. return 0;
  1345. }
  1346. int Write(detail::JackChannelTransactionInterface* trans)
  1347. {
  1348. CheckRes(JackRequest::Write(trans, Size()));
  1349. CheckRes(trans->Write(&fSubject, sizeof(fSubject)));
  1350. CheckRes(trans->Write(&fKey, sizeof(fKey)));
  1351. CheckRes(trans->Write(&fChange, sizeof(fChange)));
  1352. return 0;
  1353. }
  1354. int Size() { return sizeof(fSubject) + sizeof(fKey) + sizeof(fChange); }
  1355. };
  1356. /*!
  1357. \brief ClientNotification.
  1358. */
  1359. struct JackClientNotification
  1360. {
  1361. int fSize;
  1362. char fName[JACK_CLIENT_NAME_SIZE+1];
  1363. int fRefNum;
  1364. int fNotify;
  1365. int fValue1;
  1366. int fValue2;
  1367. int fSync;
  1368. char fMessage[JACK_MESSAGE_SIZE+1];
  1369. JackClientNotification(): fSize(0), fRefNum(0), fNotify(-1), fValue1(-1), fValue2(-1), fSync(0)
  1370. {
  1371. memset(fName, 0, sizeof(fName));
  1372. memset(fMessage, 0, sizeof(fMessage));
  1373. }
  1374. JackClientNotification(const char* name, int refnum, int notify, int sync, const char* message, int value1, int value2)
  1375. : fRefNum(refnum), fNotify(notify), fValue1(value1), fValue2(value2), fSync(sync)
  1376. {
  1377. memset(fName, 0, sizeof(fName));
  1378. memset(fMessage, 0, sizeof(fMessage));
  1379. strncpy(fName, name, sizeof(fName)-1);
  1380. if (message) {
  1381. strncpy(fMessage, message, sizeof(fMessage)-1);
  1382. }
  1383. fSize = Size();
  1384. }
  1385. int Read(detail::JackChannelTransactionInterface* trans)
  1386. {
  1387. CheckSize();
  1388. CheckRes(trans->Read(&fName, sizeof(fName)));
  1389. CheckRes(trans->Read(&fRefNum, sizeof(int)));
  1390. CheckRes(trans->Read(&fNotify, sizeof(int)));
  1391. CheckRes(trans->Read(&fValue1, sizeof(int)));
  1392. CheckRes(trans->Read(&fValue2, sizeof(int)));
  1393. CheckRes(trans->Read(&fSync, sizeof(int)));
  1394. CheckRes(trans->Read(&fMessage, sizeof(fMessage)));
  1395. return 0;
  1396. }
  1397. int Write(detail::JackChannelTransactionInterface* trans)
  1398. {
  1399. CheckRes(trans->Write(&fSize, sizeof(int)));
  1400. CheckRes(trans->Write(&fName, sizeof(fName)));
  1401. CheckRes(trans->Write(&fRefNum, sizeof(int)));
  1402. CheckRes(trans->Write(&fNotify, sizeof(int)));
  1403. CheckRes(trans->Write(&fValue1, sizeof(int)));
  1404. CheckRes(trans->Write(&fValue2, sizeof(int)));
  1405. CheckRes(trans->Write(&fSync, sizeof(int)));
  1406. CheckRes(trans->Write(&fMessage, sizeof(fMessage)));
  1407. return 0;
  1408. }
  1409. int Size() { return sizeof(int) + sizeof(fName) + 5 * sizeof(int) + sizeof(fMessage); }
  1410. };
  1411. } // end of namespace
  1412. #endif