amf.c 32 KB

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