amf.c 25 KB

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