evt.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. /*
  2. * Copyright (c) 2004-2005 Mark Haverkamp
  3. * Copyright (c) 2004-2005 Open Source Development Lab
  4. *
  5. * All rights reserved.
  6. *
  7. * This software licensed under BSD license, the text of which follows:
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * - Neither the name of the Open Source Developement Lab nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  31. * THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <sys/types.h>
  34. #include <errno.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <unistd.h>
  39. #include <sys/time.h>
  40. #include <sys/socket.h>
  41. #include "../include/ipc_evt.h"
  42. #include "util.h"
  43. #include "../exec/totempg.h"
  44. static void evtHandleInstanceDestructor(void *instance);
  45. static void chanHandleInstanceDestructor(void *instance);
  46. static void eventHandleInstanceDestructor(void *instance);
  47. /*
  48. * Versions of the SAF AIS specification supported by this library
  49. */
  50. static SaVersionT supported_versions[] = {
  51. {'B', 0x01, 0x01},
  52. {'b', 0x01, 0x01}
  53. };
  54. static struct saVersionDatabase evt_version_database = {
  55. sizeof(supported_versions) / sizeof(SaVersionT),
  56. supported_versions
  57. };
  58. /*
  59. * Event instance data
  60. */
  61. struct saHandleDatabase evt_instance_handle_db = {
  62. .handleCount = 0,
  63. .handles = 0,
  64. .mutex = PTHREAD_MUTEX_INITIALIZER,
  65. .handleInstanceDestructor = evtHandleInstanceDestructor
  66. };
  67. /*
  68. * Channel instance data
  69. */
  70. struct saHandleDatabase channel_handle_db = {
  71. .handleCount = 0,
  72. .handles = 0,
  73. .mutex = PTHREAD_MUTEX_INITIALIZER,
  74. .handleInstanceDestructor = chanHandleInstanceDestructor
  75. };
  76. /*
  77. * Event instance data
  78. */
  79. struct saHandleDatabase event_handle_db = {
  80. .handleCount = 0,
  81. .handles = 0,
  82. .mutex = PTHREAD_MUTEX_INITIALIZER,
  83. .handleInstanceDestructor = eventHandleInstanceDestructor
  84. };
  85. struct message_overlay {
  86. struct res_header header;
  87. char data[0];
  88. };
  89. /*
  90. * data required to support events for a given initialization
  91. *
  92. * ei_fd: fd received from the evtInitialize call.
  93. * ei_callback: callback function.
  94. * ei_version: version sent to the evtInitialize call.
  95. * ei_node_id: our node id.
  96. * ei_node_name: our node name.
  97. * ei_finalize: instance in finalize flag
  98. * ei_queue: queue for async messages while doing sync commands
  99. * ei_mutex: instance mutex
  100. *
  101. */
  102. struct event_instance {
  103. int ei_fd;
  104. SaEvtCallbacksT ei_callback;
  105. SaVersionT ei_version;
  106. SaClmNodeIdT ei_node_id;
  107. SaNameT ei_node_name;
  108. int ei_finalize;
  109. struct queue ei_inq;
  110. char ei_message[MESSAGE_SIZE_MAX];
  111. pthread_mutex_t ei_mutex;
  112. };
  113. /*
  114. * Data associated with an opened channel
  115. *
  116. * eci_channel_name: name of channel
  117. * eci_open_flags: channel open flags
  118. * eci_svr_channel_handle: channel handle returned from server
  119. * eci_closing: channel in process of being closed
  120. * eci_mutex: channel mutex
  121. *
  122. */
  123. struct event_channel_instance {
  124. SaNameT eci_channel_name;
  125. SaEvtChannelOpenFlagsT eci_open_flags;
  126. uint32_t eci_svr_channel_handle;
  127. SaEvtHandleT eci_instance_handle;
  128. int eci_closing;
  129. pthread_mutex_t eci_mutex;
  130. };
  131. /*
  132. * Event data.
  133. *
  134. * Store event data from saEvtEventAllocate function.
  135. * Store event data from received events.
  136. *
  137. * edi_channel_handle: handle (local) of assocated channel
  138. * edi_patterns: event patterns
  139. * edi_priority: event priority
  140. * edi_retention_time: event's retention time
  141. * edi_pub_name: event's publisher name
  142. * edi_pub_node: event's publisher node
  143. * edi_pub_time: event's publish time
  144. * edi_event_id: event's Id
  145. * edi_event_data: event's data
  146. * edi_event_data_size: size of edi_event_data
  147. * edi_freeing: event is being freed
  148. * edi_mutex: event data mutex
  149. *
  150. */
  151. struct event_data_instance {
  152. SaEvtChannelHandleT edi_channel_handle;
  153. SaEvtEventPatternArrayT edi_patterns;
  154. SaUint8T edi_priority;
  155. SaTimeT edi_retention_time;
  156. SaNameT edi_pub_name;
  157. SaClmNodeIdT edi_pub_node;
  158. SaTimeT edi_pub_time;
  159. SaEvtEventIdT edi_event_id;
  160. void *edi_event_data;
  161. SaSizeT edi_event_data_size;
  162. int edi_freeing;
  163. pthread_mutex_t edi_mutex;
  164. };
  165. #define min(a,b) ((a) < (b) ? (a) : (b))
  166. /*
  167. * Clean up function for an evt instance (saEvtInitialize) handle
  168. */
  169. static void evtHandleInstanceDestructor(void *instance)
  170. {
  171. struct event_instance *evti = instance;
  172. void **msg;
  173. int empty;
  174. /*
  175. * Empty out the queue if there are any pending messages
  176. */
  177. while ((saQueueIsEmpty(&evti->ei_inq, &empty) == SA_AIS_OK) && !empty) {
  178. saQueueItemGet(&evti->ei_inq, (void *)&msg);
  179. saQueueItemRemove(&evti->ei_inq);
  180. free(*msg);
  181. }
  182. /*
  183. * clean up the queue itself
  184. */
  185. if (evti->ei_inq.items) {
  186. free(evti->ei_inq.items);
  187. }
  188. /*
  189. * Disconnect from the server
  190. */
  191. if (evti->ei_fd != -1) {
  192. shutdown(evti->ei_fd, 0);
  193. close(evti->ei_fd);
  194. }
  195. }
  196. /*
  197. * Clean up function for an open channel handle
  198. */
  199. static void chanHandleInstanceDestructor(void *instance)
  200. {
  201. }
  202. /*
  203. * Clean up function for an event handle
  204. */
  205. static void eventHandleInstanceDestructor(void *instance)
  206. {
  207. struct event_data_instance *edi = instance;
  208. int i;
  209. for (i = 0; i < edi->edi_patterns.patternsNumber; i++) {
  210. free(edi->edi_patterns.patterns[i].pattern);
  211. }
  212. if (edi->edi_patterns.patterns) {
  213. free(edi->edi_patterns.patterns);
  214. }
  215. if (edi->edi_event_data) {
  216. free(edi->edi_event_data);
  217. }
  218. }
  219. /*
  220. * The saEvtInitialize() function initializes the Event Service for the
  221. * invoking process. A user of the Event Service must invoke this function
  222. * before it invokes any other function of the Event Service API. Each
  223. * initialization returns a different callback handle that the process
  224. * can use to communicate with that library instance.
  225. */
  226. SaAisErrorT
  227. saEvtInitialize(
  228. SaEvtHandleT *evtHandle,
  229. const SaEvtCallbacksT *callbacks,
  230. SaVersionT *version)
  231. {
  232. SaAisErrorT error = SA_AIS_OK;
  233. struct event_instance *evti;
  234. /*
  235. * validate the requested version with what we support
  236. */
  237. error = saVersionVerify(&evt_version_database, version);
  238. if (error != SA_AIS_OK) {
  239. goto error_nofree;
  240. }
  241. /*
  242. * Allocate instance data, allocate unique handle for instance,
  243. * assign instance data to unique handle
  244. */
  245. error = saHandleCreate(&evt_instance_handle_db, sizeof(*evti),
  246. (void*)evtHandle);
  247. if (error != SA_AIS_OK) {
  248. goto error_nofree;
  249. }
  250. error = saHandleInstanceGet(&evt_instance_handle_db, *evtHandle,
  251. (void*)&evti);
  252. if (error != SA_AIS_OK) {
  253. goto error_handle_free;
  254. }
  255. memset(evti, 0, sizeof(*evti));
  256. /*
  257. * Save the version so we can check with the event server
  258. * and see if it supports this version.
  259. */
  260. evti->ei_version = *version;
  261. /*
  262. * An inq is needed to store async messages while waiting for a
  263. * sync response
  264. */
  265. error = saQueueInit(&evti->ei_inq, 1024, sizeof(void *));
  266. if (error != SA_AIS_OK) {
  267. goto error_handle_put;
  268. }
  269. /*
  270. * Set up communication with the event server
  271. */
  272. error = saServiceConnect(&evti->ei_fd, MESSAGE_REQ_EVT_INIT);
  273. if (error != SA_AIS_OK) {
  274. goto error_handle_put;
  275. }
  276. /*
  277. * The callback function is saved in the event instance for
  278. * saEvtDispatch() to use.
  279. */
  280. if (callbacks) {
  281. memcpy(&evti->ei_callback, callbacks,
  282. sizeof(evti->ei_callback));
  283. }
  284. pthread_mutex_init(&evti->ei_mutex, NULL);
  285. saHandleInstancePut(&evt_instance_handle_db, *evtHandle);
  286. return SA_AIS_OK;
  287. error_handle_put:
  288. saHandleInstancePut(&evt_instance_handle_db, *evtHandle);
  289. error_handle_free:
  290. (void)saHandleDestroy(&evt_instance_handle_db, *evtHandle);
  291. error_nofree:
  292. return error;
  293. }
  294. /*
  295. * The saEvtSelectionObjectGet() function returns the operating system
  296. * handle selectionObject, associated with the handle evtHandle, allowing
  297. * the invoking process to ascertain when callbacks are pending. This
  298. * function allows a process to avoid repeated invoking saEvtDispatch() to
  299. * see if there is a new event, thus, needlessly consuming CPU time. In a
  300. * POSIX environment the system handle could be a file descriptor that is
  301. * used with the poll() or select() system calls to detect incoming callbacks.
  302. */
  303. SaAisErrorT
  304. saEvtSelectionObjectGet(
  305. SaEvtHandleT evtHandle,
  306. SaSelectionObjectT *selectionObject)
  307. {
  308. struct event_instance *evti;
  309. SaAisErrorT error;
  310. error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
  311. (void *)&evti);
  312. if (error != SA_AIS_OK) {
  313. return error;
  314. }
  315. *selectionObject = evti->ei_fd;
  316. saHandleInstancePut(&evt_instance_handle_db, evtHandle);
  317. return SA_AIS_OK;
  318. }
  319. /*
  320. * Alocate an event data structure and associated handle to be
  321. * used to supply event data to a call back function.
  322. */
  323. static SaAisErrorT make_event(SaEvtEventHandleT *event_handle,
  324. struct lib_event_data *evt)
  325. {
  326. struct event_data_instance *edi;
  327. SaEvtEventPatternT *pat;
  328. SaUint8T *str;
  329. SaAisErrorT error;
  330. int i;
  331. error = saHandleCreate(&event_handle_db, sizeof(*edi),
  332. (void*)event_handle);
  333. if (error != SA_AIS_OK) {
  334. goto make_evt_done;
  335. }
  336. error = saHandleInstanceGet(&event_handle_db, *event_handle,
  337. (void*)&edi);
  338. if (error != SA_AIS_OK) {
  339. goto make_evt_done;
  340. }
  341. memset(edi, 0, sizeof(*edi));
  342. pthread_mutex_init(&edi->edi_mutex, NULL);
  343. edi->edi_freeing = 0;
  344. edi->edi_channel_handle = evt->led_lib_channel_handle;
  345. edi->edi_priority = evt->led_priority;
  346. edi->edi_retention_time = evt->led_retention_time;
  347. edi->edi_pub_node = evt->led_publisher_node_id;
  348. edi->edi_pub_time = evt->led_publish_time;
  349. edi->edi_event_data_size = evt->led_user_data_size;
  350. edi->edi_event_id = evt->led_event_id;
  351. edi->edi_pub_name = evt->led_publisher_name;
  352. if (edi->edi_event_data_size) {
  353. edi->edi_event_data = malloc(edi->edi_event_data_size);
  354. memcpy(edi->edi_event_data,
  355. evt->led_body + evt->led_user_data_offset,
  356. edi->edi_event_data_size);
  357. }
  358. /*
  359. * Move the pattern bits into the SaEvtEventPatternArrayT
  360. */
  361. edi->edi_patterns.patternsNumber = evt->led_patterns_number;
  362. edi->edi_patterns.patterns = malloc(sizeof(SaEvtEventPatternT) *
  363. edi->edi_patterns.patternsNumber);
  364. pat = (SaEvtEventPatternT *)evt->led_body;
  365. str = evt->led_body + sizeof(SaEvtEventPatternT) *
  366. edi->edi_patterns.patternsNumber;
  367. for (i = 0; i < evt->led_patterns_number; i++) {
  368. edi->edi_patterns.patterns[i].patternSize = pat->patternSize;
  369. edi->edi_patterns.patterns[i].pattern = malloc(pat->patternSize);
  370. if (!edi->edi_patterns.patterns[i].pattern) {
  371. printf("make_event: couldn't alloc %d bytes\n", pat->patternSize);
  372. error = SA_AIS_ERR_NO_MEMORY;
  373. break;
  374. }
  375. memcpy(edi->edi_patterns.patterns[i].pattern,
  376. str, pat->patternSize);
  377. str += pat->patternSize;
  378. pat++;
  379. }
  380. saHandleInstancePut (&event_handle_db, *event_handle);
  381. make_evt_done:
  382. return error;
  383. }
  384. /*
  385. * The saEvtDispatch() function invokes, in the context of the calling
  386. * thread, one or all of the pending callbacks for the handle evtHandle.
  387. */
  388. SaAisErrorT
  389. saEvtDispatch(
  390. SaEvtHandleT evtHandle,
  391. SaDispatchFlagsT dispatchFlags)
  392. {
  393. struct pollfd ufds;
  394. int timeout = -1;
  395. SaAisErrorT error;
  396. int dispatch_avail;
  397. struct event_instance *evti;
  398. SaEvtEventHandleT event_handle;
  399. SaEvtCallbacksT callbacks;
  400. struct res_header **queue_msg;
  401. struct res_header *msg = 0;
  402. int empty;
  403. int ignore_dispatch = 0;
  404. int cont = 1; /* always continue do loop except when set to 0 */
  405. int poll_fd;
  406. struct message_overlay *dispatch_data;
  407. struct lib_event_data *evt;
  408. struct res_evt_event_data res;
  409. error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
  410. (void *)&evti);
  411. if (error != SA_AIS_OK) {
  412. return error;
  413. }
  414. /*
  415. * Timeout instantly for SA_DISPATCH_ALL
  416. */
  417. if (dispatchFlags == SA_DISPATCH_ALL) {
  418. timeout = 0;
  419. }
  420. do {
  421. poll_fd = evti->ei_fd;
  422. ufds.fd = poll_fd;
  423. ufds.events = POLLIN;
  424. ufds.revents = 0;
  425. pthread_mutex_lock(&evti->ei_mutex);
  426. saQueueIsEmpty(&evti->ei_inq, &empty);
  427. /*
  428. * Read from the socket if there is nothing in
  429. * our queue.
  430. */
  431. if (empty == 1) {
  432. pthread_mutex_unlock(&evti->ei_mutex);
  433. error = saPollRetry(&ufds, 1, timeout);
  434. if (error != SA_AIS_OK) {
  435. goto error_nounlock;
  436. }
  437. pthread_mutex_lock(&evti->ei_mutex);
  438. }
  439. /*
  440. * Handle has been finalized in another thread
  441. */
  442. if (evti->ei_finalize == 1) {
  443. error = SA_AIS_OK;
  444. pthread_mutex_unlock(&evti->ei_mutex);
  445. goto error_unlock;
  446. }
  447. dispatch_avail = (ufds.revents & POLLIN) | (empty == 0);
  448. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  449. pthread_mutex_unlock(&evti->ei_mutex);
  450. break; /* exit do while cont is 1 loop */
  451. } else
  452. if (dispatch_avail == 0) {
  453. pthread_mutex_unlock(&evti->ei_mutex);
  454. continue; /* next poll */
  455. }
  456. saQueueIsEmpty(&evti->ei_inq, &empty);
  457. if (empty == 0) {
  458. /*
  459. * Queue is not empty, read data from queue
  460. */
  461. saQueueItemGet(&evti->ei_inq, (void *)&queue_msg);
  462. msg = *queue_msg;
  463. dispatch_data = (struct message_overlay *)msg;
  464. saQueueItemRemove(&evti->ei_inq);
  465. } else {
  466. /*
  467. * Queue empty, read response from socket
  468. */
  469. dispatch_data = (struct message_overlay *)&evti->ei_message;
  470. error = saRecvRetry(evti->ei_fd, &dispatch_data->header,
  471. sizeof(struct res_header), MSG_WAITALL | MSG_NOSIGNAL);
  472. if (error != SA_AIS_OK) {
  473. pthread_mutex_unlock(&evti->ei_mutex);
  474. goto error_unlock;
  475. }
  476. if (dispatch_data->header.size > sizeof(struct res_header)) {
  477. error = saRecvRetry(evti->ei_fd, dispatch_data->data,
  478. dispatch_data->header.size - sizeof(struct res_header),
  479. MSG_WAITALL | MSG_NOSIGNAL);
  480. if (error != SA_AIS_OK) {
  481. pthread_mutex_unlock(&evti->ei_mutex);
  482. goto error_unlock;
  483. }
  484. }
  485. }
  486. /*
  487. * Make copy of callbacks, message data, unlock instance,
  488. * and call callback. A risk of this dispatch method is that
  489. * the callback routines may operate at the same time that
  490. * EvtFinalize has been called in another thread.
  491. */
  492. memcpy(&callbacks, &evti->ei_callback, sizeof(evti->ei_callback));
  493. pthread_mutex_unlock(&evti->ei_mutex);
  494. /*
  495. * Dispatch incoming response
  496. */
  497. switch (dispatch_data->header.id) {
  498. case MESSAGE_RES_LIB_ACTIVATEPOLL:
  499. /*
  500. * This is a do nothing message which the node
  501. * executive sends to activate the file evtHandle
  502. * in poll when the library has queued a message into
  503. * evti->ei_inq. The dispatch is ignored for the
  504. * following two cases:
  505. * 1) setting of timeout to zero for the
  506. * DISPATCH_ALL case
  507. * 2) expiration of the do loop for the
  508. * DISPATCH_ONE case
  509. */
  510. ignore_dispatch = 1;
  511. break;
  512. case MESSAGE_RES_EVT_AVAILABLE:
  513. /*
  514. * There are events available. Send a request for one and then
  515. * dispatch it.
  516. */
  517. evt = (struct lib_event_data *)&evti->ei_message;
  518. res.evd_head.id = MESSAGE_REQ_EVT_EVENT_DATA;
  519. res.evd_head.size = sizeof(res);
  520. error = saSendRetry(evti->ei_fd, &res, sizeof(res), MSG_NOSIGNAL);
  521. if (error != SA_AIS_OK) {
  522. printf("MESSAGE_RES_EVT_AVAILABLE: send failed: %d\n", error);
  523. break;
  524. }
  525. error = saRecvQueue(evti->ei_fd, evt, &evti->ei_inq,
  526. MESSAGE_RES_EVT_EVENT_DATA);
  527. if (error != SA_AIS_OK) {
  528. printf("MESSAGE_RES_EVT_AVAILABLE: receive failed: %d\n",
  529. error);
  530. break;
  531. }
  532. /*
  533. * No data available. This is OK.
  534. */
  535. if (evt->led_head.error == SA_AIS_ERR_NOT_EXIST) {
  536. // printf("MESSAGE_RES_EVT_AVAILABLE: No event data\n");
  537. error = SA_AIS_OK;
  538. break;
  539. }
  540. if (evt->led_head.error != SA_AIS_OK) {
  541. error = evt->led_head.error;
  542. printf("MESSAGE_RES_EVT_AVAILABLE: Error returned: %d\n",
  543. error);
  544. break;
  545. }
  546. error = make_event(&event_handle, evt);
  547. if (error != SA_AIS_OK) {
  548. break;
  549. }
  550. callbacks.saEvtEventDeliverCallback(evt->led_sub_id, event_handle,
  551. evt->led_user_data_size);
  552. break;
  553. case MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK:
  554. {
  555. struct res_evt_open_chan_async *resa =
  556. (struct res_evt_open_chan_async *)dispatch_data;
  557. struct event_channel_instance *eci;
  558. /*
  559. * Check for errors. If there are none, then
  560. * look up the local channel via the handle that we
  561. * got from the callback request. All we need to do
  562. * is place in the handle from the server side and then
  563. * we can call the callback.
  564. */
  565. error = resa->ica_head.error;
  566. if (error == SA_AIS_OK) {
  567. error = saHandleInstanceGet(&channel_handle_db,
  568. resa->ica_c_handle, (void*)&eci);
  569. if (error == SA_AIS_OK) {
  570. eci->eci_svr_channel_handle = resa->ica_channel_handle;
  571. saHandleInstancePut (&channel_handle_db,
  572. resa->ica_c_handle);
  573. }
  574. }
  575. callbacks.saEvtChannelOpenCallback(resa->ica_invocation,
  576. resa->ica_c_handle, error);
  577. }
  578. break;
  579. default:
  580. printf("Dispatch: Bad message type 0x%x\n",
  581. dispatch_data->header.id);
  582. error = SA_AIS_ERR_LIBRARY;
  583. goto error_nounlock;
  584. break;
  585. }
  586. /*
  587. * If empty is zero it means the we got the
  588. * message from the queue and we are responsible
  589. * for freeing it.
  590. */
  591. if (empty == 0) {
  592. free(msg);
  593. }
  594. /*
  595. * Determine if more messages should be processed
  596. */
  597. switch (dispatchFlags) {
  598. case SA_DISPATCH_ONE:
  599. if (ignore_dispatch) {
  600. ignore_dispatch = 0;
  601. } else {
  602. cont = 0;
  603. }
  604. break;
  605. case SA_DISPATCH_ALL:
  606. if (ignore_dispatch) {
  607. ignore_dispatch = 0;
  608. }
  609. break;
  610. case SA_DISPATCH_BLOCKING:
  611. break;
  612. }
  613. } while (cont);
  614. error_unlock:
  615. saHandleInstancePut(&evt_instance_handle_db, evtHandle);
  616. error_nounlock:
  617. return error;
  618. }
  619. /*
  620. * The saEvtFinalize() function closes the association, represented by the
  621. * evtHandle parameter, between the process and the Event Service. It may
  622. * free up resources.
  623. * This function cannot be invoked before the process has invoked the
  624. * corresponding saEvtInitialize() function for the Event Service. After
  625. * this function is invoked, the selection object is no longer valid.
  626. * Moreover, the Event Service is unavailable for further use unless it is
  627. * reinitialized using the saEvtInitialize() function.
  628. */
  629. SaAisErrorT
  630. saEvtFinalize(SaEvtHandleT evtHandle)
  631. {
  632. struct event_instance *evti;
  633. SaAisErrorT error;
  634. error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
  635. (void *)&evti);
  636. if (error != SA_AIS_OK) {
  637. return error;
  638. }
  639. pthread_mutex_lock(&evti->ei_mutex);
  640. /*
  641. * Another thread has already started finalizing
  642. */
  643. if (evti->ei_finalize) {
  644. pthread_mutex_unlock(&evti->ei_mutex);
  645. saHandleInstancePut(&evt_instance_handle_db, evtHandle);
  646. return SA_AIS_ERR_BAD_HANDLE;
  647. }
  648. evti->ei_finalize = 1;
  649. saActivatePoll(evti->ei_fd);
  650. pthread_mutex_unlock(&evti->ei_mutex);
  651. saHandleDestroy(&evt_instance_handle_db, evtHandle);
  652. saHandleInstancePut(&evt_instance_handle_db, evtHandle);
  653. return error;
  654. }
  655. /*
  656. * The saEvtChannelOpen() function creates a new event channel or open an
  657. * existing channel. The saEvtChannelOpen() function is a blocking operation
  658. * and returns a new event channel handle. An event channel may be opened
  659. * multiple times by the same or different processes for publishing, and
  660. * subscribing to, events. If a process opens an event channel multiple
  661. * times, it is possible to receive the same event multiple times. However,
  662. * a process shall never receive an event more than once on a particular
  663. * event channel handle. If a process opens a channel twice and an event is
  664. * matched on both open channels, the Event Service performs two
  665. * callbacks -- one for each opened channel.
  666. */
  667. SaAisErrorT
  668. saEvtChannelOpen(
  669. SaEvtHandleT evtHandle,
  670. const SaNameT *channelName,
  671. SaEvtChannelOpenFlagsT channelOpenFlags,
  672. SaTimeT timeout,
  673. SaEvtChannelHandleT *channelHandle)
  674. {
  675. struct event_instance *evti;
  676. struct req_evt_channel_open req;
  677. struct res_evt_channel_open res;
  678. struct event_channel_instance *eci;
  679. SaAisErrorT error;
  680. error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
  681. (void*)&evti);
  682. if (error != SA_AIS_OK) {
  683. goto chan_open_done;
  684. }
  685. /*
  686. * create a handle for this open channel
  687. */
  688. error = saHandleCreate(&channel_handle_db, sizeof(*eci),
  689. (void*)channelHandle);
  690. if (error != SA_AIS_OK) {
  691. goto chan_open_put;
  692. }
  693. error = saHandleInstanceGet(&channel_handle_db, *channelHandle,
  694. (void*)&eci);
  695. if (error != SA_AIS_OK) {
  696. saHandleDestroy(&channel_handle_db, *channelHandle);
  697. goto chan_open_put;
  698. }
  699. /*
  700. * Send the request to the server and wait for a response
  701. */
  702. req.ico_head.size = sizeof(req);
  703. req.ico_head.id = MESSAGE_REQ_EVT_OPEN_CHANNEL;
  704. req.ico_c_handle = *channelHandle;
  705. req.ico_timeout = timeout;
  706. req.ico_open_flag = channelOpenFlags;
  707. req.ico_channel_name = *channelName;
  708. pthread_mutex_lock(&evti->ei_mutex);
  709. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  710. if (error != SA_AIS_OK) {
  711. pthread_mutex_unlock (&evti->ei_mutex);
  712. goto chan_open_free;
  713. }
  714. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  715. MESSAGE_RES_EVT_OPEN_CHANNEL);
  716. pthread_mutex_unlock (&evti->ei_mutex);
  717. if (error != SA_AIS_OK) {
  718. goto chan_open_free;
  719. }
  720. error = res.ico_head.error;
  721. if (error != SA_AIS_OK) {
  722. goto chan_open_free;
  723. }
  724. eci->eci_svr_channel_handle = res.ico_channel_handle;
  725. eci->eci_channel_name = *channelName;
  726. eci->eci_open_flags = channelOpenFlags;
  727. eci->eci_instance_handle = evtHandle;
  728. eci->eci_closing = 0;
  729. pthread_mutex_init(&eci->eci_mutex, NULL);
  730. saHandleInstancePut (&evt_instance_handle_db, evtHandle);
  731. saHandleInstancePut (&channel_handle_db, *channelHandle);
  732. return SA_AIS_OK;
  733. chan_open_free:
  734. saHandleDestroy(&channel_handle_db, *channelHandle);
  735. saHandleInstancePut (&channel_handle_db, *channelHandle);
  736. chan_open_put:
  737. saHandleInstancePut (&evt_instance_handle_db, evtHandle);
  738. chan_open_done:
  739. return error;
  740. }
  741. /*
  742. * The saEvtChannelClose() function closes an event channel and frees
  743. * resources allocated for that event channel in the invoking process.
  744. */
  745. SaAisErrorT
  746. saEvtChannelClose(SaEvtChannelHandleT channelHandle)
  747. {
  748. SaAisErrorT error;
  749. struct event_instance *evti;
  750. struct event_channel_instance *eci;
  751. struct req_evt_channel_close req;
  752. struct res_evt_channel_close res;
  753. error = saHandleInstanceGet(&channel_handle_db, channelHandle,
  754. (void*)&eci);
  755. if (error != SA_AIS_OK) {
  756. goto chan_close_done;
  757. }
  758. /*
  759. * get the evt handle for the fd
  760. */
  761. error = saHandleInstanceGet(&evt_instance_handle_db,
  762. eci->eci_instance_handle, (void*)&evti);
  763. if (error != SA_AIS_OK) {
  764. goto chan_close_put1;
  765. }
  766. /*
  767. * Make sure that the channel isn't being closed elsewhere
  768. */
  769. pthread_mutex_lock(&eci->eci_mutex);
  770. if (eci->eci_closing) {
  771. pthread_mutex_unlock(&eci->eci_mutex);
  772. saHandleInstancePut(&channel_handle_db, channelHandle);
  773. return SA_AIS_ERR_BAD_HANDLE;
  774. }
  775. eci->eci_closing = 1;
  776. saActivatePoll(evti->ei_fd);
  777. pthread_mutex_unlock(&eci->eci_mutex);
  778. /*
  779. * Send the request to the server and wait for a response
  780. */
  781. req.icc_head.size = sizeof(req);
  782. req.icc_head.id = MESSAGE_REQ_EVT_CLOSE_CHANNEL;
  783. req.icc_channel_handle = eci->eci_svr_channel_handle;
  784. pthread_mutex_lock(&evti->ei_mutex);
  785. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  786. if (error != SA_AIS_OK) {
  787. pthread_mutex_unlock(&evti->ei_mutex);
  788. eci->eci_closing = 0;
  789. goto chan_close_put2;
  790. }
  791. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  792. MESSAGE_RES_EVT_CLOSE_CHANNEL);
  793. pthread_mutex_unlock(&evti->ei_mutex);
  794. if (error != SA_AIS_OK) {
  795. eci->eci_closing = 0;
  796. goto chan_close_put2;
  797. }
  798. error = res.icc_head.error;
  799. saHandleInstancePut(&evt_instance_handle_db,
  800. eci->eci_instance_handle);
  801. saHandleDestroy(&channel_handle_db, channelHandle);
  802. saHandleInstancePut(&channel_handle_db, channelHandle);
  803. return error;
  804. chan_close_put2:
  805. saHandleInstancePut(&evt_instance_handle_db,
  806. eci->eci_instance_handle);
  807. chan_close_put1:
  808. saHandleInstancePut(&channel_handle_db, channelHandle);
  809. chan_close_done:
  810. return error;
  811. }
  812. /*
  813. * The saEvtChannelOpenAsync() function creates a new event channel or open an
  814. * existing channel. The saEvtChannelOpenAsync() function is a non-blocking
  815. * operation. A new event channel handle is returned in the channel open
  816. * callback function (SaEvtChannelOpenCallbackT).
  817. */
  818. SaAisErrorT
  819. saEvtChannelOpenAsync(SaEvtHandleT evtHandle,
  820. SaInvocationT invocation,
  821. const SaNameT *channelName,
  822. SaEvtChannelOpenFlagsT channelOpenFlags)
  823. {
  824. struct event_instance *evti;
  825. struct req_evt_channel_open req;
  826. struct res_evt_channel_open res;
  827. struct event_channel_instance *eci;
  828. SaEvtChannelHandleT channel_handle;
  829. SaAisErrorT error;
  830. error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
  831. (void*)&evti);
  832. if (error != SA_AIS_OK) {
  833. goto chan_open_done;
  834. }
  835. /*
  836. * create a handle for this open channel
  837. */
  838. error = saHandleCreate(&channel_handle_db, sizeof(*eci),
  839. &channel_handle);
  840. if (error != SA_AIS_OK) {
  841. goto chan_open_put;
  842. }
  843. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  844. (void*)&eci);
  845. if (error != SA_AIS_OK) {
  846. saHandleDestroy(&channel_handle_db, channel_handle);
  847. goto chan_open_put;
  848. }
  849. /*
  850. * Send the request to the server. The response isn't the open channel,
  851. * just an ack. The open channel will be returned when the channel open
  852. * callback is called.
  853. */
  854. req.ico_head.size = sizeof(req);
  855. req.ico_head.id = MESSAGE_REQ_EVT_OPEN_CHANNEL_ASYNC;
  856. req.ico_c_handle = channel_handle;
  857. req.ico_timeout = 0;
  858. req.ico_invocation = invocation;
  859. req.ico_open_flag = channelOpenFlags;
  860. req.ico_channel_name = *channelName;
  861. pthread_mutex_lock(&evti->ei_mutex);
  862. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  863. if (error != SA_AIS_OK) {
  864. pthread_mutex_unlock (&evti->ei_mutex);
  865. goto chan_open_free;
  866. }
  867. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  868. MESSAGE_RES_EVT_OPEN_CHANNEL);
  869. pthread_mutex_unlock (&evti->ei_mutex);
  870. if (error != SA_AIS_OK) {
  871. goto chan_open_free;
  872. }
  873. error = res.ico_head.error;
  874. if (error != SA_AIS_OK) {
  875. goto chan_open_free;
  876. }
  877. eci->eci_svr_channel_handle = 0; /* filled in by callback */
  878. eci->eci_channel_name = *channelName;
  879. eci->eci_open_flags = channelOpenFlags;
  880. eci->eci_instance_handle = evtHandle;
  881. eci->eci_closing = 0;
  882. pthread_mutex_init(&eci->eci_mutex, NULL);
  883. saHandleInstancePut (&evt_instance_handle_db, evtHandle);
  884. saHandleInstancePut (&channel_handle_db, channel_handle);
  885. return SA_AIS_OK;
  886. chan_open_free:
  887. saHandleDestroy(&channel_handle_db, channel_handle);
  888. saHandleInstancePut (&channel_handle_db, channel_handle);
  889. chan_open_put:
  890. saHandleInstancePut (&evt_instance_handle_db, evtHandle);
  891. chan_open_done:
  892. return error;
  893. }
  894. /*
  895. * The SaEvtChannelUnlink function deletes an existing event channel
  896. * from the cluster.
  897. *
  898. * After completion of the invocation:
  899. * - An open of the channel name without a create will fail.
  900. * - The channel remains available to any already opened instances.
  901. * - If an open/create is performed on this channel name a new instance
  902. * is created.
  903. * - The ulinked channel's resources will be deleted when the last open
  904. * instance is closed.
  905. *
  906. * Note that an event channel is only deleted from the cluster
  907. * namespace when saEvtChannelUnlink() is invoked on it. The deletion
  908. * of an event channel frees all resources allocated by the Event
  909. * Service for it, such as published events with non-zero retention
  910. * time.
  911. */
  912. SaAisErrorT
  913. saEvtChannelUnlink(
  914. SaEvtHandleT evtHandle,
  915. const SaNameT *channelName)
  916. {
  917. struct event_instance *evti;
  918. struct req_evt_channel_unlink req;
  919. struct res_evt_channel_unlink res;
  920. SaAisErrorT error;
  921. error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
  922. (void*)&evti);
  923. if (error != SA_AIS_OK) {
  924. goto chan_unlink_done;
  925. }
  926. /*
  927. * Send the request to the server and wait for a response
  928. */
  929. req.iuc_head.size = sizeof(req);
  930. req.iuc_head.id = MESSAGE_REQ_EVT_UNLINK_CHANNEL;
  931. req.iuc_channel_name = *channelName;
  932. pthread_mutex_lock(&evti->ei_mutex);
  933. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  934. if (error != SA_AIS_OK) {
  935. pthread_mutex_unlock (&evti->ei_mutex);
  936. goto chan_unlink_put;
  937. }
  938. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  939. MESSAGE_RES_EVT_UNLINK_CHANNEL);
  940. pthread_mutex_unlock (&evti->ei_mutex);
  941. if (error != SA_AIS_OK) {
  942. goto chan_unlink_put;
  943. }
  944. error = res.iuc_head.error;
  945. chan_unlink_put:
  946. saHandleInstancePut (&evt_instance_handle_db, evtHandle);
  947. chan_unlink_done:
  948. return error;
  949. }
  950. /*
  951. * The saEvtEventAllocate() function allocates memory for the event, but not
  952. * for the eventHandle, and initializes all event attributes to default values.
  953. * The event allocated by saEvtEventAllocate() is freed by invoking
  954. * saEvtEventFree().
  955. * The memory associated with the eventHandle is not deallocated by the
  956. * saEvtEventAllocate() function or the saEvtEventFree() function. It is the
  957. * responsibility of the invoking process to deallocate the memory for the
  958. * eventHandle when the process has published the event and has freed the
  959. * event by invoking saEvtEventFree().
  960. */
  961. SaAisErrorT
  962. saEvtEventAllocate(
  963. const SaEvtChannelHandleT channelHandle,
  964. SaEvtEventHandleT *eventHandle)
  965. {
  966. SaAisErrorT error;
  967. struct event_data_instance *edi;
  968. struct event_instance *evti;
  969. struct event_channel_instance *eci;
  970. error = saHandleInstanceGet(&channel_handle_db, channelHandle,
  971. (void*)&eci);
  972. if (error != SA_AIS_OK) {
  973. goto alloc_done;
  974. }
  975. error = saHandleInstanceGet(&evt_instance_handle_db,
  976. eci->eci_instance_handle, (void*)&evti);
  977. if (error != SA_AIS_OK) {
  978. goto alloc_put1;
  979. }
  980. error = saHandleCreate(&event_handle_db, sizeof(*edi),
  981. (void*)eventHandle);
  982. if (error != SA_AIS_OK) {
  983. goto alloc_put2;
  984. }
  985. error = saHandleInstanceGet(&event_handle_db, *eventHandle,
  986. (void*)&edi);
  987. if (error != SA_AIS_OK) {
  988. goto alloc_put2;
  989. }
  990. memset(edi, 0, sizeof(*edi));
  991. pthread_mutex_init(&edi->edi_mutex, NULL);
  992. edi->edi_freeing = 0;
  993. edi->edi_channel_handle = channelHandle;
  994. edi->edi_pub_node = evti->ei_node_id;
  995. edi->edi_priority = SA_EVT_LOWEST_PRIORITY;
  996. edi->edi_event_id = SA_EVT_EVENTID_NONE;
  997. saHandleInstancePut (&event_handle_db, *eventHandle);
  998. alloc_put2:
  999. saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle);
  1000. alloc_put1:
  1001. saHandleInstancePut (&channel_handle_db, edi->edi_channel_handle);
  1002. alloc_done:
  1003. return error;
  1004. }
  1005. /*
  1006. * The saEvtEventFree() function gives the Event Service premission to
  1007. * deallocate the memory that contains the attributes of the event that is
  1008. * associated with eventHandle. The function is used to free events allocated
  1009. * by saEvtEventAllocate() and by saEvtEventDeliverCallback().
  1010. */
  1011. SaAisErrorT
  1012. saEvtEventFree(SaEvtEventHandleT eventHandle)
  1013. {
  1014. SaAisErrorT error;
  1015. struct event_data_instance *edi;
  1016. error = saHandleInstanceGet(&event_handle_db, eventHandle,
  1017. (void*)&edi);
  1018. if (error != SA_AIS_OK) {
  1019. goto evt_free_done;
  1020. }
  1021. /*
  1022. * Make sure that the event isn't being freed elsewhere
  1023. */
  1024. pthread_mutex_lock(&edi->edi_mutex);
  1025. if (edi->edi_freeing) {
  1026. pthread_mutex_unlock(&edi->edi_mutex);
  1027. saHandleInstancePut(&event_handle_db, eventHandle);
  1028. return SA_AIS_ERR_BAD_HANDLE;
  1029. }
  1030. edi->edi_freeing = 1;
  1031. pthread_mutex_unlock(&edi->edi_mutex);
  1032. saHandleDestroy(&event_handle_db, eventHandle);
  1033. saHandleInstancePut(&event_handle_db, eventHandle);
  1034. evt_free_done:
  1035. return error;
  1036. }
  1037. /*
  1038. * This function may be used to assign writeable event attributes. It takes
  1039. * as arguments an event handle eventHandle and the attribute to be set in
  1040. * the event structure of the event with that handle. Note: The only
  1041. * attributes that a process can set are the patternArray, priority,
  1042. * retentionTime and publisherName attributes.
  1043. */
  1044. SaAisErrorT
  1045. saEvtEventAttributesSet(
  1046. const SaEvtEventHandleT eventHandle,
  1047. const SaEvtEventPatternArrayT *patternArray,
  1048. SaEvtEventPriorityT priority,
  1049. SaTimeT retentionTime,
  1050. const SaNameT *publisherName)
  1051. {
  1052. SaEvtEventPatternT *oldpatterns;
  1053. SaSizeT oldnumber;
  1054. SaAisErrorT error;
  1055. struct event_data_instance *edi;
  1056. int i;
  1057. error = saHandleInstanceGet(&event_handle_db, eventHandle,
  1058. (void*)&edi);
  1059. if (error != SA_AIS_OK) {
  1060. goto attr_set_done;
  1061. }
  1062. pthread_mutex_lock(&edi->edi_mutex);
  1063. edi->edi_priority = priority;
  1064. edi->edi_retention_time = retentionTime;
  1065. /*
  1066. * publisherName or patternArray not allowed to be NULL
  1067. */
  1068. if (!publisherName || !patternArray) {
  1069. error = SA_AIS_ERR_INVALID_PARAM;
  1070. goto attr_set_unlock;
  1071. }
  1072. edi->edi_pub_name = *publisherName;
  1073. oldpatterns = edi->edi_patterns.patterns;
  1074. oldnumber = edi->edi_patterns.patternsNumber;
  1075. edi->edi_patterns.patterns = 0;
  1076. edi->edi_patterns.patterns = malloc(sizeof(SaEvtEventPatternT) *
  1077. patternArray->patternsNumber);
  1078. if (!edi->edi_patterns.patterns) {
  1079. error = SA_AIS_ERR_NO_MEMORY;
  1080. goto attr_set_done_reset;
  1081. }
  1082. edi->edi_patterns.patternsNumber = patternArray->patternsNumber;
  1083. /*
  1084. * copy the patterns from the caller. allocating memory for
  1085. * of all the strings.
  1086. */
  1087. for (i = 0; i < patternArray->patternsNumber; i++) {
  1088. edi->edi_patterns.patterns[i].pattern =
  1089. malloc(patternArray->patterns[i].patternSize);
  1090. if (!edi->edi_patterns.patterns[i].pattern) {
  1091. int j;
  1092. for (j = 0; j < i; j++) {
  1093. free(edi->edi_patterns.patterns[j].pattern);
  1094. }
  1095. free(edi->edi_patterns.patterns);
  1096. error = SA_AIS_ERR_NO_MEMORY;
  1097. goto attr_set_done_reset;
  1098. }
  1099. memcpy(edi->edi_patterns.patterns[i].pattern,
  1100. patternArray->patterns[i].pattern,
  1101. patternArray->patterns[i].patternSize);
  1102. edi->edi_patterns.patterns[i].patternSize =
  1103. patternArray->patterns[i].patternSize;
  1104. }
  1105. /*
  1106. * free up the old pattern memory
  1107. */
  1108. if (oldpatterns) {
  1109. for (i = 0; i < oldnumber; i++) {
  1110. if (oldpatterns[i].pattern) {
  1111. free(oldpatterns[i].pattern);
  1112. }
  1113. }
  1114. free (oldpatterns);
  1115. }
  1116. goto attr_set_unlock;
  1117. attr_set_done_reset:
  1118. edi->edi_patterns.patterns = oldpatterns;
  1119. edi->edi_patterns.patternsNumber = oldnumber;
  1120. attr_set_unlock:
  1121. pthread_mutex_unlock(&edi->edi_mutex);
  1122. saHandleInstancePut(&event_handle_db, eventHandle);
  1123. attr_set_done:
  1124. return error;
  1125. }
  1126. /*
  1127. * This function takes as parameters an event handle eventHandle and the
  1128. * attributes of the event with that handle. The function retrieves the
  1129. * value of the attributes for the event and stores them at the address
  1130. * provided for the out parameters.
  1131. * It is the responsibility of the invoking process to allocate memory for
  1132. * the out parameters before it invokes this function. The Event Service
  1133. * assigns the out values into that memory. For each of the out, or in/out,
  1134. * parameters, if the invoking process provides a NULL reference, the
  1135. * Availability Management Framework does not return the out value.
  1136. * Similarly, it is the responsibility of the invoking process to allocate
  1137. * memory for the patternArray.
  1138. */
  1139. SaAisErrorT
  1140. saEvtEventAttributesGet(
  1141. SaEvtEventHandleT eventHandle,
  1142. SaEvtEventPatternArrayT *patternArray,
  1143. SaEvtEventPriorityT *priority,
  1144. SaTimeT *retentionTime,
  1145. SaNameT *publisherName,
  1146. SaTimeT *publishTime,
  1147. SaEvtEventIdT *eventId)
  1148. {
  1149. SaAisErrorT error;
  1150. struct event_data_instance *edi;
  1151. SaSizeT npats;
  1152. int i;
  1153. error = saHandleInstanceGet(&event_handle_db, eventHandle,
  1154. (void*)&edi);
  1155. if (error != SA_AIS_OK) {
  1156. goto attr_get_done;
  1157. }
  1158. pthread_mutex_lock(&edi->edi_mutex);
  1159. /*
  1160. * Go through the args and send back information if the pointer
  1161. * isn't NULL
  1162. */
  1163. if (eventId) {
  1164. *eventId = edi->edi_event_id;
  1165. }
  1166. if (publishTime) {
  1167. *publishTime = edi->edi_pub_time;
  1168. }
  1169. if (publisherName) {
  1170. *publisherName = edi->edi_pub_name;
  1171. }
  1172. if (retentionTime) {
  1173. *retentionTime = edi->edi_retention_time;
  1174. }
  1175. if (priority) {
  1176. *priority = edi->edi_priority;
  1177. }
  1178. if (!patternArray) {
  1179. goto attr_get_unlock;
  1180. }
  1181. npats = min(patternArray->patternsNumber,
  1182. edi->edi_patterns.patternsNumber);
  1183. /*
  1184. * We set the returned number of patterns to the actual
  1185. * pattern count of the event. This way the caller can tell
  1186. * if it got all the possible patterns. If the returned number
  1187. * is more that the number supplied, then some available patterns
  1188. * were not returned.
  1189. *
  1190. * The same thing happens when copying the pattern strings.
  1191. */
  1192. patternArray->patternsNumber = edi->edi_patterns.patternsNumber;
  1193. for (i = 0; i < npats; i++) {
  1194. memcpy(patternArray->patterns[i].pattern,
  1195. edi->edi_patterns.patterns[i].pattern,
  1196. min(patternArray->patterns[i].patternSize,
  1197. edi->edi_patterns.patterns[i].patternSize));
  1198. patternArray->patterns[i].patternSize =
  1199. edi->edi_patterns.patterns[i].patternSize;
  1200. }
  1201. attr_get_unlock:
  1202. pthread_mutex_unlock(&edi->edi_mutex);
  1203. saHandleInstancePut(&event_handle_db, eventHandle);
  1204. attr_get_done:
  1205. return error;
  1206. }
  1207. /*
  1208. * The saEvtEventDataGet() function allows a process to retrieve the data
  1209. * associated with an event previously delivered by
  1210. * saEvtEventDeliverCallback().
  1211. */
  1212. SaAisErrorT
  1213. saEvtEventDataGet(
  1214. const SaEvtEventHandleT eventHandle,
  1215. void *eventData,
  1216. SaSizeT *eventDataSize)
  1217. {
  1218. SaAisErrorT error = SA_AIS_OK;
  1219. struct event_data_instance *edi;
  1220. SaSizeT xfsize;
  1221. if (!eventData || !eventDataSize) {
  1222. goto data_get_done;
  1223. }
  1224. error = saHandleInstanceGet(&event_handle_db, eventHandle,
  1225. (void*)&edi);
  1226. if (error != SA_AIS_OK) {
  1227. goto data_get_done;
  1228. }
  1229. pthread_mutex_lock(&edi->edi_mutex);
  1230. if (edi->edi_event_data && edi->edi_event_data_size) {
  1231. xfsize = min(*eventDataSize, edi->edi_event_data_size);
  1232. *eventDataSize = edi->edi_event_data_size;
  1233. memcpy(eventData, edi->edi_event_data, xfsize);
  1234. } else {
  1235. *eventDataSize = 0;
  1236. }
  1237. pthread_mutex_unlock(&edi->edi_mutex);
  1238. saHandleInstancePut(&event_handle_db, eventHandle);
  1239. data_get_done:
  1240. return error;
  1241. }
  1242. /*
  1243. * Calculate the size in bytes for patterns
  1244. */
  1245. static size_t patt_size(const SaEvtEventPatternArrayT *patterns)
  1246. {
  1247. int i;
  1248. size_t size = sizeof(SaEvtEventPatternArrayT);
  1249. for (i = 0; i < patterns->patternsNumber; i++) {
  1250. size += sizeof(SaEvtEventPatternT);
  1251. size += patterns->patterns[i].patternSize;
  1252. }
  1253. return size;
  1254. }
  1255. /*
  1256. * copy patterns to a form for sending to the server
  1257. */
  1258. static uint32_t aispatt_to_evt_patt(const SaEvtEventPatternArrayT *patterns,
  1259. void *data)
  1260. {
  1261. int i;
  1262. SaEvtEventPatternT *pats = data;
  1263. SaUint8T *str = (SaUint8T *)pats +
  1264. (patterns->patternsNumber * sizeof(*pats));
  1265. /*
  1266. * Pointers are replaced with offsets into the data array. These
  1267. * will be later converted back into pointers when received as events.
  1268. */
  1269. for (i = 0; i < patterns->patternsNumber; i++) {
  1270. memcpy(str, patterns->patterns[i].pattern,
  1271. patterns->patterns[i].patternSize);
  1272. pats->patternSize = patterns->patterns[i].patternSize;
  1273. pats->pattern = (SaUint8T *)((void *)str - data);
  1274. str += patterns->patterns[i].patternSize;
  1275. pats++;
  1276. }
  1277. return patterns->patternsNumber;
  1278. }
  1279. /*
  1280. * Calculate the size in bytes for filters
  1281. */
  1282. static size_t filt_size(const SaEvtEventFilterArrayT *filters)
  1283. {
  1284. int i;
  1285. size_t size = sizeof(SaEvtEventFilterArrayT);
  1286. for (i = 0; i < filters->filtersNumber; i++) {
  1287. size += sizeof(SaEvtEventFilterT);
  1288. size += filters->filters[i].filter.patternSize;
  1289. }
  1290. return size;
  1291. }
  1292. /*
  1293. * Convert the Sa filters to a form that can be sent over the network
  1294. * i.e. replace pointers with offsets. The pointers will be reconstituted
  1295. * by the receiver.
  1296. */
  1297. static uint32_t aisfilt_to_evt_filt(const SaEvtEventFilterArrayT *filters,
  1298. void *data)
  1299. {
  1300. int i;
  1301. SaEvtEventFilterArrayT *filta = data;
  1302. SaEvtEventFilterT *filts = data + sizeof(SaEvtEventFilterArrayT);
  1303. SaUint8T *str = (SaUint8T *)filts +
  1304. (filters->filtersNumber * sizeof(*filts));
  1305. /*
  1306. * Pointers are replaced with offsets into the data array. These
  1307. * will be later converted back into pointers by the evt server.
  1308. */
  1309. filta->filters = (SaEvtEventFilterT *)((void *)filts - data);
  1310. filta->filtersNumber = filters->filtersNumber;
  1311. for (i = 0; i < filters->filtersNumber; i++) {
  1312. filts->filterType = filters->filters[i].filterType;
  1313. filts->filter.patternSize =
  1314. filters->filters[i].filter.patternSize;
  1315. memcpy(str,
  1316. filters->filters[i].filter.pattern,
  1317. filters->filters[i].filter.patternSize);
  1318. filts->filter.pattern = (SaUint8T *)((void *)str - data);
  1319. str += filters->filters[i].filter.patternSize;
  1320. filts++;
  1321. }
  1322. return filters->filtersNumber;
  1323. }
  1324. /*
  1325. * The saEvtEventPublish() function publishes an event on the associated
  1326. * channel. The event to be published consists of a
  1327. * standard set of attributes (the event header) and an optional data part.
  1328. * Before an event can be published, the publisher process must invoke the
  1329. * saEvtEventPatternArraySet() function to set the event patterns. The event
  1330. * is delivered to subscribers whose subscription filter matches the event
  1331. * patterns.
  1332. * When the Event Service publishes an event, it automatically sets
  1333. * the following readonly event attributes:
  1334. * - Event attribute time
  1335. * - Event publisher identifier
  1336. * - Event publisher node identifier
  1337. * - Event identifier
  1338. * In addition to the event attributes, a process can supply values for the
  1339. * eventData and eventDataSize parameters for publication as part of the
  1340. * event. The data portion of the event may be at most SA_EVT_DATA_MAX_LEN
  1341. * bytes in length.
  1342. * The process may assume that the invocation of saEvtEventPublish() copies
  1343. * all pertinent parameters, including the memory associated with the
  1344. * eventHandle and eventData parameters, to its own local memory. However,
  1345. * the invocation does not automatically deallocate memory associated with
  1346. * the eventHandle and eventData parameters. It is the responsibility of the
  1347. * invoking process to deallocate the memory for those parameters after
  1348. * saEvtEventPublish() returns.
  1349. */
  1350. SaAisErrorT
  1351. saEvtEventPublish(
  1352. const SaEvtEventHandleT eventHandle,
  1353. const void *eventData,
  1354. SaSizeT eventDataSize,
  1355. SaEvtEventIdT *eventId)
  1356. {
  1357. SaAisErrorT error;
  1358. struct event_data_instance *edi;
  1359. struct event_instance *evti;
  1360. struct event_channel_instance *eci;
  1361. struct lib_event_data *req;
  1362. struct res_evt_event_publish res;
  1363. size_t pattern_size;
  1364. struct event_pattern *patterns;
  1365. void *data_start;
  1366. if (eventDataSize > SA_EVT_DATA_MAX_LEN) {
  1367. error = SA_AIS_ERR_INVALID_PARAM;
  1368. goto pub_done;
  1369. }
  1370. error = saHandleInstanceGet(&event_handle_db, eventHandle,
  1371. (void*)&edi);
  1372. if (error != SA_AIS_OK) {
  1373. goto pub_done;
  1374. }
  1375. pthread_mutex_lock(&edi->edi_mutex);
  1376. /*
  1377. * See if patterns have been set for this event. If not, we
  1378. * can't publish.
  1379. */
  1380. if (!edi->edi_patterns.patterns) {
  1381. error = SA_AIS_ERR_INVALID_PARAM;
  1382. goto pub_put1;
  1383. }
  1384. error = saHandleInstanceGet(&channel_handle_db, edi->edi_channel_handle,
  1385. (void*)&eci);
  1386. if (error != SA_AIS_OK) {
  1387. goto pub_put1;
  1388. }
  1389. /*
  1390. * See if we can publish to this channel
  1391. */
  1392. if (!(eci->eci_open_flags & SA_EVT_CHANNEL_PUBLISHER)) {
  1393. error = SA_AIS_ERR_ACCESS;
  1394. goto pub_put2;
  1395. }
  1396. error = saHandleInstanceGet(&evt_instance_handle_db,
  1397. eci->eci_instance_handle, (void*)&evti);
  1398. if (error != SA_AIS_OK) {
  1399. goto pub_put2;
  1400. }
  1401. /*
  1402. * Figure out how much memory we need for the patterns and data
  1403. */
  1404. pattern_size = patt_size(&edi->edi_patterns);
  1405. req = malloc(sizeof(*req) + eventDataSize + pattern_size);
  1406. patterns = (struct event_pattern *)req->led_body;
  1407. data_start = (void *)req->led_body + pattern_size;
  1408. if (!req) {
  1409. error = SA_AIS_ERR_NO_MEMORY;
  1410. goto pub_put3;
  1411. }
  1412. /*
  1413. * copy everything to the request structure
  1414. */
  1415. aispatt_to_evt_patt(&edi->edi_patterns, patterns);
  1416. req->led_patterns_number = edi->edi_patterns.patternsNumber;
  1417. req->led_user_data_offset = pattern_size;
  1418. if (eventData && eventDataSize) {
  1419. memcpy(data_start, eventData, eventDataSize);
  1420. req->led_user_data_size = eventDataSize;
  1421. } else {
  1422. req->led_user_data_size = 0;
  1423. }
  1424. req->led_head.id = MESSAGE_REQ_EVT_PUBLISH;
  1425. req->led_head.size = sizeof(*req) + pattern_size + eventDataSize;
  1426. req->led_svr_channel_handle = eci->eci_svr_channel_handle;
  1427. req->led_retention_time = edi->edi_retention_time;
  1428. req->led_publish_time = clustTimeNow();
  1429. req->led_priority = edi->edi_priority;
  1430. req->led_publisher_name = edi->edi_pub_name;
  1431. pthread_mutex_lock(&evti->ei_mutex);
  1432. error = saSendRetry(evti->ei_fd, req, req->led_head.size, MSG_NOSIGNAL);
  1433. free(req);
  1434. if (error != SA_AIS_OK) {
  1435. pthread_mutex_unlock (&evti->ei_mutex);
  1436. goto pub_put3;
  1437. }
  1438. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1439. MESSAGE_RES_EVT_PUBLISH);
  1440. pthread_mutex_unlock (&evti->ei_mutex);
  1441. if (error != SA_AIS_OK) {
  1442. goto pub_put3;
  1443. }
  1444. error = res.iep_head.error;
  1445. if (error == SA_AIS_OK) {
  1446. *eventId = res.iep_event_id;
  1447. }
  1448. pub_put3:
  1449. saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle);
  1450. pub_put2:
  1451. saHandleInstancePut (&channel_handle_db, edi->edi_channel_handle);
  1452. pub_put1:
  1453. pthread_mutex_unlock(&edi->edi_mutex);
  1454. saHandleInstancePut(&event_handle_db, eventHandle);
  1455. pub_done:
  1456. return error;
  1457. }
  1458. /*
  1459. * The saEvtEventSubscribe() function enables a process to subscribe for
  1460. * events on an event channel by registering one or more filters on that
  1461. * event channel. The process must have opened the event channel, designated
  1462. * by channelHandle, with the SA_EVT_CHANNEL_SUBSCRIBER flag set for an
  1463. * invocation of this function to be successful.
  1464. * The memory associated with the filters is not deallocated by the
  1465. * saEvtEventSubscribe() function. It is the responsibility of the invoking
  1466. * process to deallocate the memory when the saEvtEventSubscribe() function
  1467. * returns.
  1468. * For a given subscription, the filters parameter cannot be modified. To
  1469. * change the filters parameter without losing events, a process must
  1470. * establish a new subscription with the new filters parameter. After the new
  1471. * subscription is established, the old subscription can be removed by
  1472. * invoking the saEvtEventUnsubscribe() function.
  1473. */
  1474. SaAisErrorT
  1475. saEvtEventSubscribe(
  1476. const SaEvtChannelHandleT channelHandle,
  1477. const SaEvtEventFilterArrayT *filters,
  1478. SaEvtSubscriptionIdT subscriptionId)
  1479. {
  1480. SaAisErrorT error;
  1481. struct event_instance *evti;
  1482. struct event_channel_instance *eci;
  1483. struct req_evt_event_subscribe *req;
  1484. struct res_evt_event_subscribe res;
  1485. int sz;
  1486. error = saHandleInstanceGet(&channel_handle_db, channelHandle,
  1487. (void*)&eci);
  1488. if (error != SA_AIS_OK) {
  1489. goto subscribe_done;
  1490. }
  1491. /*
  1492. * get the evt handle for the fd
  1493. */
  1494. error = saHandleInstanceGet(&evt_instance_handle_db,
  1495. eci->eci_instance_handle, (void*)&evti);
  1496. if (error != SA_AIS_OK) {
  1497. goto subscribe_put1;
  1498. }
  1499. /*
  1500. * See if we can subscribe to this channel
  1501. */
  1502. if (!(eci->eci_open_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
  1503. error = SA_AIS_ERR_INVALID_PARAM;
  1504. goto subscribe_put2;
  1505. }
  1506. /*
  1507. * calculate size needed to store the filters
  1508. */
  1509. sz = filt_size(filters);
  1510. req = malloc(sizeof(*req) + sz);
  1511. if (!req) {
  1512. error = SA_AIS_ERR_NO_MEMORY;
  1513. goto subscribe_put2;
  1514. }
  1515. /*
  1516. * Copy the supplied filters to the request
  1517. */
  1518. req->ics_filter_count = aisfilt_to_evt_filt(filters,
  1519. req->ics_filter_data);
  1520. req->ics_head.id = MESSAGE_REQ_EVT_SUBSCRIBE;
  1521. req->ics_head.size = sizeof(*req) + sz;
  1522. req->ics_channel_handle = eci->eci_svr_channel_handle;
  1523. req->ics_sub_id = subscriptionId;
  1524. req->ics_filter_size = sz;
  1525. pthread_mutex_lock(&evti->ei_mutex);
  1526. error = saSendRetry(evti->ei_fd, req, req->ics_head.size, MSG_NOSIGNAL);
  1527. free(req);
  1528. if (error != SA_AIS_OK) {
  1529. pthread_mutex_unlock (&evti->ei_mutex);
  1530. goto subscribe_put2;
  1531. }
  1532. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1533. MESSAGE_RES_EVT_SUBSCRIBE);
  1534. pthread_mutex_unlock (&evti->ei_mutex);
  1535. if (error != SA_AIS_OK) {
  1536. goto subscribe_put2;
  1537. }
  1538. error = res.ics_head.error;
  1539. subscribe_put2:
  1540. saHandleInstancePut(&evt_instance_handle_db,
  1541. eci->eci_instance_handle);
  1542. subscribe_put1:
  1543. saHandleInstancePut(&channel_handle_db, channelHandle);
  1544. subscribe_done:
  1545. return error;
  1546. }
  1547. /*
  1548. * The saEvtEventUnsubscribe() function allows a process to stop receiving
  1549. * events for a particular subscription on an event channel by removing the
  1550. * subscription. The saEvtEventUnsubscribe() operation is successful if the
  1551. * subscriptionId parameter matches a previously registered subscription.
  1552. * Pending events that no longer match any subscription, because the
  1553. * saEvtEventUnsubscribe() operation had been invoked, are purged. a process
  1554. * that wishes to modify a subscription without losing any events must
  1555. * establish the new subscription before removing the existing subscription.
  1556. */
  1557. SaAisErrorT
  1558. saEvtEventUnsubscribe(
  1559. const SaEvtChannelHandleT channelHandle,
  1560. SaEvtSubscriptionIdT subscriptionId)
  1561. {
  1562. SaAisErrorT error;
  1563. struct event_instance *evti;
  1564. struct event_channel_instance *eci;
  1565. struct req_evt_event_unsubscribe req;
  1566. struct res_evt_event_unsubscribe res;
  1567. error = saHandleInstanceGet(&channel_handle_db, channelHandle,
  1568. (void*)&eci);
  1569. if (error != SA_AIS_OK) {
  1570. goto unsubscribe_done;
  1571. }
  1572. error = saHandleInstanceGet(&evt_instance_handle_db,
  1573. eci->eci_instance_handle, (void*)&evti);
  1574. if (error != SA_AIS_OK) {
  1575. goto unsubscribe_put1;
  1576. }
  1577. req.icu_head.id = MESSAGE_REQ_EVT_UNSUBSCRIBE;
  1578. req.icu_head.size = sizeof(req);
  1579. req.icu_channel_handle = eci->eci_svr_channel_handle;
  1580. req.icu_sub_id = subscriptionId;
  1581. pthread_mutex_lock(&evti->ei_mutex);
  1582. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  1583. if (error != SA_AIS_OK) {
  1584. pthread_mutex_unlock (&evti->ei_mutex);
  1585. goto unsubscribe_put2;
  1586. }
  1587. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1588. MESSAGE_RES_EVT_UNSUBSCRIBE);
  1589. pthread_mutex_unlock (&evti->ei_mutex);
  1590. if (error != SA_AIS_OK) {
  1591. goto unsubscribe_put2;
  1592. }
  1593. error = res.icu_head.error;
  1594. unsubscribe_put2:
  1595. saHandleInstancePut(&evt_instance_handle_db,
  1596. eci->eci_instance_handle);
  1597. unsubscribe_put1:
  1598. saHandleInstancePut(&channel_handle_db, channelHandle);
  1599. unsubscribe_done:
  1600. return error;
  1601. }
  1602. /*
  1603. * The saEvtEventRetentionTimeClear() function is used to clear the retention
  1604. * time of a published event. It indicates to the Event Service that it does
  1605. * not need to keep the event any longer for potential new subscribers. Once
  1606. * the value of the retention time is reset to 0, the event is no longer
  1607. * available for new subscribers. The event is held until all old subscribers
  1608. * in the system process the event and free the event using saEvtEventFree().
  1609. */
  1610. SaAisErrorT
  1611. saEvtEventRetentionTimeClear(
  1612. const SaEvtChannelHandleT channelHandle,
  1613. const SaEvtEventIdT eventId)
  1614. {
  1615. SaAisErrorT error;
  1616. struct event_instance *evti;
  1617. struct event_channel_instance *eci;
  1618. struct req_evt_event_clear_retentiontime req;
  1619. struct res_evt_event_clear_retentiontime res;
  1620. error = saHandleInstanceGet(&channel_handle_db, channelHandle,
  1621. (void*)&eci);
  1622. if (error != SA_AIS_OK) {
  1623. goto ret_time_done;
  1624. }
  1625. error = saHandleInstanceGet(&evt_instance_handle_db,
  1626. eci->eci_instance_handle, (void*)&evti);
  1627. if (error != SA_AIS_OK) {
  1628. goto ret_time_put1;
  1629. }
  1630. req.iec_head.id = MESSAGE_REQ_EVT_CLEAR_RETENTIONTIME;
  1631. req.iec_head.size = sizeof(req);
  1632. req.iec_channel_handle = eci->eci_svr_channel_handle;
  1633. req.iec_event_id = eventId;
  1634. pthread_mutex_lock(&evti->ei_mutex);
  1635. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  1636. if (error != SA_AIS_OK) {
  1637. pthread_mutex_unlock (&evti->ei_mutex);
  1638. goto ret_time_put2;
  1639. }
  1640. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1641. MESSAGE_RES_EVT_CLEAR_RETENTIONTIME);
  1642. pthread_mutex_unlock (&evti->ei_mutex);
  1643. if (error != SA_AIS_OK) {
  1644. goto ret_time_put2;
  1645. }
  1646. error = res.iec_head.error;
  1647. ret_time_put2:
  1648. saHandleInstancePut(&evt_instance_handle_db,
  1649. eci->eci_instance_handle);
  1650. ret_time_put1:
  1651. saHandleInstancePut(&channel_handle_db, channelHandle);
  1652. ret_time_done:
  1653. return error;
  1654. }
  1655. /*
  1656. * vi: set autoindent tabstop=4 shiftwidth=4 :
  1657. */