msg.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@redhat.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 <saAis.h>
  47. #include <saMsg.h>
  48. #include <ipc_gen.h>
  49. #include <ipc_msg.h>
  50. #include <ais_util.h>
  51. #include <list.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. struct msgInstance *msgInstance = instance;
  119. pthread_mutex_destroy (&msgInstance->response_mutex);
  120. pthread_mutex_destroy (&msgInstance->dispatch_mutex);
  121. }
  122. void queueHandleInstanceDestructor (void *instance)
  123. {
  124. return;
  125. }
  126. #ifdef COMPILE_OUT
  127. static void msgQueueInstanceFinalize (struct msgQueueInstance *msgQueueInstance)
  128. {
  129. struct msgSectionIterationInstance *sectionIterationInstance;
  130. struct list_head *sectionIterationList;
  131. struct list_head *sectionIterationListNext;
  132. for (sectionIterationList = msgQueueInstance->section_iteration_list_head.next,
  133. sectionIterationListNext = sectionIterationList->next;
  134. sectionIterationList != &msgQueueInstance->section_iteration_list_head;
  135. sectionIterationList = sectionIterationListNext,
  136. sectionIterationListNext = sectionIterationList->next) {
  137. sectionIterationInstance = list_entry (sectionIterationList,
  138. struct msgSectionIterationInstance, list);
  139. msgSectionIterationInstanceFinalize (sectionIterationInstance);
  140. }
  141. list_del (&msgQueueInstance->list);
  142. saHandleDestroy (&queueHandleDatabase, msgQueueInstance->queueHandle);
  143. }
  144. static void msgInstanceFinalize (struct msgInstance *msgInstance)
  145. {
  146. struct msgQueueInstance *msgQueueInstance;
  147. struct list_head *queueInstanceList;
  148. struct list_head *queueInstanceListNext;
  149. for (queueInstanceList = msgInstance->queue_list.next,
  150. queueInstanceListNext = queueInstanceList->next;
  151. queueInstanceList != &msgInstance->queue_list;
  152. queueInstanceList = queueInstanceListNext,
  153. queueInstanceListNext = queueInstanceList->next) {
  154. msgQueueInstance = list_entry (queueInstanceList,
  155. struct msgQueueInstance, list);
  156. msgQueueInstanceFinalize (msgQueueInstance);
  157. }
  158. saHandleDestroy (&msgHandleDatabase, msgInstance->msgHandle);
  159. }
  160. #endif /* COMPILE_OUT */
  161. SaAisErrorT
  162. saMsgInitialize (
  163. SaMsgHandleT *msgHandle,
  164. const SaMsgCallbacksT *callbacks,
  165. SaVersionT *version)
  166. {
  167. SaAisErrorT error;
  168. struct msgInstance *msgInstance;
  169. if (msgHandle == NULL) {
  170. return (SA_AIS_ERR_INVALID_PARAM);
  171. }
  172. error = saVersionVerify (&msgVersionDatabase, version);
  173. if (error != SA_AIS_OK) {
  174. goto error_no_destroy;
  175. }
  176. error = saHandleCreate (&msgHandleDatabase, sizeof (struct msgInstance),
  177. msgHandle);
  178. if (error != SA_AIS_OK) {
  179. goto error_no_destroy;
  180. }
  181. error = saHandleInstanceGet (&msgHandleDatabase, *msgHandle,
  182. (void *)&msgInstance);
  183. if (error != SA_AIS_OK) {
  184. goto error_destroy;
  185. }
  186. /* DEBUG */
  187. printf ("[DEBUG]: saMsgInitialize { msgHandle = %llx }\n",
  188. (unsigned long long) *msgHandle);
  189. msgInstance->response_fd = -1;
  190. error = saServiceConnect (&msgInstance->response_fd,
  191. &msgInstance->dispatch_fd, MSG_SERVICE);
  192. if (error != SA_AIS_OK) {
  193. goto error_put_destroy;
  194. }
  195. if (callbacks) {
  196. memcpy (&msgInstance->callbacks, callbacks, sizeof (SaMsgCallbacksT));
  197. } else {
  198. memset (&msgInstance->callbacks, 0, sizeof (SaMsgCallbacksT));
  199. }
  200. list_init (&msgInstance->queue_list);
  201. msgInstance->msgHandle = *msgHandle;
  202. pthread_mutex_init (&msgInstance->response_mutex, NULL);
  203. saHandleInstancePut (&msgHandleDatabase, *msgHandle);
  204. return (SA_AIS_OK);
  205. error_put_destroy:
  206. saHandleInstancePut (&msgHandleDatabase, *msgHandle);
  207. error_destroy:
  208. saHandleDestroy (&msgHandleDatabase, *msgHandle);
  209. error_no_destroy:
  210. return (error);
  211. }
  212. SaAisErrorT
  213. saMsgSelectionObjectGet (
  214. const SaMsgHandleT msgHandle,
  215. SaSelectionObjectT *selectionObject)
  216. {
  217. struct msgInstance *msgInstance;
  218. SaAisErrorT error;
  219. /* DEBUG */
  220. printf ("[DEBUG]: saMsgSelectionObjectGet { msgHandle = %llx }\n",
  221. (unsigned long long) msgHandle);
  222. if (selectionObject == NULL) {
  223. return (SA_AIS_ERR_INVALID_PARAM);
  224. }
  225. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  226. (void *)&msgInstance);
  227. if (error != SA_AIS_OK) {
  228. return (error);
  229. }
  230. *selectionObject = msgInstance->dispatch_fd;
  231. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  232. return (SA_AIS_OK);
  233. }
  234. SaAisErrorT
  235. saMsgDispatch (
  236. const SaMsgHandleT msgHandle,
  237. SaDispatchFlagsT dispatchFlags)
  238. {
  239. struct pollfd ufds;
  240. int poll_fd;
  241. int timeout = 1;
  242. SaMsgCallbacksT callbacks;
  243. SaAisErrorT error;
  244. int dispatch_avail;
  245. struct msgInstance *msgInstance;
  246. struct msgQueueInstance *msgQueueInstance;
  247. int cont = 1; /* always continue do loop except when set to 0 */
  248. struct message_overlay dispatch_data;
  249. struct res_lib_msg_queueopenasync *res_lib_msg_queueopenasync;
  250. struct res_lib_msg_messagesendasync *res_lib_msg_messagesendasync;
  251. if (dispatchFlags != SA_DISPATCH_ONE &&
  252. dispatchFlags != SA_DISPATCH_ALL &&
  253. dispatchFlags != SA_DISPATCH_BLOCKING)
  254. {
  255. return (SA_AIS_ERR_INVALID_PARAM);
  256. }
  257. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  258. (void *)&msgInstance);
  259. if (error != SA_AIS_OK) {
  260. goto error_exit;
  261. }
  262. /*
  263. * Timeout instantly for SA_DISPATCH_ALL
  264. */
  265. if (dispatchFlags == SA_DISPATCH_ALL) {
  266. timeout = 0;
  267. }
  268. do {
  269. /*
  270. * Read data directly from socket
  271. */
  272. poll_fd = msgInstance->dispatch_fd;
  273. ufds.fd = poll_fd;
  274. ufds.events = POLLIN;
  275. ufds.revents = 0;
  276. error = saPollRetry(&ufds, 1, timeout);
  277. if (error != SA_AIS_OK) {
  278. goto error_put;
  279. }
  280. pthread_mutex_lock(&msgInstance->dispatch_mutex);
  281. if (msgInstance->finalize == 1) {
  282. error = SA_AIS_OK;
  283. goto error_unlock;
  284. }
  285. if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
  286. error = SA_AIS_ERR_BAD_HANDLE;
  287. goto error_unlock;
  288. }
  289. dispatch_avail = (ufds.revents & POLLIN);
  290. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  291. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  292. break; /* exit do while cont is 1 loop */
  293. } else
  294. if (dispatch_avail == 0) {
  295. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  296. continue;
  297. }
  298. memset(&dispatch_data, 0, sizeof(struct message_overlay));
  299. error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.header,
  300. sizeof (mar_res_header_t));
  301. if (error != SA_AIS_OK) {
  302. goto error_unlock;
  303. }
  304. if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
  305. error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.data,
  306. dispatch_data.header.size - sizeof (mar_res_header_t));
  307. if (error != SA_AIS_OK) {
  308. goto error_unlock;
  309. }
  310. }
  311. /*
  312. * Make copy of callbacks, message data, unlock instance,
  313. * and call callback. A risk of this dispatch method is that
  314. * the callback routines may operate at the same time that
  315. * MsgFinalize has been called in another thread.
  316. */
  317. memcpy(&callbacks, &msgInstance->callbacks,
  318. sizeof(msgInstance->callbacks));
  319. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  320. /* DEBUG */
  321. printf ("[DEBUG]: saMsgDispatch { id = %d }\n",
  322. dispatch_data.header.id);
  323. /*
  324. * Dispatch incoming response
  325. */
  326. switch (dispatch_data.header.id)
  327. {
  328. case MESSAGE_RES_MSG_QUEUEOPENASYNC:
  329. if (callbacks.saMsgQueueOpenCallback == NULL) {
  330. continue;
  331. }
  332. res_lib_msg_queueopenasync =
  333. (struct res_lib_msg_queueopenasync *) &dispatch_data;
  334. /*
  335. * This instance get/listadd/put required so that close
  336. * later has the proper list of queues
  337. */
  338. if (res_lib_msg_queueopenasync->header.error == SA_AIS_OK) {
  339. error = saHandleInstanceGet (&queueHandleDatabase,
  340. res_lib_msg_queueopenasync->queueHandle,
  341. (void *)&msgQueueInstance);
  342. assert (error == SA_AIS_OK);
  343. /*
  344. * open succeeded without error
  345. */
  346. list_init (&msgQueueInstance->list);
  347. list_init (&msgQueueInstance->section_iteration_list_head);
  348. list_add (&msgQueueInstance->list,
  349. &msgInstance->queue_list);
  350. callbacks.saMsgQueueOpenCallback(
  351. res_lib_msg_queueopenasync->invocation,
  352. res_lib_msg_queueopenasync->queueHandle,
  353. res_lib_msg_queueopenasync->header.error);
  354. saHandleInstancePut (&queueHandleDatabase,
  355. res_lib_msg_queueopenasync->queueHandle);
  356. } else {
  357. /*
  358. * open failed with error
  359. */
  360. callbacks.saMsgQueueOpenCallback(
  361. res_lib_msg_queueopenasync->invocation,
  362. -1,
  363. res_lib_msg_queueopenasync->header.error);
  364. }
  365. break;
  366. case MESSAGE_RES_MSG_MESSAGESENDASYNC:
  367. if (callbacks.saMsgMessageDeliveredCallback == NULL) {
  368. continue;
  369. }
  370. res_lib_msg_messagesendasync =
  371. (struct res_lib_msg_messagesendasync *) &dispatch_data;
  372. callbacks.saMsgMessageDeliveredCallback (
  373. res_lib_msg_messagesendasync->invocation,
  374. res_lib_msg_messagesendasync->header.error);
  375. break;
  376. default:
  377. /* TODO */
  378. break;
  379. }
  380. /*
  381. * Determine if more messages should be processed
  382. */
  383. switch (dispatchFlags)
  384. {
  385. case SA_DISPATCH_ONE:
  386. cont = 0;
  387. break;
  388. case SA_DISPATCH_ALL:
  389. break;
  390. case SA_DISPATCH_BLOCKING:
  391. break;
  392. }
  393. } while (cont);
  394. error_unlock:
  395. pthread_mutex_unlock(&msgInstance->dispatch_mutex);
  396. error_put:
  397. saHandleInstancePut(&msgHandleDatabase, msgHandle);
  398. error_exit:
  399. return (error);
  400. }
  401. SaAisErrorT
  402. saMsgFinalize (
  403. const SaMsgHandleT msgHandle)
  404. {
  405. SaAisErrorT error;
  406. struct msgInstance *msgInstance;
  407. /* DEBUG */
  408. printf ("[DEBUG]: saMsgFinalize { msgHandle = %llx }\n",
  409. (unsigned long long) msgHandle);
  410. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  411. (void *)&msgInstance);
  412. if (error != SA_AIS_OK) {
  413. return (error);
  414. }
  415. pthread_mutex_lock (&msgInstance->response_mutex);
  416. /*
  417. * Another thread has already started finalizing
  418. */
  419. if (msgInstance->finalize) {
  420. pthread_mutex_unlock (&msgInstance->response_mutex);
  421. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  422. return (SA_AIS_ERR_BAD_HANDLE);
  423. }
  424. msgInstance->finalize = 1;
  425. pthread_mutex_unlock (&msgInstance->response_mutex);
  426. /* TODO */
  427. /* msgInstanceFinalize (msgInstance); */
  428. if (msgInstance->response_fd != -1) {
  429. shutdown (msgInstance->response_fd, 0);
  430. close (msgInstance->response_fd);
  431. }
  432. if (msgInstance->dispatch_fd != -1) {
  433. shutdown (msgInstance->dispatch_fd, 0);
  434. close (msgInstance->dispatch_fd);
  435. }
  436. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  437. return (SA_AIS_OK);
  438. }
  439. SaAisErrorT
  440. saMsgQueueOpen (
  441. SaMsgHandleT msgHandle,
  442. const SaNameT *queueName,
  443. const SaMsgQueueCreationAttributesT *creationAttributes,
  444. SaMsgQueueOpenFlagsT openFlags,
  445. SaTimeT timeout,
  446. SaMsgQueueHandleT *queueHandle)
  447. {
  448. SaAisErrorT error;
  449. struct msgInstance *msgInstance;
  450. struct msgQueueInstance *msgQueueInstance;
  451. struct req_lib_msg_queueopen req_lib_msg_queueopen;
  452. struct res_lib_msg_queueopen res_lib_msg_queueopen;
  453. /* DEBUG */
  454. printf ("[DEBUG]: saMsgQueueOpen { queueName = %s }\n",
  455. (char *) queueName->value);
  456. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  457. (void *)&msgInstance);
  458. if (error != SA_AIS_OK) {
  459. goto error_exit;
  460. }
  461. error = saHandleCreate (&queueHandleDatabase,
  462. sizeof (struct msgQueueInstance), queueHandle);
  463. if (error != SA_AIS_OK) {
  464. goto error_put_msg;
  465. }
  466. error = saHandleInstanceGet (&queueHandleDatabase,
  467. *queueHandle, (void *)&msgQueueInstance);
  468. if (error != SA_AIS_OK) {
  469. goto error_destroy;
  470. }
  471. msgQueueInstance->response_fd = msgInstance->response_fd;
  472. msgQueueInstance->response_mutex = &msgInstance->response_mutex;
  473. msgQueueInstance->msgHandle = msgHandle;
  474. msgQueueInstance->queueHandle = *queueHandle;
  475. msgQueueInstance->openFlags = openFlags;
  476. req_lib_msg_queueopen.header.size =
  477. sizeof (struct req_lib_msg_queueopen);
  478. req_lib_msg_queueopen.header.id =
  479. MESSAGE_REQ_MSG_QUEUEOPEN;
  480. memcpy (&req_lib_msg_queueopen.queueName, queueName,
  481. sizeof (SaNameT));
  482. memcpy (&msgQueueInstance->queueName, queueName,
  483. sizeof (SaNameT));
  484. req_lib_msg_queueopen.invocation = 0;
  485. req_lib_msg_queueopen.creationAttributesSet = 0;
  486. if (creationAttributes) {
  487. memcpy (&req_lib_msg_queueopen.creationAttributes,
  488. creationAttributes,
  489. sizeof (SaMsgQueueCreationAttributesT));
  490. req_lib_msg_queueopen.creationAttributesSet = 1;
  491. }
  492. req_lib_msg_queueopen.openFlags = openFlags; /* ? */
  493. req_lib_msg_queueopen.queueHandle = *queueHandle; /* ? */
  494. req_lib_msg_queueopen.timeout = timeout; /* ? */
  495. pthread_mutex_lock (msgQueueInstance->response_mutex);
  496. error = saSendReceiveReply (msgQueueInstance->response_fd,
  497. &req_lib_msg_queueopen,
  498. sizeof (struct req_lib_msg_queueopen),
  499. &res_lib_msg_queueopen,
  500. sizeof (struct res_lib_msg_queueopen));
  501. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  502. if (res_lib_msg_queueopen.header.error != SA_AIS_OK) {
  503. error = res_lib_msg_queueopen.header.error;
  504. goto error_put_destroy;
  505. }
  506. saHandleInstancePut (&queueHandleDatabase, *queueHandle);
  507. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  508. return (error);
  509. error_put_destroy:
  510. saHandleInstancePut (&queueHandleDatabase, *queueHandle);
  511. error_destroy:
  512. saHandleDestroy (&queueHandleDatabase, *queueHandle);
  513. error_put_msg:
  514. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  515. error_exit:
  516. return (error);
  517. }
  518. SaAisErrorT
  519. saMsgQueueOpenAsync (
  520. SaMsgHandleT msgHandle,
  521. SaInvocationT invocation,
  522. const SaNameT *queueName,
  523. const SaMsgQueueCreationAttributesT *creationAttributes,
  524. SaMsgQueueOpenFlagsT openFlags)
  525. {
  526. SaAisErrorT error;
  527. SaMsgQueueHandleT queueHandle;
  528. struct msgInstance *msgInstance;
  529. struct msgQueueInstance *msgQueueInstance;
  530. struct req_lib_msg_queueopen req_lib_msg_queueopen;
  531. struct res_lib_msg_queueopenasync res_lib_msg_queueopenasync;
  532. /* DEBUG */
  533. printf ("[DEBUG]: saMsgQueueOpenAsync { queueName = %s }\n",
  534. (char *) queueName->value);
  535. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  536. (void *)&msgInstance);
  537. if (error != SA_AIS_OK) {
  538. goto error_exit;
  539. }
  540. if (msgInstance->callbacks.saMsgQueueOpenCallback == NULL) {
  541. error = SA_AIS_ERR_INIT;
  542. goto error_put_msg;
  543. }
  544. error = saHandleCreate (&queueHandleDatabase,
  545. sizeof (struct msgQueueInstance), &queueHandle);
  546. if (error != SA_AIS_OK) {
  547. goto error_put_msg;
  548. }
  549. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  550. (void *)&msgQueueInstance);
  551. if (error != SA_AIS_OK) {
  552. goto error_destroy;
  553. }
  554. msgQueueInstance->response_fd = msgInstance->response_fd;
  555. msgQueueInstance->response_mutex = &msgInstance->response_mutex;
  556. msgQueueInstance->msgHandle = msgHandle;
  557. msgQueueInstance->queueHandle = queueHandle;
  558. msgQueueInstance->openFlags = openFlags;
  559. req_lib_msg_queueopen.header.size =
  560. sizeof (struct req_lib_msg_queueopen);
  561. req_lib_msg_queueopen.header.id =
  562. MESSAGE_REQ_MSG_QUEUEOPENASYNC;
  563. memcpy (&req_lib_msg_queueopen.queueName, queueName,
  564. sizeof (SaNameT));
  565. memcpy (&msgQueueInstance->queueName, queueName,
  566. sizeof (SaNameT));
  567. req_lib_msg_queueopen.invocation = invocation;
  568. req_lib_msg_queueopen.creationAttributesSet = 0;
  569. if (creationAttributes) {
  570. memcpy (&req_lib_msg_queueopen.creationAttributes,
  571. creationAttributes,
  572. sizeof (SaMsgQueueCreationAttributesT));
  573. req_lib_msg_queueopen.creationAttributesSet = 1;
  574. }
  575. req_lib_msg_queueopen.openFlags = openFlags; /* ? */
  576. req_lib_msg_queueopen.queueHandle = queueHandle; /* ? */
  577. req_lib_msg_queueopen.timeout = 0; /* ? */
  578. pthread_mutex_lock (msgQueueInstance->response_mutex);
  579. error = saSendReceiveReply (msgQueueInstance->response_fd,
  580. &req_lib_msg_queueopen,
  581. sizeof (struct req_lib_msg_queueopen),
  582. &res_lib_msg_queueopenasync,
  583. sizeof (struct res_lib_msg_queueopenasync));
  584. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  585. if (res_lib_msg_queueopenasync.header.error != SA_AIS_OK) {
  586. error = res_lib_msg_queueopenasync.header.error;
  587. goto error_put_destroy;
  588. }
  589. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  590. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  591. return (error);
  592. error_put_destroy:
  593. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  594. error_destroy:
  595. saHandleDestroy (&queueHandleDatabase, queueHandle);
  596. error_put_msg:
  597. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  598. error_exit:
  599. return (error);
  600. }
  601. SaAisErrorT
  602. saMsgQueueClose (
  603. SaMsgQueueHandleT queueHandle)
  604. {
  605. SaAisErrorT error;
  606. struct msgQueueInstance *msgQueueInstance;
  607. struct req_lib_msg_queueclose req_lib_msg_queueclose;
  608. struct res_lib_msg_queueclose res_lib_msg_queueclose;
  609. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  610. (void *)&msgQueueInstance);
  611. if (error != SA_AIS_OK) {
  612. return (error);
  613. }
  614. req_lib_msg_queueclose.header.size =
  615. sizeof (struct req_lib_msg_queueclose);
  616. req_lib_msg_queueclose.header.id =
  617. MESSAGE_REQ_MSG_QUEUECLOSE;
  618. memcpy (&req_lib_msg_queueclose.queueName, &msgQueueInstance->queueName,
  619. sizeof (SaNameT));
  620. pthread_mutex_lock (msgQueueInstance->response_mutex);
  621. error = saSendReceiveReply (msgQueueInstance->response_fd,
  622. &req_lib_msg_queueclose,
  623. sizeof (struct req_lib_msg_queueclose),
  624. &res_lib_msg_queueclose,
  625. sizeof (struct res_lib_msg_queueclose));
  626. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  627. if (error == SA_AIS_OK) {
  628. error = res_lib_msg_queueclose.header.error;
  629. }
  630. if (error == SA_AIS_OK) {
  631. /* TODO */
  632. /* msgQueueInstanceFinalize (msgQueueInstance); */
  633. }
  634. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  635. return (error);
  636. }
  637. SaAisErrorT
  638. saMsgQueueStatusGet (
  639. SaMsgHandleT msgHandle,
  640. const SaNameT *queueName,
  641. SaMsgQueueStatusT *queueStatus)
  642. {
  643. SaAisErrorT error;
  644. struct msgInstance *msgInstance;
  645. struct req_lib_msg_queuestatusget req_lib_msg_queuestatusget;
  646. struct res_lib_msg_queuestatusget res_lib_msg_queuestatusget;
  647. if (queueName == NULL) {
  648. return (SA_AIS_ERR_INVALID_PARAM);
  649. }
  650. /* DEBUG */
  651. printf ("[DEBUG]: saMsgQueueStatusGet { queueName = %s }\n",
  652. (char *) queueName->value);
  653. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  654. (void *)&msgInstance);
  655. if (error != SA_AIS_OK) {
  656. return (error);
  657. }
  658. req_lib_msg_queuestatusget.header.size =
  659. sizeof (struct req_lib_msg_queuestatusget);
  660. req_lib_msg_queuestatusget.header.id =
  661. MESSAGE_REQ_MSG_QUEUESTATUSGET;
  662. memcpy (&req_lib_msg_queuestatusget.queueName, queueName,
  663. sizeof (SaNameT));
  664. pthread_mutex_lock (&msgInstance->response_mutex);
  665. error = saSendReceiveReply (msgInstance->response_fd,
  666. &req_lib_msg_queuestatusget,
  667. sizeof (struct req_lib_msg_queuestatusget),
  668. &res_lib_msg_queuestatusget,
  669. sizeof (struct res_lib_msg_queuestatusget));
  670. pthread_mutex_unlock (&msgInstance->response_mutex);
  671. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  672. if (error == SA_AIS_OK)
  673. error = res_lib_msg_queuestatusget.header.error;
  674. if (error == SA_AIS_OK) {
  675. memcpy (queueStatus, &res_lib_msg_queuestatusget.queueStatus,
  676. sizeof (SaMsgQueueStatusT));
  677. }
  678. return (error);
  679. }
  680. SaAisErrorT
  681. saMsgQueueRetentionTimeSet (
  682. SaMsgQueueHandleT queueHandle,
  683. SaTimeT *retentionTime)
  684. {
  685. SaAisErrorT error;
  686. struct msgQueueInstance *msgQueueInstance;
  687. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  688. (void *)&msgQueueInstance);
  689. if (error != SA_AIS_OK) {
  690. return (error);
  691. }
  692. /* TODO */
  693. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  694. return (error);
  695. }
  696. SaAisErrorT
  697. saMsgQueueUnlink (
  698. SaMsgHandleT msgHandle,
  699. const SaNameT *queueName)
  700. {
  701. SaAisErrorT error;
  702. struct msgInstance *msgInstance;
  703. struct req_lib_msg_queueunlink req_lib_msg_queueunlink;
  704. struct res_lib_msg_queueunlink res_lib_msg_queueunlink;
  705. if (queueName == NULL) {
  706. return (SA_AIS_ERR_INVALID_PARAM);
  707. }
  708. /* DEBUG */
  709. printf ("[DEBUG]: saMsgQueueUnlink { queueName = %s }\n",
  710. (char *) queueName->value);
  711. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  712. (void *)&msgInstance);
  713. if (error != SA_AIS_OK) {
  714. return (error);
  715. }
  716. req_lib_msg_queueunlink.header.size =
  717. sizeof (struct req_lib_msg_queueunlink);
  718. req_lib_msg_queueunlink.header.id =
  719. MESSAGE_REQ_MSG_QUEUEUNLINK;
  720. memcpy (&req_lib_msg_queueunlink.queueName, queueName,
  721. sizeof (SaNameT));
  722. pthread_mutex_lock (&msgInstance->response_mutex);
  723. error = saSendReceiveReply (msgInstance->response_fd,
  724. &req_lib_msg_queueunlink,
  725. sizeof (struct req_lib_msg_queueunlink),
  726. &res_lib_msg_queueunlink,
  727. sizeof (struct res_lib_msg_queueunlink));
  728. pthread_mutex_unlock (&msgInstance->response_mutex);
  729. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  730. return (error == SA_AIS_OK ? res_lib_msg_queueunlink.header.error : error);
  731. }
  732. SaAisErrorT
  733. saMsgQueueGroupCreate (
  734. SaMsgHandleT msgHandle,
  735. const SaNameT *queueGroupName,
  736. SaMsgQueueGroupPolicyT queueGroupPolicy)
  737. {
  738. SaAisErrorT error;
  739. struct msgInstance *msgInstance;
  740. struct req_lib_msg_queuegroupcreate req_lib_msg_queuegroupcreate;
  741. struct res_lib_msg_queuegroupcreate res_lib_msg_queuegroupcreate;
  742. if (queueGroupName == NULL) {
  743. return (SA_AIS_ERR_INVALID_PARAM);
  744. }
  745. /* DEBUG */
  746. printf ("[DEBUG]: saMsgQueueGroupCreate { queueGroupName = %s }\n",
  747. (char *) queueGroupName->value);
  748. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  749. (void *)&msgInstance);
  750. if (error != SA_AIS_OK) {
  751. return (error);
  752. }
  753. req_lib_msg_queuegroupcreate.header.size =
  754. sizeof (struct req_lib_msg_queuegroupcreate);
  755. req_lib_msg_queuegroupcreate.header.id =
  756. MESSAGE_REQ_MSG_QUEUEGROUPCREATE;
  757. memcpy (&req_lib_msg_queuegroupcreate.queueGroupName, queueGroupName,
  758. sizeof (SaNameT));
  759. req_lib_msg_queuegroupcreate.queueGroupPolicy = queueGroupPolicy;
  760. pthread_mutex_lock (&msgInstance->response_mutex);
  761. error = saSendReceiveReply (msgInstance->response_fd,
  762. &req_lib_msg_queuegroupcreate,
  763. sizeof (struct req_lib_msg_queuegroupcreate),
  764. &res_lib_msg_queuegroupcreate,
  765. sizeof (struct res_lib_msg_queuegroupcreate));
  766. pthread_mutex_unlock (&msgInstance->response_mutex);
  767. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  768. return (error == SA_AIS_OK ? res_lib_msg_queuegroupcreate.header.error : error);
  769. }
  770. SaAisErrorT
  771. saMsgQueueGroupInsert (
  772. SaMsgHandleT msgHandle,
  773. const SaNameT *queueGroupName,
  774. const SaNameT *queueName)
  775. {
  776. SaAisErrorT error;
  777. struct msgInstance *msgInstance;
  778. struct req_lib_msg_queuegroupinsert req_lib_msg_queuegroupinsert;
  779. struct res_lib_msg_queuegroupinsert res_lib_msg_queuegroupinsert;
  780. if (queueName == NULL) {
  781. return (SA_AIS_ERR_INVALID_PARAM);
  782. }
  783. /* DEBUG */
  784. printf ("[DEBUG]: saMsgQueueGroupInsert { queueGroupName = %s }\n",
  785. (char *) queueGroupName->value);
  786. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  787. (void *)&msgInstance);
  788. if (error != SA_AIS_OK) {
  789. return (error);
  790. }
  791. req_lib_msg_queuegroupinsert.header.size =
  792. sizeof (struct req_lib_msg_queuegroupinsert);
  793. req_lib_msg_queuegroupinsert.header.id =
  794. MESSAGE_REQ_MSG_QUEUEGROUPINSERT;
  795. memcpy (&req_lib_msg_queuegroupinsert.queueName, queueName,
  796. sizeof (SaNameT));
  797. memcpy (&req_lib_msg_queuegroupinsert.queueGroupName, queueGroupName,
  798. sizeof (SaNameT));
  799. pthread_mutex_lock (&msgInstance->response_mutex);
  800. error = saSendReceiveReply (msgInstance->response_fd,
  801. &req_lib_msg_queuegroupinsert,
  802. sizeof (struct req_lib_msg_queuegroupinsert),
  803. &res_lib_msg_queuegroupinsert,
  804. sizeof (struct res_lib_msg_queuegroupinsert));
  805. pthread_mutex_unlock (&msgInstance->response_mutex);
  806. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  807. return (error == SA_AIS_OK ? res_lib_msg_queuegroupinsert.header.error : error);
  808. }
  809. SaAisErrorT
  810. saMsgQueueGroupRemove (
  811. SaMsgHandleT msgHandle,
  812. const SaNameT *queueGroupName,
  813. const SaNameT *queueName)
  814. {
  815. SaAisErrorT error;
  816. struct msgInstance *msgInstance;
  817. struct req_lib_msg_queuegroupremove req_lib_msg_queuegroupremove;
  818. struct res_lib_msg_queuegroupremove res_lib_msg_queuegroupremove;
  819. if (queueName == NULL) {
  820. return (SA_AIS_ERR_INVALID_PARAM);
  821. }
  822. /* DEBUG */
  823. printf ("[DEBUG]: saMsgQueueGroupRemove { queueGroupName = %s }\n",
  824. (char *) queueGroupName->value);
  825. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  826. (void *)&msgInstance);
  827. if (error != SA_AIS_OK) {
  828. return (error);
  829. }
  830. req_lib_msg_queuegroupremove.header.size =
  831. sizeof (struct req_lib_msg_queuegroupremove);
  832. req_lib_msg_queuegroupremove.header.id =
  833. MESSAGE_REQ_MSG_QUEUEGROUPREMOVE;
  834. memcpy (&req_lib_msg_queuegroupremove.queueName, queueName,
  835. sizeof (SaNameT));
  836. memcpy (&req_lib_msg_queuegroupremove.queueGroupName, queueGroupName,
  837. sizeof (SaNameT));
  838. pthread_mutex_lock (&msgInstance->response_mutex);
  839. error = saSendReceiveReply (msgInstance->response_fd,
  840. &req_lib_msg_queuegroupremove,
  841. sizeof (struct req_lib_msg_queuegroupremove),
  842. &res_lib_msg_queuegroupremove,
  843. sizeof (struct res_lib_msg_queuegroupremove));
  844. pthread_mutex_unlock (&msgInstance->response_mutex);
  845. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  846. return (error == SA_AIS_OK ? res_lib_msg_queuegroupremove.header.error : error);
  847. }
  848. SaAisErrorT
  849. saMsgQueueGroupDelete (
  850. SaMsgHandleT msgHandle,
  851. const SaNameT *queueGroupName)
  852. {
  853. SaAisErrorT error;
  854. struct msgInstance *msgInstance;
  855. struct req_lib_msg_queuegroupdelete req_lib_msg_queuegroupdelete;
  856. struct res_lib_msg_queuegroupdelete res_lib_msg_queuegroupdelete;
  857. if (queueGroupName == NULL) {
  858. return (SA_AIS_ERR_INVALID_PARAM);
  859. }
  860. /* DEBUG */
  861. printf ("[DEBUG]: saMsgQueueGroupDelete { queueGroupName = %s }\n",
  862. (char *) queueGroupName->value);
  863. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  864. (void *)&msgInstance);
  865. if (error != SA_AIS_OK) {
  866. return (error);
  867. }
  868. req_lib_msg_queuegroupdelete.header.size =
  869. sizeof (struct req_lib_msg_queuegroupdelete);
  870. req_lib_msg_queuegroupdelete.header.id =
  871. MESSAGE_REQ_MSG_QUEUEGROUPDELETE;
  872. memcpy (&req_lib_msg_queuegroupdelete.queueGroupName, queueGroupName,
  873. sizeof (SaNameT));
  874. pthread_mutex_lock (&msgInstance->response_mutex);
  875. error = saSendReceiveReply (msgInstance->response_fd,
  876. &req_lib_msg_queuegroupdelete,
  877. sizeof (struct req_lib_msg_queuegroupdelete),
  878. &res_lib_msg_queuegroupdelete,
  879. sizeof (struct res_lib_msg_queuegroupdelete));
  880. pthread_mutex_unlock (&msgInstance->response_mutex);
  881. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  882. return (error == SA_AIS_OK ? res_lib_msg_queuegroupdelete.header.error : error);
  883. }
  884. SaAisErrorT
  885. saMsgQueueGroupTrack (
  886. SaMsgHandleT msgHandle,
  887. const SaNameT *queueGroupName,
  888. SaUint8T trackFlags,
  889. SaMsgQueueGroupNotificationBufferT *notificationBuffer)
  890. {
  891. SaAisErrorT error;
  892. struct msgInstance *msgInstance;
  893. struct req_lib_msg_queuegrouptrack req_lib_msg_queuegrouptrack;
  894. struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack;
  895. if (queueGroupName == NULL) {
  896. return (SA_AIS_ERR_INVALID_PARAM);
  897. }
  898. /* DEBUG */
  899. printf ("[DEBUG]: saMsgQueueGroupTrack { queueGroupName = %s }\n",
  900. (char *) queueGroupName->value);
  901. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  902. (void *)&msgInstance);
  903. if (error != SA_AIS_OK) {
  904. return (error);
  905. }
  906. req_lib_msg_queuegrouptrack.header.size =
  907. sizeof (struct req_lib_msg_queuegrouptrack);
  908. req_lib_msg_queuegrouptrack.header.id =
  909. MESSAGE_REQ_MSG_QUEUEGROUPTRACK;
  910. req_lib_msg_queuegrouptrack.trackFlags = trackFlags;
  911. memcpy (&req_lib_msg_queuegrouptrack.queueGroupName, queueGroupName,
  912. sizeof (SaNameT));
  913. pthread_mutex_lock (&msgInstance->response_mutex);
  914. error = saSendReceiveReply (msgInstance->response_fd,
  915. &req_lib_msg_queuegrouptrack,
  916. sizeof (struct req_lib_msg_queuegrouptrack),
  917. &res_lib_msg_queuegrouptrack,
  918. sizeof (struct res_lib_msg_queuegrouptrack));
  919. pthread_mutex_unlock (&msgInstance->response_mutex);
  920. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  921. return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrack.header.error : error);
  922. }
  923. SaAisErrorT
  924. saMsgQueueGroupTrackStop (
  925. SaMsgHandleT msgHandle,
  926. const SaNameT *queueGroupName)
  927. {
  928. SaAisErrorT error;
  929. struct msgInstance *msgInstance;
  930. struct req_lib_msg_queuegrouptrackstop req_lib_msg_queuegrouptrackstop;
  931. struct res_lib_msg_queuegrouptrackstop res_lib_msg_queuegrouptrackstop;
  932. if (queueGroupName == NULL) {
  933. return (SA_AIS_ERR_INVALID_PARAM);
  934. }
  935. /* DEBUG */
  936. printf ("[DEBUG]: saMsgQueueGroupTrackStop { queueGroupName = %s }\n",
  937. (char *) queueGroupName->value);
  938. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  939. (void *)&msgInstance);
  940. if (error != SA_AIS_OK) {
  941. return (error);
  942. }
  943. req_lib_msg_queuegrouptrackstop.header.size =
  944. sizeof (struct req_lib_msg_queuegrouptrackstop);
  945. req_lib_msg_queuegrouptrackstop.header.id =
  946. MESSAGE_REQ_MSG_QUEUEGROUPTRACKSTOP;
  947. memcpy (&req_lib_msg_queuegrouptrackstop.queueGroupName, queueGroupName,
  948. sizeof (SaNameT));
  949. pthread_mutex_lock (&msgInstance->response_mutex);
  950. error = saSendReceiveReply (msgInstance->response_fd,
  951. &req_lib_msg_queuegrouptrackstop,
  952. sizeof (struct req_lib_msg_queuegrouptrackstop),
  953. &res_lib_msg_queuegrouptrackstop,
  954. sizeof (struct res_lib_msg_queuegrouptrackstop));
  955. pthread_mutex_unlock (&msgInstance->response_mutex);
  956. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  957. return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrackstop.header.error : error);
  958. }
  959. SaAisErrorT
  960. saMsgQueueGroupNotificationFree (
  961. SaMsgHandleT msgHandle,
  962. SaMsgQueueGroupNotificationT *notification)
  963. {
  964. SaAisErrorT error;
  965. struct msgInstance *msgInstance;
  966. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  967. (void *)&msgInstance);
  968. if (error != SA_AIS_OK) {
  969. return (error);
  970. }
  971. /* TODO */
  972. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  973. return (error);
  974. }
  975. SaAisErrorT
  976. saMsgMessageSend (
  977. SaMsgHandleT msgHandle,
  978. const SaNameT *destination,
  979. const SaMsgMessageT *message,
  980. SaTimeT timeout)
  981. {
  982. SaAisErrorT error;
  983. struct msgInstance *msgInstance;
  984. struct req_lib_msg_messagesend req_lib_msg_messagesend;
  985. struct res_lib_msg_messagesend res_lib_msg_messagesend;
  986. /* DEBUG */
  987. printf ("[DEBUG]: saMsgMessageSend { msgHandle = %llx }\n",
  988. (unsigned long long) msgHandle);
  989. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  990. (void *)&msgInstance);
  991. if (error != SA_AIS_OK) {
  992. return (error);
  993. }
  994. req_lib_msg_messagesend.header.size =
  995. sizeof (struct req_lib_msg_messagesend) + message->size;
  996. req_lib_msg_messagesend.header.id =
  997. MESSAGE_REQ_MSG_MESSAGESEND;
  998. memcpy (&req_lib_msg_messagesend.destination, destination,
  999. sizeof (SaNameT));
  1000. memcpy (&req_lib_msg_messagesend.message, message,
  1001. sizeof (SaMsgMessageT));
  1002. req_lib_msg_messagesend.invocation = 0;
  1003. req_lib_msg_messagesend.ackFlags = 0;
  1004. req_lib_msg_messagesend.async_call = 0;
  1005. req_lib_msg_messagesend.timeout = timeout;
  1006. pthread_mutex_lock (&msgInstance->response_mutex);
  1007. /*
  1008. error = saSendReceiveReply (msgInstance->response_fd,
  1009. &req_lib_msg_messagesend,
  1010. sizeof (struct req_lib_msg_messagesend),
  1011. &res_lib_msg_messagesend,
  1012. sizeof (struct res_lib_msg_messagesend));
  1013. */
  1014. error = saSendRetry (msgInstance->response_fd, &req_lib_msg_messagesend,
  1015. sizeof (struct req_lib_msg_messagesend));
  1016. if (error != SA_AIS_OK) {
  1017. goto error_exit;
  1018. }
  1019. error = saSendRetry (msgInstance->response_fd,
  1020. message->data, message->size);
  1021. if (error != SA_AIS_OK) {
  1022. goto error_exit;
  1023. }
  1024. error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_messagesend,
  1025. sizeof (struct res_lib_msg_messagesend));
  1026. error_exit:
  1027. pthread_mutex_unlock (&msgInstance->response_mutex);
  1028. error_put_msg:
  1029. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1030. return (error == SA_AIS_OK ? res_lib_msg_messagesend.header.error : error);
  1031. }
  1032. SaAisErrorT
  1033. saMsgMessageSendAsync (
  1034. SaMsgHandleT msgHandle,
  1035. SaInvocationT invocation,
  1036. const SaNameT *destination,
  1037. const SaMsgMessageT *message,
  1038. SaMsgAckFlagsT ackFlags)
  1039. {
  1040. SaAisErrorT error;
  1041. struct msgInstance *msgInstance;
  1042. struct req_lib_msg_messagesend req_lib_msg_messagesend;
  1043. struct res_lib_msg_messagesendasync res_lib_msg_messagesendasync;
  1044. /* DEBUG */
  1045. printf ("[DEBUG]: saMsgMessageSendAsync { msgHandle = %llx }\n",
  1046. (unsigned long long) msgHandle);
  1047. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1048. (void *)&msgInstance);
  1049. if (error != SA_AIS_OK) {
  1050. return (error);
  1051. }
  1052. req_lib_msg_messagesend.header.size =
  1053. sizeof (struct req_lib_msg_messagesend) + message->size;
  1054. req_lib_msg_messagesend.header.id =
  1055. MESSAGE_REQ_MSG_MESSAGESENDASYNC;
  1056. memcpy (&req_lib_msg_messagesend.destination, destination,
  1057. sizeof (SaNameT));
  1058. memcpy (&req_lib_msg_messagesend.message, message,
  1059. sizeof (SaMsgMessageT));
  1060. req_lib_msg_messagesend.invocation = invocation;
  1061. req_lib_msg_messagesend.ackFlags = ackFlags;
  1062. req_lib_msg_messagesend.async_call = 1;
  1063. req_lib_msg_messagesend.timeout = 0;
  1064. pthread_mutex_lock (&msgInstance->response_mutex);
  1065. /*
  1066. error = saSendReceiveReply (msgInstance->response_fd,
  1067. &req_lib_msg_messagesend,
  1068. sizeof (struct req_lib_msg_messagesend),
  1069. &res_lib_msg_messagesendasync,
  1070. sizeof (struct res_lib_msg_messagesendasync));
  1071. */
  1072. error = saSendRetry (msgInstance->response_fd, &req_lib_msg_messagesend,
  1073. sizeof (struct req_lib_msg_messagesend));
  1074. if (error != SA_AIS_OK) {
  1075. goto error_exit;
  1076. }
  1077. error = saSendRetry (msgInstance->response_fd,
  1078. message->data, message->size);
  1079. if (error != SA_AIS_OK) {
  1080. goto error_exit;
  1081. }
  1082. error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_messagesendasync,
  1083. sizeof (struct res_lib_msg_messagesendasync));
  1084. error_exit:
  1085. pthread_mutex_unlock (&msgInstance->response_mutex);
  1086. error_put_msg:
  1087. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1088. return (error == SA_AIS_OK ? res_lib_msg_messagesendasync.header.error : error);
  1089. }
  1090. SaAisErrorT
  1091. saMsgMessageGet (
  1092. SaMsgQueueHandleT queueHandle,
  1093. SaMsgMessageT *message,
  1094. SaTimeT *sendTime,
  1095. SaMsgSenderIdT *senderId,
  1096. SaTimeT timeout)
  1097. {
  1098. SaAisErrorT error;
  1099. struct msgQueueInstance *msgQueueInstance;
  1100. struct req_lib_msg_messageget req_lib_msg_messageget;
  1101. struct res_lib_msg_messageget res_lib_msg_messageget;
  1102. /* DEBUG */
  1103. printf ("[DEBUG]: saMsgMessageGet { queueHandle = %llx }\n",
  1104. (unsigned long long) queueHandle);
  1105. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  1106. (void *)&msgQueueInstance);
  1107. if (error != SA_AIS_OK) {
  1108. return (error);
  1109. }
  1110. req_lib_msg_messageget.header.size =
  1111. sizeof (struct req_lib_msg_messageget);
  1112. req_lib_msg_messageget.header.id =
  1113. MESSAGE_REQ_MSG_MESSAGEGET;
  1114. memcpy (&req_lib_msg_messageget.queueName, &msgQueueInstance->queueName,
  1115. sizeof (SaNameT));
  1116. req_lib_msg_messageget.timeout = timeout;
  1117. pthread_mutex_lock (msgQueueInstance->response_mutex);
  1118. /*
  1119. error = saSendReceiveReply (msgQueueInstance->response_fd,
  1120. &req_lib_msg_messageget,
  1121. sizeof (struct req_lib_msg_messageget),
  1122. &res_lib_msg_messageget,
  1123. sizeof (struct res_lib_msg_messageget));
  1124. */
  1125. error = saSendRetry (msgQueueInstance->response_fd, &req_lib_msg_messageget,
  1126. sizeof (struct req_lib_msg_messageget));
  1127. if (error != SA_AIS_OK) {
  1128. goto error_exit;
  1129. }
  1130. error = saRecvRetry (msgQueueInstance->response_fd, &res_lib_msg_messageget,
  1131. sizeof (struct res_lib_msg_messageget));
  1132. if (error != SA_AIS_OK) {
  1133. goto error_exit;
  1134. }
  1135. if (message->data == NULL) {
  1136. message->size = res_lib_msg_messageget.message.size;
  1137. message->data = malloc (message->size);
  1138. if (message->data == NULL) {
  1139. error = SA_AIS_ERR_NO_MEMORY;
  1140. goto error_exit;
  1141. }
  1142. } else {
  1143. if (res_lib_msg_messageget.message.size > message->size) {
  1144. error = SA_AIS_ERR_NO_SPACE;
  1145. goto error_exit;
  1146. }
  1147. }
  1148. error = saRecvRetry (msgQueueInstance->response_fd,
  1149. message->data, message->size);
  1150. error_exit:
  1151. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  1152. error_put_msg:
  1153. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  1154. if (error == SA_AIS_OK)
  1155. error = res_lib_msg_messageget.header.error;
  1156. if (error == SA_AIS_OK) {
  1157. *sendTime = res_lib_msg_messageget.sendTime;
  1158. memcpy (senderId, &res_lib_msg_messageget.senderId,
  1159. sizeof (SaMsgSenderIdT));
  1160. }
  1161. return (error);
  1162. }
  1163. SaAisErrorT
  1164. saMsgMessageDataFree (
  1165. SaMsgHandleT msgHandle,
  1166. void *data)
  1167. {
  1168. SaAisErrorT error;
  1169. struct msgInstance *msgInstance;
  1170. if (data == NULL) {
  1171. return (SA_AIS_ERR_INVALID_PARAM);
  1172. }
  1173. /* DEBUG */
  1174. printf ("[DEBUG]: saMsgMessageDataFree { msgHandle = %llx }\n",
  1175. (unsigned long long) msgHandle);
  1176. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1177. (void *)&msgInstance);
  1178. if (error != SA_AIS_OK) {
  1179. return (error);
  1180. }
  1181. free (data);
  1182. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1183. return (error);
  1184. }
  1185. SaAisErrorT
  1186. saMsgMessageCancel (
  1187. SaMsgQueueHandleT queueHandle)
  1188. {
  1189. SaAisErrorT error;
  1190. struct msgQueueInstance *msgQueueInstance;
  1191. struct req_lib_msg_messagecancel req_lib_msg_messagecancel;
  1192. struct res_lib_msg_messagecancel res_lib_msg_messagecancel;
  1193. /* DEBUG */
  1194. printf ("[DEBUG]: saMsgMessageCancel { queueHandle = %llx }\n",
  1195. (unsigned long long) queueHandle);
  1196. error = saHandleInstanceGet (&msgHandleDatabase, queueHandle,
  1197. (void *)&msgQueueInstance);
  1198. if (error != SA_AIS_OK) {
  1199. return (error);
  1200. }
  1201. req_lib_msg_messagecancel.header.size =
  1202. sizeof (struct req_lib_msg_messagecancel);
  1203. req_lib_msg_messagecancel.header.id =
  1204. MESSAGE_REQ_MSG_MESSAGECANCEL;
  1205. pthread_mutex_lock (msgQueueInstance->response_mutex);
  1206. error = saSendReceiveReply (msgQueueInstance->response_fd,
  1207. &req_lib_msg_messagecancel,
  1208. sizeof (struct req_lib_msg_messagecancel),
  1209. &res_lib_msg_messagecancel,
  1210. sizeof (struct res_lib_msg_messagecancel));
  1211. pthread_mutex_unlock (msgQueueInstance->response_mutex);
  1212. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  1213. return (error == SA_AIS_OK ? res_lib_msg_messagecancel.header.error : error);
  1214. }
  1215. SaAisErrorT
  1216. saMsgMessageSendReceive (
  1217. SaMsgHandleT msgHandle,
  1218. const SaNameT *destination,
  1219. const SaMsgMessageT *sendMessage,
  1220. SaMsgMessageT *receiveMessage,
  1221. SaTimeT *replySendTime,
  1222. SaTimeT timeout)
  1223. {
  1224. SaAisErrorT error;
  1225. struct msgInstance *msgInstance;
  1226. struct req_lib_msg_messagesendreceive req_lib_msg_messagesendreceive;
  1227. struct res_lib_msg_messagesendreceive res_lib_msg_messagesendreceive;
  1228. /* DEBUG */
  1229. printf ("[DEBUG]: saMsgMessageSendReceive { msgHandle = %llx }\n",
  1230. (unsigned long long) msgHandle);
  1231. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1232. (void *)&msgInstance);
  1233. if (error != SA_AIS_OK) {
  1234. return (error);
  1235. }
  1236. req_lib_msg_messagesendreceive.header.size =
  1237. sizeof (struct req_lib_msg_messagesendreceive);
  1238. req_lib_msg_messagesendreceive.header.id =
  1239. MESSAGE_REQ_MSG_MESSAGEREPLY;
  1240. memcpy (&req_lib_msg_messagesendreceive.destination, destination,
  1241. sizeof (SaNameT));
  1242. req_lib_msg_messagesendreceive.timeout = timeout;
  1243. pthread_mutex_lock (&msgInstance->response_mutex);
  1244. error = saSendReceiveReply (msgInstance->response_fd,
  1245. &req_lib_msg_messagesendreceive,
  1246. sizeof (struct req_lib_msg_messagesendreceive),
  1247. &res_lib_msg_messagesendreceive,
  1248. sizeof (struct res_lib_msg_messagesendreceive));
  1249. pthread_mutex_unlock (&msgInstance->response_mutex);
  1250. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1251. if (error == SA_AIS_OK)
  1252. error = res_lib_msg_messagesendreceive.header.error;
  1253. if (error == SA_AIS_OK) {
  1254. *replySendTime = res_lib_msg_messagesendreceive.replySendTime;
  1255. }
  1256. return (error);
  1257. }
  1258. SaAisErrorT
  1259. saMsgMessageReply (
  1260. SaMsgHandleT msgHandle,
  1261. const SaMsgMessageT *replyMessage,
  1262. const SaMsgSenderIdT *senderId,
  1263. SaTimeT timeout)
  1264. {
  1265. SaAisErrorT error;
  1266. struct msgInstance *msgInstance;
  1267. struct req_lib_msg_messagereply req_lib_msg_messagereply;
  1268. struct res_lib_msg_messagereply res_lib_msg_messagereply;
  1269. /* DEBUG */
  1270. printf ("[DEBUG]: saMsgMessageReply { msgHandle = %llx }\n",
  1271. (unsigned long long) msgHandle);
  1272. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1273. (void *)&msgInstance);
  1274. if (error != SA_AIS_OK) {
  1275. return (error);
  1276. }
  1277. req_lib_msg_messagereply.header.size =
  1278. sizeof (struct req_lib_msg_messagereply);
  1279. req_lib_msg_messagereply.header.id =
  1280. MESSAGE_REQ_MSG_MESSAGEREPLY;
  1281. memcpy (&req_lib_msg_messagereply.senderId, senderId,
  1282. sizeof (SaMsgSenderIdT));
  1283. pthread_mutex_lock (&msgInstance->response_mutex);
  1284. error = saSendReceiveReply (msgInstance->response_fd,
  1285. &req_lib_msg_messagereply,
  1286. sizeof (struct req_lib_msg_messagereply),
  1287. &res_lib_msg_messagereply,
  1288. sizeof (struct res_lib_msg_messagereply));
  1289. pthread_mutex_unlock (&msgInstance->response_mutex);
  1290. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1291. return (error == SA_AIS_OK ? res_lib_msg_messagereply.header.error : error);
  1292. }
  1293. SaAisErrorT
  1294. saMsgMessageReplyAsync (
  1295. SaMsgHandleT msgHandle,
  1296. SaInvocationT invocation,
  1297. const SaMsgMessageT *replyMessage,
  1298. const SaMsgSenderIdT *senderId,
  1299. SaMsgAckFlagsT ackFlags)
  1300. {
  1301. SaAisErrorT error;
  1302. struct msgInstance *msgInstance;
  1303. struct req_lib_msg_messagereply req_lib_msg_messagereply;
  1304. struct res_lib_msg_messagereplyasync res_lib_msg_messagereplyasync;
  1305. /* DEBUG */
  1306. printf ("[DEBUG]: saMsgMessageReplyAsync { msgHandle = %llx }\n",
  1307. (unsigned long long) msgHandle);
  1308. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1309. (void *)&msgInstance);
  1310. if (error != SA_AIS_OK) {
  1311. return (error);
  1312. }
  1313. req_lib_msg_messagereply.header.size =
  1314. sizeof (struct req_lib_msg_messagereply);
  1315. req_lib_msg_messagereply.header.id =
  1316. MESSAGE_REQ_MSG_MESSAGEREPLY;
  1317. memcpy (&req_lib_msg_messagereply.senderId, senderId,
  1318. sizeof (SaMsgSenderIdT));
  1319. pthread_mutex_lock (&msgInstance->response_mutex);
  1320. error = saSendReceiveReply (msgInstance->response_fd,
  1321. &req_lib_msg_messagereply,
  1322. sizeof (struct req_lib_msg_messagereply),
  1323. &res_lib_msg_messagereplyasync,
  1324. sizeof (struct res_lib_msg_messagereplyasync));
  1325. pthread_mutex_unlock (&msgInstance->response_mutex);
  1326. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1327. return (error == SA_AIS_OK ? res_lib_msg_messagereplyasync.header.error : error);
  1328. }
  1329. SaAisErrorT
  1330. saMsgQueueCapacityThresholdSet (
  1331. SaMsgQueueHandleT queueHandle,
  1332. const SaMsgQueueThresholdsT *thresholds)
  1333. {
  1334. SaAisErrorT error;
  1335. struct msgQueueInstance *msgQueueInstance;
  1336. /* DEBUG */
  1337. printf ("[DEBUG]: saMsgQueueCapacityThresholdsSet { queueHandle = %llx }\n",
  1338. (unsigned long long) queueHandle);
  1339. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  1340. (void *)&msgQueueInstance);
  1341. if (error != SA_AIS_OK) {
  1342. return (error);
  1343. }
  1344. /* TODO */
  1345. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  1346. return (error);
  1347. }
  1348. SaAisErrorT
  1349. saMsgQueueCapacityThresholdGet (
  1350. SaMsgQueueHandleT queueHandle,
  1351. SaMsgQueueThresholdsT *thresholds)
  1352. {
  1353. SaAisErrorT error;
  1354. struct msgQueueInstance *msgQueueInstance;
  1355. /* DEBUG */
  1356. printf ("[DEBUG]: saMsgQueueCapacityThresholdGet { queueHandle = %llx }\n",
  1357. (unsigned long long) queueHandle);
  1358. error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
  1359. (void *)&msgQueueInstance);
  1360. if (error != SA_AIS_OK) {
  1361. return (error);
  1362. }
  1363. /* TODO */
  1364. saHandleInstancePut (&queueHandleDatabase, queueHandle);
  1365. return (error);
  1366. }
  1367. SaAisErrorT
  1368. saMsgMetadataSizeGet (
  1369. SaMsgHandleT msgHandle,
  1370. SaUint32T *metadataSize)
  1371. {
  1372. SaAisErrorT error;
  1373. struct msgInstance *msgInstance;
  1374. /* DEBUG */
  1375. printf ("[DEBUG]: saMsgMetadataSizeGet { msgHandle = %llx }\n",
  1376. (unsigned long long) msgHandle);
  1377. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1378. (void *)&msgInstance);
  1379. if (error != SA_AIS_OK) {
  1380. return (error);
  1381. }
  1382. /* TODO */
  1383. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1384. return (error);
  1385. }
  1386. SaAisErrorT
  1387. saMsgLimitGet (
  1388. SaMsgHandleT msgHandle,
  1389. SaMsgLimitIdT limitId,
  1390. SaLimitValueT *limitValue)
  1391. {
  1392. SaAisErrorT error;
  1393. struct msgInstance *msgInstance;
  1394. /* DEBUG */
  1395. printf ("[DEBUG]: saMsgLimitGet { msgHandle = %llx }\n",
  1396. (unsigned long long) msgHandle);
  1397. error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
  1398. (void *)&msgInstance);
  1399. if (error != SA_AIS_OK) {
  1400. return (error);
  1401. }
  1402. /* TODO */
  1403. saHandleInstancePut (&msgHandleDatabase, msgHandle);
  1404. return (error);
  1405. }