amf.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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 req_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_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
  171. struct res_lib_amf_readinessstatesetcallback *res_lib_amf_readinessstatesetcallback;
  172. struct res_lib_amf_csisetcallback *res_lib_amf_csisetcallback;
  173. struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
  174. struct res_lib_amf_protectiongrouptrackcallback *res_lib_amf_protectiongrouptrackcallback;
  175. struct req_header **queue_msg;
  176. struct req_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 req_header), MSG_WAITALL | MSG_NOSIGNAL);
  239. if (error != SA_OK) {
  240. goto error_unlock;
  241. }
  242. if (dispatch_data.header.size > sizeof (struct req_header)) {
  243. error = saRecvRetry (amfInstance->fd, &dispatch_data.data,
  244. dispatch_data.header.size - sizeof (struct req_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_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
  275. callbacks.saAmfHealthcheckCallback (
  276. res_lib_amf_healthcheckcallback->invocation,
  277. &res_lib_amf_healthcheckcallback->compName,
  278. res_lib_amf_healthcheckcallback->checkType);
  279. break;
  280. case MESSAGE_RES_AMF_READINESSSTATESETCALLBACK:
  281. res_lib_amf_readinessstatesetcallback = (struct res_lib_amf_readinessstatesetcallback *)&dispatch_data;
  282. callbacks.saAmfReadinessStateSetCallback (
  283. res_lib_amf_readinessstatesetcallback->invocation,
  284. &res_lib_amf_readinessstatesetcallback->compName,
  285. res_lib_amf_readinessstatesetcallback->readinessState);
  286. break;
  287. case MESSAGE_RES_AMF_CSISETCALLBACK:
  288. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  289. callbacks.saAmfCSISetCallback (
  290. res_lib_amf_csisetcallback->invocation,
  291. &res_lib_amf_csisetcallback->compName,
  292. &res_lib_amf_csisetcallback->csiName,
  293. res_lib_amf_csisetcallback->csiFlags,
  294. &res_lib_amf_csisetcallback->haState,
  295. &res_lib_amf_csisetcallback->activeCompName,
  296. res_lib_amf_csisetcallback->transitionDescriptor);
  297. break;
  298. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  299. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  300. callbacks.saAmfCSIRemoveCallback (
  301. res_lib_amf_csiremovecallback->invocation,
  302. &res_lib_amf_csiremovecallback->compName,
  303. &res_lib_amf_csiremovecallback->csiName,
  304. &res_lib_amf_csiremovecallback->csiFlags);
  305. break;
  306. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  307. res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
  308. memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  309. res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
  310. res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  311. callbacks.saAmfProtectionGroupTrackCallback(
  312. &res_lib_amf_protectiongrouptrackcallback->csiName,
  313. res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  314. res_lib_amf_protectiongrouptrackcallback->numberOfItems,
  315. res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
  316. res_lib_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.size = sizeof (struct req_lib_amf_componentregister);
  385. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  386. memcpy (&req_lib_amf_componentregister.compName, compName, sizeof (SaNameT));
  387. if (proxyCompName) {
  388. memcpy (&req_lib_amf_componentregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  389. } else {
  390. memset (&req_lib_amf_componentregister.proxyCompName, 0, sizeof (SaNameT));
  391. }
  392. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  393. if (error != SA_OK) {
  394. return (error);
  395. }
  396. pthread_mutex_lock (&amfInstance->mutex);
  397. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentregister, sizeof (struct req_lib_amf_componentregister), MSG_NOSIGNAL);
  398. if (error != SA_OK) {
  399. goto error_unlock;
  400. }
  401. /*
  402. * Search for COMPONENTREGISTER responses and queue any
  403. * messages that dont match in this amfHandle's inq.
  404. * This must be done to avoid dropping async messages
  405. * during this sync message retrieval
  406. */
  407. error = saRecvQueue (amfInstance->fd, &res_lib_amf_componentregister,
  408. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTREGISTER);
  409. if (error != SA_OK) {
  410. goto error_unlock;
  411. }
  412. if (res_lib_amf_componentregister.header.error == SA_OK) {
  413. amfInstance->compRegistered = 1;
  414. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  415. }
  416. error = res_lib_amf_componentregister.header.error;
  417. error_unlock:
  418. pthread_mutex_unlock (&amfInstance->mutex);
  419. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  420. return (error);
  421. }
  422. SaErrorT
  423. saAmfComponentUnregister (
  424. const SaAmfHandleT *amfHandle,
  425. const SaNameT *compName,
  426. const SaNameT *proxyCompName)
  427. {
  428. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  429. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  430. struct amfInstance *amfInstance;
  431. SaErrorT error;
  432. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  433. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  434. memcpy (&req_lib_amf_componentunregister.compName, compName, sizeof (SaNameT));
  435. if (proxyCompName) {
  436. memcpy (&req_lib_amf_componentunregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  437. } else {
  438. memset (&req_lib_amf_componentunregister.proxyCompName, 0, sizeof (SaNameT));
  439. }
  440. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  441. if (error != SA_OK) {
  442. return (error);
  443. }
  444. pthread_mutex_lock (&amfInstance->mutex);
  445. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentunregister,
  446. sizeof (struct req_lib_amf_componentunregister), MSG_NOSIGNAL);
  447. if (error != SA_OK) {
  448. goto error_unlock;
  449. }
  450. /*
  451. * Search for COMPONENTUNREGISTER responses and queue any
  452. * messages that dont match in this amfHandle's inq.
  453. * This must be done to avoid dropping async messages
  454. * during this sync message retrieval
  455. */
  456. error = saRecvQueue (amfInstance->fd, &res_lib_amf_componentunregister,
  457. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTUNREGISTER);
  458. if (error != SA_OK) {
  459. goto error_unlock;
  460. }
  461. if (res_lib_amf_componentunregister.header.error == SA_OK) {
  462. amfInstance->compRegistered = 0;
  463. }
  464. error = res_lib_amf_componentunregister.header.error;
  465. error_unlock:
  466. pthread_mutex_unlock (&amfInstance->mutex);
  467. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  468. return (error);
  469. }
  470. SaErrorT
  471. saAmfCompNameGet (
  472. const SaAmfHandleT *amfHandle,
  473. SaNameT *compName)
  474. {
  475. struct amfInstance *amfInstance;
  476. SaErrorT error;
  477. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  478. if (error != SA_OK) {
  479. return (error);
  480. }
  481. pthread_mutex_lock (&amfInstance->mutex);
  482. if (amfInstance->compRegistered == 0) {
  483. pthread_mutex_unlock (&amfInstance->mutex);
  484. return (SA_ERR_NOT_EXIST);
  485. }
  486. memcpy (compName, &amfInstance->compName, sizeof (SaNameT));
  487. pthread_mutex_unlock (&amfInstance->mutex);
  488. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  489. return (SA_OK);
  490. }
  491. SaErrorT
  492. saAmfReadinessStateGet (
  493. const SaNameT *compName,
  494. SaAmfReadinessStateT *readinessState)
  495. {
  496. int fd;
  497. SaErrorT error;
  498. struct req_amf_readinessstateget req_amf_readinessstateget;
  499. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  500. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  501. if (error != SA_OK) {
  502. goto exit_noclose;
  503. }
  504. req_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  505. req_amf_readinessstateget.header.size = sizeof (struct req_amf_readinessstateget);
  506. memcpy (&req_amf_readinessstateget.compName, compName, sizeof (SaNameT));
  507. error = saSendRetry (fd, &req_amf_readinessstateget,
  508. sizeof (struct req_amf_readinessstateget), MSG_NOSIGNAL);
  509. if (error != SA_OK) {
  510. goto exit_close;
  511. }
  512. error = saRecvRetry (fd, &res_lib_amf_readinessstateget,
  513. sizeof (struct res_lib_amf_readinessstateget), MSG_WAITALL | MSG_NOSIGNAL);
  514. if (error == SA_OK) {
  515. memcpy (readinessState, &res_lib_amf_readinessstateget.readinessState,
  516. sizeof (SaAmfReadinessStateT));
  517. error = res_lib_amf_readinessstateget.header.error;
  518. }
  519. exit_close:
  520. close (fd);
  521. exit_noclose:
  522. return (error);
  523. }
  524. SaErrorT
  525. saAmfStoppingComplete (
  526. SaInvocationT invocation,
  527. SaErrorT error)
  528. {
  529. struct req_amf_stoppingcomplete req_amf_stoppingcomplete;
  530. int fd;
  531. SaErrorT errorResult;
  532. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  533. if (errorResult != SA_OK) {
  534. goto exit_noclose;
  535. }
  536. req_amf_stoppingcomplete.header.id = MESSAGE_REQ_AMF_STOPPINGCOMPLETE;
  537. req_amf_stoppingcomplete.header.size = sizeof (struct req_amf_stoppingcomplete);
  538. req_amf_stoppingcomplete.invocation = invocation;
  539. req_amf_stoppingcomplete.error = error;
  540. errorResult = saSendRetry (fd, &req_amf_stoppingcomplete,
  541. sizeof (struct req_amf_stoppingcomplete), MSG_NOSIGNAL);
  542. close (fd);
  543. exit_noclose:
  544. return (errorResult);
  545. }
  546. SaErrorT
  547. saAmfHAStateGet (
  548. const SaNameT *compName,
  549. const SaNameT *csiName,
  550. SaAmfHAStateT *haState) {
  551. struct req_amf_hastateget req_amf_hastateget;
  552. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  553. int fd;
  554. SaErrorT error;
  555. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  556. if (error != SA_OK) {
  557. goto exit_noclose;
  558. }
  559. req_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  560. req_amf_hastateget.header.size = sizeof (struct req_amf_hastateget);
  561. memcpy (&req_amf_hastateget.compName, compName, sizeof (SaNameT));
  562. memcpy (&req_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  563. error = saSendRetry (fd, &req_amf_hastateget,
  564. sizeof (struct req_amf_hastateget), MSG_NOSIGNAL);
  565. if (error != SA_OK) {
  566. goto exit_close;
  567. }
  568. error = saRecvRetry (fd, &res_lib_amf_hastateget,
  569. sizeof (struct res_lib_amf_hastateget), MSG_WAITALL | MSG_NOSIGNAL);
  570. if (error == SA_OK) {
  571. memcpy (haState, &res_lib_amf_hastateget.haState, sizeof (SaAmfHAStateT));
  572. error = res_lib_amf_hastateget.header.error;
  573. }
  574. exit_close:
  575. close (fd);
  576. exit_noclose:
  577. return (error);
  578. }
  579. SaErrorT
  580. saAmfProtectionGroupTrackStart (
  581. const SaAmfHandleT *amfHandle,
  582. const SaNameT *csiName,
  583. SaUint8T trackFlags,
  584. const SaAmfProtectionGroupNotificationT *notificationBuffer,
  585. SaUint32T numberOfItems) {
  586. struct amfInstance *amfInstance;
  587. struct req_amf_protectiongrouptrackstart req_amf_protectiongrouptrackstart;
  588. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  589. SaErrorT error;
  590. req_amf_protectiongrouptrackstart.header.size = sizeof (struct req_amf_protectiongrouptrackstart);
  591. req_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  592. memcpy (&req_amf_protectiongrouptrackstart.csiName, csiName, sizeof (SaNameT));
  593. req_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  594. req_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  595. req_amf_protectiongrouptrackstart.numberOfItems = numberOfItems;
  596. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  597. if (error != SA_OK) {
  598. return (error);
  599. }
  600. pthread_mutex_lock (&amfInstance->mutex);
  601. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstart,
  602. sizeof (struct req_amf_protectiongrouptrackstart), MSG_NOSIGNAL);
  603. if (error != SA_OK) {
  604. goto error_unlock;
  605. }
  606. error = saRecvQueue (amfInstance->fd, &res_lib_amf_protectiongrouptrackstart,
  607. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART);
  608. error = res_lib_amf_protectiongrouptrackstart.header.error;
  609. error_unlock:
  610. pthread_mutex_unlock (&amfInstance->mutex);
  611. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  612. return (error);
  613. }
  614. SaErrorT
  615. saAmfProtectionGroupTrackStop (
  616. const SaAmfHandleT *amfHandle,
  617. const SaNameT *csiName) {
  618. struct amfInstance *amfInstance;
  619. struct req_amf_protectiongrouptrackstop req_amf_protectiongrouptrackstop;
  620. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  621. SaErrorT error;
  622. req_amf_protectiongrouptrackstop.header.size = sizeof (struct req_amf_protectiongrouptrackstop);
  623. req_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  624. memcpy (&req_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  625. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  626. if (error != SA_OK) {
  627. return (error);
  628. }
  629. pthread_mutex_lock (&amfInstance->mutex);
  630. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstop,
  631. sizeof (struct req_amf_protectiongrouptrackstop), MSG_NOSIGNAL);
  632. if (error != SA_OK) {
  633. goto error_unlock;
  634. }
  635. error = saRecvQueue (amfInstance->fd, &res_lib_amf_protectiongrouptrackstop,
  636. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP);
  637. error = res_lib_amf_protectiongrouptrackstop.header.error;
  638. error_unlock:
  639. pthread_mutex_unlock (&amfInstance->mutex);
  640. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  641. return (error);
  642. }
  643. SaErrorT
  644. saAmfErrorReport (
  645. const SaNameT *reportingComponent,
  646. const SaNameT *erroneousComponent,
  647. SaTimeT errorDetectionTime,
  648. const SaAmfErrorDescriptorT *errorDescriptor,
  649. const SaAmfAdditionalDataT *additionalData) {
  650. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  651. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  652. int fd;
  653. SaErrorT error;
  654. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  655. if (error != SA_OK) {
  656. goto exit_noclose;
  657. }
  658. req_lib_amf_errorreport.header.id = MESSAGE_REQ_AMF_ERRORREPORT;
  659. req_lib_amf_errorreport.header.size = sizeof (struct req_lib_amf_errorreport);
  660. memcpy (&req_lib_amf_errorreport.reportingComponent, reportingComponent, sizeof (SaNameT));
  661. memcpy (&req_lib_amf_errorreport.erroneousComponent, erroneousComponent, sizeof (SaNameT));
  662. req_lib_amf_errorreport.errorDetectionTime = errorDetectionTime;
  663. memcpy (&req_lib_amf_errorreport.errorDescriptor,
  664. errorDescriptor, sizeof (SaAmfErrorDescriptorT));
  665. /* TODO this is wrong, and needs some thinking
  666. memcpy (&req_lib_amf_errorreport.additionalData,
  667. additionalData, sizeof (SaAmfAdditionalDataT));
  668. */
  669. error = saSendRetry (fd, &req_lib_amf_errorreport,
  670. sizeof (struct req_lib_amf_errorreport), MSG_NOSIGNAL);
  671. /*
  672. * Get response from executive and respond to user application
  673. */
  674. error = saRecvRetry (fd, &res_lib_amf_errorreport,
  675. sizeof (struct res_lib_amf_errorreport), MSG_WAITALL | MSG_NOSIGNAL);
  676. if (error != SA_OK) {
  677. goto exit_close;
  678. }
  679. error = res_lib_amf_errorreport.header.error;
  680. exit_close:
  681. close (fd);
  682. exit_noclose:
  683. return (error);
  684. }
  685. SaErrorT
  686. saAmfErrorCancelAll (
  687. const SaNameT *compName) {
  688. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  689. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  690. int fd;
  691. SaErrorT error;
  692. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  693. if (error != SA_OK) {
  694. goto exit_noclose;
  695. }
  696. req_lib_amf_errorcancelall.header.id = MESSAGE_REQ_AMF_ERRORCANCELALL;
  697. req_lib_amf_errorcancelall.header.size = sizeof (struct req_lib_amf_errorcancelall);
  698. memcpy (&req_lib_amf_errorcancelall.compName, compName, sizeof (SaNameT));
  699. error = saSendRetry (fd, &req_lib_amf_errorcancelall,
  700. sizeof (struct req_lib_amf_errorcancelall), MSG_NOSIGNAL);
  701. /*
  702. * Get response from executive and respond to user application
  703. */
  704. error = saRecvRetry (fd, &res_lib_amf_errorcancelall,
  705. sizeof (struct res_lib_amf_errorcancelall), MSG_WAITALL | MSG_NOSIGNAL);
  706. if (error != SA_OK) {
  707. goto exit_close;
  708. }
  709. error = res_lib_amf_errorcancelall.header.error;
  710. exit_close:
  711. close (fd);
  712. exit_noclose:
  713. return (error);
  714. }
  715. SaErrorT
  716. saAmfComponentCapabilityModelGet (
  717. const SaNameT *compName,
  718. SaAmfComponentCapabilityModelT *componentCapabilityModel)
  719. {
  720. int fd;
  721. SaErrorT error;
  722. struct req_amf_componentcapabilitymodelget req_amf_componentcapabilitymodelget;
  723. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  724. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  725. if (error != SA_OK) {
  726. goto exit_noclose;
  727. }
  728. req_amf_componentcapabilitymodelget.header.id = MESSAGE_REQ_AMF_COMPONENTCAPABILITYMODELGET;
  729. req_amf_componentcapabilitymodelget.header.size = sizeof (struct req_amf_componentcapabilitymodelget);
  730. memcpy (&req_amf_componentcapabilitymodelget.compName, compName, sizeof (SaNameT));
  731. error = saSendRetry (fd, &req_amf_componentcapabilitymodelget,
  732. sizeof (struct req_amf_componentcapabilitymodelget), MSG_NOSIGNAL);
  733. if (error != SA_OK) {
  734. goto exit_close;
  735. }
  736. error = saRecvRetry (fd, &res_lib_amf_componentcapabilitymodelget,
  737. sizeof (struct res_lib_amf_componentcapabilitymodelget), MSG_WAITALL | MSG_NOSIGNAL);
  738. if (error == SA_OK) {
  739. memcpy (componentCapabilityModel,
  740. &res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  741. sizeof (SaAmfComponentCapabilityModelT));
  742. error = res_lib_amf_componentcapabilitymodelget.header.error;
  743. }
  744. exit_close:
  745. close (fd);
  746. exit_noclose:
  747. return (error);
  748. }
  749. SaErrorT
  750. saAmfPendingOperationGet (
  751. const SaNameT *compName,
  752. SaAmfPendingOperationFlagsT *pendingOperationFlags) {
  753. *pendingOperationFlags = 0;
  754. return (SA_OK);
  755. }
  756. SaErrorT
  757. saAmfResponse (
  758. SaInvocationT invocation,
  759. SaErrorT error)
  760. {
  761. struct req_amf_response req_amf_response;
  762. int fd;
  763. SaErrorT errorResult;
  764. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  765. if (errorResult != SA_OK) {
  766. goto exit_noclose;
  767. }
  768. req_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  769. req_amf_response.header.size = sizeof (struct req_amf_response);
  770. req_amf_response.invocation = invocation;
  771. req_amf_response.error = error;
  772. errorResult = saSendRetry (fd, &req_amf_response,
  773. sizeof (struct req_amf_response), MSG_NOSIGNAL);
  774. close (fd);
  775. exit_noclose:
  776. return (errorResult);
  777. }