amf.c 28 KB

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