amf.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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), MSG_WAITALL | MSG_NOSIGNAL);
  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. MSG_WAITALL | MSG_NOSIGNAL);
  224. if (error != SA_AIS_OK) {
  225. goto error_unlock;
  226. }
  227. }
  228. } else {
  229. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  230. continue;
  231. }
  232. /*
  233. * Make copy of callbacks, message data, unlock instance, and call callback
  234. * A risk of this dispatch method is that the callback routines may
  235. * operate at the same time that amfFinalize has been called in another thread.
  236. */
  237. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  238. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  239. /*
  240. * Dispatch incoming response
  241. */
  242. switch (dispatch_data.header.id) {
  243. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  244. res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
  245. callbacks.saAmfHealthcheckCallback (
  246. res_lib_amf_healthcheckcallback->invocation,
  247. &res_lib_amf_healthcheckcallback->compName,
  248. &res_lib_amf_healthcheckcallback->key);
  249. break;
  250. case MESSAGE_RES_AMF_CSISETCALLBACK:
  251. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  252. callbacks.saAmfCSISetCallback (
  253. res_lib_amf_csisetcallback->invocation,
  254. &res_lib_amf_csisetcallback->compName,
  255. res_lib_amf_csisetcallback->haState,
  256. &res_lib_amf_csisetcallback->csiDescriptor);
  257. break;
  258. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  259. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  260. callbacks.saAmfCSIRemoveCallback (
  261. res_lib_amf_csiremovecallback->invocation,
  262. &res_lib_amf_csiremovecallback->compName,
  263. &res_lib_amf_csiremovecallback->csiName,
  264. res_lib_amf_csiremovecallback->csiFlags);
  265. break;
  266. case MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK:
  267. res_lib_amf_componentterminatecallback = (struct res_lib_amf_componentterminatecallback *)&dispatch_data;
  268. callbacks.saAmfComponentTerminateCallback (
  269. res_lib_amf_componentterminatecallback->invocation,
  270. &res_lib_amf_componentterminatecallback->compName);
  271. break;
  272. #ifdef COMPILE_OUT
  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. #endif
  285. break;
  286. default:
  287. error = SA_AIS_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. SaAisErrorT
  310. saAmfFinalize (
  311. SaAmfHandleT amfHandle)
  312. {
  313. struct amfInstance *amfInstance;
  314. SaAisErrorT error;
  315. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
  316. if (error != SA_AIS_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_AIS_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. SaAisErrorT
  346. saAmfComponentRegister (
  347. SaAmfHandleT amfHandle,
  348. const SaNameT *compName,
  349. const SaNameT *proxyCompName)
  350. {
  351. struct amfInstance *amfInstance;
  352. SaAisErrorT error;
  353. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  354. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  355. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  356. (void *)&amfInstance);
  357. if (error != SA_AIS_OK) {
  358. return (error);
  359. }
  360. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  361. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  362. memcpy (&req_lib_amf_componentregister.compName, compName,
  363. sizeof (SaNameT));
  364. if (proxyCompName) {
  365. memcpy (&req_lib_amf_componentregister.proxyCompName,
  366. proxyCompName, sizeof (SaNameT));
  367. } else {
  368. memset (&req_lib_amf_componentregister.proxyCompName, 0,
  369. sizeof (SaNameT));
  370. }
  371. pthread_mutex_lock (&amfInstance->response_mutex);
  372. error = saSendReceiveReply (amfInstance->response_fd,
  373. &req_lib_amf_componentregister,
  374. sizeof (struct req_lib_amf_componentregister),
  375. &res_lib_amf_componentregister,
  376. sizeof (struct res_lib_amf_componentregister));
  377. pthread_mutex_unlock (&amfInstance->response_mutex);
  378. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  379. if (res_lib_amf_componentregister.header.error == SA_AIS_OK) {
  380. amfInstance->compRegistered = 1;
  381. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  382. }
  383. return (error == SA_AIS_OK ? res_lib_amf_componentregister.header.error : error);
  384. }
  385. SaAisErrorT
  386. saAmfComponentUnregister (
  387. 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. SaAisErrorT error;
  395. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  396. (void *)&amfInstance);
  397. if (error != SA_AIS_OK) {
  398. return (error);
  399. }
  400. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  401. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  402. memcpy (&req_lib_amf_componentunregister.compName, compName,
  403. sizeof (SaNameT));
  404. if (proxyCompName) {
  405. memcpy (&req_lib_amf_componentunregister.proxyCompName,
  406. proxyCompName, sizeof (SaNameT));
  407. } else {
  408. memset (&req_lib_amf_componentunregister.proxyCompName, 0,
  409. sizeof (SaNameT));
  410. }
  411. pthread_mutex_lock (&amfInstance->response_mutex);
  412. error = saSendReceiveReply (amfInstance->response_fd,
  413. &req_lib_amf_componentunregister,
  414. sizeof (struct req_lib_amf_componentunregister),
  415. &res_lib_amf_componentunregister,
  416. sizeof (struct res_lib_amf_componentunregister));
  417. pthread_mutex_unlock (&amfInstance->response_mutex);
  418. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  419. return (error == SA_AIS_OK ? res_lib_amf_componentunregister.header.error : error);
  420. }
  421. SaAisErrorT
  422. saAmfComponentNameGet (
  423. SaAmfHandleT amfHandle,
  424. SaNameT *compName)
  425. {
  426. struct amfInstance *amfInstance;
  427. SaAisErrorT error;
  428. char *env_value;
  429. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  430. (void *)&amfInstance);
  431. if (error != SA_AIS_OK) {
  432. return (error);
  433. }
  434. pthread_mutex_lock (&amfInstance->response_mutex);
  435. error = SA_AIS_OK;
  436. env_value = getenv ("SA_AMF_COMPONENT_NAME");
  437. if (env_value == 0) {
  438. error = SA_AIS_ERR_NOT_EXIST;
  439. goto error_exit;
  440. }
  441. strcpy (compName->value, env_value);
  442. compName->length = strlen (env_value);
  443. error_exit:
  444. pthread_mutex_unlock (&amfInstance->response_mutex);
  445. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  446. return (error);
  447. }
  448. SaAisErrorT
  449. saAmfPmStart (
  450. SaAmfHandleT amfHandle,
  451. const SaNameT *compName,
  452. SaUint64T processId,
  453. SaInt32T descendentsTreeDepth,
  454. SaAmfPmErrorsT pmErrors,
  455. SaAmfRecommendedRecoveryT recommendedRecovery)
  456. {
  457. struct req_lib_amf_pmstart req_lib_amf_pmstart;
  458. struct res_lib_amf_pmstart res_lib_amf_pmstart;
  459. struct amfInstance *amfInstance;
  460. SaAisErrorT error;
  461. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  462. (void *)&amfInstance);
  463. if (error != SA_AIS_OK) {
  464. return (error);
  465. }
  466. req_lib_amf_pmstart.header.size = sizeof (struct req_lib_amf_componentunregister);
  467. req_lib_amf_pmstart.header.id = MESSAGE_REQ_AMF_PMSTART;
  468. memcpy (&req_lib_amf_pmstart.compName, compName,
  469. sizeof (SaNameT));
  470. req_lib_amf_pmstart.processId = processId;
  471. req_lib_amf_pmstart.descendentsTreeDepth = descendentsTreeDepth;
  472. req_lib_amf_pmstart.pmErrors = pmErrors;
  473. pthread_mutex_lock (&amfInstance->response_mutex);
  474. error = saSendReceiveReply (amfInstance->response_fd,
  475. &req_lib_amf_pmstart,
  476. sizeof (struct req_lib_amf_pmstart),
  477. &res_lib_amf_pmstart,
  478. sizeof (struct res_lib_amf_pmstart));
  479. pthread_mutex_unlock (&amfInstance->response_mutex);
  480. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  481. return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error);
  482. }
  483. SaAisErrorT
  484. saAmfPmStop (
  485. SaAmfHandleT amfHandle,
  486. const SaNameT *compName,
  487. SaAmfPmStopQualifierT stopQualifier,
  488. SaInt64T processId,
  489. SaAmfPmErrorsT pmErrors)
  490. {
  491. struct req_lib_amf_pmstop req_lib_amf_pmstop;
  492. struct res_lib_amf_pmstop res_lib_amf_pmstop;
  493. struct amfInstance *amfInstance;
  494. SaAisErrorT error;
  495. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  496. (void *)&amfInstance);
  497. if (error != SA_AIS_OK) {
  498. return (error);
  499. }
  500. req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop);
  501. req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP;
  502. memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT));
  503. req_lib_amf_pmstop.stopQualifier = stopQualifier;
  504. req_lib_amf_pmstop.processId = processId;
  505. req_lib_amf_pmstop.pmErrors = pmErrors;
  506. pthread_mutex_lock (&amfInstance->response_mutex);
  507. error = saSendReceiveReply (amfInstance->response_fd,
  508. &req_lib_amf_pmstop,
  509. sizeof (struct req_lib_amf_pmstop),
  510. &res_lib_amf_pmstop,
  511. sizeof (struct res_lib_amf_pmstop));
  512. pthread_mutex_unlock (&amfInstance->response_mutex);
  513. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  514. return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error);
  515. return (SA_AIS_OK);
  516. }
  517. SaAisErrorT
  518. saAmfHealthcheckStart (
  519. SaAmfHandleT amfHandle,
  520. const SaNameT *compName,
  521. const SaAmfHealthcheckKeyT *healthcheckKey,
  522. SaAmfHealthcheckInvocationT invocationType,
  523. SaAmfRecommendedRecoveryT recommendedRecovery)
  524. {
  525. struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart;
  526. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  527. struct amfInstance *amfInstance;
  528. SaAisErrorT error;
  529. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  530. (void *)&amfInstance);
  531. if (error != SA_AIS_OK) {
  532. return (error);
  533. }
  534. req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart);
  535. req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART;
  536. memcpy (&req_lib_amf_healthcheckstart.compName, compName,
  537. sizeof (SaNameT));
  538. memcpy (&req_lib_amf_healthcheckstart.healthcheckKey,
  539. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  540. req_lib_amf_healthcheckstart.invocationType = invocationType;
  541. req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery;
  542. pthread_mutex_lock (&amfInstance->response_mutex);
  543. error = saSendReceiveReply (amfInstance->response_fd,
  544. &req_lib_amf_healthcheckstart,
  545. sizeof (struct req_lib_amf_healthcheckstart),
  546. &res_lib_amf_healthcheckstart,
  547. sizeof (struct res_lib_amf_healthcheckstart));
  548. pthread_mutex_unlock (&amfInstance->response_mutex);
  549. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  550. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error);
  551. }
  552. SaAisErrorT
  553. saAmfHealthcheckConfirm (
  554. SaAmfHandleT amfHandle,
  555. const SaNameT *compName,
  556. const SaAmfHealthcheckKeyT *healthcheckKey,
  557. SaAisErrorT healthcheckResult)
  558. {
  559. struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm;
  560. struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm;
  561. struct amfInstance *amfInstance;
  562. SaAisErrorT error;
  563. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  564. (void *)&amfInstance);
  565. if (error != SA_AIS_OK) {
  566. return (error);
  567. }
  568. req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_componentunregister);
  569. req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM;
  570. memcpy (&req_lib_amf_healthcheckconfirm.compName, compName,
  571. sizeof (SaNameT));
  572. memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey,
  573. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  574. req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult;
  575. pthread_mutex_lock (&amfInstance->response_mutex);
  576. error = saSendReceiveReply (amfInstance->response_fd,
  577. &req_lib_amf_healthcheckconfirm,
  578. sizeof (struct req_lib_amf_healthcheckconfirm),
  579. &res_lib_amf_healthcheckconfirm,
  580. sizeof (struct res_lib_amf_healthcheckconfirm));
  581. pthread_mutex_unlock (&amfInstance->response_mutex);
  582. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  583. return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error);
  584. }
  585. SaAisErrorT
  586. saAmfHealthcheckStop (
  587. SaAmfHandleT amfHandle,
  588. const SaNameT *compName,
  589. const SaAmfHealthcheckKeyT *healthcheckKey)
  590. {
  591. struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop;
  592. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  593. struct amfInstance *amfInstance;
  594. SaAisErrorT error;
  595. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  596. (void *)&amfInstance);
  597. if (error != SA_AIS_OK) {
  598. return (error);
  599. }
  600. req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop);
  601. req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP;
  602. memcpy (&req_lib_amf_healthcheckstop.compName, compName,
  603. sizeof (SaNameT));
  604. memcpy (&req_lib_amf_healthcheckstop.healthcheckKey,
  605. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  606. pthread_mutex_lock (&amfInstance->response_mutex);
  607. error = saSendReceiveReply (amfInstance->response_fd,
  608. &req_lib_amf_healthcheckstop,
  609. sizeof (struct req_lib_amf_healthcheckstop),
  610. &res_lib_amf_healthcheckstop,
  611. sizeof (struct res_lib_amf_healthcheckstop));
  612. pthread_mutex_unlock (&amfInstance->response_mutex);
  613. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  614. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error);
  615. }
  616. SaAisErrorT
  617. saAmfHAStateGet (
  618. SaAmfHandleT amfHandle,
  619. const SaNameT *compName,
  620. const SaNameT *csiName,
  621. SaAmfHAStateT *haState)
  622. {
  623. struct amfInstance *amfInstance;
  624. struct req_lib_amf_hastateget req_lib_amf_hastateget;
  625. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  626. SaAisErrorT error;
  627. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  628. (void *)&amfInstance);
  629. if (error != SA_AIS_OK) {
  630. return (error);
  631. }
  632. pthread_mutex_lock (&amfInstance->response_mutex);
  633. req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  634. req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget);
  635. memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT));
  636. memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  637. error = saSendReceiveReply (amfInstance->response_fd,
  638. &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget),
  639. &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  640. pthread_mutex_unlock (&amfInstance->response_mutex);
  641. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  642. if (res_lib_amf_hastateget.header.error == SA_AIS_OK) {
  643. memcpy (haState, &res_lib_amf_hastateget.haState,
  644. sizeof (SaAmfHAStateT));
  645. }
  646. return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error);
  647. }
  648. SaAisErrorT
  649. saAmfCSIQuiescingComplete (
  650. SaAmfHandleT amfHandle,
  651. SaInvocationT invocation,
  652. SaAisErrorT error)
  653. {
  654. struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete;
  655. struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete;
  656. struct amfInstance *amfInstance;
  657. SaAisErrorT errorResult;
  658. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  659. (void *)&amfInstance);
  660. if (error != SA_AIS_OK) {
  661. return (error);
  662. }
  663. req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_componentunregister);
  664. req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE;
  665. req_lib_amf_csiquiescingcomplete.invocation = invocation;
  666. req_lib_amf_csiquiescingcomplete.error = error;
  667. pthread_mutex_lock (&amfInstance->response_mutex);
  668. errorResult = saSendReceiveReply (amfInstance->response_fd,
  669. &req_lib_amf_csiquiescingcomplete,
  670. sizeof (struct req_lib_amf_csiquiescingcomplete),
  671. &res_lib_amf_csiquiescingcomplete,
  672. sizeof (struct res_lib_amf_csiquiescingcomplete));
  673. pthread_mutex_unlock (&amfInstance->response_mutex);
  674. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  675. return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult);
  676. }
  677. SaAisErrorT
  678. saAmfProtectionGroupTrackStart (
  679. SaAmfHandleT amfHandle,
  680. const SaNameT *csiName,
  681. SaUint8T trackFlags,
  682. const SaAmfProtectionGroupNotificationT *notificationBuffer)
  683. {
  684. struct amfInstance *amfInstance;
  685. struct req_lib_amf_protectiongrouptrackstart req_lib_amf_protectiongrouptrackstart;
  686. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  687. SaAisErrorT error;
  688. req_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstart);
  689. req_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART;
  690. memcpy (&req_lib_amf_protectiongrouptrackstart.csiName, csiName,
  691. sizeof (SaNameT));
  692. req_lib_amf_protectiongrouptrackstart.trackFlags = trackFlags;
  693. req_lib_amf_protectiongrouptrackstart.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  694. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  695. (void *)&amfInstance);
  696. if (error != SA_AIS_OK) {
  697. return (error);
  698. }
  699. pthread_mutex_lock (&amfInstance->response_mutex);
  700. error = saSendReceiveReply (amfInstance->response_fd,
  701. &req_lib_amf_protectiongrouptrackstart,
  702. sizeof (struct req_lib_amf_protectiongrouptrackstart),
  703. &res_lib_amf_protectiongrouptrackstart,
  704. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  705. pthread_mutex_unlock (&amfInstance->response_mutex);
  706. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  707. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstart.header.error : error);
  708. }
  709. SaAisErrorT
  710. saAmfProtectionGroupTrackStop (
  711. SaAmfHandleT amfHandle,
  712. const SaNameT *csiName)
  713. {
  714. struct amfInstance *amfInstance;
  715. struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop;
  716. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  717. SaAisErrorT error;
  718. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  719. (void *)&amfInstance);
  720. if (error != SA_AIS_OK) {
  721. return (error);
  722. }
  723. req_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop);
  724. req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  725. memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  726. pthread_mutex_lock (&amfInstance->response_mutex);
  727. error = saSendReceiveReply (amfInstance->response_fd,
  728. &req_lib_amf_protectiongrouptrackstop,
  729. sizeof (struct req_lib_amf_protectiongrouptrackstop),
  730. &res_lib_amf_protectiongrouptrackstop,
  731. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  732. pthread_mutex_unlock (&amfInstance->response_mutex);
  733. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  734. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error);
  735. }
  736. SaAisErrorT
  737. saAmfComponentErrorReport (
  738. SaAmfHandleT amfHandle,
  739. const SaNameT *erroneousComponent,
  740. SaTimeT errorDetectionTime,
  741. SaAmfRecommendedRecoveryT recommendedRecovery,
  742. SaNtfIdentifierT ntfIdentifier)
  743. {
  744. struct amfInstance *amfInstance;
  745. struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport;
  746. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  747. SaAisErrorT error;
  748. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  749. (void *)&amfInstance);
  750. if (error != SA_AIS_OK) {
  751. return (error);
  752. }
  753. req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT;
  754. req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport);
  755. memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent,
  756. sizeof (SaNameT));
  757. req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime;
  758. printf ("start error report\n");
  759. error = saSendReceiveReply (amfInstance->response_fd,
  760. &req_lib_amf_componenterrorreport,
  761. sizeof (struct req_lib_amf_componenterrorreport),
  762. &res_lib_amf_componenterrorreport,
  763. sizeof (struct res_lib_amf_componenterrorreport));
  764. printf ("end error report\n");
  765. error = res_lib_amf_componenterrorreport.header.error;
  766. pthread_mutex_unlock (&amfInstance->response_mutex);
  767. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  768. return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error);
  769. }
  770. SaAisErrorT
  771. saAmfComponentErrorClear (
  772. SaAmfHandleT amfHandle,
  773. const SaNameT *compName,
  774. SaNtfIdentifierT ntfIdentifier)
  775. {
  776. struct amfInstance *amfInstance;
  777. struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear;
  778. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  779. SaAisErrorT error;
  780. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  781. (void *)&amfInstance);
  782. if (error != SA_AIS_OK) {
  783. return (error);
  784. }
  785. req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR;
  786. req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear);
  787. memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT));
  788. error = saSendReceiveReply (amfInstance->response_fd,
  789. &req_lib_amf_componenterrorclear,
  790. sizeof (struct req_lib_amf_componenterrorclear),
  791. &res_lib_amf_componenterrorclear,
  792. sizeof (struct res_lib_amf_componenterrorclear));
  793. pthread_mutex_unlock (&amfInstance->response_mutex);
  794. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  795. return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error);
  796. }
  797. SaAisErrorT
  798. saAmfResponse (
  799. SaAmfHandleT amfHandle,
  800. SaInvocationT invocation,
  801. SaAisErrorT error)
  802. {
  803. struct amfInstance *amfInstance;
  804. struct req_lib_amf_response req_lib_amf_response;
  805. struct res_lib_amf_response res_lib_amf_response;
  806. SaAisErrorT errorResult;
  807. errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  808. (void *)&amfInstance);
  809. if (errorResult != SA_AIS_OK) {
  810. return (error);
  811. }
  812. req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  813. req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response);
  814. req_lib_amf_response.invocation = invocation;
  815. req_lib_amf_response.error = error;
  816. pthread_mutex_lock (&amfInstance->response_mutex);
  817. errorResult = saSendReceiveReply (amfInstance->response_fd,
  818. &req_lib_amf_response, sizeof (struct req_lib_amf_response),
  819. &res_lib_amf_response, sizeof (struct res_lib_amf_response));
  820. pthread_mutex_unlock (&amfInstance->response_mutex);
  821. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  822. return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult);
  823. }