amf.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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. req_lib_amf_pmstart.recommendedRecovery = recommendedRecovery;
  503. pthread_mutex_lock (&amfInstance->response_mutex);
  504. error = saSendReceiveReply (amfInstance->response_fd,
  505. &req_lib_amf_pmstart,
  506. sizeof (struct req_lib_amf_pmstart),
  507. &res_lib_amf_pmstart,
  508. sizeof (struct res_lib_amf_pmstart));
  509. pthread_mutex_unlock (&amfInstance->response_mutex);
  510. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  511. return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error);
  512. }
  513. SaAisErrorT
  514. saAmfPmStop (
  515. SaAmfHandleT amfHandle,
  516. const SaNameT *compName,
  517. SaAmfPmStopQualifierT stopQualifier,
  518. SaInt64T processId,
  519. SaAmfPmErrorsT pmErrors)
  520. {
  521. struct req_lib_amf_pmstop req_lib_amf_pmstop;
  522. struct res_lib_amf_pmstop res_lib_amf_pmstop;
  523. struct amfInstance *amfInstance;
  524. SaAisErrorT error;
  525. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  526. (void *)&amfInstance);
  527. if (error != SA_AIS_OK) {
  528. return (error);
  529. }
  530. req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop);
  531. req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP;
  532. memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT));
  533. req_lib_amf_pmstop.stopQualifier = stopQualifier;
  534. req_lib_amf_pmstop.processId = processId;
  535. req_lib_amf_pmstop.pmErrors = pmErrors;
  536. pthread_mutex_lock (&amfInstance->response_mutex);
  537. error = saSendReceiveReply (amfInstance->response_fd,
  538. &req_lib_amf_pmstop,
  539. sizeof (struct req_lib_amf_pmstop),
  540. &res_lib_amf_pmstop,
  541. sizeof (struct res_lib_amf_pmstop));
  542. pthread_mutex_unlock (&amfInstance->response_mutex);
  543. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  544. return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error);
  545. return (SA_AIS_OK);
  546. }
  547. SaAisErrorT
  548. saAmfHealthcheckStart (
  549. SaAmfHandleT amfHandle,
  550. const SaNameT *compName,
  551. const SaAmfHealthcheckKeyT *healthcheckKey,
  552. SaAmfHealthcheckInvocationT invocationType,
  553. SaAmfRecommendedRecoveryT recommendedRecovery)
  554. {
  555. struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart;
  556. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  557. struct amfInstance *amfInstance;
  558. SaAisErrorT error;
  559. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  560. (void *)&amfInstance);
  561. if (error != SA_AIS_OK) {
  562. return (error);
  563. }
  564. req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart);
  565. req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART;
  566. memcpy (&req_lib_amf_healthcheckstart.compName, compName,
  567. sizeof (SaNameT));
  568. memcpy (&req_lib_amf_healthcheckstart.healthcheckKey,
  569. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  570. req_lib_amf_healthcheckstart.invocationType = invocationType;
  571. req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery;
  572. pthread_mutex_lock (&amfInstance->response_mutex);
  573. error = saSendReceiveReply (amfInstance->response_fd,
  574. &req_lib_amf_healthcheckstart,
  575. sizeof (struct req_lib_amf_healthcheckstart),
  576. &res_lib_amf_healthcheckstart,
  577. sizeof (struct res_lib_amf_healthcheckstart));
  578. pthread_mutex_unlock (&amfInstance->response_mutex);
  579. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  580. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error);
  581. }
  582. SaAisErrorT
  583. saAmfHealthcheckConfirm (
  584. SaAmfHandleT amfHandle,
  585. const SaNameT *compName,
  586. const SaAmfHealthcheckKeyT *healthcheckKey,
  587. SaAisErrorT healthcheckResult)
  588. {
  589. struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm;
  590. struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm;
  591. struct amfInstance *amfInstance;
  592. SaAisErrorT error;
  593. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  594. (void *)&amfInstance);
  595. if (error != SA_AIS_OK) {
  596. return (error);
  597. }
  598. req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_healthcheckconfirm);
  599. req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM;
  600. memcpy (&req_lib_amf_healthcheckconfirm.compName, compName,
  601. sizeof (SaNameT));
  602. memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey,
  603. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  604. req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult;
  605. pthread_mutex_lock (&amfInstance->response_mutex);
  606. error = saSendReceiveReply (amfInstance->response_fd,
  607. &req_lib_amf_healthcheckconfirm,
  608. sizeof (struct req_lib_amf_healthcheckconfirm),
  609. &res_lib_amf_healthcheckconfirm,
  610. sizeof (struct res_lib_amf_healthcheckconfirm));
  611. pthread_mutex_unlock (&amfInstance->response_mutex);
  612. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  613. return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error);
  614. }
  615. SaAisErrorT
  616. saAmfHealthcheckStop (
  617. SaAmfHandleT amfHandle,
  618. const SaNameT *compName,
  619. const SaAmfHealthcheckKeyT *healthcheckKey)
  620. {
  621. struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop;
  622. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  623. struct amfInstance *amfInstance;
  624. SaAisErrorT error;
  625. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  626. (void *)&amfInstance);
  627. if (error != SA_AIS_OK) {
  628. return (error);
  629. }
  630. req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop);
  631. req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP;
  632. memcpy (&req_lib_amf_healthcheckstop.compName, compName,
  633. sizeof (SaNameT));
  634. memcpy (&req_lib_amf_healthcheckstop.healthcheckKey,
  635. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  636. pthread_mutex_lock (&amfInstance->response_mutex);
  637. error = saSendReceiveReply (amfInstance->response_fd,
  638. &req_lib_amf_healthcheckstop,
  639. sizeof (struct req_lib_amf_healthcheckstop),
  640. &res_lib_amf_healthcheckstop,
  641. sizeof (struct res_lib_amf_healthcheckstop));
  642. pthread_mutex_unlock (&amfInstance->response_mutex);
  643. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  644. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error);
  645. }
  646. SaAisErrorT
  647. saAmfHAStateGet (
  648. SaAmfHandleT amfHandle,
  649. const SaNameT *compName,
  650. const SaNameT *csiName,
  651. SaAmfHAStateT *haState)
  652. {
  653. struct amfInstance *amfInstance;
  654. struct req_lib_amf_hastateget req_lib_amf_hastateget;
  655. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  656. SaAisErrorT error;
  657. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  658. (void *)&amfInstance);
  659. if (error != SA_AIS_OK) {
  660. return (error);
  661. }
  662. pthread_mutex_lock (&amfInstance->response_mutex);
  663. req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  664. req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget);
  665. memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT));
  666. memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  667. error = saSendReceiveReply (amfInstance->response_fd,
  668. &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget),
  669. &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  670. pthread_mutex_unlock (&amfInstance->response_mutex);
  671. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  672. if (res_lib_amf_hastateget.header.error == SA_AIS_OK) {
  673. memcpy (haState, &res_lib_amf_hastateget.haState,
  674. sizeof (SaAmfHAStateT));
  675. }
  676. return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error);
  677. }
  678. SaAisErrorT
  679. saAmfCSIQuiescingComplete (
  680. SaAmfHandleT amfHandle,
  681. SaInvocationT invocation,
  682. SaAisErrorT error)
  683. {
  684. struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete;
  685. struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete;
  686. struct amfInstance *amfInstance;
  687. SaAisErrorT errorResult;
  688. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  689. (void *)&amfInstance);
  690. if (error != SA_AIS_OK) {
  691. return (error);
  692. }
  693. req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_csiquiescingcomplete);
  694. req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE;
  695. req_lib_amf_csiquiescingcomplete.invocation = invocation;
  696. req_lib_amf_csiquiescingcomplete.error = error;
  697. pthread_mutex_lock (&amfInstance->response_mutex);
  698. errorResult = saSendReceiveReply (amfInstance->response_fd,
  699. &req_lib_amf_csiquiescingcomplete,
  700. sizeof (struct req_lib_amf_csiquiescingcomplete),
  701. &res_lib_amf_csiquiescingcomplete,
  702. sizeof (struct res_lib_amf_csiquiescingcomplete));
  703. pthread_mutex_unlock (&amfInstance->response_mutex);
  704. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  705. return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult);
  706. }
  707. SaAisErrorT
  708. saAmfProtectionGroupTrack (
  709. SaAmfHandleT amfHandle,
  710. const SaNameT *csiName,
  711. SaUint8T trackFlags,
  712. SaAmfProtectionGroupNotificationBufferT *notificationBuffer)
  713. {
  714. struct amfInstance *amfInstance;
  715. struct req_lib_amf_protectiongrouptrack req_lib_amf_protectiongrouptrack;
  716. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  717. SaAisErrorT error;
  718. req_lib_amf_protectiongrouptrack.header.size = sizeof (struct req_lib_amf_protectiongrouptrack);
  719. req_lib_amf_protectiongrouptrack.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK;
  720. memcpy (&req_lib_amf_protectiongrouptrack.csiName, csiName,
  721. sizeof (SaNameT));
  722. req_lib_amf_protectiongrouptrack.trackFlags = trackFlags;
  723. req_lib_amf_protectiongrouptrack.notificationBufferAddress = (SaAmfProtectionGroupNotificationBufferT *)notificationBuffer;
  724. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  725. (void *)&amfInstance);
  726. if (error != SA_AIS_OK) {
  727. return (error);
  728. }
  729. pthread_mutex_lock (&amfInstance->response_mutex);
  730. error = saSendReceiveReply (amfInstance->response_fd,
  731. &req_lib_amf_protectiongrouptrack,
  732. sizeof (struct req_lib_amf_protectiongrouptrack),
  733. &res_lib_amf_protectiongrouptrack,
  734. sizeof (struct res_lib_amf_protectiongrouptrack));
  735. pthread_mutex_unlock (&amfInstance->response_mutex);
  736. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  737. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrack.header.error : error);
  738. }
  739. SaAisErrorT
  740. saAmfProtectionGroupTrackStop (
  741. SaAmfHandleT amfHandle,
  742. const SaNameT *csiName)
  743. {
  744. struct amfInstance *amfInstance;
  745. struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop;
  746. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  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_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop);
  754. req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  755. memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  756. pthread_mutex_lock (&amfInstance->response_mutex);
  757. error = saSendReceiveReply (amfInstance->response_fd,
  758. &req_lib_amf_protectiongrouptrackstop,
  759. sizeof (struct req_lib_amf_protectiongrouptrackstop),
  760. &res_lib_amf_protectiongrouptrackstop,
  761. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  762. pthread_mutex_unlock (&amfInstance->response_mutex);
  763. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  764. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error);
  765. }
  766. SaAisErrorT
  767. saAmfComponentErrorReport (
  768. SaAmfHandleT amfHandle,
  769. const SaNameT *erroneousComponent,
  770. SaTimeT errorDetectionTime,
  771. SaAmfRecommendedRecoveryT recommendedRecovery,
  772. SaNtfIdentifierT ntfIdentifier)
  773. {
  774. struct amfInstance *amfInstance;
  775. struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport;
  776. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  777. SaAisErrorT error;
  778. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  779. (void *)&amfInstance);
  780. if (error != SA_AIS_OK) {
  781. return (error);
  782. }
  783. req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT;
  784. req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport);
  785. memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent,
  786. sizeof (SaNameT));
  787. req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime;
  788. req_lib_amf_componenterrorreport.recommendedRecovery = recommendedRecovery;
  789. DPRINT (("start error report\n"));
  790. error = saSendReceiveReply (amfInstance->response_fd,
  791. &req_lib_amf_componenterrorreport,
  792. sizeof (struct req_lib_amf_componenterrorreport),
  793. &res_lib_amf_componenterrorreport,
  794. sizeof (struct res_lib_amf_componenterrorreport));
  795. DPRINT (("end error report\n"));
  796. error = res_lib_amf_componenterrorreport.header.error;
  797. pthread_mutex_unlock (&amfInstance->response_mutex);
  798. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  799. return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error);
  800. }
  801. SaAisErrorT
  802. saAmfComponentErrorClear (
  803. SaAmfHandleT amfHandle,
  804. const SaNameT *compName,
  805. SaNtfIdentifierT ntfIdentifier)
  806. {
  807. struct amfInstance *amfInstance;
  808. struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear;
  809. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  810. SaAisErrorT error;
  811. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  812. (void *)&amfInstance);
  813. if (error != SA_AIS_OK) {
  814. return (error);
  815. }
  816. req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR;
  817. req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear);
  818. memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT));
  819. error = saSendReceiveReply (amfInstance->response_fd,
  820. &req_lib_amf_componenterrorclear,
  821. sizeof (struct req_lib_amf_componenterrorclear),
  822. &res_lib_amf_componenterrorclear,
  823. sizeof (struct res_lib_amf_componenterrorclear));
  824. pthread_mutex_unlock (&amfInstance->response_mutex);
  825. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  826. return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error);
  827. }
  828. SaAisErrorT
  829. saAmfResponse (
  830. SaAmfHandleT amfHandle,
  831. SaInvocationT invocation,
  832. SaAisErrorT error)
  833. {
  834. struct amfInstance *amfInstance;
  835. struct req_lib_amf_response req_lib_amf_response;
  836. struct res_lib_amf_response res_lib_amf_response;
  837. SaAisErrorT errorResult;
  838. errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  839. (void *)&amfInstance);
  840. if (errorResult != SA_AIS_OK) {
  841. return (errorResult);
  842. }
  843. req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  844. req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response);
  845. req_lib_amf_response.invocation = invocation;
  846. req_lib_amf_response.error = error;
  847. pthread_mutex_lock (&amfInstance->response_mutex);
  848. errorResult = saSendReceiveReply (amfInstance->response_fd,
  849. &req_lib_amf_response, sizeof (struct req_lib_amf_response),
  850. &res_lib_amf_response, sizeof (struct res_lib_amf_response));
  851. pthread_mutex_unlock (&amfInstance->response_mutex);
  852. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  853. return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult);
  854. }