amf.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /*
  2. * Copyright (c) 2002-2003 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * thread locking model is as follows
  36. *
  37. * APIs that use handles:
  38. *
  39. * Every handle database has a lock.
  40. * Each interface started with SaAmfInitialize has a lock.
  41. * Handle database lock is taken.
  42. * amfInstance lock is taken.
  43. * Handle database lock is released early.
  44. * amfInstance lock is released after amfInstance is out of use.
  45. *
  46. * Finalize API:
  47. * Handle database lock is taken
  48. * amf instance lock is taken
  49. * handle is removed
  50. * amf instance lock is released
  51. * handle database lock is released
  52. */
  53. #include <stdio.h>
  54. #include <string.h>
  55. #include <stdlib.h>
  56. #include <unistd.h>
  57. #include <errno.h>
  58. #include <signal.h>
  59. #include <pthread.h>
  60. #include <sys/types.h>
  61. #include <sys/socket.h>
  62. #include <sys/select.h>
  63. #include <sys/un.h>
  64. #include "../include/ais_types.h"
  65. #include "../include/ais_amf.h"
  66. #include "../include/ais_msg.h"
  67. #include "util.h"
  68. struct message_overlay {
  69. struct message_header header;
  70. char data[4096];
  71. };
  72. /*
  73. * Data structure for instance data
  74. */
  75. struct amfInstance {
  76. int fd;
  77. SaAmfCallbacksT callbacks;
  78. struct queue inq;
  79. SaNameT compName;
  80. int compRegistered;
  81. struct message_overlay message;
  82. pthread_mutex_t mutex;
  83. };
  84. #define AMFINSTANCE_MUTEX_OFFSET offset_of(struct amfInstance, mutex)
  85. /*
  86. * All instances in one database
  87. */
  88. static struct saHandleDatabase amfHandleDatabase = {
  89. handleCount: 0,
  90. handles: 0,
  91. generation: 0,
  92. mutex: PTHREAD_MUTEX_INITIALIZER
  93. };
  94. /*
  95. * Versions supported
  96. */
  97. static SaVersionT amfVersionsSupported[] = {
  98. { 'A', 1, 1 },
  99. { 'a', 1, 1 }
  100. };
  101. static struct saVersionDatabase amfVersionDatabase = {
  102. sizeof (amfVersionsSupported) / sizeof (SaVersionT),
  103. amfVersionsSupported
  104. };
  105. /*
  106. * Implementation
  107. */
  108. SaErrorT
  109. saAmfInitialize (
  110. SaAmfHandleT *amfHandle,
  111. const SaAmfCallbacksT *amfCallbacks,
  112. const SaVersionT *version)
  113. {
  114. struct amfInstance *amfInstance;
  115. SaErrorT error = SA_OK;
  116. error = saVersionVerify (&amfVersionDatabase, version);
  117. if (error != SA_OK) {
  118. goto error_nofree;
  119. }
  120. error = saHandleCreate (&amfHandleDatabase, (void *)&amfInstance,
  121. sizeof (struct amfInstance), amfHandle);
  122. if (error != SA_OK) {
  123. goto error_nofree;
  124. }
  125. /*
  126. * An inq is needed to store async messages while waiting for a
  127. * sync response
  128. */
  129. error = saQueueInit (&amfInstance->inq, 512, sizeof (void *));
  130. if (error != SA_OK) {
  131. goto error_free;
  132. }
  133. error = saServiceConnect (&amfInstance->fd, MESSAGE_REQ_AMF_INIT);
  134. if (error != SA_OK) {
  135. goto error_free2;
  136. }
  137. memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT));
  138. pthread_mutex_init (&amfInstance->mutex, NULL);
  139. return (SA_OK);
  140. error_free2:
  141. free (amfInstance->inq.items);
  142. error_free:
  143. saHandleRemove (&amfHandleDatabase, *amfHandle);
  144. error_nofree:
  145. return (error);
  146. }
  147. SaErrorT
  148. saAmfSelectionObjectGet (
  149. const SaAmfHandleT *amfHandle,
  150. SaSelectionObjectT *selectionObject)
  151. {
  152. struct amfInstance *amfInstance;
  153. SaErrorT error;
  154. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, 0);
  155. if (error != SA_OK) {
  156. return (error);
  157. }
  158. *selectionObject = amfInstance->fd;
  159. pthread_mutex_unlock (&amfInstance->mutex);
  160. return (SA_OK);
  161. }
  162. SaErrorT
  163. saAmfDispatch (
  164. const SaAmfHandleT *amfHandle,
  165. SaDispatchFlagsT dispatchFlags)
  166. {
  167. struct pollfd ufds;
  168. int timeout = -1;
  169. SaErrorT error;
  170. int dispatch_avail;
  171. struct amfInstance *amfInstance;
  172. SaAmfCallbacksT callbacks;
  173. struct res_amf_healthcheckcallback *res_amf_healthcheckcallback;
  174. struct res_amf_readinessstatesetcallback *res_amf_readinessstatesetcallback;
  175. struct res_amf_csisetcallback *res_amf_csisetcallback;
  176. struct res_amf_csiremovecallback *res_amf_csiremovecallback;
  177. struct res_amf_protectiongrouptrackcallback *res_amf_protectiongrouptrackcallback;
  178. struct message_header **queue_msg;
  179. struct message_header *msg;
  180. int empty;
  181. int ignore_dispatch = 0;
  182. int cont = 1; /* always continue do loop except when set to 0 */
  183. int handle_verified = 0;
  184. int poll_fd;
  185. unsigned int gen_first;
  186. unsigned int gen_second;
  187. /*
  188. * Timeout instantly for SA_DISPATCH_ALL
  189. */
  190. if (dispatchFlags == SA_DISPATCH_ALL) {
  191. timeout = 0;
  192. }
  193. do {
  194. /*
  195. * If flags are SA_DISPATCH_BLOCKING and handle has been
  196. * verified, return SA_OK because a Finalize has been
  197. * called. Else return error from saHandleConvert
  198. */
  199. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, &gen_first);
  200. if (error != SA_OK) {
  201. return (handle_verified ? SA_OK : error);
  202. }
  203. handle_verified = 1;
  204. poll_fd = amfInstance->fd;
  205. /*
  206. * Unlock mutex for potentially long wait in select. If fd
  207. * is closed by amfFinalize in select, select will return
  208. */
  209. pthread_mutex_unlock (&amfInstance->mutex);
  210. /*
  211. * Read data directly from socket
  212. */
  213. ufds.fd = poll_fd;
  214. ufds.events = POLLIN;
  215. ufds.revents = 0;
  216. error = saPollRetry (&ufds, 1, timeout);
  217. if (error != SA_OK) {
  218. goto error_nounlock;
  219. }
  220. dispatch_avail = ufds.revents & POLLIN;
  221. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  222. break; /* exit do while cont is 1 loop */
  223. } else
  224. if (dispatch_avail == 0) {
  225. continue; /* next select */
  226. }
  227. /*
  228. * Re-verify amfHandle
  229. */
  230. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, &gen_second);
  231. if (error != SA_OK) {
  232. return (handle_verified ? SA_OK : error);
  233. }
  234. /*
  235. * Handle has been removed and then reallocated
  236. */
  237. if (gen_first != gen_second) {
  238. return (SA_OK);
  239. }
  240. saQueueIsEmpty(&amfInstance->inq, &empty);
  241. if (empty == 0) {
  242. /*
  243. * Queue is not empty, read data from queue
  244. */
  245. saQueueItemGet (&amfInstance->inq, (void *)&queue_msg);
  246. msg = *queue_msg;
  247. memcpy (&amfInstance->message, msg, msg->size);
  248. saQueueItemRemove (&amfInstance->inq);
  249. } else {
  250. /*
  251. * Queue empty, read response from socket
  252. */
  253. error = saRecvRetry (amfInstance->fd, &amfInstance->message.header, sizeof (struct message_header), MSG_WAITALL | MSG_NOSIGNAL);
  254. if (error != SA_OK) {
  255. goto error_unlock;
  256. }
  257. if (amfInstance->message.header.size > sizeof (struct message_header)) {
  258. error = saRecvRetry (amfInstance->fd, &amfInstance->message.data,
  259. amfInstance->message.header.size - sizeof (struct message_header), MSG_WAITALL | MSG_NOSIGNAL);
  260. if (error != SA_OK) {
  261. goto error_unlock;
  262. }
  263. }
  264. }
  265. /*
  266. * Make copy of callbacks, unlock instance, and call callback
  267. * A risk of this dispatch method is that the callback routines may
  268. * operate at the same time that amfFinalize has been called.
  269. */
  270. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  271. pthread_mutex_unlock (&amfInstance->mutex);
  272. /*
  273. * Dispatch incoming response
  274. */
  275. switch (amfInstance->message.header.id) {
  276. case MESSAGE_RES_AMF_ACTIVATEPOLL:
  277. /*
  278. * This is a do nothing message which the node executive sends
  279. * to activate the file handle in poll when the library has
  280. * queued a message into amfHandle->inq
  281. * The dispatch is ignored for the following two cases:
  282. * 1) setting of timeout to zero for the DISPATCH_ALL case
  283. * 2) expiration of the do loop for the DISPATCH_ONE case
  284. */
  285. ignore_dispatch = 1;
  286. break;
  287. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  288. res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&amfInstance->message;
  289. pthread_mutex_unlock (&amfInstance->mutex);
  290. callbacks.saAmfHealthcheckCallback (
  291. res_amf_healthcheckcallback->invocation,
  292. &res_amf_healthcheckcallback->compName,
  293. res_amf_healthcheckcallback->checkType);
  294. break;
  295. case MESSAGE_RES_AMF_READINESSSTATESETCALLBACK:
  296. res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&amfInstance->message;
  297. callbacks.saAmfReadinessStateSetCallback (
  298. res_amf_readinessstatesetcallback->invocation,
  299. &res_amf_readinessstatesetcallback->compName,
  300. res_amf_readinessstatesetcallback->readinessState);
  301. break;
  302. case MESSAGE_RES_AMF_CSISETCALLBACK:
  303. res_amf_csisetcallback = (struct res_amf_csisetcallback *)&amfInstance->message;
  304. callbacks.saAmfCSISetCallback (
  305. res_amf_csisetcallback->invocation,
  306. &res_amf_csisetcallback->compName,
  307. &res_amf_csisetcallback->csiName,
  308. res_amf_csisetcallback->csiFlags,
  309. &res_amf_csisetcallback->haState,
  310. &res_amf_csisetcallback->activeCompName,
  311. res_amf_csisetcallback->transitionDescriptor);
  312. break;
  313. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  314. res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&amfInstance->message;
  315. callbacks.saAmfCSIRemoveCallback (
  316. res_amf_csiremovecallback->invocation,
  317. &res_amf_csiremovecallback->compName,
  318. &res_amf_csiremovecallback->csiName,
  319. &res_amf_csiremovecallback->csiFlags);
  320. break;
  321. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  322. res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&amfInstance->message;
  323. memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  324. res_amf_protectiongrouptrackcallback->notificationBuffer,
  325. res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  326. callbacks.saAmfProtectionGroupTrackCallback(
  327. &res_amf_protectiongrouptrackcallback->csiName,
  328. res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  329. res_amf_protectiongrouptrackcallback->numberOfItems,
  330. res_amf_protectiongrouptrackcallback->numberOfMembers,
  331. res_amf_protectiongrouptrackcallback->error);
  332. break;
  333. default:
  334. error = SA_ERR_LIBRARY;
  335. goto error_nounlock;
  336. break;
  337. }
  338. /*
  339. * Determine if more messages should be processed
  340. */
  341. switch (dispatchFlags) {
  342. case SA_DISPATCH_ONE:
  343. if (ignore_dispatch) {
  344. ignore_dispatch = 0;
  345. } else {
  346. cont = 0;
  347. }
  348. break;
  349. case SA_DISPATCH_ALL:
  350. if (ignore_dispatch) {
  351. ignore_dispatch = 0;
  352. }
  353. break;
  354. case SA_DISPATCH_BLOCKING:
  355. break;
  356. }
  357. } while (cont);
  358. return (error);
  359. error_unlock:
  360. pthread_mutex_unlock (&amfInstance->mutex);
  361. error_nounlock:
  362. return (error);
  363. }
  364. SaErrorT
  365. saAmfFinalize (
  366. const SaAmfHandleT *amfHandle)
  367. {
  368. struct amfInstance *amfInstance;
  369. SaErrorT error;
  370. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET | HANDLECONVERT_DONTUNLOCKDB, 0);
  371. if (error != SA_OK) {
  372. return (error);
  373. }
  374. shutdown (amfInstance->fd, 0);
  375. close (amfInstance->fd);
  376. free (amfInstance->inq.items);
  377. error = saHandleRemove (&amfHandleDatabase, *amfHandle);
  378. pthread_mutex_unlock (&amfInstance->mutex);
  379. saHandleUnlockDatabase (&amfHandleDatabase);
  380. return (error);
  381. }
  382. SaErrorT
  383. saAmfComponentRegister (
  384. const SaAmfHandleT *amfHandle,
  385. const SaNameT *compName,
  386. const SaNameT *proxyCompName)
  387. {
  388. struct amfInstance *amfInstance;
  389. SaErrorT error;
  390. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  391. struct res_lib_amf_componentregister *res_lib_amf_componentregister;
  392. req_lib_amf_componentregister.header.magic = MESSAGE_MAGIC;
  393. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  394. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  395. memcpy (&req_lib_amf_componentregister.compName, compName, sizeof (SaNameT));
  396. if (proxyCompName) {
  397. memcpy (&req_lib_amf_componentregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  398. } else {
  399. memset (&req_lib_amf_componentregister.proxyCompName, 0, sizeof (SaNameT));
  400. }
  401. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, 0);
  402. if (error != SA_OK) {
  403. return (error);
  404. }
  405. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentregister, sizeof (struct req_lib_amf_componentregister), MSG_NOSIGNAL);
  406. if (error != SA_OK) {
  407. goto error_unlock;
  408. }
  409. /*
  410. * Search for COMPONENTREGISTER responses and queue any
  411. * messages that dont match in this handle's inq.
  412. * This must be done to avoid dropping async messages
  413. * during this sync message retrieval
  414. */
  415. error = saRecvQueue (amfInstance->fd, &amfInstance->message,
  416. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTREGISTER);
  417. if (error != SA_OK) {
  418. goto error_unlock;
  419. }
  420. res_lib_amf_componentregister = (struct res_lib_amf_componentregister *)&amfInstance->message;
  421. if (res_lib_amf_componentregister->error == SA_OK) {
  422. amfInstance->compRegistered = 1;
  423. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  424. }
  425. error = res_lib_amf_componentregister->error;
  426. error_unlock:
  427. pthread_mutex_unlock (&amfInstance->mutex);
  428. return (error);
  429. }
  430. SaErrorT
  431. saAmfComponentUnregister (
  432. const SaAmfHandleT *amfHandle,
  433. const SaNameT *compName,
  434. const SaNameT *proxyCompName)
  435. {
  436. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  437. struct res_lib_amf_componentunregister *res_lib_amf_componentunregister;
  438. struct amfInstance *amfInstance;
  439. SaErrorT error;
  440. req_lib_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  441. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  442. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  443. memcpy (&req_lib_amf_componentunregister.compName, compName, sizeof (SaNameT));
  444. if (proxyCompName) {
  445. memcpy (&req_lib_amf_componentunregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  446. } else {
  447. memset (&req_lib_amf_componentunregister.proxyCompName, 0, sizeof (SaNameT));
  448. }
  449. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, 0);
  450. if (error != SA_OK) {
  451. return (error);
  452. }
  453. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentunregister,
  454. sizeof (struct req_lib_amf_componentunregister), MSG_NOSIGNAL);
  455. if (error != SA_OK) {
  456. goto error_unlock;
  457. }
  458. /*
  459. * Search for COMPONENTUNREGISTER responses and queue any
  460. * messages that dont match in this handle's inq.
  461. * This must be done to avoid dropping async messages
  462. * during this sync message retrieval
  463. */
  464. error = saRecvQueue (amfInstance->fd, &amfInstance->message,
  465. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTUNREGISTER);
  466. if (error != SA_OK) {
  467. goto error_unlock;
  468. }
  469. res_lib_amf_componentunregister = (struct res_lib_amf_componentunregister *)&amfInstance->message;
  470. if (res_lib_amf_componentunregister->error == SA_OK) {
  471. amfInstance->compRegistered = 0;
  472. }
  473. error = res_lib_amf_componentunregister->error;
  474. error_unlock:
  475. pthread_mutex_unlock (&amfInstance->mutex);
  476. return (error);
  477. }
  478. SaErrorT
  479. saAmfCompNameGet (
  480. const SaAmfHandleT *amfHandle,
  481. SaNameT *compName)
  482. {
  483. struct amfInstance *amfInstance;
  484. SaErrorT error;
  485. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, 0);
  486. if (error != SA_OK) {
  487. return (error);
  488. }
  489. if (amfInstance->compRegistered == 0) {
  490. return (SA_ERR_NOT_EXIST);
  491. }
  492. memcpy (compName, &amfInstance->compName, sizeof (SaNameT));
  493. pthread_mutex_unlock (&amfInstance->mutex);
  494. return (SA_OK);
  495. }
  496. SaErrorT
  497. saAmfReadinessStateGet (
  498. const SaNameT *compName,
  499. SaAmfReadinessStateT *readinessState)
  500. {
  501. int fd;
  502. SaErrorT error;
  503. struct req_amf_readinessstateget req_amf_readinessstateget;
  504. struct res_amf_readinessstateget *res_amf_readinessstateget;
  505. struct message_overlay message;
  506. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  507. if (error != SA_OK) {
  508. goto exit_noclose;
  509. }
  510. req_amf_readinessstateget.header.magic = MESSAGE_MAGIC;
  511. req_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  512. req_amf_readinessstateget.header.size = sizeof (struct req_amf_readinessstateget);
  513. memcpy (&req_amf_readinessstateget.compName, compName, sizeof (SaNameT));
  514. error = saSendRetry (fd, &req_amf_readinessstateget,
  515. sizeof (struct req_amf_readinessstateget), MSG_NOSIGNAL);
  516. if (error != SA_OK) {
  517. goto exit_close;
  518. }
  519. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_READINESSSTATEGET);
  520. res_amf_readinessstateget = (struct res_amf_readinessstateget *)&message;
  521. if (error == SA_OK) {
  522. memcpy (readinessState, &res_amf_readinessstateget->readinessState,
  523. sizeof (SaAmfReadinessStateT));
  524. error = res_amf_readinessstateget->error;
  525. }
  526. exit_close:
  527. close (fd);
  528. exit_noclose:
  529. return (error);
  530. }
  531. SaErrorT
  532. saAmfStoppingComplete (
  533. SaInvocationT invocation,
  534. SaErrorT error)
  535. {
  536. struct req_amf_stoppingcomplete req_amf_stoppingcomplete;
  537. int fd;
  538. SaErrorT errorResult;
  539. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  540. if (errorResult != SA_OK) {
  541. goto exit_noclose;
  542. }
  543. req_amf_stoppingcomplete.header.magic = MESSAGE_MAGIC;
  544. req_amf_stoppingcomplete.header.id = MESSAGE_REQ_AMF_STOPPINGCOMPLETE;
  545. req_amf_stoppingcomplete.header.size = sizeof (struct req_amf_stoppingcomplete);
  546. req_amf_stoppingcomplete.invocation = invocation;
  547. req_amf_stoppingcomplete.error = error;
  548. errorResult = saSendRetry (fd, &req_amf_stoppingcomplete,
  549. sizeof (struct req_amf_stoppingcomplete), MSG_NOSIGNAL);
  550. close (fd);
  551. exit_noclose:
  552. return (errorResult);
  553. }
  554. SaErrorT
  555. saAmfHAStateGet (
  556. const SaNameT *compName,
  557. const SaNameT *csiName,
  558. SaAmfHAStateT *haState) {
  559. struct req_amf_hastateget req_amf_hastateget;
  560. struct res_amf_hastateget *res_amf_hastateget;
  561. int fd;
  562. SaErrorT error;
  563. struct message_overlay message;
  564. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  565. if (error != SA_OK) {
  566. goto exit_noclose;
  567. }
  568. req_amf_hastateget.header.magic = MESSAGE_MAGIC;
  569. req_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  570. req_amf_hastateget.header.size = sizeof (struct req_amf_hastateget);
  571. memcpy (&req_amf_hastateget.compName, compName, sizeof (SaNameT));
  572. memcpy (&req_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  573. error = saSendRetry (fd, &req_amf_hastateget,
  574. sizeof (struct req_amf_hastateget), MSG_NOSIGNAL);
  575. if (error != SA_OK) {
  576. goto exit_close;
  577. }
  578. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_HASTATEGET);
  579. res_amf_hastateget = (struct res_amf_hastateget *)&message;
  580. if (error != SA_OK) {
  581. goto exit_close;
  582. }
  583. error = res_amf_hastateget->error;
  584. if (error == SA_OK) {
  585. memcpy (haState, &res_amf_hastateget->haState, sizeof (SaAmfHAStateT));
  586. }
  587. exit_close:
  588. close (fd);
  589. exit_noclose:
  590. return (error);
  591. }
  592. SaErrorT
  593. saAmfProtectionGroupTrackStart (
  594. const SaAmfHandleT *amfHandle,
  595. const SaNameT *csiName,
  596. SaUint8T trackFlags,
  597. const SaAmfProtectionGroupNotificationT *notificationBuffer,
  598. SaUint32T numberOfItems) {
  599. struct amfInstance *amfInstance;
  600. struct req_amf_protectiongrouptrackstart req_amf_protectiongrouptrackstart;
  601. struct res_amf_protectiongrouptrackstart *res_amf_protectiongrouptrackstart;
  602. SaErrorT error;
  603. req_amf_protectiongrouptrackstart.header.magic = MESSAGE_MAGIC;
  604. req_amf_protectiongrouptrackstart.header.size = sizeof (struct req_amf_protectiongrouptrackstart);
  605. req_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  606. memcpy (&req_amf_protectiongrouptrackstart.csiName, csiName, sizeof (SaNameT));
  607. req_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  608. req_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  609. req_amf_protectiongrouptrackstart.numberOfItems = numberOfItems;
  610. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, 0);
  611. if (error != SA_OK) {
  612. return (error);
  613. }
  614. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstart,
  615. sizeof (struct req_amf_protectiongrouptrackstart), MSG_NOSIGNAL);
  616. if (error != SA_OK) {
  617. goto error_unlock;
  618. }
  619. error = saRecvQueue (amfInstance->fd, &amfInstance->message,
  620. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART);
  621. pthread_mutex_unlock (&amfInstance->mutex);
  622. res_amf_protectiongrouptrackstart = (struct res_amf_protectiongrouptrackstart *)&amfInstance->message;
  623. if (error == SA_OK) {
  624. return (res_amf_protectiongrouptrackstart->error);
  625. }
  626. return (error);
  627. error_unlock:
  628. pthread_mutex_unlock (&amfInstance->mutex);
  629. return (error);
  630. }
  631. SaErrorT
  632. saAmfProtectionGroupTrackStop (
  633. const SaAmfHandleT *amfHandle,
  634. const SaNameT *csiName) {
  635. struct amfInstance *amfInstance;
  636. struct req_amf_protectiongrouptrackstop req_amf_protectiongrouptrackstop;
  637. struct res_amf_protectiongrouptrackstop *res_amf_protectiongrouptrackstop;
  638. SaErrorT error;
  639. req_amf_protectiongrouptrackstop.header.magic = MESSAGE_MAGIC;
  640. req_amf_protectiongrouptrackstop.header.size = sizeof (struct req_amf_protectiongrouptrackstop);
  641. req_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  642. memcpy (&req_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  643. error = saHandleConvert (&amfHandleDatabase, *amfHandle, (void *)&amfInstance, AMFINSTANCE_MUTEX_OFFSET, 0);
  644. if (error != SA_OK) {
  645. return (error);
  646. }
  647. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstop,
  648. sizeof (struct req_amf_protectiongrouptrackstop), MSG_NOSIGNAL);
  649. if (error != SA_OK) {
  650. goto error_unlock;
  651. }
  652. error = saRecvQueue (amfInstance->fd, &amfInstance->message,
  653. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP);
  654. pthread_mutex_unlock (&amfInstance->mutex);
  655. res_amf_protectiongrouptrackstop = (struct res_amf_protectiongrouptrackstop *)&amfInstance->message;
  656. if (error == SA_OK) {
  657. return (res_amf_protectiongrouptrackstop->error);
  658. }
  659. return (error);
  660. error_unlock:
  661. pthread_mutex_unlock (&amfInstance->mutex);
  662. return (error);
  663. }
  664. SaErrorT
  665. saAmfErrorReport (
  666. const SaNameT *reportingComponent,
  667. const SaNameT *erroneousComponent,
  668. SaTimeT errorDetectionTime,
  669. const SaAmfErrorDescriptorT *errorDescriptor,
  670. const SaAmfAdditionalDataT *additionalData) {
  671. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  672. struct res_lib_amf_errorreport *res_lib_amf_errorreport;
  673. struct message_overlay message;
  674. int fd;
  675. SaErrorT error;
  676. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  677. if (error != SA_OK) {
  678. goto exit_noclose;
  679. }
  680. req_lib_amf_errorreport.header.magic = MESSAGE_MAGIC;
  681. req_lib_amf_errorreport.header.id = MESSAGE_REQ_AMF_ERRORREPORT;
  682. req_lib_amf_errorreport.header.size = sizeof (struct req_lib_amf_errorreport);
  683. memcpy (&req_lib_amf_errorreport.reportingComponent, reportingComponent, sizeof (SaNameT));
  684. memcpy (&req_lib_amf_errorreport.erroneousComponent, erroneousComponent, sizeof (SaNameT));
  685. req_lib_amf_errorreport.errorDetectionTime = errorDetectionTime;
  686. memcpy (&req_lib_amf_errorreport.errorDescriptor,
  687. errorDescriptor, sizeof (SaAmfErrorDescriptorT));
  688. /* TODO this is wrong, and needs some thinking
  689. memcpy (&req_lib_amf_errorreport.additionalData,
  690. additionalData, sizeof (SaAmfAdditionalDataT));
  691. */
  692. error = saSendRetry (fd, &req_lib_amf_errorreport,
  693. sizeof (struct req_lib_amf_errorreport), MSG_NOSIGNAL);
  694. /*
  695. * Get response from executive and respond to user application
  696. */
  697. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_ERRORREPORT);
  698. if (error != SA_OK) {
  699. goto exit_close;
  700. }
  701. res_lib_amf_errorreport = (struct res_lib_amf_errorreport *)&message;
  702. error = res_lib_amf_errorreport->error;
  703. exit_close:
  704. close (fd);
  705. exit_noclose:
  706. return (error);
  707. }
  708. SaErrorT
  709. saAmfErrorCancelAll (
  710. const SaNameT *compName) {
  711. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  712. struct res_lib_amf_errorcancelall *res_lib_amf_errorcancelall;
  713. struct message_overlay message;
  714. int fd;
  715. SaErrorT error;
  716. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  717. if (error != SA_OK) {
  718. goto exit_noclose;
  719. }
  720. req_lib_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  721. req_lib_amf_errorcancelall.header.id = MESSAGE_REQ_AMF_ERRORCANCELALL;
  722. req_lib_amf_errorcancelall.header.size = sizeof (struct req_lib_amf_errorcancelall);
  723. memcpy (&req_lib_amf_errorcancelall.compName, compName, sizeof (SaNameT));
  724. error = saSendRetry (fd, &req_lib_amf_errorcancelall,
  725. sizeof (struct req_lib_amf_errorcancelall), MSG_NOSIGNAL);
  726. /*
  727. * Get response from executive and respond to user application
  728. */
  729. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_ERRORCANCELALL);
  730. if (error != SA_OK) {
  731. goto exit_close;
  732. }
  733. res_lib_amf_errorcancelall = (struct res_lib_amf_errorcancelall *)&message;
  734. error = res_lib_amf_errorcancelall->error;
  735. exit_close:
  736. close (fd);
  737. exit_noclose:
  738. return (error);
  739. }
  740. SaErrorT
  741. saAmfComponentCapabilityModelGet (
  742. const SaNameT *compName,
  743. SaAmfComponentCapabilityModelT *componentCapabilityModel)
  744. {
  745. int fd;
  746. SaErrorT error;
  747. struct req_amf_componentcapabilitymodelget req_amf_componentcapabilitymodelget;
  748. struct res_amf_componentcapabilitymodelget *res_amf_componentcapabilitymodelget;
  749. struct message_overlay message;
  750. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  751. if (error != SA_OK) {
  752. goto exit_noclose;
  753. }
  754. req_amf_componentcapabilitymodelget.header.magic = MESSAGE_MAGIC;
  755. req_amf_componentcapabilitymodelget.header.id = MESSAGE_REQ_AMF_COMPONENTCAPABILITYMODELGET;
  756. req_amf_componentcapabilitymodelget.header.size = sizeof (struct req_amf_componentcapabilitymodelget);
  757. memcpy (&req_amf_componentcapabilitymodelget.compName, compName, sizeof (SaNameT));
  758. error = saSendRetry (fd, &req_amf_componentcapabilitymodelget,
  759. sizeof (struct req_amf_componentcapabilitymodelget), MSG_NOSIGNAL);
  760. if (error != SA_OK) {
  761. goto exit_close;
  762. }
  763. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET);
  764. res_amf_componentcapabilitymodelget = (struct res_amf_componentcapabilitymodelget *)&message;
  765. if (error == SA_OK) {
  766. memcpy (componentCapabilityModel,
  767. &res_amf_componentcapabilitymodelget->componentCapabilityModel,
  768. sizeof (SaAmfComponentCapabilityModelT));
  769. error = res_amf_componentcapabilitymodelget->error;
  770. }
  771. exit_close:
  772. close (fd);
  773. exit_noclose:
  774. return (error);
  775. }
  776. SaErrorT
  777. saAmfPendingOperationGet (
  778. const SaNameT *compName,
  779. SaAmfPendingOperationFlagsT *pendingOperationFlags) {
  780. *pendingOperationFlags = 0;
  781. return (SA_OK);
  782. }
  783. SaErrorT
  784. saAmfResponse (
  785. SaInvocationT invocation,
  786. SaErrorT error)
  787. {
  788. struct req_amf_response req_amf_response;
  789. int fd;
  790. SaErrorT errorResult;
  791. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  792. if (errorResult != SA_OK) {
  793. goto exit_noclose;
  794. }
  795. req_amf_response.header.magic = MESSAGE_MAGIC;
  796. req_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  797. req_amf_response.header.size = sizeof (struct req_amf_response);
  798. req_amf_response.invocation = invocation;
  799. req_amf_response.error = error;
  800. errorResult = saSendRetry (fd, &req_amf_response,
  801. sizeof (struct req_amf_response), MSG_NOSIGNAL);
  802. close (fd);
  803. exit_noclose:
  804. return (errorResult);
  805. }