amf.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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. // this is wrong
  133. }
  134. memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT));
  135. pthread_mutex_init (&amfInstance->mutex, NULL);
  136. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  137. return (SA_OK);
  138. error_put_destroy:
  139. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  140. error_destroy:
  141. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  142. error_no_destroy:
  143. return (error);
  144. }
  145. SaErrorT
  146. saAmfSelectionObjectGet (
  147. const SaAmfHandleT *amfHandle,
  148. SaSelectionObjectT *selectionObject)
  149. {
  150. struct amfInstance *amfInstance;
  151. SaErrorT error;
  152. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  153. if (error != SA_OK) {
  154. return (error);
  155. }
  156. *selectionObject = amfInstance->fd;
  157. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  158. return (SA_OK);
  159. }
  160. SaErrorT
  161. saAmfDispatch (
  162. const SaAmfHandleT *amfHandle,
  163. SaDispatchFlagsT dispatchFlags)
  164. {
  165. struct pollfd ufds;
  166. int timeout = -1;
  167. SaErrorT error;
  168. int dispatch_avail;
  169. struct amfInstance *amfInstance;
  170. SaAmfCallbacksT callbacks;
  171. struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
  172. struct res_lib_amf_readinessstatesetcallback *res_lib_amf_readinessstatesetcallback;
  173. struct res_lib_amf_csisetcallback *res_lib_amf_csisetcallback;
  174. struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
  175. struct res_lib_amf_protectiongrouptrackcallback *res_lib_amf_protectiongrouptrackcallback;
  176. struct req_header **queue_msg;
  177. struct req_header *msg;
  178. int empty;
  179. int ignore_dispatch = 0;
  180. int cont = 1; /* always continue do loop except when set to 0 */
  181. int poll_fd;
  182. struct message_overlay dispatch_data;
  183. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle,
  184. (void *)&amfInstance);
  185. if (error != SA_OK) {
  186. return (error);
  187. }
  188. /*
  189. * Timeout instantly for SA_DISPATCH_ALL
  190. */
  191. if (dispatchFlags == SA_DISPATCH_ALL) {
  192. timeout = 0;
  193. }
  194. do {
  195. poll_fd = amfInstance->fd;
  196. /*
  197. * Read data directly from socket
  198. */
  199. ufds.fd = poll_fd;
  200. ufds.events = POLLIN;
  201. ufds.revents = 0;
  202. error = saPollRetry (&ufds, 1, timeout);
  203. if (error != SA_OK) {
  204. goto error_nounlock;
  205. }
  206. pthread_mutex_lock (&amfInstance->mutex);
  207. /*
  208. * Handle has been finalized in another thread
  209. */
  210. if (amfInstance->finalize == 1) {
  211. error = SA_OK;
  212. pthread_mutex_unlock (&amfInstance->mutex);
  213. goto error_unlock;
  214. }
  215. dispatch_avail = ufds.revents & POLLIN;
  216. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  217. pthread_mutex_unlock (&amfInstance->mutex);
  218. break; /* exit do while cont is 1 loop */
  219. } else
  220. if (dispatch_avail == 0) {
  221. pthread_mutex_unlock (&amfInstance->mutex);
  222. continue; /* next poll */
  223. }
  224. saQueueIsEmpty(&amfInstance->inq, &empty);
  225. if (empty == 0) {
  226. /*
  227. * Queue is not empty, read data from queue
  228. */
  229. saQueueItemGet (&amfInstance->inq, (void *)&queue_msg);
  230. msg = *queue_msg;
  231. memcpy (&dispatch_data, msg, msg->size);
  232. saQueueItemRemove (&amfInstance->inq);
  233. free (msg);
  234. } else {
  235. /*
  236. * Queue empty, read response from socket
  237. */
  238. error = saRecvRetry (amfInstance->fd, &dispatch_data.header,
  239. sizeof (struct req_header), MSG_WAITALL | MSG_NOSIGNAL);
  240. if (error != SA_OK) {
  241. goto error_unlock;
  242. }
  243. if (dispatch_data.header.size > sizeof (struct req_header)) {
  244. error = saRecvRetry (amfInstance->fd, &dispatch_data.data,
  245. dispatch_data.header.size - sizeof (struct req_header),
  246. MSG_WAITALL | MSG_NOSIGNAL);
  247. if (error != SA_OK) {
  248. goto error_unlock;
  249. }
  250. }
  251. }
  252. /*
  253. * Make copy of callbacks, message data, unlock instance, and call callback
  254. * A risk of this dispatch method is that the callback routines may
  255. * operate at the same time that amfFinalize has been called in another thread.
  256. */
  257. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  258. pthread_mutex_unlock (&amfInstance->mutex);
  259. /*
  260. * Dispatch incoming response
  261. */
  262. switch (dispatch_data.header.id) {
  263. case MESSAGE_RES_LIB_ACTIVATEPOLL:
  264. /*
  265. * This is a do nothing message which the node executive sends
  266. * to activate the file amfHandle in poll when the library has
  267. * queued a message into amfHandle->inq
  268. * The dispatch is ignored for the following two cases:
  269. * 1) setting of timeout to zero for the DISPATCH_ALL case
  270. * 2) expiration of the do loop for the DISPATCH_ONE case
  271. */
  272. ignore_dispatch = 1;
  273. break;
  274. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  275. res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
  276. callbacks.saAmfHealthcheckCallback (
  277. res_lib_amf_healthcheckcallback->invocation,
  278. &res_lib_amf_healthcheckcallback->compName,
  279. res_lib_amf_healthcheckcallback->checkType);
  280. break;
  281. case MESSAGE_RES_AMF_READINESSSTATESETCALLBACK:
  282. res_lib_amf_readinessstatesetcallback = (struct res_lib_amf_readinessstatesetcallback *)&dispatch_data;
  283. callbacks.saAmfReadinessStateSetCallback (
  284. res_lib_amf_readinessstatesetcallback->invocation,
  285. &res_lib_amf_readinessstatesetcallback->compName,
  286. res_lib_amf_readinessstatesetcallback->readinessState);
  287. break;
  288. case MESSAGE_RES_AMF_CSISETCALLBACK:
  289. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  290. callbacks.saAmfCSISetCallback (
  291. res_lib_amf_csisetcallback->invocation,
  292. &res_lib_amf_csisetcallback->compName,
  293. &res_lib_amf_csisetcallback->csiName,
  294. res_lib_amf_csisetcallback->csiFlags,
  295. &res_lib_amf_csisetcallback->haState,
  296. &res_lib_amf_csisetcallback->activeCompName,
  297. res_lib_amf_csisetcallback->transitionDescriptor);
  298. break;
  299. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  300. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  301. callbacks.saAmfCSIRemoveCallback (
  302. res_lib_amf_csiremovecallback->invocation,
  303. &res_lib_amf_csiremovecallback->compName,
  304. &res_lib_amf_csiremovecallback->csiName,
  305. &res_lib_amf_csiremovecallback->csiFlags);
  306. break;
  307. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  308. res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
  309. memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  310. res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
  311. res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  312. callbacks.saAmfProtectionGroupTrackCallback(
  313. &res_lib_amf_protectiongrouptrackcallback->csiName,
  314. res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  315. res_lib_amf_protectiongrouptrackcallback->numberOfItems,
  316. res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
  317. res_lib_amf_protectiongrouptrackcallback->error);
  318. break;
  319. default:
  320. error = SA_ERR_LIBRARY;
  321. goto error_nounlock;
  322. break;
  323. }
  324. /*
  325. * Determine if more messages should be processed
  326. */
  327. switch (dispatchFlags) {
  328. case SA_DISPATCH_ONE:
  329. if (ignore_dispatch) {
  330. ignore_dispatch = 0;
  331. } else {
  332. cont = 0;
  333. }
  334. break;
  335. case SA_DISPATCH_ALL:
  336. if (ignore_dispatch) {
  337. ignore_dispatch = 0;
  338. }
  339. break;
  340. case SA_DISPATCH_BLOCKING:
  341. break;
  342. }
  343. } while (cont);
  344. error_unlock:
  345. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  346. error_nounlock:
  347. return (error);
  348. }
  349. SaErrorT
  350. saAmfFinalize (
  351. const SaAmfHandleT *amfHandle)
  352. {
  353. struct amfInstance *amfInstance;
  354. SaErrorT error;
  355. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  356. if (error != SA_OK) {
  357. return (error);
  358. }
  359. pthread_mutex_lock (&amfInstance->mutex);
  360. /*
  361. * Another thread has already started finalizing
  362. */
  363. if (amfInstance->finalize) {
  364. pthread_mutex_unlock (&amfInstance->mutex);
  365. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  366. return (SA_ERR_BAD_HANDLE);
  367. }
  368. amfInstance->finalize = 1;
  369. saActivatePoll (amfInstance->fd);
  370. pthread_mutex_unlock (&amfInstance->mutex);
  371. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  372. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  373. return (error);
  374. }
  375. SaErrorT
  376. saAmfComponentRegister (
  377. const SaAmfHandleT *amfHandle,
  378. const SaNameT *compName,
  379. const SaNameT *proxyCompName)
  380. {
  381. struct amfInstance *amfInstance;
  382. SaErrorT error;
  383. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  384. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  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.header.error == SA_OK) {
  414. amfInstance->compRegistered = 1;
  415. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  416. }
  417. error = res_lib_amf_componentregister.header.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.size = sizeof (struct req_lib_amf_componentunregister);
  434. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  435. memcpy (&req_lib_amf_componentunregister.compName, compName, sizeof (SaNameT));
  436. if (proxyCompName) {
  437. memcpy (&req_lib_amf_componentunregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  438. } else {
  439. memset (&req_lib_amf_componentunregister.proxyCompName, 0, sizeof (SaNameT));
  440. }
  441. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  442. if (error != SA_OK) {
  443. return (error);
  444. }
  445. pthread_mutex_lock (&amfInstance->mutex);
  446. error = saSendRetry (amfInstance->fd, &req_lib_amf_componentunregister,
  447. sizeof (struct req_lib_amf_componentunregister), MSG_NOSIGNAL);
  448. if (error != SA_OK) {
  449. goto error_unlock;
  450. }
  451. /*
  452. * Search for COMPONENTUNREGISTER responses and queue any
  453. * messages that dont match in this amfHandle's inq.
  454. * This must be done to avoid dropping async messages
  455. * during this sync message retrieval
  456. */
  457. error = saRecvQueue (amfInstance->fd, &res_lib_amf_componentunregister,
  458. &amfInstance->inq, MESSAGE_RES_AMF_COMPONENTUNREGISTER);
  459. if (error != SA_OK) {
  460. goto error_unlock;
  461. }
  462. if (res_lib_amf_componentunregister.header.error == SA_OK) {
  463. amfInstance->compRegistered = 0;
  464. }
  465. error = res_lib_amf_componentunregister.header.error;
  466. error_unlock:
  467. pthread_mutex_unlock (&amfInstance->mutex);
  468. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  469. return (error);
  470. }
  471. SaErrorT
  472. saAmfCompNameGet (
  473. const SaAmfHandleT *amfHandle,
  474. SaNameT *compName)
  475. {
  476. struct amfInstance *amfInstance;
  477. SaErrorT error;
  478. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  479. if (error != SA_OK) {
  480. return (error);
  481. }
  482. pthread_mutex_lock (&amfInstance->mutex);
  483. if (amfInstance->compRegistered == 0) {
  484. pthread_mutex_unlock (&amfInstance->mutex);
  485. return (SA_ERR_NOT_EXIST);
  486. }
  487. memcpy (compName, &amfInstance->compName, sizeof (SaNameT));
  488. pthread_mutex_unlock (&amfInstance->mutex);
  489. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  490. return (SA_OK);
  491. }
  492. SaErrorT
  493. saAmfReadinessStateGet (
  494. const SaNameT *compName,
  495. SaAmfReadinessStateT *readinessState)
  496. {
  497. int fd;
  498. SaErrorT error;
  499. struct req_amf_readinessstateget req_amf_readinessstateget;
  500. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  501. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  502. if (error != SA_OK) {
  503. goto exit_noclose;
  504. }
  505. req_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  506. req_amf_readinessstateget.header.size = sizeof (struct req_amf_readinessstateget);
  507. memcpy (&req_amf_readinessstateget.compName, compName, sizeof (SaNameT));
  508. error = saSendRetry (fd, &req_amf_readinessstateget,
  509. sizeof (struct req_amf_readinessstateget), MSG_NOSIGNAL);
  510. if (error != SA_OK) {
  511. goto exit_close;
  512. }
  513. error = saRecvRetry (fd, &res_lib_amf_readinessstateget,
  514. sizeof (struct res_lib_amf_readinessstateget), MSG_WAITALL | MSG_NOSIGNAL);
  515. if (error == SA_OK) {
  516. memcpy (readinessState, &res_lib_amf_readinessstateget.readinessState,
  517. sizeof (SaAmfReadinessStateT));
  518. error = res_lib_amf_readinessstateget.header.error;
  519. }
  520. exit_close:
  521. close (fd);
  522. exit_noclose:
  523. return (error);
  524. }
  525. SaErrorT
  526. saAmfStoppingComplete (
  527. SaInvocationT invocation,
  528. SaErrorT error)
  529. {
  530. struct req_amf_stoppingcomplete req_amf_stoppingcomplete;
  531. int fd;
  532. SaErrorT errorResult;
  533. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  534. if (errorResult != SA_OK) {
  535. goto exit_noclose;
  536. }
  537. req_amf_stoppingcomplete.header.id = MESSAGE_REQ_AMF_STOPPINGCOMPLETE;
  538. req_amf_stoppingcomplete.header.size = sizeof (struct req_amf_stoppingcomplete);
  539. req_amf_stoppingcomplete.invocation = invocation;
  540. req_amf_stoppingcomplete.error = error;
  541. errorResult = saSendRetry (fd, &req_amf_stoppingcomplete,
  542. sizeof (struct req_amf_stoppingcomplete), MSG_NOSIGNAL);
  543. close (fd);
  544. exit_noclose:
  545. return (errorResult);
  546. }
  547. SaErrorT
  548. saAmfHAStateGet (
  549. const SaNameT *compName,
  550. const SaNameT *csiName,
  551. SaAmfHAStateT *haState) {
  552. struct req_amf_hastateget req_amf_hastateget;
  553. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  554. int fd;
  555. SaErrorT error;
  556. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  557. if (error != SA_OK) {
  558. goto exit_noclose;
  559. }
  560. req_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  561. req_amf_hastateget.header.size = sizeof (struct req_amf_hastateget);
  562. memcpy (&req_amf_hastateget.compName, compName, sizeof (SaNameT));
  563. memcpy (&req_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  564. error = saSendRetry (fd, &req_amf_hastateget,
  565. sizeof (struct req_amf_hastateget), MSG_NOSIGNAL);
  566. if (error != SA_OK) {
  567. goto exit_close;
  568. }
  569. error = saRecvRetry (fd, &res_lib_amf_hastateget,
  570. sizeof (struct res_lib_amf_hastateget), MSG_WAITALL | MSG_NOSIGNAL);
  571. if (error == SA_OK) {
  572. memcpy (haState, &res_lib_amf_hastateget.haState, sizeof (SaAmfHAStateT));
  573. error = res_lib_amf_hastateget.header.error;
  574. }
  575. exit_close:
  576. close (fd);
  577. exit_noclose:
  578. return (error);
  579. }
  580. SaErrorT
  581. saAmfProtectionGroupTrackStart (
  582. const SaAmfHandleT *amfHandle,
  583. const SaNameT *csiName,
  584. SaUint8T trackFlags,
  585. const SaAmfProtectionGroupNotificationT *notificationBuffer,
  586. SaUint32T numberOfItems) {
  587. struct amfInstance *amfInstance;
  588. struct req_amf_protectiongrouptrackstart req_amf_protectiongrouptrackstart;
  589. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  590. SaErrorT error;
  591. req_amf_protectiongrouptrackstart.header.size = sizeof (struct req_amf_protectiongrouptrackstart);
  592. req_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  593. memcpy (&req_amf_protectiongrouptrackstart.csiName, csiName, sizeof (SaNameT));
  594. req_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  595. req_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  596. req_amf_protectiongrouptrackstart.numberOfItems = numberOfItems;
  597. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  598. if (error != SA_OK) {
  599. return (error);
  600. }
  601. pthread_mutex_lock (&amfInstance->mutex);
  602. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstart,
  603. sizeof (struct req_amf_protectiongrouptrackstart), MSG_NOSIGNAL);
  604. if (error != SA_OK) {
  605. goto error_unlock;
  606. }
  607. error = saRecvQueue (amfInstance->fd, &res_lib_amf_protectiongrouptrackstart,
  608. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART);
  609. error = res_lib_amf_protectiongrouptrackstart.header.error;
  610. error_unlock:
  611. pthread_mutex_unlock (&amfInstance->mutex);
  612. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  613. return (error);
  614. }
  615. SaErrorT
  616. saAmfProtectionGroupTrackStop (
  617. const SaAmfHandleT *amfHandle,
  618. const SaNameT *csiName) {
  619. struct amfInstance *amfInstance;
  620. struct req_amf_protectiongrouptrackstop req_amf_protectiongrouptrackstop;
  621. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  622. SaErrorT error;
  623. req_amf_protectiongrouptrackstop.header.size = sizeof (struct req_amf_protectiongrouptrackstop);
  624. req_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  625. memcpy (&req_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  626. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  627. if (error != SA_OK) {
  628. return (error);
  629. }
  630. pthread_mutex_lock (&amfInstance->mutex);
  631. error = saSendRetry (amfInstance->fd, &req_amf_protectiongrouptrackstop,
  632. sizeof (struct req_amf_protectiongrouptrackstop), MSG_NOSIGNAL);
  633. if (error != SA_OK) {
  634. goto error_unlock;
  635. }
  636. error = saRecvQueue (amfInstance->fd, &res_lib_amf_protectiongrouptrackstop,
  637. &amfInstance->inq, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP);
  638. error = res_lib_amf_protectiongrouptrackstop.header.error;
  639. error_unlock:
  640. pthread_mutex_unlock (&amfInstance->mutex);
  641. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  642. return (error);
  643. }
  644. SaErrorT
  645. saAmfErrorReport (
  646. const SaNameT *reportingComponent,
  647. const SaNameT *erroneousComponent,
  648. SaTimeT errorDetectionTime,
  649. const SaAmfErrorDescriptorT *errorDescriptor,
  650. const SaAmfAdditionalDataT *additionalData) {
  651. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  652. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  653. int fd;
  654. SaErrorT error;
  655. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  656. if (error != SA_OK) {
  657. goto exit_noclose;
  658. }
  659. req_lib_amf_errorreport.header.id = MESSAGE_REQ_AMF_ERRORREPORT;
  660. req_lib_amf_errorreport.header.size = sizeof (struct req_lib_amf_errorreport);
  661. memcpy (&req_lib_amf_errorreport.reportingComponent, reportingComponent, sizeof (SaNameT));
  662. memcpy (&req_lib_amf_errorreport.erroneousComponent, erroneousComponent, sizeof (SaNameT));
  663. req_lib_amf_errorreport.errorDetectionTime = errorDetectionTime;
  664. memcpy (&req_lib_amf_errorreport.errorDescriptor,
  665. errorDescriptor, sizeof (SaAmfErrorDescriptorT));
  666. /* TODO this is wrong, and needs some thinking
  667. memcpy (&req_lib_amf_errorreport.additionalData,
  668. additionalData, sizeof (SaAmfAdditionalDataT));
  669. */
  670. error = saSendRetry (fd, &req_lib_amf_errorreport,
  671. sizeof (struct req_lib_amf_errorreport), MSG_NOSIGNAL);
  672. /*
  673. * Get response from executive and respond to user application
  674. */
  675. error = saRecvRetry (fd, &res_lib_amf_errorreport,
  676. sizeof (struct res_lib_amf_errorreport), MSG_WAITALL | MSG_NOSIGNAL);
  677. if (error != SA_OK) {
  678. goto exit_close;
  679. }
  680. error = res_lib_amf_errorreport.header.error;
  681. exit_close:
  682. close (fd);
  683. exit_noclose:
  684. return (error);
  685. }
  686. SaErrorT
  687. saAmfErrorCancelAll (
  688. const SaNameT *compName) {
  689. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  690. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  691. int fd;
  692. SaErrorT error;
  693. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  694. if (error != SA_OK) {
  695. goto exit_noclose;
  696. }
  697. req_lib_amf_errorcancelall.header.id = MESSAGE_REQ_AMF_ERRORCANCELALL;
  698. req_lib_amf_errorcancelall.header.size = sizeof (struct req_lib_amf_errorcancelall);
  699. memcpy (&req_lib_amf_errorcancelall.compName, compName, sizeof (SaNameT));
  700. error = saSendRetry (fd, &req_lib_amf_errorcancelall,
  701. sizeof (struct req_lib_amf_errorcancelall), MSG_NOSIGNAL);
  702. /*
  703. * Get response from executive and respond to user application
  704. */
  705. error = saRecvRetry (fd, &res_lib_amf_errorcancelall,
  706. sizeof (struct res_lib_amf_errorcancelall), MSG_WAITALL | MSG_NOSIGNAL);
  707. if (error != SA_OK) {
  708. goto exit_close;
  709. }
  710. error = res_lib_amf_errorcancelall.header.error;
  711. exit_close:
  712. close (fd);
  713. exit_noclose:
  714. return (error);
  715. }
  716. SaErrorT
  717. saAmfComponentCapabilityModelGet (
  718. const SaNameT *compName,
  719. SaAmfComponentCapabilityModelT *componentCapabilityModel)
  720. {
  721. int fd;
  722. SaErrorT error;
  723. struct req_amf_componentcapabilitymodelget req_amf_componentcapabilitymodelget;
  724. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  725. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  726. if (error != SA_OK) {
  727. goto exit_noclose;
  728. }
  729. req_amf_componentcapabilitymodelget.header.id = MESSAGE_REQ_AMF_COMPONENTCAPABILITYMODELGET;
  730. req_amf_componentcapabilitymodelget.header.size = sizeof (struct req_amf_componentcapabilitymodelget);
  731. memcpy (&req_amf_componentcapabilitymodelget.compName, compName, sizeof (SaNameT));
  732. error = saSendRetry (fd, &req_amf_componentcapabilitymodelget,
  733. sizeof (struct req_amf_componentcapabilitymodelget), MSG_NOSIGNAL);
  734. if (error != SA_OK) {
  735. goto exit_close;
  736. }
  737. error = saRecvRetry (fd, &res_lib_amf_componentcapabilitymodelget,
  738. sizeof (struct res_lib_amf_componentcapabilitymodelget), MSG_WAITALL | MSG_NOSIGNAL);
  739. if (error == SA_OK) {
  740. memcpy (componentCapabilityModel,
  741. &res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  742. sizeof (SaAmfComponentCapabilityModelT));
  743. error = res_lib_amf_componentcapabilitymodelget.header.error;
  744. }
  745. exit_close:
  746. close (fd);
  747. exit_noclose:
  748. return (error);
  749. }
  750. SaErrorT
  751. saAmfPendingOperationGet (
  752. const SaNameT *compName,
  753. SaAmfPendingOperationFlagsT *pendingOperationFlags) {
  754. *pendingOperationFlags = 0;
  755. return (SA_OK);
  756. }
  757. SaErrorT
  758. saAmfResponse (
  759. SaInvocationT invocation,
  760. SaErrorT error)
  761. {
  762. struct req_amf_response req_amf_response;
  763. int fd;
  764. SaErrorT errorResult;
  765. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  766. if (errorResult != SA_OK) {
  767. goto exit_noclose;
  768. }
  769. req_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  770. req_amf_response.header.size = sizeof (struct req_amf_response);
  771. req_amf_response.invocation = invocation;
  772. req_amf_response.error = error;
  773. errorResult = saSendRetry (fd, &req_amf_response,
  774. sizeof (struct req_amf_response), MSG_NOSIGNAL);
  775. close (fd);
  776. exit_noclose:
  777. return (errorResult);
  778. }