amf.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <errno.h>
  39. #include <signal.h>
  40. #include <pthread.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <sys/select.h>
  44. #include <sys/un.h>
  45. #include "../include/ais_types.h"
  46. #include "../include/ais_amf.h"
  47. #include "../include/ais_msg.h"
  48. #include "util.h"
  49. struct message_overlay {
  50. struct message_header header;
  51. char data[4096];
  52. };
  53. /*
  54. * Data structure for instance data
  55. */
  56. struct amfInstance {
  57. int fd;
  58. SaAmfCallbacksT callbacks;
  59. struct queue inq;
  60. SaNameT compName;
  61. int compRegistered;
  62. int finalize;
  63. pthread_mutex_t mutex;
  64. };
  65. static void amfHandleInstanceDestructor (void *);
  66. /*
  67. * All instances in one database
  68. */
  69. static struct saHandleDatabase amfHandleDatabase = {
  70. handleCount: 0,
  71. handles: 0,
  72. mutex: PTHREAD_MUTEX_INITIALIZER,
  73. handleInstanceDestructor: amfHandleInstanceDestructor
  74. };
  75. /*
  76. * Versions supported
  77. */
  78. static SaVersionT amfVersionsSupported[] = {
  79. { 'A', 1, 1 },
  80. { 'a', 1, 1 }
  81. };
  82. static struct saVersionDatabase amfVersionDatabase = {
  83. sizeof (amfVersionsSupported) / sizeof (SaVersionT),
  84. amfVersionsSupported
  85. };
  86. /*
  87. * Implementation
  88. */
  89. void amfHandleInstanceDestructor (void *instance)
  90. {
  91. struct amfInstance *amfInstance = (struct amfInstance *)instance;
  92. if (amfInstance->fd != -1) {
  93. shutdown (amfInstance->fd, 0);
  94. close (amfInstance->fd);
  95. }
  96. if (amfInstance->inq.items) {
  97. free (amfInstance->inq.items);
  98. }
  99. }
  100. SaErrorT
  101. saAmfInitialize (
  102. SaAmfHandleT *amfHandle,
  103. const SaAmfCallbacksT *amfCallbacks,
  104. const SaVersionT *version)
  105. {
  106. struct amfInstance *amfInstance;
  107. SaErrorT error = SA_OK;
  108. error = saVersionVerify (&amfVersionDatabase, version);
  109. if (error != SA_OK) {
  110. goto error_no_destroy;
  111. }
  112. error = saHandleCreate (&amfHandleDatabase, sizeof (struct amfInstance), amfHandle);
  113. if (error != SA_OK) {
  114. goto error_no_destroy;
  115. }
  116. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  117. if (error != SA_OK) {
  118. goto error_destroy;
  119. }
  120. amfInstance->fd = -1;
  121. /*
  122. * An inq is needed to store async messages while waiting for a
  123. * sync response
  124. */
  125. error = saQueueInit (&amfInstance->inq, 512, sizeof (void *));
  126. if (error != SA_OK) {
  127. goto error_put_destroy;
  128. }
  129. error = saServiceConnect (&amfInstance->fd, MESSAGE_REQ_AMF_INIT);
  130. if (error != SA_OK) {
  131. goto error_put_destroy;
  132. }
  133. memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT));
  134. pthread_mutex_init (&amfInstance->mutex, NULL);
  135. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  136. return (SA_OK);
  137. error_put_destroy:
  138. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  139. error_destroy:
  140. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  141. error_no_destroy:
  142. return (error);
  143. }
  144. SaErrorT
  145. saAmfSelectionObjectGet (
  146. const SaAmfHandleT *amfHandle,
  147. SaSelectionObjectT *selectionObject)
  148. {
  149. struct amfInstance *amfInstance;
  150. SaErrorT error;
  151. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  152. if (error != SA_OK) {
  153. return (error);
  154. }
  155. *selectionObject = amfInstance->fd;
  156. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  157. return (SA_OK);
  158. }
  159. SaErrorT
  160. saAmfDispatch (
  161. const SaAmfHandleT *amfHandle,
  162. SaDispatchFlagsT dispatchFlags)
  163. {
  164. struct pollfd ufds;
  165. int timeout = -1;
  166. SaErrorT error;
  167. int dispatch_avail;
  168. struct amfInstance *amfInstance;
  169. SaAmfCallbacksT callbacks;
  170. struct res_amf_healthcheckcallback *res_amf_healthcheckcallback;
  171. struct res_amf_readinessstatesetcallback *res_amf_readinessstatesetcallback;
  172. struct res_amf_csisetcallback *res_amf_csisetcallback;
  173. struct res_amf_csiremovecallback *res_amf_csiremovecallback;
  174. struct res_amf_protectiongrouptrackcallback *res_amf_protectiongrouptrackcallback;
  175. struct message_header **queue_msg;
  176. struct message_header *msg;
  177. int empty;
  178. int ignore_dispatch = 0;
  179. int cont = 1; /* always continue do loop except when set to 0 */
  180. int poll_fd;
  181. struct message_overlay dispatch_data;
  182. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle,
  183. (void *)&amfInstance);
  184. if (error != SA_OK) {
  185. return (error);
  186. }
  187. /*
  188. * Timeout instantly for SA_DISPATCH_ALL
  189. */
  190. if (dispatchFlags == SA_DISPATCH_ALL) {
  191. timeout = 0;
  192. }
  193. do {
  194. poll_fd = amfInstance->fd;
  195. /*
  196. * Read data directly from socket
  197. */
  198. ufds.fd = poll_fd;
  199. ufds.events = POLLIN;
  200. ufds.revents = 0;
  201. error = saPollRetry (&ufds, 1, timeout);
  202. if (error != SA_OK) {
  203. goto error_nounlock;
  204. }
  205. pthread_mutex_lock (&amfInstance->mutex);
  206. /*
  207. * Handle has been finalized in another thread
  208. */
  209. if (amfInstance->finalize == 1) {
  210. error = SA_OK;
  211. pthread_mutex_unlock (&amfInstance->mutex);
  212. goto error_unlock;
  213. }
  214. dispatch_avail = ufds.revents & POLLIN;
  215. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  216. pthread_mutex_unlock (&amfInstance->mutex);
  217. break; /* exit do while cont is 1 loop */
  218. } else
  219. if (dispatch_avail == 0) {
  220. pthread_mutex_unlock (&amfInstance->mutex);
  221. continue; /* next poll */
  222. }
  223. saQueueIsEmpty(&amfInstance->inq, &empty);
  224. if (empty == 0) {
  225. /*
  226. * Queue is not empty, read data from queue
  227. */
  228. saQueueItemGet (&amfInstance->inq, (void *)&queue_msg);
  229. msg = *queue_msg;
  230. memcpy (&dispatch_data, msg, msg->size);
  231. saQueueItemRemove (&amfInstance->inq);
  232. } else {
  233. /*
  234. * Queue empty, read response from socket
  235. */
  236. error = saRecvRetry (amfInstance->fd, &dispatch_data.header,
  237. sizeof (struct message_header), MSG_WAITALL | MSG_NOSIGNAL);
  238. if (error != SA_OK) {
  239. goto error_unlock;
  240. }
  241. if (dispatch_data.header.size > sizeof (struct message_header)) {
  242. error = saRecvRetry (amfInstance->fd, &dispatch_data.data,
  243. dispatch_data.header.size - sizeof (struct message_header),
  244. MSG_WAITALL | MSG_NOSIGNAL);
  245. if (error != SA_OK) {
  246. goto error_unlock;
  247. }
  248. }
  249. }
  250. /*
  251. * Make copy of callbacks, message data, unlock instance, and call callback
  252. * A risk of this dispatch method is that the callback routines may
  253. * operate at the same time that amfFinalize has been called in another thread.
  254. */
  255. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  256. pthread_mutex_unlock (&amfInstance->mutex);
  257. /*
  258. * Dispatch incoming response
  259. */
  260. switch (dispatch_data.header.id) {
  261. case MESSAGE_RES_LIB_ACTIVATEPOLL:
  262. /*
  263. * This is a do nothing message which the node executive sends
  264. * to activate the file amfHandle in poll when the library has
  265. * queued a message into amfHandle->inq
  266. * The dispatch is ignored for the following two cases:
  267. * 1) setting of timeout to zero for the DISPATCH_ALL case
  268. * 2) expiration of the do loop for the DISPATCH_ONE case
  269. */
  270. ignore_dispatch = 1;
  271. break;
  272. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  273. res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&dispatch_data;
  274. callbacks.saAmfHealthcheckCallback (
  275. res_amf_healthcheckcallback->invocation,
  276. &res_amf_healthcheckcallback->compName,
  277. res_amf_healthcheckcallback->checkType);
  278. break;
  279. case MESSAGE_RES_AMF_READINESSSTATESETCALLBACK:
  280. res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&dispatch_data;
  281. callbacks.saAmfReadinessStateSetCallback (
  282. res_amf_readinessstatesetcallback->invocation,
  283. &res_amf_readinessstatesetcallback->compName,
  284. res_amf_readinessstatesetcallback->readinessState);
  285. break;
  286. case MESSAGE_RES_AMF_CSISETCALLBACK:
  287. res_amf_csisetcallback = (struct res_amf_csisetcallback *)&dispatch_data;
  288. callbacks.saAmfCSISetCallback (
  289. res_amf_csisetcallback->invocation,
  290. &res_amf_csisetcallback->compName,
  291. &res_amf_csisetcallback->csiName,
  292. res_amf_csisetcallback->csiFlags,
  293. &res_amf_csisetcallback->haState,
  294. &res_amf_csisetcallback->activeCompName,
  295. res_amf_csisetcallback->transitionDescriptor);
  296. break;
  297. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  298. res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&dispatch_data;
  299. callbacks.saAmfCSIRemoveCallback (
  300. res_amf_csiremovecallback->invocation,
  301. &res_amf_csiremovecallback->compName,
  302. &res_amf_csiremovecallback->csiName,
  303. &res_amf_csiremovecallback->csiFlags);
  304. break;
  305. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  306. res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&dispatch_data;
  307. memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  308. res_amf_protectiongrouptrackcallback->notificationBuffer,
  309. res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  310. callbacks.saAmfProtectionGroupTrackCallback(
  311. &res_amf_protectiongrouptrackcallback->csiName,
  312. res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  313. res_amf_protectiongrouptrackcallback->numberOfItems,
  314. res_amf_protectiongrouptrackcallback->numberOfMembers,
  315. res_amf_protectiongrouptrackcallback->error);
  316. break;
  317. default:
  318. error = SA_ERR_LIBRARY;
  319. goto error_nounlock;
  320. break;
  321. }
  322. /*
  323. * Determine if more messages should be processed
  324. */
  325. switch (dispatchFlags) {
  326. case SA_DISPATCH_ONE:
  327. if (ignore_dispatch) {
  328. ignore_dispatch = 0;
  329. } else {
  330. cont = 0;
  331. }
  332. break;
  333. case SA_DISPATCH_ALL:
  334. if (ignore_dispatch) {
  335. ignore_dispatch = 0;
  336. }
  337. break;
  338. case SA_DISPATCH_BLOCKING:
  339. break;
  340. }
  341. } while (cont);
  342. error_unlock:
  343. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  344. error_nounlock:
  345. return (error);
  346. }
  347. SaErrorT
  348. saAmfFinalize (
  349. const SaAmfHandleT *amfHandle)
  350. {
  351. struct amfInstance *amfInstance;
  352. SaErrorT error;
  353. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  354. if (error != SA_OK) {
  355. return (error);
  356. }
  357. pthread_mutex_lock (&amfInstance->mutex);
  358. /*
  359. * Another thread has already started finalizing
  360. */
  361. if (amfInstance->finalize) {
  362. pthread_mutex_unlock (&amfInstance->mutex);
  363. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  364. return (SA_ERR_BAD_HANDLE);
  365. }
  366. amfInstance->finalize = 1;
  367. saActivatePoll (amfInstance->fd);
  368. pthread_mutex_unlock (&amfInstance->mutex);
  369. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  370. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  371. return (error);
  372. }
  373. SaErrorT
  374. saAmfComponentRegister (
  375. const SaAmfHandleT *amfHandle,
  376. const SaNameT *compName,
  377. const SaNameT *proxyCompName)
  378. {
  379. struct amfInstance *amfInstance;
  380. SaErrorT error;
  381. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  382. struct res_lib_amf_componentregister *res_lib_amf_componentregister;
  383. struct message_overlay message;
  384. req_lib_amf_componentregister.header.magic = MESSAGE_MAGIC;
  385. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  386. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  387. memcpy (&req_lib_amf_componentregister.compName, compName, sizeof (SaNameT));
  388. if (proxyCompName) {
  389. memcpy (&req_lib_amf_componentregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  390. } else {
  391. memset (&req_lib_amf_componentregister.proxyCompName, 0, sizeof (SaNameT));
  392. }
  393. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  394. if (error != SA_OK) {
  395. return (error);
  396. }
  397. pthread_mutex_lock (&amfInstance->mutex);
  398. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentregister, sizeof (struct req_lib_amf_componentregister), MSG_NOSIGNAL);
  399. if (error != SA_OK) {
  400. goto error_unlock;
  401. }
  402. /*
  403. * Search for COMPONENTREGISTER responses and queue any
  404. * messages that dont match in this amfHandle's inq.
  405. * This must be done to avoid dropping async messages
  406. * during this sync message retrieval
  407. */
  408. error = saRecvQueue (amfInstance->fd, &message,
  409. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTREGISTER);
  410. if (error != SA_OK) {
  411. goto error_unlock;
  412. }
  413. res_lib_amf_componentregister = (struct res_lib_amf_componentregister *)&message;
  414. if (res_lib_amf_componentregister->error == SA_OK) {
  415. amfInstance->compRegistered = 1;
  416. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  417. }
  418. error = res_lib_amf_componentregister->error;
  419. error_unlock:
  420. pthread_mutex_unlock (&amfInstance->mutex);
  421. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  422. return (error);
  423. }
  424. SaErrorT
  425. saAmfComponentUnregister (
  426. const SaAmfHandleT *amfHandle,
  427. const SaNameT *compName,
  428. const SaNameT *proxyCompName)
  429. {
  430. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  431. struct res_lib_amf_componentunregister *res_lib_amf_componentunregister;
  432. struct amfInstance *amfInstance;
  433. struct message_overlay message;
  434. SaErrorT error;
  435. req_lib_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  436. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  437. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  438. memcpy (&req_lib_amf_componentunregister.compName, compName, sizeof (SaNameT));
  439. if (proxyCompName) {
  440. memcpy (&req_lib_amf_componentunregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  441. } else {
  442. memset (&req_lib_amf_componentunregister.proxyCompName, 0, sizeof (SaNameT));
  443. }
  444. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  445. if (error != SA_OK) {
  446. return (error);
  447. }
  448. pthread_mutex_lock (&amfInstance->mutex);
  449. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentunregister,
  450. sizeof (struct req_lib_amf_componentunregister), MSG_NOSIGNAL);
  451. if (error != SA_OK) {
  452. goto error_unlock;
  453. }
  454. /*
  455. * Search for COMPONENTUNREGISTER responses and queue any
  456. * messages that dont match in this amfHandle's inq.
  457. * This must be done to avoid dropping async messages
  458. * during this sync message retrieval
  459. */
  460. error = saRecvQueue (amfInstance->fd, &message,
  461. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTUNREGISTER);
  462. if (error != SA_OK) {
  463. goto error_unlock;
  464. }
  465. res_lib_amf_componentunregister = (struct res_lib_amf_componentunregister *)&message;
  466. if (res_lib_amf_componentunregister->error == SA_OK) {
  467. amfInstance->compRegistered = 0;
  468. }
  469. error = res_lib_amf_componentunregister->error;
  470. error_unlock:
  471. pthread_mutex_unlock (&amfInstance->mutex);
  472. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  473. return (error);
  474. }
  475. SaErrorT
  476. saAmfCompNameGet (
  477. const SaAmfHandleT *amfHandle,
  478. SaNameT *compName)
  479. {
  480. struct amfInstance *amfInstance;
  481. SaErrorT error;
  482. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  483. if (error != SA_OK) {
  484. return (error);
  485. }
  486. pthread_mutex_lock (&amfInstance->mutex);
  487. if (amfInstance->compRegistered == 0) {
  488. pthread_mutex_unlock (&amfInstance->mutex);
  489. return (SA_ERR_NOT_EXIST);
  490. }
  491. memcpy (compName, &amfInstance->compName, sizeof (SaNameT));
  492. pthread_mutex_unlock (&amfInstance->mutex);
  493. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  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. struct message_overlay message;
  603. SaErrorT error;
  604. req_amf_protectiongrouptrackstart.header.magic = MESSAGE_MAGIC;
  605. req_amf_protectiongrouptrackstart.header.size = sizeof (struct req_amf_protectiongrouptrackstart);
  606. req_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  607. memcpy (&req_amf_protectiongrouptrackstart.csiName, csiName, sizeof (SaNameT));
  608. req_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  609. req_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  610. req_amf_protectiongrouptrackstart.numberOfItems = numberOfItems;
  611. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  612. if (error != SA_OK) {
  613. return (error);
  614. }
  615. pthread_mutex_lock (&amfInstance->mutex);
  616. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstart,
  617. sizeof (struct req_amf_protectiongrouptrackstart), MSG_NOSIGNAL);
  618. if (error != SA_OK) {
  619. goto error_unlock;
  620. }
  621. error = saRecvQueue (amfInstance->fd, &message,
  622. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART);
  623. res_amf_protectiongrouptrackstart = (struct res_amf_protectiongrouptrackstart *)&message;
  624. error = res_amf_protectiongrouptrackstart->error;
  625. error_unlock:
  626. pthread_mutex_unlock (&amfInstance->mutex);
  627. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  628. return (error);
  629. }
  630. SaErrorT
  631. saAmfProtectionGroupTrackStop (
  632. const SaAmfHandleT *amfHandle,
  633. const SaNameT *csiName) {
  634. struct amfInstance *amfInstance;
  635. struct req_amf_protectiongrouptrackstop req_amf_protectiongrouptrackstop;
  636. struct res_amf_protectiongrouptrackstop *res_amf_protectiongrouptrackstop;
  637. struct message_overlay message;
  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 = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  644. if (error != SA_OK) {
  645. return (error);
  646. }
  647. pthread_mutex_lock (&amfInstance->mutex);
  648. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstop,
  649. sizeof (struct req_amf_protectiongrouptrackstop), MSG_NOSIGNAL);
  650. if (error != SA_OK) {
  651. goto error_unlock;
  652. }
  653. error = saRecvQueue (amfInstance->fd, &message,
  654. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP);
  655. res_amf_protectiongrouptrackstop = (struct res_amf_protectiongrouptrackstop *)&message;
  656. error = res_amf_protectiongrouptrackstop->error;
  657. error_unlock:
  658. pthread_mutex_unlock (&amfInstance->mutex);
  659. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  660. return (error);
  661. }
  662. SaErrorT
  663. saAmfErrorReport (
  664. const SaNameT *reportingComponent,
  665. const SaNameT *erroneousComponent,
  666. SaTimeT errorDetectionTime,
  667. const SaAmfErrorDescriptorT *errorDescriptor,
  668. const SaAmfAdditionalDataT *additionalData) {
  669. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  670. struct res_lib_amf_errorreport *res_lib_amf_errorreport;
  671. struct message_overlay message;
  672. int fd;
  673. SaErrorT error;
  674. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  675. if (error != SA_OK) {
  676. goto exit_noclose;
  677. }
  678. req_lib_amf_errorreport.header.magic = MESSAGE_MAGIC;
  679. req_lib_amf_errorreport.header.id = MESSAGE_REQ_AMF_ERRORREPORT;
  680. req_lib_amf_errorreport.header.size = sizeof (struct req_lib_amf_errorreport);
  681. memcpy (&req_lib_amf_errorreport.reportingComponent, reportingComponent, sizeof (SaNameT));
  682. memcpy (&req_lib_amf_errorreport.erroneousComponent, erroneousComponent, sizeof (SaNameT));
  683. req_lib_amf_errorreport.errorDetectionTime = errorDetectionTime;
  684. memcpy (&req_lib_amf_errorreport.errorDescriptor,
  685. errorDescriptor, sizeof (SaAmfErrorDescriptorT));
  686. /* TODO this is wrong, and needs some thinking
  687. memcpy (&req_lib_amf_errorreport.additionalData,
  688. additionalData, sizeof (SaAmfAdditionalDataT));
  689. */
  690. error = saSendRetry (fd, &req_lib_amf_errorreport,
  691. sizeof (struct req_lib_amf_errorreport), MSG_NOSIGNAL);
  692. /*
  693. * Get response from executive and respond to user application
  694. */
  695. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_ERRORREPORT);
  696. if (error != SA_OK) {
  697. goto exit_close;
  698. }
  699. res_lib_amf_errorreport = (struct res_lib_amf_errorreport *)&message;
  700. error = res_lib_amf_errorreport->error;
  701. exit_close:
  702. close (fd);
  703. exit_noclose:
  704. return (error);
  705. }
  706. SaErrorT
  707. saAmfErrorCancelAll (
  708. const SaNameT *compName) {
  709. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  710. struct res_lib_amf_errorcancelall *res_lib_amf_errorcancelall;
  711. struct message_overlay message;
  712. int fd;
  713. SaErrorT error;
  714. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  715. if (error != SA_OK) {
  716. goto exit_noclose;
  717. }
  718. req_lib_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  719. req_lib_amf_errorcancelall.header.id = MESSAGE_REQ_AMF_ERRORCANCELALL;
  720. req_lib_amf_errorcancelall.header.size = sizeof (struct req_lib_amf_errorcancelall);
  721. memcpy (&req_lib_amf_errorcancelall.compName, compName, sizeof (SaNameT));
  722. error = saSendRetry (fd, &req_lib_amf_errorcancelall,
  723. sizeof (struct req_lib_amf_errorcancelall), MSG_NOSIGNAL);
  724. /*
  725. * Get response from executive and respond to user application
  726. */
  727. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_ERRORCANCELALL);
  728. if (error != SA_OK) {
  729. goto exit_close;
  730. }
  731. res_lib_amf_errorcancelall = (struct res_lib_amf_errorcancelall *)&message;
  732. error = res_lib_amf_errorcancelall->error;
  733. exit_close:
  734. close (fd);
  735. exit_noclose:
  736. return (error);
  737. }
  738. SaErrorT
  739. saAmfComponentCapabilityModelGet (
  740. const SaNameT *compName,
  741. SaAmfComponentCapabilityModelT *componentCapabilityModel)
  742. {
  743. int fd;
  744. SaErrorT error;
  745. struct req_amf_componentcapabilitymodelget req_amf_componentcapabilitymodelget;
  746. struct res_amf_componentcapabilitymodelget *res_amf_componentcapabilitymodelget;
  747. struct message_overlay message;
  748. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  749. if (error != SA_OK) {
  750. goto exit_noclose;
  751. }
  752. req_amf_componentcapabilitymodelget.header.magic = MESSAGE_MAGIC;
  753. req_amf_componentcapabilitymodelget.header.id = MESSAGE_REQ_AMF_COMPONENTCAPABILITYMODELGET;
  754. req_amf_componentcapabilitymodelget.header.size = sizeof (struct req_amf_componentcapabilitymodelget);
  755. memcpy (&req_amf_componentcapabilitymodelget.compName, compName, sizeof (SaNameT));
  756. error = saSendRetry (fd, &req_amf_componentcapabilitymodelget,
  757. sizeof (struct req_amf_componentcapabilitymodelget), MSG_NOSIGNAL);
  758. if (error != SA_OK) {
  759. goto exit_close;
  760. }
  761. error = saRecvQueue (fd, &message, 0, MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET);
  762. res_amf_componentcapabilitymodelget = (struct res_amf_componentcapabilitymodelget *)&message;
  763. if (error == SA_OK) {
  764. memcpy (componentCapabilityModel,
  765. &res_amf_componentcapabilitymodelget->componentCapabilityModel,
  766. sizeof (SaAmfComponentCapabilityModelT));
  767. error = res_amf_componentcapabilitymodelget->error;
  768. }
  769. exit_close:
  770. close (fd);
  771. exit_noclose:
  772. return (error);
  773. }
  774. SaErrorT
  775. saAmfPendingOperationGet (
  776. const SaNameT *compName,
  777. SaAmfPendingOperationFlagsT *pendingOperationFlags) {
  778. *pendingOperationFlags = 0;
  779. return (SA_OK);
  780. }
  781. SaErrorT
  782. saAmfResponse (
  783. SaInvocationT invocation,
  784. SaErrorT error)
  785. {
  786. struct req_amf_response req_amf_response;
  787. int fd;
  788. SaErrorT errorResult;
  789. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  790. if (errorResult != SA_OK) {
  791. goto exit_noclose;
  792. }
  793. req_amf_response.header.magic = MESSAGE_MAGIC;
  794. req_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  795. req_amf_response.header.size = sizeof (struct req_amf_response);
  796. req_amf_response.invocation = invocation;
  797. req_amf_response.error = error;
  798. errorResult = saSendRetry (fd, &req_amf_response,
  799. sizeof (struct req_amf_response), MSG_NOSIGNAL);
  800. close (fd);
  801. exit_noclose:
  802. return (errorResult);
  803. }