amf.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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. free (msg);
  233. } else {
  234. /*
  235. * Queue empty, read response from socket
  236. */
  237. error = saRecvRetry (amfInstance->fd, &dispatch_data.header,
  238. sizeof (struct message_header), MSG_WAITALL | MSG_NOSIGNAL);
  239. if (error != SA_OK) {
  240. goto error_unlock;
  241. }
  242. if (dispatch_data.header.size > sizeof (struct message_header)) {
  243. error = saRecvRetry (amfInstance->fd, &dispatch_data.data,
  244. dispatch_data.header.size - sizeof (struct message_header),
  245. MSG_WAITALL | MSG_NOSIGNAL);
  246. if (error != SA_OK) {
  247. goto error_unlock;
  248. }
  249. }
  250. }
  251. /*
  252. * Make copy of callbacks, message data, unlock instance, and call callback
  253. * A risk of this dispatch method is that the callback routines may
  254. * operate at the same time that amfFinalize has been called in another thread.
  255. */
  256. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  257. pthread_mutex_unlock (&amfInstance->mutex);
  258. /*
  259. * Dispatch incoming response
  260. */
  261. switch (dispatch_data.header.id) {
  262. case MESSAGE_RES_LIB_ACTIVATEPOLL:
  263. /*
  264. * This is a do nothing message which the node executive sends
  265. * to activate the file amfHandle in poll when the library has
  266. * queued a message into amfHandle->inq
  267. * The dispatch is ignored for the following two cases:
  268. * 1) setting of timeout to zero for the DISPATCH_ALL case
  269. * 2) expiration of the do loop for the DISPATCH_ONE case
  270. */
  271. ignore_dispatch = 1;
  272. break;
  273. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  274. res_amf_healthcheckcallback = (struct res_amf_healthcheckcallback *)&dispatch_data;
  275. callbacks.saAmfHealthcheckCallback (
  276. res_amf_healthcheckcallback->invocation,
  277. &res_amf_healthcheckcallback->compName,
  278. res_amf_healthcheckcallback->checkType);
  279. break;
  280. case MESSAGE_RES_AMF_READINESSSTATESETCALLBACK:
  281. res_amf_readinessstatesetcallback = (struct res_amf_readinessstatesetcallback *)&dispatch_data;
  282. callbacks.saAmfReadinessStateSetCallback (
  283. res_amf_readinessstatesetcallback->invocation,
  284. &res_amf_readinessstatesetcallback->compName,
  285. res_amf_readinessstatesetcallback->readinessState);
  286. break;
  287. case MESSAGE_RES_AMF_CSISETCALLBACK:
  288. res_amf_csisetcallback = (struct res_amf_csisetcallback *)&dispatch_data;
  289. callbacks.saAmfCSISetCallback (
  290. res_amf_csisetcallback->invocation,
  291. &res_amf_csisetcallback->compName,
  292. &res_amf_csisetcallback->csiName,
  293. res_amf_csisetcallback->csiFlags,
  294. &res_amf_csisetcallback->haState,
  295. &res_amf_csisetcallback->activeCompName,
  296. res_amf_csisetcallback->transitionDescriptor);
  297. break;
  298. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  299. res_amf_csiremovecallback = (struct res_amf_csiremovecallback *)&dispatch_data;
  300. callbacks.saAmfCSIRemoveCallback (
  301. res_amf_csiremovecallback->invocation,
  302. &res_amf_csiremovecallback->compName,
  303. &res_amf_csiremovecallback->csiName,
  304. &res_amf_csiremovecallback->csiFlags);
  305. break;
  306. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  307. res_amf_protectiongrouptrackcallback = (struct res_amf_protectiongrouptrackcallback *)&dispatch_data;
  308. memcpy (res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  309. res_amf_protectiongrouptrackcallback->notificationBuffer,
  310. res_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  311. callbacks.saAmfProtectionGroupTrackCallback(
  312. &res_amf_protectiongrouptrackcallback->csiName,
  313. res_amf_protectiongrouptrackcallback->notificationBufferAddress,
  314. res_amf_protectiongrouptrackcallback->numberOfItems,
  315. res_amf_protectiongrouptrackcallback->numberOfMembers,
  316. res_amf_protectiongrouptrackcallback->error);
  317. break;
  318. default:
  319. error = SA_ERR_LIBRARY;
  320. goto error_nounlock;
  321. break;
  322. }
  323. /*
  324. * Determine if more messages should be processed
  325. */
  326. switch (dispatchFlags) {
  327. case SA_DISPATCH_ONE:
  328. if (ignore_dispatch) {
  329. ignore_dispatch = 0;
  330. } else {
  331. cont = 0;
  332. }
  333. break;
  334. case SA_DISPATCH_ALL:
  335. if (ignore_dispatch) {
  336. ignore_dispatch = 0;
  337. }
  338. break;
  339. case SA_DISPATCH_BLOCKING:
  340. break;
  341. }
  342. } while (cont);
  343. error_unlock:
  344. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  345. error_nounlock:
  346. return (error);
  347. }
  348. SaErrorT
  349. saAmfFinalize (
  350. const SaAmfHandleT *amfHandle)
  351. {
  352. struct amfInstance *amfInstance;
  353. SaErrorT error;
  354. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  355. if (error != SA_OK) {
  356. return (error);
  357. }
  358. pthread_mutex_lock (&amfInstance->mutex);
  359. /*
  360. * Another thread has already started finalizing
  361. */
  362. if (amfInstance->finalize) {
  363. pthread_mutex_unlock (&amfInstance->mutex);
  364. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  365. return (SA_ERR_BAD_HANDLE);
  366. }
  367. amfInstance->finalize = 1;
  368. saActivatePoll (amfInstance->fd);
  369. pthread_mutex_unlock (&amfInstance->mutex);
  370. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  371. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  372. return (error);
  373. }
  374. SaErrorT
  375. saAmfComponentRegister (
  376. const SaAmfHandleT *amfHandle,
  377. const SaNameT *compName,
  378. const SaNameT *proxyCompName)
  379. {
  380. struct amfInstance *amfInstance;
  381. SaErrorT error;
  382. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  383. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  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, &res_lib_amf_componentregister,
  409. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTREGISTER);
  410. if (error != SA_OK) {
  411. goto error_unlock;
  412. }
  413. if (res_lib_amf_componentregister.error == SA_OK) {
  414. amfInstance->compRegistered = 1;
  415. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  416. }
  417. error = res_lib_amf_componentregister.error;
  418. error_unlock:
  419. pthread_mutex_unlock (&amfInstance->mutex);
  420. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  421. return (error);
  422. }
  423. SaErrorT
  424. saAmfComponentUnregister (
  425. const SaAmfHandleT *amfHandle,
  426. const SaNameT *compName,
  427. const SaNameT *proxyCompName)
  428. {
  429. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  430. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  431. struct amfInstance *amfInstance;
  432. SaErrorT error;
  433. req_lib_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  434. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  435. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  436. memcpy (&req_lib_amf_componentunregister.compName, compName, sizeof (SaNameT));
  437. if (proxyCompName) {
  438. memcpy (&req_lib_amf_componentunregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  439. } else {
  440. memset (&req_lib_amf_componentunregister.proxyCompName, 0, sizeof (SaNameT));
  441. }
  442. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  443. if (error != SA_OK) {
  444. return (error);
  445. }
  446. pthread_mutex_lock (&amfInstance->mutex);
  447. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentunregister,
  448. sizeof (struct req_lib_amf_componentunregister), MSG_NOSIGNAL);
  449. if (error != SA_OK) {
  450. goto error_unlock;
  451. }
  452. /*
  453. * Search for COMPONENTUNREGISTER responses and queue any
  454. * messages that dont match in this amfHandle's inq.
  455. * This must be done to avoid dropping async messages
  456. * during this sync message retrieval
  457. */
  458. error = saRecvQueue (amfInstance->fd, &res_lib_amf_componentunregister,
  459. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTUNREGISTER);
  460. if (error != SA_OK) {
  461. goto error_unlock;
  462. }
  463. if (res_lib_amf_componentunregister.error == SA_OK) {
  464. amfInstance->compRegistered = 0;
  465. }
  466. error = res_lib_amf_componentunregister.error;
  467. error_unlock:
  468. pthread_mutex_unlock (&amfInstance->mutex);
  469. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  470. return (error);
  471. }
  472. SaErrorT
  473. saAmfCompNameGet (
  474. const SaAmfHandleT *amfHandle,
  475. SaNameT *compName)
  476. {
  477. struct amfInstance *amfInstance;
  478. SaErrorT error;
  479. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  480. if (error != SA_OK) {
  481. return (error);
  482. }
  483. pthread_mutex_lock (&amfInstance->mutex);
  484. if (amfInstance->compRegistered == 0) {
  485. pthread_mutex_unlock (&amfInstance->mutex);
  486. return (SA_ERR_NOT_EXIST);
  487. }
  488. memcpy (compName, &amfInstance->compName, sizeof (SaNameT));
  489. pthread_mutex_unlock (&amfInstance->mutex);
  490. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  491. return (SA_OK);
  492. }
  493. SaErrorT
  494. saAmfReadinessStateGet (
  495. const SaNameT *compName,
  496. SaAmfReadinessStateT *readinessState)
  497. {
  498. int fd;
  499. SaErrorT error;
  500. struct req_amf_readinessstateget req_amf_readinessstateget;
  501. struct res_amf_readinessstateget res_amf_readinessstateget;
  502. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  503. if (error != SA_OK) {
  504. goto exit_noclose;
  505. }
  506. req_amf_readinessstateget.header.magic = MESSAGE_MAGIC;
  507. req_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  508. req_amf_readinessstateget.header.size = sizeof (struct req_amf_readinessstateget);
  509. memcpy (&req_amf_readinessstateget.compName, compName, sizeof (SaNameT));
  510. error = saSendRetry (fd, &req_amf_readinessstateget,
  511. sizeof (struct req_amf_readinessstateget), MSG_NOSIGNAL);
  512. if (error != SA_OK) {
  513. goto exit_close;
  514. }
  515. error = saRecvRetry (fd, &res_amf_readinessstateget,
  516. sizeof (struct res_amf_readinessstateget), MSG_WAITALL | MSG_NOSIGNAL);
  517. if (error == SA_OK) {
  518. memcpy (readinessState, &res_amf_readinessstateget.readinessState,
  519. sizeof (SaAmfReadinessStateT));
  520. error = res_amf_readinessstateget.error;
  521. }
  522. exit_close:
  523. close (fd);
  524. exit_noclose:
  525. return (error);
  526. }
  527. SaErrorT
  528. saAmfStoppingComplete (
  529. SaInvocationT invocation,
  530. SaErrorT error)
  531. {
  532. struct req_amf_stoppingcomplete req_amf_stoppingcomplete;
  533. int fd;
  534. SaErrorT errorResult;
  535. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  536. if (errorResult != SA_OK) {
  537. goto exit_noclose;
  538. }
  539. req_amf_stoppingcomplete.header.magic = MESSAGE_MAGIC;
  540. req_amf_stoppingcomplete.header.id = MESSAGE_REQ_AMF_STOPPINGCOMPLETE;
  541. req_amf_stoppingcomplete.header.size = sizeof (struct req_amf_stoppingcomplete);
  542. req_amf_stoppingcomplete.invocation = invocation;
  543. req_amf_stoppingcomplete.error = error;
  544. errorResult = saSendRetry (fd, &req_amf_stoppingcomplete,
  545. sizeof (struct req_amf_stoppingcomplete), MSG_NOSIGNAL);
  546. close (fd);
  547. exit_noclose:
  548. return (errorResult);
  549. }
  550. SaErrorT
  551. saAmfHAStateGet (
  552. const SaNameT *compName,
  553. const SaNameT *csiName,
  554. SaAmfHAStateT *haState) {
  555. struct req_amf_hastateget req_amf_hastateget;
  556. struct res_amf_hastateget res_amf_hastateget;
  557. int fd;
  558. SaErrorT error;
  559. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  560. if (error != SA_OK) {
  561. goto exit_noclose;
  562. }
  563. req_amf_hastateget.header.magic = MESSAGE_MAGIC;
  564. req_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  565. req_amf_hastateget.header.size = sizeof (struct req_amf_hastateget);
  566. memcpy (&req_amf_hastateget.compName, compName, sizeof (SaNameT));
  567. memcpy (&req_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  568. error = saSendRetry (fd, &req_amf_hastateget,
  569. sizeof (struct req_amf_hastateget), MSG_NOSIGNAL);
  570. if (error != SA_OK) {
  571. goto exit_close;
  572. }
  573. error = saRecvRetry (fd, &res_amf_hastateget,
  574. sizeof (struct res_amf_hastateget), MSG_WAITALL | MSG_NOSIGNAL);
  575. if (error == SA_OK) {
  576. memcpy (haState, &res_amf_hastateget.haState, sizeof (SaAmfHAStateT));
  577. error = res_amf_hastateget.error;
  578. }
  579. exit_close:
  580. close (fd);
  581. exit_noclose:
  582. return (error);
  583. }
  584. SaErrorT
  585. saAmfProtectionGroupTrackStart (
  586. const SaAmfHandleT *amfHandle,
  587. const SaNameT *csiName,
  588. SaUint8T trackFlags,
  589. const SaAmfProtectionGroupNotificationT *notificationBuffer,
  590. SaUint32T numberOfItems) {
  591. struct amfInstance *amfInstance;
  592. struct req_amf_protectiongrouptrackstart req_amf_protectiongrouptrackstart;
  593. struct res_amf_protectiongrouptrackstart res_amf_protectiongrouptrackstart;
  594. SaErrorT error;
  595. req_amf_protectiongrouptrackstart.header.magic = MESSAGE_MAGIC;
  596. req_amf_protectiongrouptrackstart.header.size = sizeof (struct req_amf_protectiongrouptrackstart);
  597. req_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  598. memcpy (&req_amf_protectiongrouptrackstart.csiName, csiName, sizeof (SaNameT));
  599. req_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  600. req_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  601. req_amf_protectiongrouptrackstart.numberOfItems = numberOfItems;
  602. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  603. if (error != SA_OK) {
  604. return (error);
  605. }
  606. pthread_mutex_lock (&amfInstance->mutex);
  607. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstart,
  608. sizeof (struct req_amf_protectiongrouptrackstart), MSG_NOSIGNAL);
  609. if (error != SA_OK) {
  610. goto error_unlock;
  611. }
  612. error = saRecvQueue (amfInstance->fd, &res_amf_protectiongrouptrackstart,
  613. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART);
  614. error = res_amf_protectiongrouptrackstart.error;
  615. error_unlock:
  616. pthread_mutex_unlock (&amfInstance->mutex);
  617. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  618. return (error);
  619. }
  620. SaErrorT
  621. saAmfProtectionGroupTrackStop (
  622. const SaAmfHandleT *amfHandle,
  623. const SaNameT *csiName) {
  624. struct amfInstance *amfInstance;
  625. struct req_amf_protectiongrouptrackstop req_amf_protectiongrouptrackstop;
  626. struct res_amf_protectiongrouptrackstop res_amf_protectiongrouptrackstop;
  627. SaErrorT error;
  628. req_amf_protectiongrouptrackstop.header.magic = MESSAGE_MAGIC;
  629. req_amf_protectiongrouptrackstop.header.size = sizeof (struct req_amf_protectiongrouptrackstop);
  630. req_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  631. memcpy (&req_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  632. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  633. if (error != SA_OK) {
  634. return (error);
  635. }
  636. pthread_mutex_lock (&amfInstance->mutex);
  637. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstop,
  638. sizeof (struct req_amf_protectiongrouptrackstop), MSG_NOSIGNAL);
  639. if (error != SA_OK) {
  640. goto error_unlock;
  641. }
  642. error = saRecvQueue (amfInstance->fd, &res_amf_protectiongrouptrackstop,
  643. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP);
  644. error = res_amf_protectiongrouptrackstop.error;
  645. error_unlock:
  646. pthread_mutex_unlock (&amfInstance->mutex);
  647. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  648. return (error);
  649. }
  650. SaErrorT
  651. saAmfErrorReport (
  652. const SaNameT *reportingComponent,
  653. const SaNameT *erroneousComponent,
  654. SaTimeT errorDetectionTime,
  655. const SaAmfErrorDescriptorT *errorDescriptor,
  656. const SaAmfAdditionalDataT *additionalData) {
  657. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  658. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  659. int fd;
  660. SaErrorT error;
  661. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  662. if (error != SA_OK) {
  663. goto exit_noclose;
  664. }
  665. req_lib_amf_errorreport.header.magic = MESSAGE_MAGIC;
  666. req_lib_amf_errorreport.header.id = MESSAGE_REQ_AMF_ERRORREPORT;
  667. req_lib_amf_errorreport.header.size = sizeof (struct req_lib_amf_errorreport);
  668. memcpy (&req_lib_amf_errorreport.reportingComponent, reportingComponent, sizeof (SaNameT));
  669. memcpy (&req_lib_amf_errorreport.erroneousComponent, erroneousComponent, sizeof (SaNameT));
  670. req_lib_amf_errorreport.errorDetectionTime = errorDetectionTime;
  671. memcpy (&req_lib_amf_errorreport.errorDescriptor,
  672. errorDescriptor, sizeof (SaAmfErrorDescriptorT));
  673. /* TODO this is wrong, and needs some thinking
  674. memcpy (&req_lib_amf_errorreport.additionalData,
  675. additionalData, sizeof (SaAmfAdditionalDataT));
  676. */
  677. error = saSendRetry (fd, &req_lib_amf_errorreport,
  678. sizeof (struct req_lib_amf_errorreport), MSG_NOSIGNAL);
  679. /*
  680. * Get response from executive and respond to user application
  681. */
  682. error = saRecvRetry (fd, &res_lib_amf_errorreport,
  683. sizeof (struct res_lib_amf_errorreport), MSG_WAITALL | MSG_NOSIGNAL);
  684. if (error != SA_OK) {
  685. goto exit_close;
  686. }
  687. error = res_lib_amf_errorreport.error;
  688. exit_close:
  689. close (fd);
  690. exit_noclose:
  691. return (error);
  692. }
  693. SaErrorT
  694. saAmfErrorCancelAll (
  695. const SaNameT *compName) {
  696. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  697. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  698. int fd;
  699. SaErrorT error;
  700. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  701. if (error != SA_OK) {
  702. goto exit_noclose;
  703. }
  704. req_lib_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  705. req_lib_amf_errorcancelall.header.id = MESSAGE_REQ_AMF_ERRORCANCELALL;
  706. req_lib_amf_errorcancelall.header.size = sizeof (struct req_lib_amf_errorcancelall);
  707. memcpy (&req_lib_amf_errorcancelall.compName, compName, sizeof (SaNameT));
  708. error = saSendRetry (fd, &req_lib_amf_errorcancelall,
  709. sizeof (struct req_lib_amf_errorcancelall), MSG_NOSIGNAL);
  710. /*
  711. * Get response from executive and respond to user application
  712. */
  713. error = saRecvRetry (fd, &res_lib_amf_errorcancelall,
  714. sizeof (struct res_lib_amf_errorcancelall), MSG_WAITALL | MSG_NOSIGNAL);
  715. if (error != SA_OK) {
  716. goto exit_close;
  717. }
  718. error = res_lib_amf_errorcancelall.error;
  719. exit_close:
  720. close (fd);
  721. exit_noclose:
  722. return (error);
  723. }
  724. SaErrorT
  725. saAmfComponentCapabilityModelGet (
  726. const SaNameT *compName,
  727. SaAmfComponentCapabilityModelT *componentCapabilityModel)
  728. {
  729. int fd;
  730. SaErrorT error;
  731. struct req_amf_componentcapabilitymodelget req_amf_componentcapabilitymodelget;
  732. struct res_amf_componentcapabilitymodelget res_amf_componentcapabilitymodelget;
  733. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  734. if (error != SA_OK) {
  735. goto exit_noclose;
  736. }
  737. req_amf_componentcapabilitymodelget.header.magic = MESSAGE_MAGIC;
  738. req_amf_componentcapabilitymodelget.header.id = MESSAGE_REQ_AMF_COMPONENTCAPABILITYMODELGET;
  739. req_amf_componentcapabilitymodelget.header.size = sizeof (struct req_amf_componentcapabilitymodelget);
  740. memcpy (&req_amf_componentcapabilitymodelget.compName, compName, sizeof (SaNameT));
  741. error = saSendRetry (fd, &req_amf_componentcapabilitymodelget,
  742. sizeof (struct req_amf_componentcapabilitymodelget), MSG_NOSIGNAL);
  743. if (error != SA_OK) {
  744. goto exit_close;
  745. }
  746. error = saRecvRetry (fd, &res_amf_componentcapabilitymodelget,
  747. sizeof (struct res_amf_componentcapabilitymodelget), MSG_WAITALL | MSG_NOSIGNAL);
  748. if (error == SA_OK) {
  749. memcpy (componentCapabilityModel,
  750. &res_amf_componentcapabilitymodelget.componentCapabilityModel,
  751. sizeof (SaAmfComponentCapabilityModelT));
  752. error = res_amf_componentcapabilitymodelget.error;
  753. }
  754. exit_close:
  755. close (fd);
  756. exit_noclose:
  757. return (error);
  758. }
  759. SaErrorT
  760. saAmfPendingOperationGet (
  761. const SaNameT *compName,
  762. SaAmfPendingOperationFlagsT *pendingOperationFlags) {
  763. *pendingOperationFlags = 0;
  764. return (SA_OK);
  765. }
  766. SaErrorT
  767. saAmfResponse (
  768. SaInvocationT invocation,
  769. SaErrorT error)
  770. {
  771. struct req_amf_response req_amf_response;
  772. int fd;
  773. SaErrorT errorResult;
  774. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  775. if (errorResult != SA_OK) {
  776. goto exit_noclose;
  777. }
  778. req_amf_response.header.magic = MESSAGE_MAGIC;
  779. req_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  780. req_amf_response.header.size = sizeof (struct req_amf_response);
  781. req_amf_response.invocation = invocation;
  782. req_amf_response.error = error;
  783. errorResult = saSendRetry (fd, &req_amf_response,
  784. sizeof (struct req_amf_response), MSG_NOSIGNAL);
  785. close (fd);
  786. exit_noclose:
  787. return (errorResult);
  788. }