amf.c 31 KB

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