| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765 |
- /*
- * Copyright (c) 2005 MontaVista Software, Inc.
- *
- * All rights reserved.
- *
- * Author: Steven Dake (sdake@redhat.com)
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <assert.h>
- #include <unistd.h>
- #include <errno.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <sys/uio.h>
- #include <sys/socket.h>
- #include <sys/select.h>
- #include <sys/un.h>
- #include <saAis.h>
- #include <saMsg.h>
- #include <ipc_gen.h>
- #include <ipc_msg.h>
- #include <ais_util.h>
- #include <list.h>
- struct message_overlay {
- mar_res_header_t header __attribute__((aligned(8)));
- char data[4096];
- };
- /*
- * Data structure for instance data
- */
- struct msgInstance {
- int response_fd;
- int dispatch_fd;
- SaMsgCallbacksT callbacks;
- int finalize;
- SaMsgHandleT msgHandle;
- pthread_mutex_t response_mutex;
- pthread_mutex_t dispatch_mutex;
- struct list_head queue_list;
- };
- struct msgQueueInstance {
- int response_fd;
- SaMsgHandleT msgHandle;
- SaMsgQueueHandleT queueHandle;
- SaMsgQueueOpenFlagsT openFlags;
- SaNameT queueName;
- struct list_head list;
- struct list_head section_iteration_list_head;
- pthread_mutex_t *response_mutex;
- };
- void msgHandleInstanceDestructor (void *instance);
- void queueHandleInstanceDestructor (void *instance);
- /*
- * All MSG instances in this database
- */
- static struct saHandleDatabase msgHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = msgHandleInstanceDestructor
- };
- /*
- * All Queue instances in this database
- */
- static struct saHandleDatabase queueHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = queueHandleInstanceDestructor
- };
- /*
- * Versions supported
- */
- static SaVersionT msgVersionsSupported[] = {
- { 'B', 1, 1 }
- };
- static struct saVersionDatabase msgVersionDatabase = {
- sizeof (msgVersionsSupported) / sizeof (SaVersionT),
- msgVersionsSupported
- };
- struct iteratorSectionIdListEntry {
- struct list_head list;
- unsigned char data[0];
- };
- /*
- * Implementation
- */
- void msgHandleInstanceDestructor (void *instance)
- {
- struct msgInstance *msgInstance = instance;
- pthread_mutex_destroy (&msgInstance->response_mutex);
- pthread_mutex_destroy (&msgInstance->dispatch_mutex);
- }
- void queueHandleInstanceDestructor (void *instance)
- {
- return;
- }
- #ifdef COMPILE_OUT
- static void msgQueueInstanceFinalize (struct msgQueueInstance *msgQueueInstance)
- {
- struct msgSectionIterationInstance *sectionIterationInstance;
- struct list_head *sectionIterationList;
- struct list_head *sectionIterationListNext;
- for (sectionIterationList = msgQueueInstance->section_iteration_list_head.next,
- sectionIterationListNext = sectionIterationList->next;
- sectionIterationList != &msgQueueInstance->section_iteration_list_head;
- sectionIterationList = sectionIterationListNext,
- sectionIterationListNext = sectionIterationList->next) {
- sectionIterationInstance = list_entry (sectionIterationList,
- struct msgSectionIterationInstance, list);
- msgSectionIterationInstanceFinalize (sectionIterationInstance);
- }
- list_del (&msgQueueInstance->list);
- saHandleDestroy (&queueHandleDatabase, msgQueueInstance->queueHandle);
- }
- static void msgInstanceFinalize (struct msgInstance *msgInstance)
- {
- struct msgQueueInstance *msgQueueInstance;
- struct list_head *queueInstanceList;
- struct list_head *queueInstanceListNext;
- for (queueInstanceList = msgInstance->queue_list.next,
- queueInstanceListNext = queueInstanceList->next;
- queueInstanceList != &msgInstance->queue_list;
- queueInstanceList = queueInstanceListNext,
- queueInstanceListNext = queueInstanceList->next) {
- msgQueueInstance = list_entry (queueInstanceList,
- struct msgQueueInstance, list);
- msgQueueInstanceFinalize (msgQueueInstance);
- }
- saHandleDestroy (&msgHandleDatabase, msgInstance->msgHandle);
- }
- #endif /* COMPILE_OUT */
- SaAisErrorT
- saMsgInitialize (
- SaMsgHandleT *msgHandle,
- const SaMsgCallbacksT *callbacks,
- SaVersionT *version)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- if (msgHandle == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- error = saVersionVerify (&msgVersionDatabase, version);
- if (error != SA_AIS_OK) {
- goto error_no_destroy;
- }
- error = saHandleCreate (&msgHandleDatabase, sizeof (struct msgInstance),
- msgHandle);
- if (error != SA_AIS_OK) {
- goto error_no_destroy;
- }
- error = saHandleInstanceGet (&msgHandleDatabase, *msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- goto error_destroy;
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgInitialize { msgHandle = %llx }\n",
- (unsigned long long) *msgHandle);
- msgInstance->response_fd = -1;
- error = saServiceConnect (&msgInstance->response_fd,
- &msgInstance->dispatch_fd, MSG_SERVICE);
- if (error != SA_AIS_OK) {
- goto error_put_destroy;
- }
- if (callbacks) {
- memcpy (&msgInstance->callbacks, callbacks, sizeof (SaMsgCallbacksT));
- } else {
- memset (&msgInstance->callbacks, 0, sizeof (SaMsgCallbacksT));
- }
- list_init (&msgInstance->queue_list);
- msgInstance->msgHandle = *msgHandle;
- pthread_mutex_init (&msgInstance->response_mutex, NULL);
- saHandleInstancePut (&msgHandleDatabase, *msgHandle);
- return (SA_AIS_OK);
- error_put_destroy:
- saHandleInstancePut (&msgHandleDatabase, *msgHandle);
- error_destroy:
- saHandleDestroy (&msgHandleDatabase, *msgHandle);
- error_no_destroy:
- return (error);
- }
- SaAisErrorT
- saMsgSelectionObjectGet (
- const SaMsgHandleT msgHandle,
- SaSelectionObjectT *selectionObject)
- {
- struct msgInstance *msgInstance;
- SaAisErrorT error;
- /* DEBUG */
- printf ("[DEBUG]: saMsgSelectionObjectGet { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- if (selectionObject == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- *selectionObject = msgInstance->dispatch_fd;
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (SA_AIS_OK);
- }
- SaAisErrorT
- saMsgDispatch (
- const SaMsgHandleT msgHandle,
- SaDispatchFlagsT dispatchFlags)
- {
- struct pollfd ufds;
- int poll_fd;
- int timeout = 1;
- SaMsgCallbacksT callbacks;
- SaAisErrorT error;
- int dispatch_avail;
- struct msgInstance *msgInstance;
- struct msgQueueInstance *msgQueueInstance;
- int cont = 1; /* always continue do loop except when set to 0 */
- struct message_overlay dispatch_data;
- struct res_lib_msg_queueopenasync *res_lib_msg_queueopenasync;
- struct res_lib_msg_messagesendasync *res_lib_msg_messagesendasync;
- if (dispatchFlags != SA_DISPATCH_ONE &&
- dispatchFlags != SA_DISPATCH_ALL &&
- dispatchFlags != SA_DISPATCH_BLOCKING)
- {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- /*
- * Timeout instantly for SA_DISPATCH_ALL
- */
- if (dispatchFlags == SA_DISPATCH_ALL) {
- timeout = 0;
- }
- do {
- /*
- * Read data directly from socket
- */
- poll_fd = msgInstance->dispatch_fd;
- ufds.fd = poll_fd;
- ufds.events = POLLIN;
- ufds.revents = 0;
- error = saPollRetry(&ufds, 1, timeout);
- if (error != SA_AIS_OK) {
- goto error_put;
- }
- pthread_mutex_lock(&msgInstance->dispatch_mutex);
- if (msgInstance->finalize == 1) {
- error = SA_AIS_OK;
- goto error_unlock;
- }
- if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
- error = SA_AIS_ERR_BAD_HANDLE;
- goto error_unlock;
- }
-
- dispatch_avail = (ufds.revents & POLLIN);
- if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
- pthread_mutex_unlock(&msgInstance->dispatch_mutex);
- break; /* exit do while cont is 1 loop */
- } else
- if (dispatch_avail == 0) {
- pthread_mutex_unlock(&msgInstance->dispatch_mutex);
- continue;
- }
-
- memset(&dispatch_data, 0, sizeof(struct message_overlay));
- error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.header,
- sizeof (mar_res_header_t));
- if (error != SA_AIS_OK) {
- goto error_unlock;
- }
- if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
- error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.data,
- dispatch_data.header.size - sizeof (mar_res_header_t));
- if (error != SA_AIS_OK) {
- goto error_unlock;
- }
- }
- /*
- * Make copy of callbacks, message data, unlock instance,
- * and call callback. A risk of this dispatch method is that
- * the callback routines may operate at the same time that
- * MsgFinalize has been called in another thread.
- */
- memcpy(&callbacks, &msgInstance->callbacks,
- sizeof(msgInstance->callbacks));
- pthread_mutex_unlock(&msgInstance->dispatch_mutex);
- /* DEBUG */
- printf ("[DEBUG]: saMsgDispatch { id = %d }\n",
- dispatch_data.header.id);
- /*
- * Dispatch incoming response
- */
- switch (dispatch_data.header.id)
- {
- case MESSAGE_RES_MSG_QUEUEOPENASYNC:
- if (callbacks.saMsgQueueOpenCallback == NULL) {
- continue;
- }
- res_lib_msg_queueopenasync =
- (struct res_lib_msg_queueopenasync *) &dispatch_data;
- /*
- * This instance get/listadd/put required so that close
- * later has the proper list of queues
- */
- if (res_lib_msg_queueopenasync->header.error == SA_AIS_OK) {
- error = saHandleInstanceGet (&queueHandleDatabase,
- res_lib_msg_queueopenasync->queueHandle,
- (void *)&msgQueueInstance);
- assert (error == SA_AIS_OK);
- /*
- * open succeeded without error
- */
- list_init (&msgQueueInstance->list);
- list_init (&msgQueueInstance->section_iteration_list_head);
- list_add (&msgQueueInstance->list,
- &msgInstance->queue_list);
- callbacks.saMsgQueueOpenCallback(
- res_lib_msg_queueopenasync->invocation,
- res_lib_msg_queueopenasync->queueHandle,
- res_lib_msg_queueopenasync->header.error);
- saHandleInstancePut (&queueHandleDatabase,
- res_lib_msg_queueopenasync->queueHandle);
- } else {
- /*
- * open failed with error
- */
- callbacks.saMsgQueueOpenCallback(
- res_lib_msg_queueopenasync->invocation,
- -1,
- res_lib_msg_queueopenasync->header.error);
- }
- break;
- case MESSAGE_RES_MSG_MESSAGESENDASYNC:
- if (callbacks.saMsgMessageDeliveredCallback == NULL) {
- continue;
- }
- res_lib_msg_messagesendasync =
- (struct res_lib_msg_messagesendasync *) &dispatch_data;
- callbacks.saMsgMessageDeliveredCallback (
- res_lib_msg_messagesendasync->invocation,
- res_lib_msg_messagesendasync->header.error);
- break;
- default:
- /* TODO */
- break;
- }
- /*
- * Determine if more messages should be processed
- */
- switch (dispatchFlags)
- {
- case SA_DISPATCH_ONE:
- cont = 0;
- break;
- case SA_DISPATCH_ALL:
- break;
- case SA_DISPATCH_BLOCKING:
- break;
- }
- } while (cont);
- error_unlock:
- pthread_mutex_unlock(&msgInstance->dispatch_mutex);
- error_put:
- saHandleInstancePut(&msgHandleDatabase, msgHandle);
- error_exit:
- return (error);
- }
- SaAisErrorT
- saMsgFinalize (
- const SaMsgHandleT msgHandle)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- /* DEBUG */
- printf ("[DEBUG]: saMsgFinalize { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- pthread_mutex_lock (&msgInstance->response_mutex);
- /*
- * Another thread has already started finalizing
- */
- if (msgInstance->finalize) {
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (SA_AIS_ERR_BAD_HANDLE);
- }
- msgInstance->finalize = 1;
- pthread_mutex_unlock (&msgInstance->response_mutex);
- /* TODO */
- /* msgInstanceFinalize (msgInstance); */
- if (msgInstance->response_fd != -1) {
- shutdown (msgInstance->response_fd, 0);
- close (msgInstance->response_fd);
- }
- if (msgInstance->dispatch_fd != -1) {
- shutdown (msgInstance->dispatch_fd, 0);
- close (msgInstance->dispatch_fd);
- }
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (SA_AIS_OK);
- }
- SaAisErrorT
- saMsgQueueOpen (
- SaMsgHandleT msgHandle,
- const SaNameT *queueName,
- const SaMsgQueueCreationAttributesT *creationAttributes,
- SaMsgQueueOpenFlagsT openFlags,
- SaTimeT timeout,
- SaMsgQueueHandleT *queueHandle)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct msgQueueInstance *msgQueueInstance;
- struct req_lib_msg_queueopen req_lib_msg_queueopen;
- struct res_lib_msg_queueopen res_lib_msg_queueopen;
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueOpen { queueName = %s }\n",
- (char *) queueName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- error = saHandleCreate (&queueHandleDatabase,
- sizeof (struct msgQueueInstance), queueHandle);
- if (error != SA_AIS_OK) {
- goto error_put_msg;
- }
- error = saHandleInstanceGet (&queueHandleDatabase,
- *queueHandle, (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- goto error_destroy;
- }
- msgQueueInstance->response_fd = msgInstance->response_fd;
- msgQueueInstance->response_mutex = &msgInstance->response_mutex;
- msgQueueInstance->msgHandle = msgHandle;
- msgQueueInstance->queueHandle = *queueHandle;
- msgQueueInstance->openFlags = openFlags;
- req_lib_msg_queueopen.header.size =
- sizeof (struct req_lib_msg_queueopen);
- req_lib_msg_queueopen.header.id =
- MESSAGE_REQ_MSG_QUEUEOPEN;
- memcpy (&req_lib_msg_queueopen.queueName, queueName,
- sizeof (SaNameT));
- memcpy (&msgQueueInstance->queueName, queueName,
- sizeof (SaNameT));
- req_lib_msg_queueopen.invocation = 0;
- req_lib_msg_queueopen.creationAttributesSet = 0;
- if (creationAttributes) {
- memcpy (&req_lib_msg_queueopen.creationAttributes,
- creationAttributes,
- sizeof (SaMsgQueueCreationAttributesT));
- req_lib_msg_queueopen.creationAttributesSet = 1;
- }
- req_lib_msg_queueopen.openFlags = openFlags; /* ? */
- req_lib_msg_queueopen.queueHandle = *queueHandle; /* ? */
- req_lib_msg_queueopen.timeout = timeout; /* ? */
- pthread_mutex_lock (msgQueueInstance->response_mutex);
- error = saSendReceiveReply (msgQueueInstance->response_fd,
- &req_lib_msg_queueopen,
- sizeof (struct req_lib_msg_queueopen),
- &res_lib_msg_queueopen,
- sizeof (struct res_lib_msg_queueopen));
- pthread_mutex_unlock (msgQueueInstance->response_mutex);
- if (res_lib_msg_queueopen.header.error != SA_AIS_OK) {
- error = res_lib_msg_queueopen.header.error;
- goto error_put_destroy;
- }
- saHandleInstancePut (&queueHandleDatabase, *queueHandle);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error);
- error_put_destroy:
- saHandleInstancePut (&queueHandleDatabase, *queueHandle);
- error_destroy:
- saHandleDestroy (&queueHandleDatabase, *queueHandle);
- error_put_msg:
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- error_exit:
- return (error);
- }
- SaAisErrorT
- saMsgQueueOpenAsync (
- SaMsgHandleT msgHandle,
- SaInvocationT invocation,
- const SaNameT *queueName,
- const SaMsgQueueCreationAttributesT *creationAttributes,
- SaMsgQueueOpenFlagsT openFlags)
- {
- SaAisErrorT error;
- SaMsgQueueHandleT queueHandle;
- struct msgInstance *msgInstance;
- struct msgQueueInstance *msgQueueInstance;
- struct req_lib_msg_queueopen req_lib_msg_queueopen;
- struct res_lib_msg_queueopenasync res_lib_msg_queueopenasync;
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueOpenAsync { queueName = %s }\n",
- (char *) queueName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- if (msgInstance->callbacks.saMsgQueueOpenCallback == NULL) {
- error = SA_AIS_ERR_INIT;
- goto error_put_msg;
- }
- error = saHandleCreate (&queueHandleDatabase,
- sizeof (struct msgQueueInstance), &queueHandle);
- if (error != SA_AIS_OK) {
- goto error_put_msg;
- }
- error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- goto error_destroy;
- }
- msgQueueInstance->response_fd = msgInstance->response_fd;
- msgQueueInstance->response_mutex = &msgInstance->response_mutex;
- msgQueueInstance->msgHandle = msgHandle;
- msgQueueInstance->queueHandle = queueHandle;
- msgQueueInstance->openFlags = openFlags;
- req_lib_msg_queueopen.header.size =
- sizeof (struct req_lib_msg_queueopen);
- req_lib_msg_queueopen.header.id =
- MESSAGE_REQ_MSG_QUEUEOPENASYNC;
- memcpy (&req_lib_msg_queueopen.queueName, queueName,
- sizeof (SaNameT));
- memcpy (&msgQueueInstance->queueName, queueName,
- sizeof (SaNameT));
- req_lib_msg_queueopen.invocation = invocation;
- req_lib_msg_queueopen.creationAttributesSet = 0;
- if (creationAttributes) {
- memcpy (&req_lib_msg_queueopen.creationAttributes,
- creationAttributes,
- sizeof (SaMsgQueueCreationAttributesT));
- req_lib_msg_queueopen.creationAttributesSet = 1;
- }
-
- req_lib_msg_queueopen.openFlags = openFlags; /* ? */
- req_lib_msg_queueopen.queueHandle = queueHandle; /* ? */
- req_lib_msg_queueopen.timeout = 0; /* ? */
- pthread_mutex_lock (msgQueueInstance->response_mutex);
- error = saSendReceiveReply (msgQueueInstance->response_fd,
- &req_lib_msg_queueopen,
- sizeof (struct req_lib_msg_queueopen),
- &res_lib_msg_queueopenasync,
- sizeof (struct res_lib_msg_queueopenasync));
-
- pthread_mutex_unlock (msgQueueInstance->response_mutex);
- if (res_lib_msg_queueopenasync.header.error != SA_AIS_OK) {
- error = res_lib_msg_queueopenasync.header.error;
- goto error_put_destroy;
- }
-
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error);
- error_put_destroy:
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- error_destroy:
- saHandleDestroy (&queueHandleDatabase, queueHandle);
- error_put_msg:
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- error_exit:
- return (error);
- }
- SaAisErrorT
- saMsgQueueClose (
- SaMsgQueueHandleT queueHandle)
- {
- SaAisErrorT error;
- struct msgQueueInstance *msgQueueInstance;
- struct req_lib_msg_queueclose req_lib_msg_queueclose;
- struct res_lib_msg_queueclose res_lib_msg_queueclose;
- error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queueclose.header.size =
- sizeof (struct req_lib_msg_queueclose);
- req_lib_msg_queueclose.header.id =
- MESSAGE_REQ_MSG_QUEUECLOSE;
- memcpy (&req_lib_msg_queueclose.queueName, &msgQueueInstance->queueName,
- sizeof (SaNameT));
- pthread_mutex_lock (msgQueueInstance->response_mutex);
- error = saSendReceiveReply (msgQueueInstance->response_fd,
- &req_lib_msg_queueclose,
- sizeof (struct req_lib_msg_queueclose),
- &res_lib_msg_queueclose,
- sizeof (struct res_lib_msg_queueclose));
- pthread_mutex_unlock (msgQueueInstance->response_mutex);
- if (error == SA_AIS_OK) {
- error = res_lib_msg_queueclose.header.error;
- }
- if (error == SA_AIS_OK) {
- /* TODO */
- /* msgQueueInstanceFinalize (msgQueueInstance); */
- }
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- return (error);
- }
- SaAisErrorT
- saMsgQueueStatusGet (
- SaMsgHandleT msgHandle,
- const SaNameT *queueName,
- SaMsgQueueStatusT *queueStatus)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuestatusget req_lib_msg_queuestatusget;
- struct res_lib_msg_queuestatusget res_lib_msg_queuestatusget;
- if (queueName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueStatusGet { queueName = %s }\n",
- (char *) queueName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuestatusget.header.size =
- sizeof (struct req_lib_msg_queuestatusget);
- req_lib_msg_queuestatusget.header.id =
- MESSAGE_REQ_MSG_QUEUESTATUSGET;
- memcpy (&req_lib_msg_queuestatusget.queueName, queueName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuestatusget,
- sizeof (struct req_lib_msg_queuestatusget),
- &res_lib_msg_queuestatusget,
- sizeof (struct res_lib_msg_queuestatusget));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- if (error == SA_AIS_OK)
- error = res_lib_msg_queuestatusget.header.error;
- if (error == SA_AIS_OK) {
- memcpy (queueStatus, &res_lib_msg_queuestatusget.queueStatus,
- sizeof (SaMsgQueueStatusT));
- }
- return (error);
- }
- SaAisErrorT
- saMsgQueueRetentionTimeSet (
- SaMsgQueueHandleT queueHandle,
- SaTimeT *retentionTime)
- {
- SaAisErrorT error;
- struct msgQueueInstance *msgQueueInstance;
- error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- /* TODO */
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- return (error);
- }
- SaAisErrorT
- saMsgQueueUnlink (
- SaMsgHandleT msgHandle,
- const SaNameT *queueName)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queueunlink req_lib_msg_queueunlink;
- struct res_lib_msg_queueunlink res_lib_msg_queueunlink;
- if (queueName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueUnlink { queueName = %s }\n",
- (char *) queueName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queueunlink.header.size =
- sizeof (struct req_lib_msg_queueunlink);
- req_lib_msg_queueunlink.header.id =
- MESSAGE_REQ_MSG_QUEUEUNLINK;
- memcpy (&req_lib_msg_queueunlink.queueName, queueName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queueunlink,
- sizeof (struct req_lib_msg_queueunlink),
- &res_lib_msg_queueunlink,
- sizeof (struct res_lib_msg_queueunlink));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queueunlink.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupCreate (
- SaMsgHandleT msgHandle,
- const SaNameT *queueGroupName,
- SaMsgQueueGroupPolicyT queueGroupPolicy)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuegroupcreate req_lib_msg_queuegroupcreate;
- struct res_lib_msg_queuegroupcreate res_lib_msg_queuegroupcreate;
- if (queueGroupName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueGroupCreate { queueGroupName = %s }\n",
- (char *) queueGroupName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuegroupcreate.header.size =
- sizeof (struct req_lib_msg_queuegroupcreate);
- req_lib_msg_queuegroupcreate.header.id =
- MESSAGE_REQ_MSG_QUEUEGROUPCREATE;
- memcpy (&req_lib_msg_queuegroupcreate.queueGroupName, queueGroupName,
- sizeof (SaNameT));
- req_lib_msg_queuegroupcreate.queueGroupPolicy = queueGroupPolicy;
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuegroupcreate,
- sizeof (struct req_lib_msg_queuegroupcreate),
- &res_lib_msg_queuegroupcreate,
- sizeof (struct res_lib_msg_queuegroupcreate));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queuegroupcreate.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupInsert (
- SaMsgHandleT msgHandle,
- const SaNameT *queueGroupName,
- const SaNameT *queueName)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuegroupinsert req_lib_msg_queuegroupinsert;
- struct res_lib_msg_queuegroupinsert res_lib_msg_queuegroupinsert;
- if (queueName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueGroupInsert { queueGroupName = %s }\n",
- (char *) queueGroupName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuegroupinsert.header.size =
- sizeof (struct req_lib_msg_queuegroupinsert);
- req_lib_msg_queuegroupinsert.header.id =
- MESSAGE_REQ_MSG_QUEUEGROUPINSERT;
- memcpy (&req_lib_msg_queuegroupinsert.queueName, queueName,
- sizeof (SaNameT));
- memcpy (&req_lib_msg_queuegroupinsert.queueGroupName, queueGroupName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuegroupinsert,
- sizeof (struct req_lib_msg_queuegroupinsert),
- &res_lib_msg_queuegroupinsert,
- sizeof (struct res_lib_msg_queuegroupinsert));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queuegroupinsert.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupRemove (
- SaMsgHandleT msgHandle,
- const SaNameT *queueGroupName,
- const SaNameT *queueName)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuegroupremove req_lib_msg_queuegroupremove;
- struct res_lib_msg_queuegroupremove res_lib_msg_queuegroupremove;
- if (queueName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueGroupRemove { queueGroupName = %s }\n",
- (char *) queueGroupName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuegroupremove.header.size =
- sizeof (struct req_lib_msg_queuegroupremove);
- req_lib_msg_queuegroupremove.header.id =
- MESSAGE_REQ_MSG_QUEUEGROUPREMOVE;
- memcpy (&req_lib_msg_queuegroupremove.queueName, queueName,
- sizeof (SaNameT));
- memcpy (&req_lib_msg_queuegroupremove.queueGroupName, queueGroupName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuegroupremove,
- sizeof (struct req_lib_msg_queuegroupremove),
- &res_lib_msg_queuegroupremove,
- sizeof (struct res_lib_msg_queuegroupremove));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queuegroupremove.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupDelete (
- SaMsgHandleT msgHandle,
- const SaNameT *queueGroupName)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuegroupdelete req_lib_msg_queuegroupdelete;
- struct res_lib_msg_queuegroupdelete res_lib_msg_queuegroupdelete;
- if (queueGroupName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueGroupDelete { queueGroupName = %s }\n",
- (char *) queueGroupName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuegroupdelete.header.size =
- sizeof (struct req_lib_msg_queuegroupdelete);
- req_lib_msg_queuegroupdelete.header.id =
- MESSAGE_REQ_MSG_QUEUEGROUPDELETE;
- memcpy (&req_lib_msg_queuegroupdelete.queueGroupName, queueGroupName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuegroupdelete,
- sizeof (struct req_lib_msg_queuegroupdelete),
- &res_lib_msg_queuegroupdelete,
- sizeof (struct res_lib_msg_queuegroupdelete));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queuegroupdelete.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupTrack (
- SaMsgHandleT msgHandle,
- const SaNameT *queueGroupName,
- SaUint8T trackFlags,
- SaMsgQueueGroupNotificationBufferT *notificationBuffer)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuegrouptrack req_lib_msg_queuegrouptrack;
- struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack;
- if (queueGroupName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueGroupTrack { queueGroupName = %s }\n",
- (char *) queueGroupName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuegrouptrack.header.size =
- sizeof (struct req_lib_msg_queuegrouptrack);
- req_lib_msg_queuegrouptrack.header.id =
- MESSAGE_REQ_MSG_QUEUEGROUPTRACK;
- req_lib_msg_queuegrouptrack.trackFlags = trackFlags;
- memcpy (&req_lib_msg_queuegrouptrack.queueGroupName, queueGroupName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuegrouptrack,
- sizeof (struct req_lib_msg_queuegrouptrack),
- &res_lib_msg_queuegrouptrack,
- sizeof (struct res_lib_msg_queuegrouptrack));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrack.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupTrackStop (
- SaMsgHandleT msgHandle,
- const SaNameT *queueGroupName)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_queuegrouptrackstop req_lib_msg_queuegrouptrackstop;
- struct res_lib_msg_queuegrouptrackstop res_lib_msg_queuegrouptrackstop;
- if (queueGroupName == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueGroupTrackStop { queueGroupName = %s }\n",
- (char *) queueGroupName->value);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_queuegrouptrackstop.header.size =
- sizeof (struct req_lib_msg_queuegrouptrackstop);
- req_lib_msg_queuegrouptrackstop.header.id =
- MESSAGE_REQ_MSG_QUEUEGROUPTRACKSTOP;
- memcpy (&req_lib_msg_queuegrouptrackstop.queueGroupName, queueGroupName,
- sizeof (SaNameT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_queuegrouptrackstop,
- sizeof (struct req_lib_msg_queuegrouptrackstop),
- &res_lib_msg_queuegrouptrackstop,
- sizeof (struct res_lib_msg_queuegrouptrackstop));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrackstop.header.error : error);
- }
- SaAisErrorT
- saMsgQueueGroupNotificationFree (
- SaMsgHandleT msgHandle,
- SaMsgQueueGroupNotificationT *notification)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- /* TODO */
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error);
- }
- SaAisErrorT
- saMsgMessageSend (
- SaMsgHandleT msgHandle,
- const SaNameT *destination,
- const SaMsgMessageT *message,
- SaTimeT timeout)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_messagesend req_lib_msg_messagesend;
- struct res_lib_msg_messagesend res_lib_msg_messagesend;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageSend { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messagesend.header.size =
- sizeof (struct req_lib_msg_messagesend) + message->size;
- req_lib_msg_messagesend.header.id =
- MESSAGE_REQ_MSG_MESSAGESEND;
- memcpy (&req_lib_msg_messagesend.destination, destination,
- sizeof (SaNameT));
- memcpy (&req_lib_msg_messagesend.message, message,
- sizeof (SaMsgMessageT));
- req_lib_msg_messagesend.invocation = 0;
- req_lib_msg_messagesend.ackFlags = 0;
- req_lib_msg_messagesend.async_call = 0;
- req_lib_msg_messagesend.timeout = timeout;
- pthread_mutex_lock (&msgInstance->response_mutex);
- /*
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_messagesend,
- sizeof (struct req_lib_msg_messagesend),
- &res_lib_msg_messagesend,
- sizeof (struct res_lib_msg_messagesend));
- */
- error = saSendRetry (msgInstance->response_fd, &req_lib_msg_messagesend,
- sizeof (struct req_lib_msg_messagesend));
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- error = saSendRetry (msgInstance->response_fd,
- message->data, message->size);
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_messagesend,
- sizeof (struct res_lib_msg_messagesend));
- error_exit:
- pthread_mutex_unlock (&msgInstance->response_mutex);
- error_put_msg:
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_messagesend.header.error : error);
- }
- SaAisErrorT
- saMsgMessageSendAsync (
- SaMsgHandleT msgHandle,
- SaInvocationT invocation,
- const SaNameT *destination,
- const SaMsgMessageT *message,
- SaMsgAckFlagsT ackFlags)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_messagesend req_lib_msg_messagesend;
- struct res_lib_msg_messagesendasync res_lib_msg_messagesendasync;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageSendAsync { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messagesend.header.size =
- sizeof (struct req_lib_msg_messagesend) + message->size;
- req_lib_msg_messagesend.header.id =
- MESSAGE_REQ_MSG_MESSAGESENDASYNC;
- memcpy (&req_lib_msg_messagesend.destination, destination,
- sizeof (SaNameT));
- memcpy (&req_lib_msg_messagesend.message, message,
- sizeof (SaMsgMessageT));
- req_lib_msg_messagesend.invocation = invocation;
- req_lib_msg_messagesend.ackFlags = ackFlags;
- req_lib_msg_messagesend.async_call = 1;
- req_lib_msg_messagesend.timeout = 0;
- pthread_mutex_lock (&msgInstance->response_mutex);
- /*
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_messagesend,
- sizeof (struct req_lib_msg_messagesend),
- &res_lib_msg_messagesendasync,
- sizeof (struct res_lib_msg_messagesendasync));
- */
- error = saSendRetry (msgInstance->response_fd, &req_lib_msg_messagesend,
- sizeof (struct req_lib_msg_messagesend));
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- error = saSendRetry (msgInstance->response_fd,
- message->data, message->size);
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_messagesendasync,
- sizeof (struct res_lib_msg_messagesendasync));
- error_exit:
- pthread_mutex_unlock (&msgInstance->response_mutex);
- error_put_msg:
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_messagesendasync.header.error : error);
- }
- SaAisErrorT
- saMsgMessageGet (
- SaMsgQueueHandleT queueHandle,
- SaMsgMessageT *message,
- SaTimeT *sendTime,
- SaMsgSenderIdT *senderId,
- SaTimeT timeout)
- {
- SaAisErrorT error;
- struct msgQueueInstance *msgQueueInstance;
- struct req_lib_msg_messageget req_lib_msg_messageget;
- struct res_lib_msg_messageget res_lib_msg_messageget;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageGet { queueHandle = %llx }\n",
- (unsigned long long) queueHandle);
- error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messageget.header.size =
- sizeof (struct req_lib_msg_messageget);
- req_lib_msg_messageget.header.id =
- MESSAGE_REQ_MSG_MESSAGEGET;
- memcpy (&req_lib_msg_messageget.queueName, &msgQueueInstance->queueName,
- sizeof (SaNameT));
- req_lib_msg_messageget.timeout = timeout;
- pthread_mutex_lock (msgQueueInstance->response_mutex);
- /*
- error = saSendReceiveReply (msgQueueInstance->response_fd,
- &req_lib_msg_messageget,
- sizeof (struct req_lib_msg_messageget),
- &res_lib_msg_messageget,
- sizeof (struct res_lib_msg_messageget));
- */
- error = saSendRetry (msgQueueInstance->response_fd, &req_lib_msg_messageget,
- sizeof (struct req_lib_msg_messageget));
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- error = saRecvRetry (msgQueueInstance->response_fd, &res_lib_msg_messageget,
- sizeof (struct res_lib_msg_messageget));
- if (error != SA_AIS_OK) {
- goto error_exit;
- }
- if (message->data == NULL) {
- message->size = res_lib_msg_messageget.message.size;
- message->data = malloc (message->size);
- if (message->data == NULL) {
- error = SA_AIS_ERR_NO_MEMORY;
- goto error_exit;
- }
- } else {
- if (res_lib_msg_messageget.message.size > message->size) {
- error = SA_AIS_ERR_NO_SPACE;
- goto error_exit;
- }
- }
- error = saRecvRetry (msgQueueInstance->response_fd,
- message->data, message->size);
- error_exit:
- pthread_mutex_unlock (msgQueueInstance->response_mutex);
- error_put_msg:
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- if (error == SA_AIS_OK)
- error = res_lib_msg_messageget.header.error;
- if (error == SA_AIS_OK) {
- *sendTime = res_lib_msg_messageget.sendTime;
- memcpy (senderId, &res_lib_msg_messageget.senderId,
- sizeof (SaMsgSenderIdT));
- }
- return (error);
- }
- SaAisErrorT
- saMsgMessageDataFree (
- SaMsgHandleT msgHandle,
- void *data)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- if (data == NULL) {
- return (SA_AIS_ERR_INVALID_PARAM);
- }
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageDataFree { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- free (data);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error);
- }
- SaAisErrorT
- saMsgMessageCancel (
- SaMsgQueueHandleT queueHandle)
- {
- SaAisErrorT error;
- struct msgQueueInstance *msgQueueInstance;
- struct req_lib_msg_messagecancel req_lib_msg_messagecancel;
- struct res_lib_msg_messagecancel res_lib_msg_messagecancel;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageCancel { queueHandle = %llx }\n",
- (unsigned long long) queueHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messagecancel.header.size =
- sizeof (struct req_lib_msg_messagecancel);
- req_lib_msg_messagecancel.header.id =
- MESSAGE_REQ_MSG_MESSAGECANCEL;
- pthread_mutex_lock (msgQueueInstance->response_mutex);
- error = saSendReceiveReply (msgQueueInstance->response_fd,
- &req_lib_msg_messagecancel,
- sizeof (struct req_lib_msg_messagecancel),
- &res_lib_msg_messagecancel,
- sizeof (struct res_lib_msg_messagecancel));
- pthread_mutex_unlock (msgQueueInstance->response_mutex);
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- return (error == SA_AIS_OK ? res_lib_msg_messagecancel.header.error : error);
- }
- SaAisErrorT
- saMsgMessageSendReceive (
- SaMsgHandleT msgHandle,
- const SaNameT *destination,
- const SaMsgMessageT *sendMessage,
- SaMsgMessageT *receiveMessage,
- SaTimeT *replySendTime,
- SaTimeT timeout)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_messagesendreceive req_lib_msg_messagesendreceive;
- struct res_lib_msg_messagesendreceive res_lib_msg_messagesendreceive;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageSendReceive { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messagesendreceive.header.size =
- sizeof (struct req_lib_msg_messagesendreceive);
- req_lib_msg_messagesendreceive.header.id =
- MESSAGE_REQ_MSG_MESSAGEREPLY;
- memcpy (&req_lib_msg_messagesendreceive.destination, destination,
- sizeof (SaNameT));
- req_lib_msg_messagesendreceive.timeout = timeout;
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_messagesendreceive,
- sizeof (struct req_lib_msg_messagesendreceive),
- &res_lib_msg_messagesendreceive,
- sizeof (struct res_lib_msg_messagesendreceive));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
-
- if (error == SA_AIS_OK)
- error = res_lib_msg_messagesendreceive.header.error;
- if (error == SA_AIS_OK) {
- *replySendTime = res_lib_msg_messagesendreceive.replySendTime;
- }
- return (error);
- }
- SaAisErrorT
- saMsgMessageReply (
- SaMsgHandleT msgHandle,
- const SaMsgMessageT *replyMessage,
- const SaMsgSenderIdT *senderId,
- SaTimeT timeout)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_messagereply req_lib_msg_messagereply;
- struct res_lib_msg_messagereply res_lib_msg_messagereply;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageReply { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messagereply.header.size =
- sizeof (struct req_lib_msg_messagereply);
- req_lib_msg_messagereply.header.id =
- MESSAGE_REQ_MSG_MESSAGEREPLY;
- memcpy (&req_lib_msg_messagereply.senderId, senderId,
- sizeof (SaMsgSenderIdT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_messagereply,
- sizeof (struct req_lib_msg_messagereply),
- &res_lib_msg_messagereply,
- sizeof (struct res_lib_msg_messagereply));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
-
- return (error == SA_AIS_OK ? res_lib_msg_messagereply.header.error : error);
- }
- SaAisErrorT
- saMsgMessageReplyAsync (
- SaMsgHandleT msgHandle,
- SaInvocationT invocation,
- const SaMsgMessageT *replyMessage,
- const SaMsgSenderIdT *senderId,
- SaMsgAckFlagsT ackFlags)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- struct req_lib_msg_messagereply req_lib_msg_messagereply;
- struct res_lib_msg_messagereplyasync res_lib_msg_messagereplyasync;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMessageReplyAsync { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- req_lib_msg_messagereply.header.size =
- sizeof (struct req_lib_msg_messagereply);
- req_lib_msg_messagereply.header.id =
- MESSAGE_REQ_MSG_MESSAGEREPLY;
- memcpy (&req_lib_msg_messagereply.senderId, senderId,
- sizeof (SaMsgSenderIdT));
- pthread_mutex_lock (&msgInstance->response_mutex);
- error = saSendReceiveReply (msgInstance->response_fd,
- &req_lib_msg_messagereply,
- sizeof (struct req_lib_msg_messagereply),
- &res_lib_msg_messagereplyasync,
- sizeof (struct res_lib_msg_messagereplyasync));
- pthread_mutex_unlock (&msgInstance->response_mutex);
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error == SA_AIS_OK ? res_lib_msg_messagereplyasync.header.error : error);
- }
- SaAisErrorT
- saMsgQueueCapacityThresholdSet (
- SaMsgQueueHandleT queueHandle,
- const SaMsgQueueThresholdsT *thresholds)
- {
- SaAisErrorT error;
- struct msgQueueInstance *msgQueueInstance;
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueCapacityThresholdsSet { queueHandle = %llx }\n",
- (unsigned long long) queueHandle);
- error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- /* TODO */
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- return (error);
- }
- SaAisErrorT
- saMsgQueueCapacityThresholdGet (
- SaMsgQueueHandleT queueHandle,
- SaMsgQueueThresholdsT *thresholds)
- {
- SaAisErrorT error;
- struct msgQueueInstance *msgQueueInstance;
- /* DEBUG */
- printf ("[DEBUG]: saMsgQueueCapacityThresholdGet { queueHandle = %llx }\n",
- (unsigned long long) queueHandle);
- error = saHandleInstanceGet (&queueHandleDatabase, queueHandle,
- (void *)&msgQueueInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- /* TODO */
- saHandleInstancePut (&queueHandleDatabase, queueHandle);
- return (error);
- }
- SaAisErrorT
- saMsgMetadataSizeGet (
- SaMsgHandleT msgHandle,
- SaUint32T *metadataSize)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- /* DEBUG */
- printf ("[DEBUG]: saMsgMetadataSizeGet { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- /* TODO */
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error);
- }
- SaAisErrorT
- saMsgLimitGet (
- SaMsgHandleT msgHandle,
- SaMsgLimitIdT limitId,
- SaLimitValueT *limitValue)
- {
- SaAisErrorT error;
- struct msgInstance *msgInstance;
- /* DEBUG */
- printf ("[DEBUG]: saMsgLimitGet { msgHandle = %llx }\n",
- (unsigned long long) msgHandle);
- error = saHandleInstanceGet (&msgHandleDatabase, msgHandle,
- (void *)&msgInstance);
- if (error != SA_AIS_OK) {
- return (error);
- }
- /* TODO */
- saHandleInstancePut (&msgHandleDatabase, msgHandle);
- return (error);
- }
|