4
0

amf.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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 res_overlay {
  50. struct res_header header;
  51. char data[4096];
  52. };
  53. /*
  54. * Data structure for instance data
  55. */
  56. struct amfInstance {
  57. int response_fd;
  58. int dispatch_fd;
  59. SaAmfCallbacksT callbacks;
  60. SaNameT compName;
  61. int compRegistered;
  62. int finalize;
  63. pthread_mutex_t response_mutex;
  64. pthread_mutex_t dispatch_mutex;
  65. };
  66. static void amfHandleInstanceDestructor (void *);
  67. /*
  68. * All instances in one database
  69. */
  70. static struct saHandleDatabase amfHandleDatabase = {
  71. .handleCount = 0,
  72. .handles = 0,
  73. .mutex = PTHREAD_MUTEX_INITIALIZER,
  74. .handleInstanceDestructor = amfHandleInstanceDestructor
  75. };
  76. /*
  77. * Versions supported
  78. */
  79. static SaVersionT amfVersionsSupported[] = {
  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. }
  92. SaErrorT
  93. saAmfInitialize (
  94. SaAmfHandleT *amfHandle,
  95. const SaAmfCallbacksT *amfCallbacks,
  96. const SaVersionT *version)
  97. {
  98. struct amfInstance *amfInstance;
  99. SaErrorT error = SA_OK;
  100. error = saVersionVerify (&amfVersionDatabase, version);
  101. if (error != SA_OK) {
  102. goto error_no_destroy;
  103. }
  104. error = saHandleCreate (&amfHandleDatabase, sizeof (struct amfInstance), amfHandle);
  105. if (error != SA_OK) {
  106. goto error_no_destroy;
  107. }
  108. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  109. if (error != SA_OK) {
  110. goto error_destroy;
  111. }
  112. amfInstance->response_fd = -1;
  113. amfInstance->dispatch_fd = -1;
  114. error = saServiceConnectTwo (&amfInstance->response_fd,
  115. &amfInstance->dispatch_fd, AMF_SERVICE);
  116. if (error != SA_OK) {
  117. goto error_put_destroy;
  118. }
  119. memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT));
  120. pthread_mutex_init (&amfInstance->response_mutex, NULL);
  121. pthread_mutex_init (&amfInstance->dispatch_mutex, NULL);
  122. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  123. return (SA_OK);
  124. error_put_destroy:
  125. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  126. error_destroy:
  127. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  128. error_no_destroy:
  129. return (error);
  130. }
  131. SaErrorT
  132. saAmfSelectionObjectGet (
  133. const SaAmfHandleT *amfHandle,
  134. SaSelectionObjectT *selectionObject)
  135. {
  136. struct amfInstance *amfInstance;
  137. SaErrorT error;
  138. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  139. if (error != SA_OK) {
  140. return (error);
  141. }
  142. *selectionObject = amfInstance->dispatch_fd;
  143. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  144. return (SA_OK);
  145. }
  146. SaErrorT
  147. saAmfDispatch (
  148. const SaAmfHandleT *amfHandle,
  149. SaDispatchFlagsT dispatchFlags)
  150. {
  151. struct pollfd ufds;
  152. int timeout = -1;
  153. SaErrorT error;
  154. int cont = 1; /* always continue do loop except when set to 0 */
  155. int dispatch_avail;
  156. struct amfInstance *amfInstance;
  157. struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
  158. struct res_lib_amf_readinessstatesetcallback *res_lib_amf_readinessstatesetcallback;
  159. struct res_lib_amf_csisetcallback *res_lib_amf_csisetcallback;
  160. struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
  161. struct res_lib_amf_protectiongrouptrackcallback *res_lib_amf_protectiongrouptrackcallback;
  162. SaAmfCallbacksT callbacks;
  163. struct res_overlay dispatch_data;
  164. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle,
  165. (void *)&amfInstance);
  166. if (error != SA_OK) {
  167. return (error);
  168. }
  169. /*
  170. * Timeout instantly for SA_DISPATCH_ALL
  171. */
  172. if (dispatchFlags == SA_DISPATCH_ALL) {
  173. timeout = 0;
  174. }
  175. do {
  176. /*
  177. * Read data directly from socket
  178. */
  179. ufds.fd = amfInstance->dispatch_fd;
  180. ufds.events = POLLIN;
  181. ufds.revents = 0;
  182. error = saPollRetry (&ufds, 1, timeout);
  183. if (error != SA_OK) {
  184. goto error_nounlock;
  185. }
  186. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  187. error = saPollRetry (&ufds, 1, 0);
  188. if (error != SA_OK) {
  189. goto error_nounlock;
  190. }
  191. /*
  192. * Handle has been finalized in another thread
  193. */
  194. if (amfInstance->finalize == 1) {
  195. error = SA_OK;
  196. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  197. goto error_unlock;
  198. }
  199. dispatch_avail = ufds.revents & POLLIN;
  200. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  201. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  202. break; /* exit do while cont is 1 loop */
  203. } else
  204. if (dispatch_avail == 0) {
  205. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  206. continue; /* next poll */
  207. }
  208. if (ufds.revents & POLLIN) {
  209. /*
  210. * Queue empty, read response from socket
  211. */
  212. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.header,
  213. sizeof (struct res_header), MSG_WAITALL | MSG_NOSIGNAL);
  214. if (error != SA_OK) {
  215. goto error_unlock;
  216. }
  217. if (dispatch_data.header.size > sizeof (struct res_header)) {
  218. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.data,
  219. dispatch_data.header.size - sizeof (struct res_header),
  220. MSG_WAITALL | MSG_NOSIGNAL);
  221. if (error != SA_OK) {
  222. goto error_unlock;
  223. }
  224. }
  225. } else {
  226. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  227. continue;
  228. }
  229. /*
  230. * Make copy of callbacks, message data, unlock instance, and call callback
  231. * A risk of this dispatch method is that the callback routines may
  232. * operate at the same time that amfFinalize has been called in another thread.
  233. */
  234. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  235. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  236. /*
  237. * Dispatch incoming response
  238. */
  239. switch (dispatch_data.header.id) {
  240. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  241. res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
  242. callbacks.saAmfHealthcheckCallback (
  243. res_lib_amf_healthcheckcallback->invocation,
  244. &res_lib_amf_healthcheckcallback->compName,
  245. res_lib_amf_healthcheckcallback->checkType);
  246. break;
  247. case MESSAGE_RES_AMF_READINESSSTATESETCALLBACK:
  248. res_lib_amf_readinessstatesetcallback = (struct res_lib_amf_readinessstatesetcallback *)&dispatch_data;
  249. callbacks.saAmfReadinessStateSetCallback (
  250. res_lib_amf_readinessstatesetcallback->invocation,
  251. &res_lib_amf_readinessstatesetcallback->compName,
  252. res_lib_amf_readinessstatesetcallback->readinessState);
  253. break;
  254. case MESSAGE_RES_AMF_CSISETCALLBACK:
  255. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  256. callbacks.saAmfCSISetCallback (
  257. res_lib_amf_csisetcallback->invocation,
  258. &res_lib_amf_csisetcallback->compName,
  259. &res_lib_amf_csisetcallback->csiName,
  260. res_lib_amf_csisetcallback->csiFlags,
  261. &res_lib_amf_csisetcallback->haState,
  262. &res_lib_amf_csisetcallback->activeCompName,
  263. res_lib_amf_csisetcallback->transitionDescriptor);
  264. break;
  265. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  266. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  267. callbacks.saAmfCSIRemoveCallback (
  268. res_lib_amf_csiremovecallback->invocation,
  269. &res_lib_amf_csiremovecallback->compName,
  270. &res_lib_amf_csiremovecallback->csiName,
  271. &res_lib_amf_csiremovecallback->csiFlags);
  272. break;
  273. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  274. res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
  275. memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  276. res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
  277. res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  278. callbacks.saAmfProtectionGroupTrackCallback(
  279. &res_lib_amf_protectiongrouptrackcallback->csiName,
  280. res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  281. res_lib_amf_protectiongrouptrackcallback->numberOfItems,
  282. res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
  283. res_lib_amf_protectiongrouptrackcallback->error);
  284. break;
  285. default:
  286. error = SA_ERR_LIBRARY;
  287. goto error_nounlock;
  288. break;
  289. }
  290. /*
  291. * Determine if more messages should be processed
  292. */
  293. switch (dispatchFlags) {
  294. case SA_DISPATCH_ONE:
  295. cont = 0;
  296. break;
  297. case SA_DISPATCH_ALL:
  298. break;
  299. case SA_DISPATCH_BLOCKING:
  300. break;
  301. }
  302. } while (cont);
  303. error_unlock:
  304. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  305. error_nounlock:
  306. return (error);
  307. }
  308. SaErrorT
  309. saAmfFinalize (
  310. const SaAmfHandleT *amfHandle)
  311. {
  312. struct amfInstance *amfInstance;
  313. SaErrorT error;
  314. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  315. if (error != SA_OK) {
  316. return (error);
  317. }
  318. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  319. pthread_mutex_lock (&amfInstance->response_mutex);
  320. /*
  321. * Another thread has already started finalizing
  322. */
  323. if (amfInstance->finalize) {
  324. pthread_mutex_unlock (&amfInstance->response_mutex);
  325. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  326. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  327. return (SA_ERR_BAD_HANDLE);
  328. }
  329. amfInstance->finalize = 1;
  330. pthread_mutex_unlock (&amfInstance->response_mutex);
  331. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  332. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  333. if (amfInstance->response_fd != -1) {
  334. shutdown (amfInstance->response_fd, 0);
  335. close (amfInstance->response_fd);
  336. }
  337. if (amfInstance->dispatch_fd != -1) {
  338. shutdown (amfInstance->dispatch_fd, 0);
  339. close (amfInstance->dispatch_fd);
  340. }
  341. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  342. return (error);
  343. }
  344. SaErrorT
  345. saAmfComponentRegister (
  346. const SaAmfHandleT *amfHandle,
  347. const SaNameT *compName,
  348. const SaNameT *proxyCompName)
  349. {
  350. struct amfInstance *amfInstance;
  351. SaErrorT error;
  352. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  353. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  354. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  355. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  356. memcpy (&req_lib_amf_componentregister.compName, compName, sizeof (SaNameT));
  357. if (proxyCompName) {
  358. memcpy (&req_lib_amf_componentregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  359. } else {
  360. memset (&req_lib_amf_componentregister.proxyCompName, 0, sizeof (SaNameT));
  361. }
  362. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  363. if (error != SA_OK) {
  364. return (error);
  365. }
  366. pthread_mutex_lock (&amfInstance->response_mutex);
  367. error - saSendReceiveReply (amfInstance->response_fd, &req_lib_amf_componentregister,
  368. sizeof (struct req_lib_amf_componentregister),
  369. &res_lib_amf_componentregister,
  370. sizeof (struct res_lib_amf_componentregister));
  371. if (error != SA_OK) {
  372. goto error_unlock;
  373. }
  374. if (res_lib_amf_componentregister.header.error == SA_OK) {
  375. amfInstance->compRegistered = 1;
  376. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  377. }
  378. error = res_lib_amf_componentregister.header.error;
  379. error_unlock:
  380. pthread_mutex_unlock (&amfInstance->response_mutex);
  381. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  382. return (error);
  383. }
  384. SaErrorT
  385. saAmfComponentUnregister (
  386. const SaAmfHandleT *amfHandle,
  387. const SaNameT *compName,
  388. const SaNameT *proxyCompName)
  389. {
  390. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  391. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  392. struct amfInstance *amfInstance;
  393. SaErrorT error;
  394. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  395. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  396. memcpy (&req_lib_amf_componentunregister.compName, compName, sizeof (SaNameT));
  397. if (proxyCompName) {
  398. memcpy (&req_lib_amf_componentunregister.proxyCompName, proxyCompName, sizeof (SaNameT));
  399. } else {
  400. memset (&req_lib_amf_componentunregister.proxyCompName, 0, sizeof (SaNameT));
  401. }
  402. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  403. if (error != SA_OK) {
  404. return (error);
  405. }
  406. pthread_mutex_lock (&amfInstance->response_mutex);
  407. error - saSendReceiveReply (amfInstance->response_fd,
  408. &req_lib_amf_componentunregister,
  409. sizeof (struct req_lib_amf_componentunregister),
  410. &res_lib_amf_componentunregister,
  411. sizeof (struct res_lib_amf_componentunregister));
  412. if (error != SA_OK) {
  413. goto error_unlock;
  414. }
  415. error = res_lib_amf_componentunregister.header.error;
  416. if (error == SA_OK) {
  417. amfInstance->compRegistered = 0;
  418. }
  419. error_unlock:
  420. pthread_mutex_unlock (&amfInstance->response_mutex);
  421. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  422. return (error);
  423. }
  424. SaErrorT
  425. saAmfCompNameGet (
  426. const SaAmfHandleT *amfHandle,
  427. SaNameT *compName)
  428. {
  429. struct amfInstance *amfInstance;
  430. SaErrorT error;
  431. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  432. if (error != SA_OK) {
  433. return (error);
  434. }
  435. pthread_mutex_lock (&amfInstance->response_mutex);
  436. if (amfInstance->compRegistered == 0) {
  437. pthread_mutex_unlock (&amfInstance->response_mutex);
  438. return (SA_ERR_NOT_EXIST);
  439. }
  440. memcpy (compName, &amfInstance->compName, sizeof (SaNameT));
  441. pthread_mutex_unlock (&amfInstance->response_mutex);
  442. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  443. return (SA_OK);
  444. }
  445. SaErrorT
  446. saAmfReadinessStateGet (
  447. const SaNameT *compName,
  448. SaAmfReadinessStateT *readinessState)
  449. {
  450. int fd_response;
  451. int fd_dispatch;
  452. SaErrorT error;
  453. struct req_amf_readinessstateget req_amf_readinessstateget;
  454. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  455. error = saServiceConnectTwo (&fd_response, &fd_dispatch, AMF_SERVICE);
  456. if (error != SA_OK) {
  457. goto exit_noclose;
  458. }
  459. req_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  460. req_amf_readinessstateget.header.size = sizeof (struct req_amf_readinessstateget);
  461. memcpy (&req_amf_readinessstateget.compName, compName, sizeof (SaNameT));
  462. error - saSendReceiveReply (fd_response,
  463. &req_amf_readinessstateget, sizeof (struct req_amf_readinessstateget),
  464. &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  465. if (error != SA_OK) {
  466. goto exit_close;
  467. }
  468. error = res_lib_amf_readinessstateget.header.error;
  469. if (error == SA_OK) {
  470. memcpy (readinessState, &res_lib_amf_readinessstateget.readinessState,
  471. sizeof (SaAmfReadinessStateT));
  472. }
  473. exit_close:
  474. close (fd_response);
  475. close (fd_dispatch);
  476. exit_noclose:
  477. return (error);
  478. }
  479. SaErrorT
  480. saAmfStoppingComplete (
  481. SaInvocationT invocation,
  482. SaErrorT error)
  483. {
  484. struct req_amf_stoppingcomplete req_amf_stoppingcomplete;
  485. struct res_lib_amf_stoppingcomplete res_lib_amf_stoppingcomplete;
  486. int fd;
  487. SaErrorT errorResult;
  488. errorResult = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  489. if (errorResult != SA_OK) {
  490. goto exit_noclose;
  491. }
  492. req_amf_stoppingcomplete.header.id = MESSAGE_REQ_AMF_STOPPINGCOMPLETE;
  493. req_amf_stoppingcomplete.header.size = sizeof (struct req_amf_stoppingcomplete);
  494. req_amf_stoppingcomplete.invocation = invocation;
  495. req_amf_stoppingcomplete.error = error;
  496. error = saSendReceiveReply (fd,
  497. &req_amf_stoppingcomplete, sizeof (struct req_amf_stoppingcomplete),
  498. &res_lib_amf_stoppingcomplete, sizeof (struct res_lib_amf_stoppingcomplete));
  499. if (error != SA_OK) {
  500. goto exit_close;
  501. }
  502. error = res_lib_amf_stoppingcomplete.header.error;
  503. // TODO executive needs to send reply of stopping complete
  504. exit_close:
  505. close (fd);
  506. exit_noclose:
  507. return (errorResult);
  508. }
  509. SaErrorT
  510. saAmfHAStateGet (
  511. const SaNameT *compName,
  512. const SaNameT *csiName,
  513. SaAmfHAStateT *haState) {
  514. struct req_amf_hastateget req_amf_hastateget;
  515. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  516. int fd;
  517. SaErrorT error;
  518. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  519. if (error != SA_OK) {
  520. goto exit_noclose;
  521. }
  522. req_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  523. req_amf_hastateget.header.size = sizeof (struct req_amf_hastateget);
  524. memcpy (&req_amf_hastateget.compName, compName, sizeof (SaNameT));
  525. memcpy (&req_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  526. error = saSendReceiveReply (fd,
  527. &req_amf_hastateget, sizeof (struct req_amf_hastateget),
  528. &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  529. if (error != SA_OK) {
  530. goto exit_close;
  531. }
  532. error = res_lib_amf_hastateget.header.error;
  533. if (error == SA_OK) {
  534. memcpy (haState, &res_lib_amf_hastateget.haState, sizeof (SaAmfHAStateT));
  535. }
  536. exit_close:
  537. close (fd);
  538. exit_noclose:
  539. return (error);
  540. }
  541. SaErrorT
  542. saAmfProtectionGroupTrackStart (
  543. const SaAmfHandleT *amfHandle,
  544. const SaNameT *csiName,
  545. SaUint8T trackFlags,
  546. const SaAmfProtectionGroupNotificationT *notificationBuffer,
  547. SaUint32T numberOfItems) {
  548. struct amfInstance *amfInstance;
  549. struct req_amf_protectiongrouptrackstart req_amf_protectiongrouptrackstart;
  550. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  551. SaErrorT error;
  552. req_amf_protectiongrouptrackstart.header.size = sizeof (struct req_amf_protectiongrouptrackstart);
  553. req_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  554. memcpy (&req_amf_protectiongrouptrackstart.csiName, csiName, sizeof (SaNameT));
  555. req_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  556. req_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  557. req_amf_protectiongrouptrackstart.numberOfItems = numberOfItems;
  558. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  559. if (error != SA_OK) {
  560. return (error);
  561. }
  562. pthread_mutex_lock (&amfInstance->response_mutex);
  563. error = saSendReceiveReply (amfInstance->response_fd,
  564. &req_amf_protectiongrouptrackstart,
  565. sizeof (struct req_amf_protectiongrouptrackstart),
  566. &res_lib_amf_protectiongrouptrackstart,
  567. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  568. if (error != SA_OK) {
  569. goto error_unlock;
  570. }
  571. error = res_lib_amf_protectiongrouptrackstart.header.error;
  572. error_unlock:
  573. pthread_mutex_unlock (&amfInstance->response_mutex);
  574. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  575. return (error);
  576. }
  577. SaErrorT
  578. saAmfProtectionGroupTrackStop (
  579. const SaAmfHandleT *amfHandle,
  580. const SaNameT *csiName) {
  581. struct amfInstance *amfInstance;
  582. struct req_amf_protectiongrouptrackstop req_amf_protectiongrouptrackstop;
  583. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  584. SaErrorT error;
  585. req_amf_protectiongrouptrackstop.header.size = sizeof (struct req_amf_protectiongrouptrackstop);
  586. req_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  587. memcpy (&req_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  588. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  589. if (error != SA_OK) {
  590. return (error);
  591. }
  592. pthread_mutex_lock (&amfInstance->response_mutex);
  593. error = saSendReceiveReply (amfInstance->response_fd,
  594. &req_amf_protectiongrouptrackstop,
  595. sizeof (struct req_amf_protectiongrouptrackstop),
  596. &res_lib_amf_protectiongrouptrackstop,
  597. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  598. if (error != SA_OK) {
  599. goto error_unlock;
  600. }
  601. error = res_lib_amf_protectiongrouptrackstop.header.error;
  602. error_unlock:
  603. pthread_mutex_unlock (&amfInstance->response_mutex);
  604. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  605. return (error);
  606. }
  607. SaErrorT
  608. saAmfErrorReport (
  609. const SaNameT *reportingComponent,
  610. const SaNameT *erroneousComponent,
  611. SaTimeT errorDetectionTime,
  612. const SaAmfErrorDescriptorT *errorDescriptor,
  613. const SaAmfAdditionalDataT *additionalData) {
  614. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  615. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  616. int fd;
  617. SaErrorT error;
  618. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  619. if (error != SA_OK) {
  620. goto exit_noclose;
  621. }
  622. req_lib_amf_errorreport.header.id = MESSAGE_REQ_AMF_ERRORREPORT;
  623. req_lib_amf_errorreport.header.size = sizeof (struct req_lib_amf_errorreport);
  624. memcpy (&req_lib_amf_errorreport.reportingComponent, reportingComponent, sizeof (SaNameT));
  625. memcpy (&req_lib_amf_errorreport.erroneousComponent, erroneousComponent, sizeof (SaNameT));
  626. req_lib_amf_errorreport.errorDetectionTime = errorDetectionTime;
  627. memcpy (&req_lib_amf_errorreport.errorDescriptor,
  628. errorDescriptor, sizeof (SaAmfErrorDescriptorT));
  629. /* TODO this is wrong, and needs some thinking
  630. memcpy (&req_lib_amf_errorreport.additionalData,
  631. additionalData, sizeof (SaAmfAdditionalDataT));
  632. */
  633. error = saSendReceiveReply (fd,
  634. &req_lib_amf_errorreport, sizeof (struct req_lib_amf_errorreport),
  635. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  636. if (error != SA_OK) {
  637. goto exit_close;
  638. }
  639. error = res_lib_amf_errorreport.header.error;
  640. exit_close:
  641. close (fd);
  642. exit_noclose:
  643. return (error);
  644. }
  645. SaErrorT
  646. saAmfErrorCancelAll (
  647. const SaNameT *compName) {
  648. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  649. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  650. int fd;
  651. SaErrorT error;
  652. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  653. if (error != SA_OK) {
  654. goto exit_noclose;
  655. }
  656. req_lib_amf_errorcancelall.header.id = MESSAGE_REQ_AMF_ERRORCANCELALL;
  657. req_lib_amf_errorcancelall.header.size = sizeof (struct req_lib_amf_errorcancelall);
  658. memcpy (&req_lib_amf_errorcancelall.compName, compName, sizeof (SaNameT));
  659. error = saSendReceiveReply (fd,
  660. &req_lib_amf_errorcancelall, sizeof (struct req_lib_amf_errorcancelall),
  661. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  662. if (error != SA_OK) {
  663. goto exit_close;
  664. }
  665. error = res_lib_amf_errorcancelall.header.error;
  666. exit_close:
  667. close (fd);
  668. exit_noclose:
  669. return (error);
  670. }
  671. SaErrorT
  672. saAmfComponentCapabilityModelGet (
  673. const SaNameT *compName,
  674. SaAmfComponentCapabilityModelT *componentCapabilityModel)
  675. {
  676. int fd;
  677. SaErrorT error;
  678. struct req_amf_componentcapabilitymodelget req_amf_componentcapabilitymodelget;
  679. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  680. error = saServiceConnect (&fd, MESSAGE_REQ_AMF_INIT);
  681. if (error != SA_OK) {
  682. goto exit_noclose;
  683. }
  684. req_amf_componentcapabilitymodelget.header.id = MESSAGE_REQ_AMF_COMPONENTCAPABILITYMODELGET;
  685. req_amf_componentcapabilitymodelget.header.size = sizeof (struct req_amf_componentcapabilitymodelget);
  686. memcpy (&req_amf_componentcapabilitymodelget.compName, compName, sizeof (SaNameT));
  687. error = saSendReceiveReply (fd,
  688. &req_amf_componentcapabilitymodelget,
  689. sizeof (struct req_amf_componentcapabilitymodelget),
  690. &res_lib_amf_componentcapabilitymodelget,
  691. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  692. if (error != SA_OK) {
  693. goto exit_close;
  694. }
  695. error = res_lib_amf_componentcapabilitymodelget.header.error;
  696. if (error == SA_OK) {
  697. memcpy (componentCapabilityModel,
  698. &res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  699. sizeof (SaAmfComponentCapabilityModelT));
  700. }
  701. exit_close:
  702. close (fd);
  703. exit_noclose:
  704. return (error);
  705. }
  706. SaErrorT
  707. saAmfPendingOperationGet (
  708. const SaNameT *compName,
  709. SaAmfPendingOperationFlagsT *pendingOperationFlags) {
  710. *pendingOperationFlags = 0;
  711. return (SA_OK);
  712. }
  713. SaErrorT
  714. saAmfResponse (
  715. SaInvocationT invocation,
  716. SaErrorT error)
  717. {
  718. struct req_amf_response req_amf_response;
  719. struct res_lib_amf_response res_lib_amf_response;
  720. int fd_response;
  721. int fd_dispatch;
  722. SaErrorT errorResult;
  723. errorResult = saServiceConnectTwo (&fd_response, &fd_dispatch, AMF_SERVICE);
  724. if (errorResult != SA_OK) {
  725. goto exit_noclose;
  726. }
  727. req_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  728. req_amf_response.header.size = sizeof (struct req_amf_response);
  729. req_amf_response.invocation = invocation;
  730. req_amf_response.error = error;
  731. errorResult = saSendReceiveReply (fd_response,
  732. &req_amf_response,
  733. sizeof (struct req_amf_response),
  734. &res_lib_amf_response,
  735. sizeof (struct res_lib_amf_response));
  736. close (fd_response);
  737. close (fd_dispatch);
  738. if (errorResult == SA_OK) {
  739. errorResult = res_lib_amf_response.header.error;
  740. }
  741. exit_noclose:
  742. return (errorResult);
  743. }