amf.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /*
  2. * Copyright (c) 2002-2005 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/saAis.h"
  46. #include "../include/saAmf.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. { 'B', 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. SaAisErrorT
  94. saAmfInitialize (
  95. SaAmfHandleT *amfHandle,
  96. const SaAmfCallbacksT *amfCallbacks,
  97. SaVersionT *version)
  98. {
  99. struct amfInstance *amfInstance;
  100. SaAisErrorT error = SA_AIS_OK;
  101. error = saVersionVerify (&amfVersionDatabase, (SaVersionT *)version);
  102. if (error != SA_AIS_OK) {
  103. goto error_no_destroy;
  104. }
  105. error = saHandleCreate (&amfHandleDatabase, sizeof (struct amfInstance), amfHandle);
  106. if (error != SA_AIS_OK) {
  107. goto error_no_destroy;
  108. }
  109. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  110. if (error != SA_AIS_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_AIS_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_AIS_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. SaAisErrorT
  133. saAmfSelectionObjectGet (
  134. SaAmfHandleT amfHandle,
  135. SaSelectionObjectT *selectionObject)
  136. {
  137. struct amfInstance *amfInstance;
  138. SaAisErrorT error;
  139. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
  140. if (error != SA_AIS_OK) {
  141. return (error);
  142. }
  143. *selectionObject = amfInstance->dispatch_fd;
  144. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  145. return (SA_AIS_OK);
  146. }
  147. SaAisErrorT
  148. saAmfDispatch (
  149. SaAmfHandleT amfHandle,
  150. SaDispatchFlagsT dispatchFlags)
  151. {
  152. struct pollfd ufds;
  153. int timeout = -1;
  154. SaAisErrorT 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_csisetcallback *res_lib_amf_csisetcallback;
  159. struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
  160. struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
  161. struct res_lib_amf_componentterminatecallback *res_lib_amf_componentterminatecallback;
  162. /*
  163. struct res_lib_amf_protectiongrouptrackcallback *res_lib_amf_protectiongrouptrackcallback;
  164. */
  165. SaAmfCallbacksT callbacks;
  166. struct res_overlay dispatch_data;
  167. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  168. (void *)&amfInstance);
  169. if (error != SA_AIS_OK) {
  170. return (error);
  171. }
  172. /*
  173. * Timeout instantly for SA_DISPATCH_ALL
  174. */
  175. if (dispatchFlags == SA_DISPATCH_ALL) {
  176. timeout = 0;
  177. }
  178. do {
  179. /*
  180. * Read data directly from socket
  181. */
  182. ufds.fd = amfInstance->dispatch_fd;
  183. ufds.events = POLLIN;
  184. ufds.revents = 0;
  185. error = saPollRetry (&ufds, 1, timeout);
  186. if (error != SA_AIS_OK) {
  187. goto error_nounlock;
  188. }
  189. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  190. error = saPollRetry (&ufds, 1, 0);
  191. if (error != SA_AIS_OK) {
  192. goto error_nounlock;
  193. }
  194. /*
  195. * Handle has been finalized in another thread
  196. */
  197. if (amfInstance->finalize == 1) {
  198. error = SA_AIS_OK;
  199. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  200. goto error_unlock;
  201. }
  202. dispatch_avail = ufds.revents & POLLIN;
  203. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  204. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  205. break; /* exit do while cont is 1 loop */
  206. } else
  207. if (dispatch_avail == 0) {
  208. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  209. continue; /* next poll */
  210. }
  211. if (ufds.revents & POLLIN) {
  212. /*
  213. * Queue empty, read response from socket
  214. */
  215. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.header,
  216. sizeof (struct res_header));
  217. if (error != SA_AIS_OK) {
  218. goto error_unlock;
  219. }
  220. if (dispatch_data.header.size > sizeof (struct res_header)) {
  221. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.data,
  222. dispatch_data.header.size - sizeof (struct res_header));
  223. if (error != SA_AIS_OK) {
  224. goto error_unlock;
  225. }
  226. }
  227. } else {
  228. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  229. continue;
  230. }
  231. /*
  232. * Make copy of callbacks, message data, unlock instance, and call callback
  233. * A risk of this dispatch method is that the callback routines may
  234. * operate at the same time that amfFinalize has been called in another thread.
  235. */
  236. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  237. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  238. /*
  239. * Dispatch incoming response
  240. */
  241. switch (dispatch_data.header.id) {
  242. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  243. res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
  244. callbacks.saAmfHealthcheckCallback (
  245. res_lib_amf_healthcheckcallback->invocation,
  246. &res_lib_amf_healthcheckcallback->compName,
  247. &res_lib_amf_healthcheckcallback->key);
  248. break;
  249. case MESSAGE_RES_AMF_CSISETCALLBACK:
  250. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  251. callbacks.saAmfCSISetCallback (
  252. res_lib_amf_csisetcallback->invocation,
  253. &res_lib_amf_csisetcallback->compName,
  254. res_lib_amf_csisetcallback->haState,
  255. &res_lib_amf_csisetcallback->csiDescriptor);
  256. break;
  257. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  258. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  259. callbacks.saAmfCSIRemoveCallback (
  260. res_lib_amf_csiremovecallback->invocation,
  261. &res_lib_amf_csiremovecallback->compName,
  262. &res_lib_amf_csiremovecallback->csiName,
  263. res_lib_amf_csiremovecallback->csiFlags);
  264. break;
  265. case MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK:
  266. res_lib_amf_componentterminatecallback = (struct res_lib_amf_componentterminatecallback *)&dispatch_data;
  267. callbacks.saAmfComponentTerminateCallback (
  268. res_lib_amf_componentterminatecallback->invocation,
  269. &res_lib_amf_componentterminatecallback->compName);
  270. break;
  271. #ifdef COMPILE_OUT
  272. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  273. res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
  274. memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  275. res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
  276. res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  277. callbacks.saAmfProtectionGroupTrackCallback(
  278. &res_lib_amf_protectiongrouptrackcallback->csiName,
  279. res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  280. res_lib_amf_protectiongrouptrackcallback->numberOfItems,
  281. res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
  282. res_lib_amf_protectiongrouptrackcallback->error);
  283. #endif
  284. break;
  285. default:
  286. error = SA_AIS_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. SaAisErrorT
  309. saAmfFinalize (
  310. SaAmfHandleT amfHandle)
  311. {
  312. struct amfInstance *amfInstance;
  313. SaAisErrorT error;
  314. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
  315. if (error != SA_AIS_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_AIS_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. SaAisErrorT
  345. saAmfComponentRegister (
  346. SaAmfHandleT amfHandle,
  347. const SaNameT *compName,
  348. const SaNameT *proxyCompName)
  349. {
  350. struct amfInstance *amfInstance;
  351. SaAisErrorT error;
  352. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  353. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  354. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  355. (void *)&amfInstance);
  356. if (error != SA_AIS_OK) {
  357. return (error);
  358. }
  359. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  360. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  361. memcpy (&req_lib_amf_componentregister.compName, compName,
  362. sizeof (SaNameT));
  363. if (proxyCompName) {
  364. memcpy (&req_lib_amf_componentregister.proxyCompName,
  365. proxyCompName, sizeof (SaNameT));
  366. } else {
  367. memset (&req_lib_amf_componentregister.proxyCompName, 0,
  368. sizeof (SaNameT));
  369. }
  370. pthread_mutex_lock (&amfInstance->response_mutex);
  371. error = saSendReceiveReply (amfInstance->response_fd,
  372. &req_lib_amf_componentregister,
  373. sizeof (struct req_lib_amf_componentregister),
  374. &res_lib_amf_componentregister,
  375. sizeof (struct res_lib_amf_componentregister));
  376. pthread_mutex_unlock (&amfInstance->response_mutex);
  377. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  378. if (res_lib_amf_componentregister.header.error == SA_AIS_OK) {
  379. amfInstance->compRegistered = 1;
  380. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  381. }
  382. return (error == SA_AIS_OK ? res_lib_amf_componentregister.header.error : error);
  383. }
  384. SaAisErrorT
  385. saAmfComponentUnregister (
  386. 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. SaAisErrorT error;
  394. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  395. (void *)&amfInstance);
  396. if (error != SA_AIS_OK) {
  397. return (error);
  398. }
  399. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  400. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  401. memcpy (&req_lib_amf_componentunregister.compName, compName,
  402. sizeof (SaNameT));
  403. if (proxyCompName) {
  404. memcpy (&req_lib_amf_componentunregister.proxyCompName,
  405. proxyCompName, sizeof (SaNameT));
  406. } else {
  407. memset (&req_lib_amf_componentunregister.proxyCompName, 0,
  408. sizeof (SaNameT));
  409. }
  410. pthread_mutex_lock (&amfInstance->response_mutex);
  411. error = saSendReceiveReply (amfInstance->response_fd,
  412. &req_lib_amf_componentunregister,
  413. sizeof (struct req_lib_amf_componentunregister),
  414. &res_lib_amf_componentunregister,
  415. sizeof (struct res_lib_amf_componentunregister));
  416. pthread_mutex_unlock (&amfInstance->response_mutex);
  417. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  418. return (error == SA_AIS_OK ? res_lib_amf_componentunregister.header.error : error);
  419. }
  420. SaAisErrorT
  421. saAmfComponentNameGet (
  422. SaAmfHandleT amfHandle,
  423. SaNameT *compName)
  424. {
  425. struct amfInstance *amfInstance;
  426. SaAisErrorT error;
  427. char *env_value;
  428. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  429. (void *)&amfInstance);
  430. if (error != SA_AIS_OK) {
  431. return (error);
  432. }
  433. pthread_mutex_lock (&amfInstance->response_mutex);
  434. error = SA_AIS_OK;
  435. env_value = getenv ("SA_AMF_COMPONENT_NAME");
  436. if (env_value == 0) {
  437. error = SA_AIS_ERR_NOT_EXIST;
  438. goto error_exit;
  439. }
  440. strcpy (compName->value, env_value);
  441. compName->length = strlen (env_value);
  442. error_exit:
  443. pthread_mutex_unlock (&amfInstance->response_mutex);
  444. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  445. return (error);
  446. }
  447. SaAisErrorT
  448. saAmfPmStart (
  449. SaAmfHandleT amfHandle,
  450. const SaNameT *compName,
  451. SaUint64T processId,
  452. SaInt32T descendentsTreeDepth,
  453. SaAmfPmErrorsT pmErrors,
  454. SaAmfRecommendedRecoveryT recommendedRecovery)
  455. {
  456. struct req_lib_amf_pmstart req_lib_amf_pmstart;
  457. struct res_lib_amf_pmstart res_lib_amf_pmstart;
  458. struct amfInstance *amfInstance;
  459. SaAisErrorT error;
  460. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  461. (void *)&amfInstance);
  462. if (error != SA_AIS_OK) {
  463. return (error);
  464. }
  465. req_lib_amf_pmstart.header.size = sizeof (struct req_lib_amf_componentunregister);
  466. req_lib_amf_pmstart.header.id = MESSAGE_REQ_AMF_PMSTART;
  467. memcpy (&req_lib_amf_pmstart.compName, compName,
  468. sizeof (SaNameT));
  469. req_lib_amf_pmstart.processId = processId;
  470. req_lib_amf_pmstart.descendentsTreeDepth = descendentsTreeDepth;
  471. req_lib_amf_pmstart.pmErrors = pmErrors;
  472. pthread_mutex_lock (&amfInstance->response_mutex);
  473. error = saSendReceiveReply (amfInstance->response_fd,
  474. &req_lib_amf_pmstart,
  475. sizeof (struct req_lib_amf_pmstart),
  476. &res_lib_amf_pmstart,
  477. sizeof (struct res_lib_amf_pmstart));
  478. pthread_mutex_unlock (&amfInstance->response_mutex);
  479. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  480. return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error);
  481. }
  482. SaAisErrorT
  483. saAmfPmStop (
  484. SaAmfHandleT amfHandle,
  485. const SaNameT *compName,
  486. SaAmfPmStopQualifierT stopQualifier,
  487. SaInt64T processId,
  488. SaAmfPmErrorsT pmErrors)
  489. {
  490. struct req_lib_amf_pmstop req_lib_amf_pmstop;
  491. struct res_lib_amf_pmstop res_lib_amf_pmstop;
  492. struct amfInstance *amfInstance;
  493. SaAisErrorT error;
  494. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  495. (void *)&amfInstance);
  496. if (error != SA_AIS_OK) {
  497. return (error);
  498. }
  499. req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop);
  500. req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP;
  501. memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT));
  502. req_lib_amf_pmstop.stopQualifier = stopQualifier;
  503. req_lib_amf_pmstop.processId = processId;
  504. req_lib_amf_pmstop.pmErrors = pmErrors;
  505. pthread_mutex_lock (&amfInstance->response_mutex);
  506. error = saSendReceiveReply (amfInstance->response_fd,
  507. &req_lib_amf_pmstop,
  508. sizeof (struct req_lib_amf_pmstop),
  509. &res_lib_amf_pmstop,
  510. sizeof (struct res_lib_amf_pmstop));
  511. pthread_mutex_unlock (&amfInstance->response_mutex);
  512. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  513. return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error);
  514. return (SA_AIS_OK);
  515. }
  516. SaAisErrorT
  517. saAmfHealthcheckStart (
  518. SaAmfHandleT amfHandle,
  519. const SaNameT *compName,
  520. const SaAmfHealthcheckKeyT *healthcheckKey,
  521. SaAmfHealthcheckInvocationT invocationType,
  522. SaAmfRecommendedRecoveryT recommendedRecovery)
  523. {
  524. struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart;
  525. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  526. struct amfInstance *amfInstance;
  527. SaAisErrorT error;
  528. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  529. (void *)&amfInstance);
  530. if (error != SA_AIS_OK) {
  531. return (error);
  532. }
  533. req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart);
  534. req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART;
  535. memcpy (&req_lib_amf_healthcheckstart.compName, compName,
  536. sizeof (SaNameT));
  537. memcpy (&req_lib_amf_healthcheckstart.healthcheckKey,
  538. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  539. req_lib_amf_healthcheckstart.invocationType = invocationType;
  540. req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery;
  541. pthread_mutex_lock (&amfInstance->response_mutex);
  542. error = saSendReceiveReply (amfInstance->response_fd,
  543. &req_lib_amf_healthcheckstart,
  544. sizeof (struct req_lib_amf_healthcheckstart),
  545. &res_lib_amf_healthcheckstart,
  546. sizeof (struct res_lib_amf_healthcheckstart));
  547. pthread_mutex_unlock (&amfInstance->response_mutex);
  548. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  549. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error);
  550. }
  551. SaAisErrorT
  552. saAmfHealthcheckConfirm (
  553. SaAmfHandleT amfHandle,
  554. const SaNameT *compName,
  555. const SaAmfHealthcheckKeyT *healthcheckKey,
  556. SaAisErrorT healthcheckResult)
  557. {
  558. struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm;
  559. struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm;
  560. struct amfInstance *amfInstance;
  561. SaAisErrorT error;
  562. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  563. (void *)&amfInstance);
  564. if (error != SA_AIS_OK) {
  565. return (error);
  566. }
  567. req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_componentunregister);
  568. req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM;
  569. memcpy (&req_lib_amf_healthcheckconfirm.compName, compName,
  570. sizeof (SaNameT));
  571. memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey,
  572. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  573. req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult;
  574. pthread_mutex_lock (&amfInstance->response_mutex);
  575. error = saSendReceiveReply (amfInstance->response_fd,
  576. &req_lib_amf_healthcheckconfirm,
  577. sizeof (struct req_lib_amf_healthcheckconfirm),
  578. &res_lib_amf_healthcheckconfirm,
  579. sizeof (struct res_lib_amf_healthcheckconfirm));
  580. pthread_mutex_unlock (&amfInstance->response_mutex);
  581. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  582. return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error);
  583. }
  584. SaAisErrorT
  585. saAmfHealthcheckStop (
  586. SaAmfHandleT amfHandle,
  587. const SaNameT *compName,
  588. const SaAmfHealthcheckKeyT *healthcheckKey)
  589. {
  590. struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop;
  591. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  592. struct amfInstance *amfInstance;
  593. SaAisErrorT error;
  594. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  595. (void *)&amfInstance);
  596. if (error != SA_AIS_OK) {
  597. return (error);
  598. }
  599. req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop);
  600. req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP;
  601. memcpy (&req_lib_amf_healthcheckstop.compName, compName,
  602. sizeof (SaNameT));
  603. memcpy (&req_lib_amf_healthcheckstop.healthcheckKey,
  604. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  605. pthread_mutex_lock (&amfInstance->response_mutex);
  606. error = saSendReceiveReply (amfInstance->response_fd,
  607. &req_lib_amf_healthcheckstop,
  608. sizeof (struct req_lib_amf_healthcheckstop),
  609. &res_lib_amf_healthcheckstop,
  610. sizeof (struct res_lib_amf_healthcheckstop));
  611. pthread_mutex_unlock (&amfInstance->response_mutex);
  612. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  613. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error);
  614. }
  615. SaAisErrorT
  616. saAmfHAStateGet (
  617. SaAmfHandleT amfHandle,
  618. const SaNameT *compName,
  619. const SaNameT *csiName,
  620. SaAmfHAStateT *haState)
  621. {
  622. struct amfInstance *amfInstance;
  623. struct req_lib_amf_hastateget req_lib_amf_hastateget;
  624. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  625. SaAisErrorT error;
  626. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  627. (void *)&amfInstance);
  628. if (error != SA_AIS_OK) {
  629. return (error);
  630. }
  631. pthread_mutex_lock (&amfInstance->response_mutex);
  632. req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  633. req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget);
  634. memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT));
  635. memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  636. error = saSendReceiveReply (amfInstance->response_fd,
  637. &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget),
  638. &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  639. pthread_mutex_unlock (&amfInstance->response_mutex);
  640. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  641. if (res_lib_amf_hastateget.header.error == SA_AIS_OK) {
  642. memcpy (haState, &res_lib_amf_hastateget.haState,
  643. sizeof (SaAmfHAStateT));
  644. }
  645. return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error);
  646. }
  647. SaAisErrorT
  648. saAmfCSIQuiescingComplete (
  649. SaAmfHandleT amfHandle,
  650. SaInvocationT invocation,
  651. SaAisErrorT error)
  652. {
  653. struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete;
  654. struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete;
  655. struct amfInstance *amfInstance;
  656. SaAisErrorT errorResult;
  657. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  658. (void *)&amfInstance);
  659. if (error != SA_AIS_OK) {
  660. return (error);
  661. }
  662. req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_componentunregister);
  663. req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE;
  664. req_lib_amf_csiquiescingcomplete.invocation = invocation;
  665. req_lib_amf_csiquiescingcomplete.error = error;
  666. pthread_mutex_lock (&amfInstance->response_mutex);
  667. errorResult = saSendReceiveReply (amfInstance->response_fd,
  668. &req_lib_amf_csiquiescingcomplete,
  669. sizeof (struct req_lib_amf_csiquiescingcomplete),
  670. &res_lib_amf_csiquiescingcomplete,
  671. sizeof (struct res_lib_amf_csiquiescingcomplete));
  672. pthread_mutex_unlock (&amfInstance->response_mutex);
  673. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  674. return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult);
  675. }
  676. SaAisErrorT
  677. saAmfProtectionGroupTrackStart (
  678. SaAmfHandleT amfHandle,
  679. const SaNameT *csiName,
  680. SaUint8T trackFlags,
  681. const SaAmfProtectionGroupNotificationT *notificationBuffer)
  682. {
  683. struct amfInstance *amfInstance;
  684. struct req_lib_amf_protectiongrouptrackstart req_lib_amf_protectiongrouptrackstart;
  685. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  686. SaAisErrorT error;
  687. req_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstart);
  688. req_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  689. memcpy (&req_lib_amf_protectiongrouptrackstart.csiName, csiName,
  690. sizeof (SaNameT));
  691. req_lib_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  692. req_lib_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  693. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  694. (void *)&amfInstance);
  695. if (error != SA_AIS_OK) {
  696. return (error);
  697. }
  698. pthread_mutex_lock (&amfInstance->response_mutex);
  699. error = saSendReceiveReply (amfInstance->response_fd,
  700. &req_lib_amf_protectiongrouptrackstart,
  701. sizeof (struct req_lib_amf_protectiongrouptrackstart),
  702. &res_lib_amf_protectiongrouptrackstart,
  703. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  704. pthread_mutex_unlock (&amfInstance->response_mutex);
  705. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  706. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstart.header.error : error);
  707. }
  708. SaAisErrorT
  709. saAmfProtectionGroupTrackStop (
  710. SaAmfHandleT amfHandle,
  711. const SaNameT *csiName)
  712. {
  713. struct amfInstance *amfInstance;
  714. struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop;
  715. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  716. SaAisErrorT error;
  717. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  718. (void *)&amfInstance);
  719. if (error != SA_AIS_OK) {
  720. return (error);
  721. }
  722. req_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop);
  723. req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  724. memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  725. pthread_mutex_lock (&amfInstance->response_mutex);
  726. error = saSendReceiveReply (amfInstance->response_fd,
  727. &req_lib_amf_protectiongrouptrackstop,
  728. sizeof (struct req_lib_amf_protectiongrouptrackstop),
  729. &res_lib_amf_protectiongrouptrackstop,
  730. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  731. pthread_mutex_unlock (&amfInstance->response_mutex);
  732. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  733. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error);
  734. }
  735. SaAisErrorT
  736. saAmfComponentErrorReport (
  737. SaAmfHandleT amfHandle,
  738. const SaNameT *erroneousComponent,
  739. SaTimeT errorDetectionTime,
  740. SaAmfRecommendedRecoveryT recommendedRecovery,
  741. SaNtfIdentifierT ntfIdentifier)
  742. {
  743. struct amfInstance *amfInstance;
  744. struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport;
  745. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  746. SaAisErrorT error;
  747. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  748. (void *)&amfInstance);
  749. if (error != SA_AIS_OK) {
  750. return (error);
  751. }
  752. req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT;
  753. req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport);
  754. memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent,
  755. sizeof (SaNameT));
  756. req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime;
  757. printf ("start error report\n");
  758. error = saSendReceiveReply (amfInstance->response_fd,
  759. &req_lib_amf_componenterrorreport,
  760. sizeof (struct req_lib_amf_componenterrorreport),
  761. &res_lib_amf_componenterrorreport,
  762. sizeof (struct res_lib_amf_componenterrorreport));
  763. printf ("end error report\n");
  764. error = res_lib_amf_componenterrorreport.header.error;
  765. pthread_mutex_unlock (&amfInstance->response_mutex);
  766. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  767. return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error);
  768. }
  769. SaAisErrorT
  770. saAmfComponentErrorClear (
  771. SaAmfHandleT amfHandle,
  772. const SaNameT *compName,
  773. SaNtfIdentifierT ntfIdentifier)
  774. {
  775. struct amfInstance *amfInstance;
  776. struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear;
  777. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  778. SaAisErrorT error;
  779. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  780. (void *)&amfInstance);
  781. if (error != SA_AIS_OK) {
  782. return (error);
  783. }
  784. req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR;
  785. req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear);
  786. memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT));
  787. error = saSendReceiveReply (amfInstance->response_fd,
  788. &req_lib_amf_componenterrorclear,
  789. sizeof (struct req_lib_amf_componenterrorclear),
  790. &res_lib_amf_componenterrorclear,
  791. sizeof (struct res_lib_amf_componenterrorclear));
  792. pthread_mutex_unlock (&amfInstance->response_mutex);
  793. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  794. return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error);
  795. }
  796. SaAisErrorT
  797. saAmfResponse (
  798. SaAmfHandleT amfHandle,
  799. SaInvocationT invocation,
  800. SaAisErrorT error)
  801. {
  802. struct amfInstance *amfInstance;
  803. struct req_lib_amf_response req_lib_amf_response;
  804. struct res_lib_amf_response res_lib_amf_response;
  805. SaAisErrorT errorResult;
  806. errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  807. (void *)&amfInstance);
  808. if (errorResult != SA_AIS_OK) {
  809. return (error);
  810. }
  811. req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  812. req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response);
  813. req_lib_amf_response.invocation = invocation;
  814. req_lib_amf_response.error = error;
  815. pthread_mutex_lock (&amfInstance->response_mutex);
  816. errorResult = saSendReceiveReply (amfInstance->response_fd,
  817. &req_lib_amf_response, sizeof (struct req_lib_amf_response),
  818. &res_lib_amf_response, sizeof (struct res_lib_amf_response));
  819. pthread_mutex_unlock (&amfInstance->response_mutex);
  820. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  821. return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult);
  822. }