msg.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include <assert.h>
  38. #include <unistd.h>
  39. #include <errno.h>
  40. #include <pthread.h>
  41. #include <sys/types.h>
  42. #include <sys/uio.h>
  43. #include <sys/socket.h>
  44. #include <sys/select.h>
  45. #include <sys/un.h>
  46. #include "../include/saAis.h"
  47. #include "../include/list.h"
  48. #include "../include/saMsg.h"
  49. #include "../include/ipc_gen.h"
  50. #include "../include/ipc_msg.h"
  51. #include "util.h"
  52. struct message_overlay {
  53. mar_res_header_t header __attribute__((aligned(8)));
  54. char data[4096];
  55. };
  56. /*
  57. * Data structure for instance data
  58. */
  59. struct msgInstance {
  60. int response_fd;
  61. int dispatch_fd;
  62. SaMsgCallbacksT callbacks;
  63. int finalize;
  64. SaMsgHandleT msgHandle;
  65. pthread_mutex_t response_mutex;
  66. pthread_mutex_t dispatch_mutex;
  67. struct list_head queue_list;
  68. };
  69. struct msgQueueInstance {
  70. int response_fd;
  71. SaMsgHandleT msgHandle;
  72. SaMsgQueueHandleT queueHandle;
  73. SaMsgQueueOpenFlagsT openFlags;
  74. SaNameT queueName;
  75. struct list_head list;
  76. struct list_head section_iteration_list_head;
  77. pthread_mutex_t *response_mutex;
  78. };
  79. void msgHandleInstanceDestructor (void *instance);
  80. void queueHandleInstanceDestructor (void *instance);
  81. /*
  82. * All MSG instances in this database
  83. */
  84. static struct saHandleDatabase msgHandleDatabase = {
  85. .handleCount = 0,
  86. .handles = 0,
  87. .mutex = PTHREAD_MUTEX_INITIALIZER,
  88. .handleInstanceDestructor = msgHandleInstanceDestructor
  89. };
  90. /*
  91. * All Queue instances in this database
  92. */
  93. static struct saHandleDatabase queueHandleDatabase = {
  94. .handleCount = 0,
  95. .handles = 0,
  96. .mutex = PTHREAD_MUTEX_INITIALIZER,
  97. .handleInstanceDestructor = queueHandleInstanceDestructor
  98. };
  99. /*
  100. * Versions supported
  101. */
  102. static SaVersionT msgVersionsSupported[] = {
  103. { 'B', 1, 1 }
  104. };
  105. static struct saVersionDatabase msgVersionDatabase = {
  106. sizeof (msgVersionsSupported) / sizeof (SaVersionT),
  107. msgVersionsSupported
  108. };
  109. struct iteratorSectionIdListEntry {
  110. struct list_head list;
  111. unsigned char data[0];
  112. };
  113. /*
  114. * Implementation
  115. */
  116. void msgHandleInstanceDestructor (void *instance)
  117. {
  118. }
  119. void queueHandleInstanceDestructor (void *instance)
  120. {
  121. return;
  122. }
  123. #ifdef COMPILE_OUT
  124. static void msgQueueInstanceFinalize (struct msgQueueInstance *msgQueueInstance)
  125. {
  126. struct msgSectionIterationInstance *sectionIterationInstance;
  127. struct list_head *sectionIterationList;
  128. struct list_head *sectionIterationListNext;
  129. for (sectionIterationList = msgQueueInstance->section_iteration_list_head.next,
  130. sectionIterationListNext = sectionIterationList->next;
  131. sectionIterationList != &msgQueueInstance->section_iteration_list_head;
  132. sectionIterationList = sectionIterationListNext,
  133. sectionIterationListNext = sectionIterationList->next) {
  134. sectionIterationInstance = list_entry (sectionIterationList,
  135. struct msgSectionIterationInstance, list);
  136. msgSectionIterationInstanceFinalize (sectionIterationInstance);
  137. }
  138. list_del (&msgQueueInstance->list);
  139. saHandleDestroy (&queueHandleDatabase, msgQueueInstance->queueHandle);
  140. }
  141. static void msgInstanceFinalize (struct msgInstance *msgInstance)
  142. {
  143. struct msgQueueInstance *msgQueueInstance;
  144. struct list_head *queueInstanceList;
  145. struct list_head *queueInstanceListNext;
  146. for (queueInstanceList = msgInstance->queue_list.next,
  147. queueInstanceListNext = queueInstanceList->next;
  148. queueInstanceList != &msgInstance->queue_list;
  149. queueInstanceList = queueInstanceListNext,
  150. queueInstanceListNext = queueInstanceList->next) {
  151. msgQueueInstance = list_entry (queueInstanceList,
  152. struct msgQueueInstance, list);
  153. msgQueueInstanceFinalize (msgQueueInstance);
  154. }
  155. saHandleDestroy (&msgHandleDatabase, msgInstance->msgHandle);
  156. }
  157. #endif
  158. SaAisErrorT
  159. saMsgInitialize (
  160. SaMsgHandleT *msgHandle,
  161. const SaMsgCallbacksT *callbacks,
  162. SaVersionT *version)
  163. {
  164. struct msgInstance *msgInstance;
  165. SaAisErrorT error = SA_AIS_OK;
  166. if (msgHandle == NULL) {
  167. return (SA_AIS_ERR_INVALID_PARAM);
  168. }
  169. error = saVersionVerify (&msgVersionDatabase, version);
  170. if (error != SA_AIS_OK) {
  171. goto error_no_destroy;
  172. }
  173. error = saHandleCreate (&msgHandleDatabase, sizeof (struct msgInstance),
  174. msgHandle);
  175. if (error != SA_AIS_OK) {
  176. goto error_no_destroy;
  177. }
  178. error = saHandleInstanceGet (&msgHandleDatabase, *msgHandle,
  179. (void *)&msgInstance);
  180. if (error != SA_AIS_OK) {
  181. goto error_destroy;
  182. }
  183. msgInstance->response_fd = -1;
  184. error = saServiceConnect (&msgInstance->response_fd,
  185. &msgInstance->dispatch_fd, MSG_SERVICE);
  186. if (error != SA_AIS_OK) {
  187. goto error_put_destroy;
  188. }
  189. if (callbacks) {
  190. memcpy (&msgInstance->callbacks, callbacks, sizeof (SaMsgCallbacksT));
  191. } else {
  192. memset (&msgInstance->callbacks, 0, sizeof (SaMsgCallbacksT));
  193. }
  194. list_init (&msgInstance->queue_list);
  195. msgInstance->msgHandle = *msgHandle;
  196. pthread_mutex_init (&msgInstance->response_mutex, NULL);
  197. saHandleInstancePut (&msgHandleDatabase, *msgHandle);
  198. return (SA_AIS_OK);
  199. error_put_destroy:
  200. saHandleInstancePut (&msgHandleDatabase, *msgHandle);
  201. error_destroy:
  202. saHandleDestroy (&msgHandleDatabase, *msgHandle);
  203. error_no_destroy:
  204. return (error);
  205. }
  206. SaAisErrorT
  207. saMsgSelectionObjectGet (
  208. const SaMsgHandleT msgHandle,
  209. SaSelectionObjectT *selectionObject)
  210. {
  211. struct msgInstance *msgInstance;
  212. SaAisErrorT error;
  213. if (selectionObject == NULL) {
  214. return (SA_AIS_ERR_INVALID_PARAM);
  215. }
  216. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  217. if (error != SA_AIS_OK) {
  218. return (error);
  219. }
  220. *selectionObject = msgInstance->dispatch_fd;
  221. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  222. return (SA_AIS_OK);
  223. }
  224. SaAisErrorT
  225. saMsgDispatch (
  226. const SaMsgHandleT msgHandle,
  227. SaDispatchFlagsT dispatchFlags)
  228. {
  229. struct pollfd ufds;
  230. int poll_fd;
  231. int timeout = 1;
  232. SaMsgCallbacksT callbacks;
  233. SaAisErrorT error;
  234. int dispatch_avail;
  235. struct msgInstance *msgInstance;
  236. int cont = 1; /* always continue do loop except when set to 0 */
  237. struct message_overlay dispatch_data;
  238. /*
  239. struct res_lib_msg_queueopenasync *res_lib_msg_queueopenasync;
  240. struct res_lib_msg_queuesynchronizeasync *res_lib_msg_queuesynchronizeasync;
  241. struct msgQueueInstance *msgQueueInstance;
  242. */
  243. if (dispatchFlags != SA_DISPATCH_ONE &&
  244. dispatchFlags != SA_DISPATCH_ALL &&
  245. dispatchFlags != SA_DISPATCH_BLOCKING) {
  246. return (SA_AIS_ERR_INVALID_PARAM);
  247. }
  248. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  249. (void *)&msgInstance);
  250. if (error != SA_AIS_OK) {
  251. goto error_exit;
  252. }
  253. /*
  254. * Timeout instantly for SA_DISPATCH_ALL
  255. */
  256. if (dispatchFlags == SA_DISPATCH_ALL) {
  257. timeout = 0;
  258. }
  259. do {
  260. /*
  261. * Read data directly from socket
  262. */
  263. poll_fd = msgInstance->dispatch_fd;
  264. ufds.fd = poll_fd;
  265. ufds.events = POLLIN;
  266. ufds.revents = 0;
  267. error = saPollRetry(&ufds, 1, timeout);
  268. if (error != SA_AIS_OK) {
  269. goto error_put;
  270. }
  271. pthread_mutex_lock(&msgInstance->dispatch_mutex);
  272. if (msgInstance->finalize == 1) {
  273. error = SA_AIS_OK;
  274. goto error_unlock;
  275. }
  276. if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
  277. error = SA_AIS_ERR_BAD_HANDLE;
  278. goto error_unlock;
  279. }
  280. dispatch_avail = (ufds.revents & POLLIN);
  281. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  282. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  283. break; /* exit do while cont is 1 loop */
  284. } else
  285. if (dispatch_avail == 0) {
  286. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  287. continue;
  288. }
  289. memset(&dispatch_data,0, sizeof(struct message_overlay));
  290. error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.header, sizeof (mar_res_header_t));
  291. if (error != SA_AIS_OK) {
  292. goto error_unlock;
  293. }
  294. if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
  295. error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.data,
  296. dispatch_data.header.size - sizeof (mar_res_header_t));
  297. if (error != SA_AIS_OK) {
  298. goto error_unlock;
  299. }
  300. }
  301. /*
  302. * Make copy of callbacks, message data, unlock instance,
  303. * and call callback. A risk of this dispatch method is that
  304. * the callback routines may operate at the same time that
  305. * MsgFinalize has been called in another thread.
  306. */
  307. memcpy(&callbacks,&msgInstance->callbacks, sizeof(msgInstance->callbacks));
  308. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  309. /*
  310. * Dispatch incoming response
  311. */
  312. switch (dispatch_data.header.id) {
  313. #ifdef COMPILE_OUT
  314. case MESSAGE_RES_MSG_QUEUE_QUEUEOPENASYNC:
  315. if (callbacks.saMsgQueueOpenCallback == NULL) {
  316. continue;
  317. }
  318. res_lib_msg_queueopenasync = (struct res_lib_msg_queueopenasync *) &dispatch_data;
  319. /*
  320. * This instance get/listadd/put required so that close
  321. * later has the proper list of queues
  322. */
  323. if (res_lib_msg_queueopenasync->header.error == SA_AIS_OK) {
  324. error = saHandleInstanceGet (&queueHandleDatabase,
  325. res_lib_msg_queueopenasync->queueHandle,
  326. (void *)&msgQueueInstance);
  327. assert (error == SA_AIS_OK); /* should only be valid handles here */
  328. /*
  329. * open succeeded without error
  330. */
  331. list_init (&msgQueueInstance->list);
  332. list_init (&msgQueueInstance->section_iteration_list_head);
  333. list_add (&msgQueueInstance->list,
  334. &msgInstance->queue_list);
  335. callbacks.saMsgQueueOpenCallback(
  336. res_lib_msg_queueopenasync->invocation,
  337. res_lib_msg_queueopenasync->queueHandle,
  338. res_lib_msg_queueopenasync->header.error);
  339. saHandleInstancePut (&queueHandleDatabase,
  340. res_lib_msg_queueopenasync->queueHandle);
  341. } else {
  342. /*
  343. * open failed with error
  344. */
  345. callbacks.saMsgQueueOpenCallback(
  346. res_lib_msg_queueopenasync->invocation,
  347. -1,
  348. res_lib_msg_queueopenasync->header.error);
  349. }
  350. break;
  351. case MESSAGE_RES_MSG_QUEUE_QUEUESYNCHRONIZEASYNC:
  352. if (callbacks.saMsgQueueSynchronizeCallback == NULL) {
  353. continue;
  354. }
  355. res_lib_msg_queuesynchronizeasync = (struct res_lib_msg_queuesynchronizeasync *) &dispatch_data;
  356. callbacks.saMsgQueueSynchronizeCallback(
  357. res_lib_msg_queuesynchronizeasync->invocation,
  358. res_lib_msg_queuesynchronizeasync->header.error);
  359. break;
  360. #endif
  361. default:
  362. /* TODO */
  363. break;
  364. }
  365. /*
  366. * Determine if more messages should be processed
  367. */
  368. switch (dispatchFlags) {
  369. case SA_DISPATCH_ONE:
  370. cont = 0;
  371. break;
  372. case SA_DISPATCH_ALL:
  373. break;
  374. case SA_DISPATCH_BLOCKING:
  375. break;
  376. }
  377. } while (cont);
  378. error_unlock:
  379. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  380. error_put:
  381. saHandleInstancePut(&msgHandleDatabase, msgHandle);
  382. error_exit:
  383. return (error);
  384. }
  385. SaAisErrorT
  386. saMsgFinalize (
  387. const SaMsgHandleT msgHandle)
  388. {
  389. struct msgInstance *msgInstance;
  390. SaAisErrorT error;
  391. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  392. (void *)&msgInstance);
  393. if (error != SA_AIS_OK) {
  394. return (error);
  395. }
  396. pthread_mutex_lock (&msgInstance->response_mutex);
  397. /*
  398. * Another thread has already started finalizing
  399. */
  400. if (msgInstance->finalize) {
  401. pthread_mutex_unlock (&msgInstance->response_mutex);
  402. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  403. return (SA_AIS_ERR_BAD_HANDLE);
  404. }
  405. msgInstance->finalize = 1;
  406. pthread_mutex_unlock (&msgInstance->response_mutex);
  407. // TODO msgInstanceFinalize (msgInstance);
  408. if (msgInstance->response_fd != -1) {
  409. shutdown (msgInstance->response_fd, 0);
  410. close (msgInstance->response_fd);
  411. }
  412. if (msgInstance->dispatch_fd != -1) {
  413. shutdown (msgInstance->dispatch_fd, 0);
  414. close (msgInstance->dispatch_fd);
  415. }
  416. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  417. return (SA_AIS_OK);
  418. }
  419. SaAisErrorT
  420. saMsgQueueOpen (
  421. SaMsgHandleT msgHandle,
  422. const SaNameT *queueName,
  423. const SaMsgQueueCreationAttributesT *creationAttributes,
  424. SaMsgQueueOpenFlagsT openFlags,
  425. SaTimeT timeout,
  426. SaMsgQueueHandleT *queueHandle)
  427. {
  428. SaAisErrorT error;
  429. struct msgQueueInstance *msgQueueInstance;
  430. struct msgInstance *msgInstance;
  431. struct req_lib_msg_queueopen req_lib_msg_queueopen;
  432. struct res_lib_msg_queueopen res_lib_msg_queueopen;
  433. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  434. (void *)&msgInstance);
  435. if (error != SA_AIS_OK) {
  436. goto error_exit;
  437. }
  438. error = saHandleCreate (&queueHandleDatabase,
  439. sizeof (struct msgQueueInstance), queueHandle);
  440. if (error != SA_AIS_OK) {
  441. goto error_put_msg;
  442. }
  443. error = saHandleInstanceGet (&queueHandleDatabase,
  444. *queueHandle, (void *)&msgQueueInstance);
  445. if (error != SA_AIS_OK) {
  446. goto error_destroy;
  447. }
  448. msgQueueInstance->response_fd = msgInstance->response_fd;
  449. msgQueueInstance->response_mutex = &msgInstance->response_mutex;
  450. msgQueueInstance->msgHandle = msgHandle;
  451. msgQueueInstance->queueHandle = *queueHandle;
  452. msgQueueInstance->openFlags = openFlags;
  453. req_lib_msg_queueopen.header.size = sizeof (struct req_lib_msg_queueopen);
  454. req_lib_msg_queueopen.header.id = MESSAGE_REQ_MSG_QUEUEOPEN;
  455. memcpy (&req_lib_msg_queueopen.queueName, queueName, sizeof (SaNameT));
  456. memcpy (&msgQueueInstance->queueName, queueName, sizeof (SaNameT));
  457. req_lib_msg_queueopen.creationAttributesSet = 0;
  458. if (creationAttributes) {
  459. memcpy (&req_lib_msg_queueopen.creationAttributes,
  460. creationAttributes,
  461. sizeof (SaMsgQueueCreationAttributesT));
  462. req_lib_msg_queueopen.creationAttributesSet = 1;
  463. }
  464. req_lib_msg_queueopen.openFlags = openFlags;
  465. req_lib_msg_queueopen.timeout = timeout;
  466. pthread_mutex_lock (msgQueueInstance->response_mutex);
  467. error = saSendReceiveReply (msgQueueInstance->response_fd,
  468. &req_lib_msg_queueopen,
  469. sizeof (struct req_lib_msg_queueopen),
  470. &res_lib_msg_queueopen,
  471. sizeof (struct res_lib_msg_queueopen));
  472. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  473. if (res_lib_msg_queueopen.header.error != SA_AIS_OK) {
  474. error = res_lib_msg_queueopen.header.error;
  475. goto error_put_destroy;
  476. }
  477. saHandleInstancePut (&queueHandleDatabase, *queueHandle);
  478. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  479. return (error);
  480. error_put_destroy:
  481. saHandleInstancePut (&queueHandleDatabase, *queueHandle);
  482. error_destroy:
  483. saHandleDestroy (&queueHandleDatabase, *queueHandle);
  484. error_put_msg:
  485. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  486. error_exit:
  487. return (error);
  488. }
  489. SaAisErrorT
  490. saMsgQueueOpenAsync (
  491. SaMsgHandleT msgHandle,
  492. SaInvocationT invocation,
  493. const SaNameT *queueName,
  494. const SaMsgQueueCreationAttributesT *creationAttributes,
  495. SaMsgQueueOpenFlagsT openFlags)
  496. {
  497. struct msgQueueInstance *msgQueueInstance;
  498. struct msgInstance *msgInstance;
  499. SaMsgQueueHandleT queueHandle;
  500. SaAisErrorT error;
  501. struct req_lib_msg_queueopen req_lib_msg_queueopen;
  502. struct res_lib_msg_queueopenasync res_lib_msg_queueopenasync;
  503. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  504. (void *)&msgInstance);
  505. if (error != SA_AIS_OK) {
  506. goto error_exit;
  507. }
  508. if (msgInstance->callbacks.saMsgQueueOpenCallback == NULL) {
  509. error = SA_AIS_ERR_INIT;
  510. goto error_put_msg;
  511. }
  512. error = saHandleCreate (&queueHandleDatabase,
  513. sizeof (struct msgQueueInstance), &queueHandle);
  514. if (error != SA_AIS_OK) {
  515. goto error_put_msg;
  516. }
  517. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  518. (void *)&msgQueueInstance);
  519. if (error != SA_AIS_OK) {
  520. goto error_destroy;
  521. }
  522. msgQueueInstance->response_fd = msgInstance->response_fd;
  523. msgQueueInstance->response_mutex = &msgInstance->response_mutex;
  524. msgQueueInstance->msgHandle = msgHandle;
  525. msgQueueInstance->queueHandle = queueHandle;
  526. msgQueueInstance->openFlags = openFlags;
  527. req_lib_msg_queueopen.header.size = sizeof (struct req_lib_msg_queueopen);
  528. req_lib_msg_queueopen.header.id = MESSAGE_REQ_MSG_QUEUEOPEN;
  529. req_lib_msg_queueopen.invocation = invocation;
  530. req_lib_msg_queueopen.creationAttributesSet = 0;
  531. if (creationAttributes) {
  532. memcpy (&req_lib_msg_queueopen.creationAttributes,
  533. creationAttributes,
  534. sizeof (SaMsgQueueCreationAttributesT));
  535. req_lib_msg_queueopen.creationAttributesSet = 1;
  536. }
  537. req_lib_msg_queueopen.openFlags = openFlags;
  538. req_lib_msg_queueopen.queueHandle = queueHandle;
  539. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  540. error = saSendReceiveReply (msgQueueInstance->response_fd,
  541. &req_lib_msg_queueopen,
  542. sizeof (struct req_lib_msg_queueopen),
  543. &res_lib_msg_queueopenasync,
  544. sizeof (struct res_lib_msg_queueopenasync));
  545. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  546. if (res_lib_msg_queueopenasync.header.error != SA_AIS_OK) {
  547. error = res_lib_msg_queueopenasync.header.error;
  548. goto error_put_destroy;
  549. }
  550. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  551. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  552. return (error);
  553. error_put_destroy:
  554. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  555. error_destroy:
  556. saHandleDestroy (&queueHandleDatabase, queueHandle);
  557. error_put_msg:
  558. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  559. error_exit:
  560. return (error);
  561. }
  562. SaAisErrorT
  563. saMsgQueueClose (
  564. SaMsgQueueHandleT queueHandle)
  565. {
  566. struct req_lib_msg_queueclose req_lib_msg_queueclose;
  567. struct res_lib_msg_queueclose res_lib_msg_queueclose;
  568. SaAisErrorT error;
  569. struct msgQueueInstance *msgQueueInstance;
  570. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  571. (void *)&msgQueueInstance);
  572. if (error != SA_AIS_OK) {
  573. return (error);
  574. }
  575. req_lib_msg_queueclose.header.size = sizeof (struct req_lib_msg_queueclose);
  576. req_lib_msg_queueclose.header.id = MESSAGE_REQ_MSG_QUEUECLOSE;
  577. memcpy (&req_lib_msg_queueclose.queueName,
  578. &msgQueueInstance->queueName, sizeof (SaNameT));
  579. pthread_mutex_lock (msgQueueInstance->response_mutex);
  580. error = saSendReceiveReply (msgQueueInstance->response_fd,
  581. &req_lib_msg_queueclose,
  582. sizeof (struct req_lib_msg_queueclose),
  583. &res_lib_msg_queueclose,
  584. sizeof (struct res_lib_msg_queueclose));
  585. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  586. if (error == SA_AIS_OK) {
  587. error = res_lib_msg_queueclose.header.error;
  588. }
  589. if (error == SA_AIS_OK) {
  590. // TODO msgQueueInstanceFinalize (msgQueueInstance);
  591. }
  592. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  593. return (error);
  594. }
  595. SaAisErrorT
  596. saMsgQueueStatusGet (
  597. SaMsgHandleT msgHandle,
  598. const SaNameT *queueName,
  599. SaMsgQueueStatusT *queueStatus)
  600. {
  601. struct msgInstance *msgInstance;
  602. struct req_lib_msg_queuestatusget req_lib_msg_queuestatusget;
  603. struct res_lib_msg_queuestatusget res_lib_msg_queuestatusget;
  604. SaAisErrorT error;
  605. if (queueName == NULL) {
  606. return (SA_AIS_ERR_INVALID_PARAM);
  607. }
  608. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  609. if (error != SA_AIS_OK) {
  610. return (error);
  611. }
  612. req_lib_msg_queuestatusget.header.size = sizeof (struct req_lib_msg_queuestatusget);
  613. req_lib_msg_queuestatusget.header.id = MESSAGE_REQ_MSG_QUEUESTATUSGET;
  614. memcpy (&req_lib_msg_queuestatusget.queueName, queueName, sizeof (SaNameT));
  615. pthread_mutex_lock (&msgInstance->response_mutex);
  616. error = saSendReceiveReply (msgInstance->response_fd,
  617. &req_lib_msg_queuestatusget,
  618. sizeof (struct req_lib_msg_queuestatusget),
  619. &res_lib_msg_queuestatusget,
  620. sizeof (struct res_lib_msg_queuestatusget));
  621. pthread_mutex_unlock (&msgInstance->response_mutex);
  622. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  623. if (error == SA_AIS_OK)
  624. error = res_lib_msg_queuestatusget.header.error;
  625. if (error == SA_AIS_OK) {
  626. memcpy (queueStatus, &res_lib_msg_queuestatusget.queueStatus,
  627. sizeof (SaMsgQueueStatusT));
  628. }
  629. return (error);
  630. }
  631. SaAisErrorT
  632. saMsgQueueUnlink (
  633. SaMsgHandleT msgHandle,
  634. const SaNameT *queueName)
  635. {
  636. SaAisErrorT error;
  637. struct msgInstance *msgInstance;
  638. struct req_lib_msg_queueunlink req_lib_msg_queueunlink;
  639. struct res_lib_msg_queueunlink res_lib_msg_queueunlink;
  640. if (queueName == NULL) {
  641. return (SA_AIS_ERR_INVALID_PARAM);
  642. }
  643. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  644. if (error != SA_AIS_OK) {
  645. return (error);
  646. }
  647. req_lib_msg_queueunlink.header.size = sizeof (struct req_lib_msg_queueunlink);
  648. req_lib_msg_queueunlink.header.id = MESSAGE_REQ_MSG_QUEUEUNLINK;
  649. memcpy (&req_lib_msg_queueunlink.queueName, queueName, sizeof (SaNameT));
  650. pthread_mutex_lock (&msgInstance->response_mutex);
  651. error = saSendReceiveReply (msgInstance->response_fd,
  652. &req_lib_msg_queueunlink,
  653. sizeof (struct req_lib_msg_queueunlink),
  654. &res_lib_msg_queueunlink,
  655. sizeof (struct res_lib_msg_queueunlink));
  656. pthread_mutex_unlock (&msgInstance->response_mutex);
  657. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  658. return (error == SA_AIS_OK ? res_lib_msg_queueunlink.header.error : error);
  659. }
  660. SaAisErrorT
  661. saMsgQueueGroupCreate (
  662. SaMsgHandleT msgHandle,
  663. const SaNameT *queueGroupName,
  664. SaMsgQueueGroupPolicyT queueGroupPolicy)
  665. {
  666. SaAisErrorT error;
  667. struct msgInstance *msgInstance;
  668. struct req_lib_msg_queuegroupcreate req_lib_msg_queuegroupcreate;
  669. struct res_lib_msg_queuegroupcreate res_lib_msg_queuegroupcreate;
  670. if (queueGroupName == NULL) {
  671. return (SA_AIS_ERR_INVALID_PARAM);
  672. }
  673. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  674. if (error != SA_AIS_OK) {
  675. return (error);
  676. }
  677. req_lib_msg_queuegroupcreate.header.size = sizeof (struct req_lib_msg_queuegroupcreate);
  678. req_lib_msg_queuegroupcreate.header.id = MESSAGE_REQ_MSG_QUEUEGROUPCREATE;
  679. memcpy (&req_lib_msg_queuegroupcreate.queueGroupName, queueGroupName,
  680. sizeof (SaNameT));
  681. req_lib_msg_queuegroupcreate.queueGroupPolicy = queueGroupPolicy;
  682. pthread_mutex_lock (&msgInstance->response_mutex);
  683. error = saSendReceiveReply (msgInstance->response_fd,
  684. &req_lib_msg_queuegroupcreate,
  685. sizeof (struct req_lib_msg_queuegroupcreate),
  686. &res_lib_msg_queuegroupcreate,
  687. sizeof (struct res_lib_msg_queuegroupcreate));
  688. pthread_mutex_unlock (&msgInstance->response_mutex);
  689. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  690. return (error == SA_AIS_OK ? res_lib_msg_queuegroupcreate.header.error : error);
  691. }
  692. SaAisErrorT
  693. saMsgQueueGroupInsert (
  694. SaMsgHandleT msgHandle,
  695. const SaNameT *queueGroupName,
  696. const SaNameT *queueName)
  697. {
  698. SaAisErrorT error;
  699. struct msgInstance *msgInstance;
  700. struct req_lib_msg_queuegroupinsert req_lib_msg_queuegroupinsert;
  701. struct res_lib_msg_queuegroupinsert res_lib_msg_queuegroupinsert;
  702. if (queueName == NULL) {
  703. return (SA_AIS_ERR_INVALID_PARAM);
  704. }
  705. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  706. if (error != SA_AIS_OK) {
  707. return (error);
  708. }
  709. req_lib_msg_queuegroupinsert.header.size = sizeof (struct req_lib_msg_queuegroupinsert);
  710. req_lib_msg_queuegroupinsert.header.id = MESSAGE_REQ_MSG_QUEUEGROUPINSERT;
  711. memcpy (&req_lib_msg_queuegroupinsert.queueName, queueName, sizeof (SaNameT));
  712. memcpy (&req_lib_msg_queuegroupinsert.queueGroupName, queueGroupName,
  713. sizeof (SaNameT));
  714. pthread_mutex_lock (&msgInstance->response_mutex);
  715. error = saSendReceiveReply (msgInstance->response_fd,
  716. &req_lib_msg_queuegroupinsert,
  717. sizeof (struct req_lib_msg_queuegroupinsert),
  718. &res_lib_msg_queuegroupinsert,
  719. sizeof (struct res_lib_msg_queuegroupinsert));
  720. pthread_mutex_unlock (&msgInstance->response_mutex);
  721. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  722. return (error == SA_AIS_OK ? res_lib_msg_queuegroupinsert.header.error : error);
  723. }
  724. SaAisErrorT
  725. saMsgQueueGroupRemove (
  726. SaMsgHandleT msgHandle,
  727. const SaNameT *queueGroupName,
  728. const SaNameT *queueName)
  729. {
  730. SaAisErrorT error;
  731. struct msgInstance *msgInstance;
  732. struct req_lib_msg_queuegroupremove req_lib_msg_queuegroupremove;
  733. struct res_lib_msg_queuegroupremove res_lib_msg_queuegroupremove;
  734. if (queueName == NULL) {
  735. return (SA_AIS_ERR_INVALID_PARAM);
  736. }
  737. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  738. if (error != SA_AIS_OK) {
  739. return (error);
  740. }
  741. req_lib_msg_queuegroupremove.header.size = sizeof (struct req_lib_msg_queuegroupremove);
  742. req_lib_msg_queuegroupremove.header.id = MESSAGE_REQ_MSG_QUEUEGROUPREMOVE;
  743. memcpy (&req_lib_msg_queuegroupremove.queueName, queueName, sizeof (SaNameT));
  744. memcpy (&req_lib_msg_queuegroupremove.queueGroupName, queueGroupName,
  745. sizeof (SaNameT));
  746. pthread_mutex_lock (&msgInstance->response_mutex);
  747. error = saSendReceiveReply (msgInstance->response_fd,
  748. &req_lib_msg_queuegroupremove,
  749. sizeof (struct req_lib_msg_queuegroupremove),
  750. &res_lib_msg_queuegroupremove,
  751. sizeof (struct res_lib_msg_queuegroupremove));
  752. pthread_mutex_unlock (&msgInstance->response_mutex);
  753. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  754. return (error == SA_AIS_OK ? res_lib_msg_queuegroupremove.header.error : error);
  755. }
  756. SaAisErrorT
  757. saMsgQueueGroupDelete (
  758. SaMsgHandleT msgHandle,
  759. const SaNameT *queueGroupName)
  760. {
  761. SaAisErrorT error;
  762. struct msgInstance *msgInstance;
  763. struct req_lib_msg_queuegroupdelete req_lib_msg_queuegroupdelete;
  764. struct res_lib_msg_queuegroupdelete res_lib_msg_queuegroupdelete;
  765. if (queueGroupName == NULL) {
  766. return (SA_AIS_ERR_INVALID_PARAM);
  767. }
  768. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  769. if (error != SA_AIS_OK) {
  770. return (error);
  771. }
  772. req_lib_msg_queuegroupdelete.header.size = sizeof (struct req_lib_msg_queuegroupdelete);
  773. req_lib_msg_queuegroupdelete.header.id = MESSAGE_REQ_MSG_QUEUEGROUPDELETE;
  774. memcpy (&req_lib_msg_queuegroupdelete.queueGroupName, queueGroupName,
  775. sizeof (SaNameT));
  776. pthread_mutex_lock (&msgInstance->response_mutex);
  777. error = saSendReceiveReply (msgInstance->response_fd,
  778. &req_lib_msg_queuegroupdelete,
  779. sizeof (struct req_lib_msg_queuegroupdelete),
  780. &res_lib_msg_queuegroupdelete,
  781. sizeof (struct res_lib_msg_queuegroupdelete));
  782. pthread_mutex_unlock (&msgInstance->response_mutex);
  783. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  784. return (error == SA_AIS_OK ? res_lib_msg_queuegroupdelete.header.error : error);
  785. }
  786. SaAisErrorT
  787. saMsgQueueGroupTrack (
  788. SaMsgHandleT msgHandle,
  789. const SaNameT *queueGroupName,
  790. SaUint8T trackFlags,
  791. SaMsgQueueGroupNotificationBufferT *notificationBuffer)
  792. {
  793. SaAisErrorT error;
  794. struct msgInstance *msgInstance;
  795. struct req_lib_msg_queuegrouptrack req_lib_msg_queuegrouptrack;
  796. struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack;
  797. if (queueGroupName == NULL) {
  798. return (SA_AIS_ERR_INVALID_PARAM);
  799. }
  800. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  801. if (error != SA_AIS_OK) {
  802. return (error);
  803. }
  804. req_lib_msg_queuegrouptrack.header.size = sizeof (struct req_lib_msg_queuegrouptrack);
  805. req_lib_msg_queuegrouptrack.header.id = MESSAGE_REQ_MSG_QUEUEGROUPTRACK;
  806. req_lib_msg_queuegrouptrack.trackFlags = trackFlags;
  807. memcpy (&req_lib_msg_queuegrouptrack.queueGroupName, queueGroupName,
  808. sizeof (SaNameT));
  809. pthread_mutex_lock (&msgInstance->response_mutex);
  810. error = saSendReceiveReply (msgInstance->response_fd,
  811. &req_lib_msg_queuegrouptrack,
  812. sizeof (struct req_lib_msg_queuegrouptrack),
  813. &res_lib_msg_queuegrouptrack,
  814. sizeof (struct res_lib_msg_queuegrouptrack));
  815. pthread_mutex_unlock (&msgInstance->response_mutex);
  816. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  817. return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrack.header.error : error);
  818. }
  819. SaAisErrorT
  820. saMsgQueueGroupTrackStop (
  821. SaMsgHandleT msgHandle,
  822. const SaNameT *queueGroupName)
  823. {
  824. SaAisErrorT error;
  825. struct msgInstance *msgInstance;
  826. struct req_lib_msg_queuegrouptrackstop req_lib_msg_queuegrouptrackstop;
  827. struct res_lib_msg_queuegrouptrackstop res_lib_msg_queuegrouptrackstop;
  828. if (queueGroupName == NULL) {
  829. return (SA_AIS_ERR_INVALID_PARAM);
  830. }
  831. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  832. if (error != SA_AIS_OK) {
  833. return (error);
  834. }
  835. req_lib_msg_queuegrouptrackstop.header.size = sizeof (struct req_lib_msg_queuegrouptrackstop);
  836. req_lib_msg_queuegrouptrackstop.header.id = MESSAGE_REQ_MSG_QUEUEGROUPTRACKSTOP;
  837. memcpy (&req_lib_msg_queuegrouptrackstop.queueGroupName, queueGroupName,
  838. sizeof (SaNameT));
  839. pthread_mutex_lock (&msgInstance->response_mutex);
  840. error = saSendReceiveReply (msgInstance->response_fd,
  841. &req_lib_msg_queuegrouptrackstop,
  842. sizeof (struct req_lib_msg_queuegrouptrackstop),
  843. &res_lib_msg_queuegrouptrackstop,
  844. sizeof (struct res_lib_msg_queuegrouptrackstop));
  845. pthread_mutex_unlock (&msgInstance->response_mutex);
  846. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  847. return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrackstop.header.error : error);
  848. }
  849. SaAisErrorT
  850. saMsgMessageSend (
  851. SaMsgHandleT msgHandle,
  852. const SaNameT *destination,
  853. const SaMsgMessageT *message,
  854. SaTimeT timeout)
  855. {
  856. SaAisErrorT error;
  857. struct msgInstance *msgInstance;
  858. struct req_lib_msg_messagesend req_lib_msg_messagesend;
  859. struct res_lib_msg_messagesend res_lib_msg_messagesend;
  860. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  861. if (error != SA_AIS_OK) {
  862. return (error);
  863. }
  864. req_lib_msg_messagesend.header.size = sizeof (struct req_lib_msg_messagesend);
  865. req_lib_msg_messagesend.header.id = MESSAGE_REQ_MSG_MESSAGESEND;
  866. memcpy (&req_lib_msg_messagesend.destination, destination, sizeof (SaNameT));
  867. pthread_mutex_lock (&msgInstance->response_mutex);
  868. error = saSendReceiveReply (msgInstance->response_fd,
  869. &req_lib_msg_messagesend,
  870. sizeof (struct req_lib_msg_messagesend),
  871. &res_lib_msg_messagesend,
  872. sizeof (struct res_lib_msg_messagesend));
  873. pthread_mutex_unlock (&msgInstance->response_mutex);
  874. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  875. return (error == SA_AIS_OK ? res_lib_msg_messagesend.header.error : error);
  876. }
  877. SaAisErrorT
  878. saMsgMessageSendAsync (
  879. SaMsgHandleT msgHandle,
  880. SaInvocationT invocation,
  881. const SaNameT *destination,
  882. const SaMsgMessageT *message,
  883. SaMsgAckFlagsT ackFlags)
  884. {
  885. SaAisErrorT error;
  886. struct msgInstance *msgInstance;
  887. struct req_lib_msg_messagesend req_lib_msg_messagesend;
  888. struct res_lib_msg_messagesendasync res_lib_msg_messagesendasync;
  889. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  890. if (error != SA_AIS_OK) {
  891. return (error);
  892. }
  893. req_lib_msg_messagesend.header.size = sizeof (struct req_lib_msg_messagesend);
  894. req_lib_msg_messagesend.header.id = MESSAGE_REQ_MSG_MESSAGESEND;
  895. memcpy (&req_lib_msg_messagesend.destination, destination, sizeof (SaNameT));
  896. pthread_mutex_lock (&msgInstance->response_mutex);
  897. error = saSendReceiveReply (msgInstance->response_fd,
  898. &req_lib_msg_messagesend,
  899. sizeof (struct req_lib_msg_messagesend),
  900. &res_lib_msg_messagesendasync,
  901. sizeof (struct res_lib_msg_messagesendasync));
  902. pthread_mutex_unlock (&msgInstance->response_mutex);
  903. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  904. return (error == SA_AIS_OK ? res_lib_msg_messagesendasync.header.error : error);
  905. }
  906. SaAisErrorT
  907. saMsgMessageGet (
  908. SaMsgQueueHandleT queueHandle,
  909. SaMsgMessageT *message,
  910. SaTimeT *sendTime,
  911. SaMsgSenderIdT *senderId,
  912. SaTimeT timeout)
  913. {
  914. SaAisErrorT error;
  915. struct msgQueueInstance *msgQueueInstance;
  916. struct req_lib_msg_messageget req_lib_msg_messageget;
  917. struct res_lib_msg_messageget res_lib_msg_messageget;
  918. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, (void *)&msgQueueInstance);
  919. if (error != SA_AIS_OK) {
  920. return (error);
  921. }
  922. req_lib_msg_messageget.header.size = sizeof (struct req_lib_msg_messageget);
  923. req_lib_msg_messageget.header.id = MESSAGE_REQ_MSG_MESSAGEGET;
  924. req_lib_msg_messageget.timeout = timeout;
  925. pthread_mutex_lock (msgQueueInstance->response_mutex);
  926. error = saSendReceiveReply (msgQueueInstance->response_fd,
  927. &req_lib_msg_messageget,
  928. sizeof (struct req_lib_msg_messageget),
  929. &res_lib_msg_messageget,
  930. sizeof (struct res_lib_msg_messageget));
  931. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  932. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  933. if (error == SA_AIS_OK)
  934. error = res_lib_msg_messageget.header.error;
  935. if (error == SA_AIS_OK) {
  936. *sendTime = res_lib_msg_messageget.sendTime;
  937. memcpy (senderId, &res_lib_msg_messageget.senderId,
  938. sizeof (SaMsgSenderIdT));
  939. }
  940. return (error);
  941. }
  942. SaAisErrorT
  943. saMsgMessageCancel (
  944. SaMsgQueueHandleT queueHandle)
  945. {
  946. SaAisErrorT error;
  947. struct msgQueueInstance *msgQueueInstance;
  948. struct req_lib_msg_messagecancel req_lib_msg_messagecancel;
  949. struct res_lib_msg_messagecancel res_lib_msg_messagecancel;
  950. error = saHandleInstanceGet (&msgHandleDatabase, queueHandle, (void *)&msgQueueInstance);
  951. if (error != SA_AIS_OK) {
  952. return (error);
  953. }
  954. req_lib_msg_messagecancel.header.size = sizeof (struct req_lib_msg_messagecancel);
  955. req_lib_msg_messagecancel.header.id = MESSAGE_REQ_MSG_MESSAGECANCEL;
  956. pthread_mutex_lock (msgQueueInstance->response_mutex);
  957. error = saSendReceiveReply (msgQueueInstance->response_fd,
  958. &req_lib_msg_messagecancel,
  959. sizeof (struct req_lib_msg_messagecancel),
  960. &res_lib_msg_messagecancel,
  961. sizeof (struct res_lib_msg_messagecancel));
  962. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  963. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  964. return (error == SA_AIS_OK ? res_lib_msg_messagecancel.header.error : error);
  965. }
  966. SaAisErrorT
  967. saMsgMessageSendReceive (
  968. SaMsgHandleT msgHandle,
  969. const SaNameT *destination,
  970. const SaMsgMessageT *sendMessage,
  971. SaMsgMessageT *receiveMessage,
  972. SaTimeT *replySendTime,
  973. SaTimeT timeout)
  974. {
  975. SaAisErrorT error;
  976. struct msgInstance *msgInstance;
  977. struct req_lib_msg_messagesendreceive req_lib_msg_messagesendreceive;
  978. struct res_lib_msg_messagesendreceive res_lib_msg_messagesendreceive;
  979. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  980. if (error != SA_AIS_OK) {
  981. return (error);
  982. }
  983. req_lib_msg_messagesendreceive.header.size = sizeof (struct req_lib_msg_messagesendreceive);
  984. req_lib_msg_messagesendreceive.header.id = MESSAGE_REQ_MSG_MESSAGEREPLY;
  985. memcpy (&req_lib_msg_messagesendreceive.destination, destination,
  986. sizeof (SaNameT));
  987. req_lib_msg_messagesendreceive.timeout = timeout;
  988. pthread_mutex_lock (&msgInstance->response_mutex);
  989. error = saSendReceiveReply (msgInstance->response_fd,
  990. &req_lib_msg_messagesendreceive,
  991. sizeof (struct req_lib_msg_messagesendreceive),
  992. &res_lib_msg_messagesendreceive,
  993. sizeof (struct res_lib_msg_messagesendreceive));
  994. pthread_mutex_unlock (&msgInstance->response_mutex);
  995. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  996. if (error == SA_AIS_OK)
  997. error = res_lib_msg_messagesendreceive.header.error;
  998. if (error == SA_AIS_OK) {
  999. *replySendTime = res_lib_msg_messagesendreceive.replySendTime;
  1000. }
  1001. return (error);
  1002. }
  1003. SaAisErrorT
  1004. saMsgMessageReply (
  1005. SaMsgHandleT msgHandle,
  1006. const SaMsgMessageT *replyMessage,
  1007. const SaMsgSenderIdT *senderId,
  1008. SaTimeT timeout)
  1009. {
  1010. SaAisErrorT error;
  1011. struct msgInstance *msgInstance;
  1012. struct req_lib_msg_messagereply req_lib_msg_messagereply;
  1013. struct res_lib_msg_messagereply res_lib_msg_messagereply;
  1014. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  1015. if (error != SA_AIS_OK) {
  1016. return (error);
  1017. }
  1018. req_lib_msg_messagereply.header.size = sizeof (struct req_lib_msg_messagereply);
  1019. req_lib_msg_messagereply.header.id = MESSAGE_REQ_MSG_MESSAGEREPLY;
  1020. memcpy (&req_lib_msg_messagereply.senderId, senderId, sizeof (SaMsgSenderIdT));
  1021. pthread_mutex_lock (&msgInstance->response_mutex);
  1022. error = saSendReceiveReply (msgInstance->response_fd,
  1023. &req_lib_msg_messagereply,
  1024. sizeof (struct req_lib_msg_messagereply),
  1025. &res_lib_msg_messagereply,
  1026. sizeof (struct res_lib_msg_messagereply));
  1027. pthread_mutex_unlock (&msgInstance->response_mutex);
  1028. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1029. return (error == SA_AIS_OK ? res_lib_msg_messagereply.header.error : error);
  1030. }
  1031. SaAisErrorT saMsgMessageReplyAsync (
  1032. SaMsgHandleT msgHandle,
  1033. SaInvocationT invocation,
  1034. const SaMsgMessageT *replyMessage,
  1035. const SaMsgSenderIdT *senderId,
  1036. SaMsgAckFlagsT ackFlags)
  1037. {
  1038. SaAisErrorT error;
  1039. struct msgInstance *msgInstance;
  1040. struct req_lib_msg_messagereply req_lib_msg_messagereply;
  1041. struct res_lib_msg_messagereplyasync res_lib_msg_messagereplyasync;
  1042. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, (void *)&msgInstance);
  1043. if (error != SA_AIS_OK) {
  1044. return (error);
  1045. }
  1046. req_lib_msg_messagereply.header.size = sizeof (struct req_lib_msg_messagereply);
  1047. req_lib_msg_messagereply.header.id = MESSAGE_REQ_MSG_MESSAGEREPLY;
  1048. memcpy (&req_lib_msg_messagereply.senderId, senderId, sizeof (SaMsgSenderIdT));
  1049. pthread_mutex_lock (&msgInstance->response_mutex);
  1050. error = saSendReceiveReply (msgInstance->response_fd,
  1051. &req_lib_msg_messagereply,
  1052. sizeof (struct req_lib_msg_messagereply),
  1053. &res_lib_msg_messagereplyasync,
  1054. sizeof (struct res_lib_msg_messagereplyasync));
  1055. pthread_mutex_unlock (&msgInstance->response_mutex);
  1056. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1057. return (error == SA_AIS_OK ? res_lib_msg_messagereplyasync.header.error : error);
  1058. }