amf.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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. mar_res_header_t header __attribute__((aligned(8)));
  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 = saServiceConnect (&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. SaAmfCallbacksT callbacks;
  163. struct res_overlay dispatch_data;
  164. if (dispatchFlags != SA_DISPATCH_ONE &&
  165. dispatchFlags != SA_DISPATCH_ALL &&
  166. dispatchFlags != SA_DISPATCH_BLOCKING) {
  167. return (SA_AIS_ERR_INVALID_PARAM);
  168. }
  169. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  170. (void *)&amfInstance);
  171. if (error != SA_AIS_OK) {
  172. return (error);
  173. }
  174. /*
  175. * Timeout instantly for SA_DISPATCH_ALL
  176. */
  177. if (dispatchFlags == SA_DISPATCH_ALL) {
  178. timeout = 0;
  179. }
  180. do {
  181. /*
  182. * Read data directly from socket
  183. */
  184. ufds.fd = amfInstance->dispatch_fd;
  185. ufds.events = POLLIN;
  186. ufds.revents = 0;
  187. error = saPollRetry (&ufds, 1, timeout);
  188. if (error != SA_AIS_OK) {
  189. goto error_put;
  190. }
  191. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  192. /*
  193. * Handle has been finalized in another thread
  194. */
  195. if (amfInstance->finalize == 1) {
  196. error = SA_AIS_OK;
  197. goto error_unlock;
  198. }
  199. if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
  200. error = SA_AIS_ERR_BAD_HANDLE;
  201. goto error_unlock;
  202. }
  203. dispatch_avail = ufds.revents & POLLIN;
  204. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  205. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  206. break; /* exit do while cont is 1 loop */
  207. } else
  208. if (dispatch_avail == 0) {
  209. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  210. continue; /* next poll */
  211. }
  212. if (ufds.revents & POLLIN) {
  213. /*
  214. * Queue empty, read response from socket
  215. */
  216. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.header,
  217. sizeof (mar_res_header_t));
  218. if (error != SA_AIS_OK) {
  219. goto error_unlock;
  220. }
  221. if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
  222. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.data,
  223. dispatch_data.header.size - sizeof (mar_res_header_t));
  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. {
  252. SaAmfCSIDescriptorT csi_descriptor;
  253. SaAmfCSIAttributeT *csi_attribute_array;
  254. char *attr_buf;
  255. int i;
  256. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  257. csi_descriptor.csiFlags = res_lib_amf_csisetcallback->csiFlags;
  258. memcpy(&csi_descriptor.csiName, &res_lib_amf_csisetcallback->csiName,
  259. sizeof(SaNameT));
  260. csi_descriptor.csiStateDescriptor = res_lib_amf_csisetcallback->csiStateDescriptor;
  261. csi_descriptor.csiAttr.number = res_lib_amf_csisetcallback->number;
  262. csi_attribute_array = malloc (sizeof (SaAmfCSIAttributeT) *
  263. csi_descriptor.csiAttr.number);
  264. if (csi_attribute_array == 0) {
  265. return SA_AIS_ERR_LIBRARY;
  266. }
  267. csi_descriptor.csiAttr.attr = csi_attribute_array;
  268. attr_buf = res_lib_amf_csisetcallback->csi_attr_buf;
  269. for (i = 0; i < csi_descriptor.csiAttr.number; i++) {
  270. csi_attribute_array[i].attrName = (SaUint8T*)attr_buf;
  271. attr_buf += strlen(attr_buf) + 1;
  272. csi_attribute_array[i].attrValue = (SaUint8T*)attr_buf;
  273. attr_buf += strlen(attr_buf) + 1;
  274. }
  275. callbacks.saAmfCSISetCallback (
  276. res_lib_amf_csisetcallback->invocation,
  277. &res_lib_amf_csisetcallback->compName,
  278. res_lib_amf_csisetcallback->haState,
  279. &csi_descriptor);
  280. if (csi_attribute_array != NULL) {
  281. free(csi_attribute_array);
  282. }
  283. break;
  284. }
  285. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  286. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  287. callbacks.saAmfCSIRemoveCallback (
  288. res_lib_amf_csiremovecallback->invocation,
  289. &res_lib_amf_csiremovecallback->compName,
  290. &res_lib_amf_csiremovecallback->csiName,
  291. res_lib_amf_csiremovecallback->csiFlags);
  292. break;
  293. case MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK:
  294. res_lib_amf_componentterminatecallback = (struct res_lib_amf_componentterminatecallback *)&dispatch_data;
  295. callbacks.saAmfComponentTerminateCallback (
  296. res_lib_amf_componentterminatecallback->invocation,
  297. &res_lib_amf_componentterminatecallback->compName);
  298. break;
  299. #ifdef COMPILE_OUT
  300. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  301. res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
  302. memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  303. res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
  304. res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  305. callbacks.saAmfProtectionGroupTrackCallback(
  306. &res_lib_amf_protectiongrouptrackcallback->csiName,
  307. res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  308. res_lib_amf_protectiongrouptrackcallback->numberOfItems,
  309. res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
  310. res_lib_amf_protectiongrouptrackcallback->error);
  311. #endif
  312. break;
  313. default:
  314. error = SA_AIS_ERR_LIBRARY;
  315. goto error_put;
  316. break;
  317. }
  318. /*
  319. * Determine if more messages should be processed
  320. */
  321. switch (dispatchFlags) {
  322. case SA_DISPATCH_ONE:
  323. cont = 0;
  324. break;
  325. case SA_DISPATCH_ALL:
  326. break;
  327. case SA_DISPATCH_BLOCKING:
  328. break;
  329. }
  330. } while (cont);
  331. error_unlock:
  332. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  333. error_put:
  334. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  335. return (error);
  336. }
  337. SaAisErrorT
  338. saAmfFinalize (
  339. SaAmfHandleT amfHandle)
  340. {
  341. struct amfInstance *amfInstance;
  342. SaAisErrorT error;
  343. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
  344. if (error != SA_AIS_OK) {
  345. return (error);
  346. }
  347. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  348. pthread_mutex_lock (&amfInstance->response_mutex);
  349. /*
  350. * Another thread has already started finalizing
  351. */
  352. if (amfInstance->finalize) {
  353. pthread_mutex_unlock (&amfInstance->response_mutex);
  354. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  355. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  356. return (SA_AIS_ERR_BAD_HANDLE);
  357. }
  358. amfInstance->finalize = 1;
  359. pthread_mutex_unlock (&amfInstance->response_mutex);
  360. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  361. saHandleDestroy (&amfHandleDatabase, amfHandle);
  362. if (amfInstance->response_fd != -1) {
  363. shutdown (amfInstance->response_fd, 0);
  364. close (amfInstance->response_fd);
  365. }
  366. if (amfInstance->dispatch_fd != -1) {
  367. shutdown (amfInstance->dispatch_fd, 0);
  368. close (amfInstance->dispatch_fd);
  369. }
  370. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  371. return (error);
  372. }
  373. SaAisErrorT
  374. saAmfComponentRegister (
  375. SaAmfHandleT amfHandle,
  376. const SaNameT *compName,
  377. const SaNameT *proxyCompName)
  378. {
  379. struct amfInstance *amfInstance;
  380. SaAisErrorT error;
  381. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  382. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  383. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  384. (void *)&amfInstance);
  385. if (error != SA_AIS_OK) {
  386. return (error);
  387. }
  388. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  389. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  390. memcpy (&req_lib_amf_componentregister.compName, compName,
  391. sizeof (SaNameT));
  392. if (proxyCompName) {
  393. memcpy (&req_lib_amf_componentregister.proxyCompName,
  394. proxyCompName, sizeof (SaNameT));
  395. } else {
  396. memset (&req_lib_amf_componentregister.proxyCompName, 0,
  397. sizeof (SaNameT));
  398. }
  399. pthread_mutex_lock (&amfInstance->response_mutex);
  400. error = saSendReceiveReply (amfInstance->response_fd,
  401. &req_lib_amf_componentregister,
  402. sizeof (struct req_lib_amf_componentregister),
  403. &res_lib_amf_componentregister,
  404. sizeof (struct res_lib_amf_componentregister));
  405. pthread_mutex_unlock (&amfInstance->response_mutex);
  406. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  407. if (res_lib_amf_componentregister.header.error == SA_AIS_OK) {
  408. amfInstance->compRegistered = 1;
  409. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  410. }
  411. return (error == SA_AIS_OK ? res_lib_amf_componentregister.header.error : error);
  412. }
  413. SaAisErrorT
  414. saAmfComponentUnregister (
  415. SaAmfHandleT amfHandle,
  416. const SaNameT *compName,
  417. const SaNameT *proxyCompName)
  418. {
  419. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  420. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  421. struct amfInstance *amfInstance;
  422. SaAisErrorT error;
  423. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  424. (void *)&amfInstance);
  425. if (error != SA_AIS_OK) {
  426. return (error);
  427. }
  428. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  429. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  430. memcpy (&req_lib_amf_componentunregister.compName, compName,
  431. sizeof (SaNameT));
  432. if (proxyCompName) {
  433. memcpy (&req_lib_amf_componentunregister.proxyCompName,
  434. proxyCompName, sizeof (SaNameT));
  435. } else {
  436. memset (&req_lib_amf_componentunregister.proxyCompName, 0,
  437. sizeof (SaNameT));
  438. }
  439. pthread_mutex_lock (&amfInstance->response_mutex);
  440. error = saSendReceiveReply (amfInstance->response_fd,
  441. &req_lib_amf_componentunregister,
  442. sizeof (struct req_lib_amf_componentunregister),
  443. &res_lib_amf_componentunregister,
  444. sizeof (struct res_lib_amf_componentunregister));
  445. pthread_mutex_unlock (&amfInstance->response_mutex);
  446. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  447. return (error == SA_AIS_OK ? res_lib_amf_componentunregister.header.error : error);
  448. }
  449. SaAisErrorT
  450. saAmfComponentNameGet (
  451. SaAmfHandleT amfHandle,
  452. SaNameT *compName)
  453. {
  454. struct amfInstance *amfInstance;
  455. SaAisErrorT error;
  456. char *env_value;
  457. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  458. (void *)&amfInstance);
  459. if (error != SA_AIS_OK) {
  460. return (error);
  461. }
  462. pthread_mutex_lock (&amfInstance->response_mutex);
  463. error = SA_AIS_OK;
  464. env_value = getenv ("SA_AMF_COMPONENT_NAME");
  465. if (env_value == 0) {
  466. error = SA_AIS_ERR_NOT_EXIST;
  467. goto error_exit;
  468. }
  469. strncpy ((char *)compName->value, env_value, SA_MAX_NAME_LENGTH-1);
  470. compName->value[SA_MAX_NAME_LENGTH-1] = '\0';
  471. compName->length = strlen (env_value);
  472. error_exit:
  473. pthread_mutex_unlock (&amfInstance->response_mutex);
  474. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  475. return (error);
  476. }
  477. SaAisErrorT
  478. saAmfPmStart (
  479. SaAmfHandleT amfHandle,
  480. const SaNameT *compName,
  481. SaUint64T processId,
  482. SaInt32T descendentsTreeDepth,
  483. SaAmfPmErrorsT pmErrors,
  484. SaAmfRecommendedRecoveryT recommendedRecovery)
  485. {
  486. struct req_lib_amf_pmstart req_lib_amf_pmstart;
  487. struct res_lib_amf_pmstart res_lib_amf_pmstart;
  488. struct amfInstance *amfInstance;
  489. SaAisErrorT error;
  490. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  491. (void *)&amfInstance);
  492. if (error != SA_AIS_OK) {
  493. return (error);
  494. }
  495. req_lib_amf_pmstart.header.size = sizeof (struct req_lib_amf_pmstart);
  496. req_lib_amf_pmstart.header.id = MESSAGE_REQ_AMF_PMSTART;
  497. memcpy (&req_lib_amf_pmstart.compName, compName,
  498. sizeof (SaNameT));
  499. req_lib_amf_pmstart.processId = processId;
  500. req_lib_amf_pmstart.descendentsTreeDepth = descendentsTreeDepth;
  501. req_lib_amf_pmstart.pmErrors = pmErrors;
  502. pthread_mutex_lock (&amfInstance->response_mutex);
  503. error = saSendReceiveReply (amfInstance->response_fd,
  504. &req_lib_amf_pmstart,
  505. sizeof (struct req_lib_amf_pmstart),
  506. &res_lib_amf_pmstart,
  507. sizeof (struct res_lib_amf_pmstart));
  508. pthread_mutex_unlock (&amfInstance->response_mutex);
  509. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  510. return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error);
  511. }
  512. SaAisErrorT
  513. saAmfPmStop (
  514. SaAmfHandleT amfHandle,
  515. const SaNameT *compName,
  516. SaAmfPmStopQualifierT stopQualifier,
  517. SaInt64T processId,
  518. SaAmfPmErrorsT pmErrors)
  519. {
  520. struct req_lib_amf_pmstop req_lib_amf_pmstop;
  521. struct res_lib_amf_pmstop res_lib_amf_pmstop;
  522. struct amfInstance *amfInstance;
  523. SaAisErrorT error;
  524. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  525. (void *)&amfInstance);
  526. if (error != SA_AIS_OK) {
  527. return (error);
  528. }
  529. req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop);
  530. req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP;
  531. memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT));
  532. req_lib_amf_pmstop.stopQualifier = stopQualifier;
  533. req_lib_amf_pmstop.processId = processId;
  534. req_lib_amf_pmstop.pmErrors = pmErrors;
  535. pthread_mutex_lock (&amfInstance->response_mutex);
  536. error = saSendReceiveReply (amfInstance->response_fd,
  537. &req_lib_amf_pmstop,
  538. sizeof (struct req_lib_amf_pmstop),
  539. &res_lib_amf_pmstop,
  540. sizeof (struct res_lib_amf_pmstop));
  541. pthread_mutex_unlock (&amfInstance->response_mutex);
  542. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  543. return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error);
  544. return (SA_AIS_OK);
  545. }
  546. SaAisErrorT
  547. saAmfHealthcheckStart (
  548. SaAmfHandleT amfHandle,
  549. const SaNameT *compName,
  550. const SaAmfHealthcheckKeyT *healthcheckKey,
  551. SaAmfHealthcheckInvocationT invocationType,
  552. SaAmfRecommendedRecoveryT recommendedRecovery)
  553. {
  554. struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart;
  555. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  556. struct amfInstance *amfInstance;
  557. SaAisErrorT error;
  558. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  559. (void *)&amfInstance);
  560. if (error != SA_AIS_OK) {
  561. return (error);
  562. }
  563. req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart);
  564. req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART;
  565. memcpy (&req_lib_amf_healthcheckstart.compName, compName,
  566. sizeof (SaNameT));
  567. memcpy (&req_lib_amf_healthcheckstart.healthcheckKey,
  568. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  569. req_lib_amf_healthcheckstart.invocationType = invocationType;
  570. req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery;
  571. pthread_mutex_lock (&amfInstance->response_mutex);
  572. error = saSendReceiveReply (amfInstance->response_fd,
  573. &req_lib_amf_healthcheckstart,
  574. sizeof (struct req_lib_amf_healthcheckstart),
  575. &res_lib_amf_healthcheckstart,
  576. sizeof (struct res_lib_amf_healthcheckstart));
  577. pthread_mutex_unlock (&amfInstance->response_mutex);
  578. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  579. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error);
  580. }
  581. SaAisErrorT
  582. saAmfHealthcheckConfirm (
  583. SaAmfHandleT amfHandle,
  584. const SaNameT *compName,
  585. const SaAmfHealthcheckKeyT *healthcheckKey,
  586. SaAisErrorT healthcheckResult)
  587. {
  588. struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm;
  589. struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm;
  590. struct amfInstance *amfInstance;
  591. SaAisErrorT error;
  592. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  593. (void *)&amfInstance);
  594. if (error != SA_AIS_OK) {
  595. return (error);
  596. }
  597. req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_healthcheckconfirm);
  598. req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM;
  599. memcpy (&req_lib_amf_healthcheckconfirm.compName, compName,
  600. sizeof (SaNameT));
  601. memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey,
  602. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  603. req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult;
  604. pthread_mutex_lock (&amfInstance->response_mutex);
  605. error = saSendReceiveReply (amfInstance->response_fd,
  606. &req_lib_amf_healthcheckconfirm,
  607. sizeof (struct req_lib_amf_healthcheckconfirm),
  608. &res_lib_amf_healthcheckconfirm,
  609. sizeof (struct res_lib_amf_healthcheckconfirm));
  610. pthread_mutex_unlock (&amfInstance->response_mutex);
  611. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  612. return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error);
  613. }
  614. SaAisErrorT
  615. saAmfHealthcheckStop (
  616. SaAmfHandleT amfHandle,
  617. const SaNameT *compName,
  618. const SaAmfHealthcheckKeyT *healthcheckKey)
  619. {
  620. struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop;
  621. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  622. struct amfInstance *amfInstance;
  623. SaAisErrorT error;
  624. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  625. (void *)&amfInstance);
  626. if (error != SA_AIS_OK) {
  627. return (error);
  628. }
  629. req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop);
  630. req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP;
  631. memcpy (&req_lib_amf_healthcheckstop.compName, compName,
  632. sizeof (SaNameT));
  633. memcpy (&req_lib_amf_healthcheckstop.healthcheckKey,
  634. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  635. pthread_mutex_lock (&amfInstance->response_mutex);
  636. error = saSendReceiveReply (amfInstance->response_fd,
  637. &req_lib_amf_healthcheckstop,
  638. sizeof (struct req_lib_amf_healthcheckstop),
  639. &res_lib_amf_healthcheckstop,
  640. sizeof (struct res_lib_amf_healthcheckstop));
  641. pthread_mutex_unlock (&amfInstance->response_mutex);
  642. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  643. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error);
  644. }
  645. SaAisErrorT
  646. saAmfHAStateGet (
  647. SaAmfHandleT amfHandle,
  648. const SaNameT *compName,
  649. const SaNameT *csiName,
  650. SaAmfHAStateT *haState)
  651. {
  652. struct amfInstance *amfInstance;
  653. struct req_lib_amf_hastateget req_lib_amf_hastateget;
  654. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  655. SaAisErrorT error;
  656. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  657. (void *)&amfInstance);
  658. if (error != SA_AIS_OK) {
  659. return (error);
  660. }
  661. pthread_mutex_lock (&amfInstance->response_mutex);
  662. req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  663. req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget);
  664. memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT));
  665. memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  666. error = saSendReceiveReply (amfInstance->response_fd,
  667. &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget),
  668. &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  669. pthread_mutex_unlock (&amfInstance->response_mutex);
  670. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  671. if (res_lib_amf_hastateget.header.error == SA_AIS_OK) {
  672. memcpy (haState, &res_lib_amf_hastateget.haState,
  673. sizeof (SaAmfHAStateT));
  674. }
  675. return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error);
  676. }
  677. SaAisErrorT
  678. saAmfCSIQuiescingComplete (
  679. SaAmfHandleT amfHandle,
  680. SaInvocationT invocation,
  681. SaAisErrorT error)
  682. {
  683. struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete;
  684. struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete;
  685. struct amfInstance *amfInstance;
  686. SaAisErrorT errorResult;
  687. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  688. (void *)&amfInstance);
  689. if (error != SA_AIS_OK) {
  690. return (error);
  691. }
  692. req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_csiquiescingcomplete);
  693. req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE;
  694. req_lib_amf_csiquiescingcomplete.invocation = invocation;
  695. req_lib_amf_csiquiescingcomplete.error = error;
  696. pthread_mutex_lock (&amfInstance->response_mutex);
  697. errorResult = saSendReceiveReply (amfInstance->response_fd,
  698. &req_lib_amf_csiquiescingcomplete,
  699. sizeof (struct req_lib_amf_csiquiescingcomplete),
  700. &res_lib_amf_csiquiescingcomplete,
  701. sizeof (struct res_lib_amf_csiquiescingcomplete));
  702. pthread_mutex_unlock (&amfInstance->response_mutex);
  703. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  704. return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult);
  705. }
  706. SaAisErrorT
  707. saAmfProtectionGroupTrack (
  708. SaAmfHandleT amfHandle,
  709. const SaNameT *csiName,
  710. SaUint8T trackFlags,
  711. SaAmfProtectionGroupNotificationBufferT *notificationBuffer)
  712. {
  713. struct amfInstance *amfInstance;
  714. struct req_lib_amf_protectiongrouptrack req_lib_amf_protectiongrouptrack;
  715. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  716. SaAisErrorT error;
  717. req_lib_amf_protectiongrouptrack.header.size = sizeof (struct req_lib_amf_protectiongrouptrack);
  718. req_lib_amf_protectiongrouptrack.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK;
  719. memcpy (&req_lib_amf_protectiongrouptrack.csiName, csiName,
  720. sizeof (SaNameT));
  721. req_lib_amf_protectiongrouptrack.trackFlags = trackFlags;
  722. req_lib_amf_protectiongrouptrack.notificationBufferAddress = (SaAmfProtectionGroupNotificationBufferT *)notificationBuffer;
  723. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  724. (void *)&amfInstance);
  725. if (error != SA_AIS_OK) {
  726. return (error);
  727. }
  728. pthread_mutex_lock (&amfInstance->response_mutex);
  729. error = saSendReceiveReply (amfInstance->response_fd,
  730. &req_lib_amf_protectiongrouptrack,
  731. sizeof (struct req_lib_amf_protectiongrouptrack),
  732. &res_lib_amf_protectiongrouptrack,
  733. sizeof (struct res_lib_amf_protectiongrouptrack));
  734. pthread_mutex_unlock (&amfInstance->response_mutex);
  735. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  736. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrack.header.error : error);
  737. }
  738. SaAisErrorT
  739. saAmfProtectionGroupTrackStop (
  740. SaAmfHandleT amfHandle,
  741. const SaNameT *csiName)
  742. {
  743. struct amfInstance *amfInstance;
  744. struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop;
  745. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  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_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop);
  753. req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  754. memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  755. pthread_mutex_lock (&amfInstance->response_mutex);
  756. error = saSendReceiveReply (amfInstance->response_fd,
  757. &req_lib_amf_protectiongrouptrackstop,
  758. sizeof (struct req_lib_amf_protectiongrouptrackstop),
  759. &res_lib_amf_protectiongrouptrackstop,
  760. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  761. pthread_mutex_unlock (&amfInstance->response_mutex);
  762. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  763. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error);
  764. }
  765. SaAisErrorT
  766. saAmfComponentErrorReport (
  767. SaAmfHandleT amfHandle,
  768. const SaNameT *erroneousComponent,
  769. SaTimeT errorDetectionTime,
  770. SaAmfRecommendedRecoveryT recommendedRecovery,
  771. SaNtfIdentifierT ntfIdentifier)
  772. {
  773. struct amfInstance *amfInstance;
  774. struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport;
  775. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  776. SaAisErrorT error;
  777. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  778. (void *)&amfInstance);
  779. if (error != SA_AIS_OK) {
  780. return (error);
  781. }
  782. req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT;
  783. req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport);
  784. memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent,
  785. sizeof (SaNameT));
  786. req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime;
  787. req_lib_amf_componenterrorreport.recommendedRecovery = recommendedRecovery;
  788. DPRINT (("start error report\n"));
  789. error = saSendReceiveReply (amfInstance->response_fd,
  790. &req_lib_amf_componenterrorreport,
  791. sizeof (struct req_lib_amf_componenterrorreport),
  792. &res_lib_amf_componenterrorreport,
  793. sizeof (struct res_lib_amf_componenterrorreport));
  794. DPRINT (("end error report\n"));
  795. error = res_lib_amf_componenterrorreport.header.error;
  796. pthread_mutex_unlock (&amfInstance->response_mutex);
  797. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  798. return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error);
  799. }
  800. SaAisErrorT
  801. saAmfComponentErrorClear (
  802. SaAmfHandleT amfHandle,
  803. const SaNameT *compName,
  804. SaNtfIdentifierT ntfIdentifier)
  805. {
  806. struct amfInstance *amfInstance;
  807. struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear;
  808. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  809. SaAisErrorT error;
  810. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  811. (void *)&amfInstance);
  812. if (error != SA_AIS_OK) {
  813. return (error);
  814. }
  815. req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR;
  816. req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear);
  817. memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT));
  818. error = saSendReceiveReply (amfInstance->response_fd,
  819. &req_lib_amf_componenterrorclear,
  820. sizeof (struct req_lib_amf_componenterrorclear),
  821. &res_lib_amf_componenterrorclear,
  822. sizeof (struct res_lib_amf_componenterrorclear));
  823. pthread_mutex_unlock (&amfInstance->response_mutex);
  824. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  825. return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error);
  826. }
  827. SaAisErrorT
  828. saAmfResponse (
  829. SaAmfHandleT amfHandle,
  830. SaInvocationT invocation,
  831. SaAisErrorT error)
  832. {
  833. struct amfInstance *amfInstance;
  834. struct req_lib_amf_response req_lib_amf_response;
  835. struct res_lib_amf_response res_lib_amf_response;
  836. SaAisErrorT errorResult;
  837. errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  838. (void *)&amfInstance);
  839. if (errorResult != SA_AIS_OK) {
  840. return (errorResult);
  841. }
  842. req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  843. req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response);
  844. req_lib_amf_response.invocation = invocation;
  845. req_lib_amf_response.error = error;
  846. pthread_mutex_lock (&amfInstance->response_mutex);
  847. errorResult = saSendReceiveReply (amfInstance->response_fd,
  848. &req_lib_amf_response, sizeof (struct req_lib_amf_response),
  849. &res_lib_amf_response, sizeof (struct res_lib_amf_response));
  850. pthread_mutex_unlock (&amfInstance->response_mutex);
  851. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  852. return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult);
  853. }