amf.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <errno.h>
  39. #include <signal.h>
  40. #include <pthread.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <sys/select.h>
  44. #include <sys/un.h>
  45. #include "../include/saAis.h"
  46. #include "../include/saAmf.h"
  47. #include "../include/ipc_gen.h"
  48. #include "../include/ipc_amf.h"
  49. #include "util.h"
  50. struct res_overlay {
  51. struct res_header header;
  52. char data[4096];
  53. };
  54. /*
  55. * Data structure for instance data
  56. */
  57. struct amfInstance {
  58. int response_fd;
  59. int dispatch_fd;
  60. SaAmfCallbacksT callbacks;
  61. SaNameT compName;
  62. int compRegistered;
  63. int finalize;
  64. pthread_mutex_t response_mutex;
  65. pthread_mutex_t dispatch_mutex;
  66. };
  67. static void amfHandleInstanceDestructor (void *);
  68. /*
  69. * All instances in one database
  70. */
  71. static struct saHandleDatabase amfHandleDatabase = {
  72. .handleCount = 0,
  73. .handles = 0,
  74. .mutex = PTHREAD_MUTEX_INITIALIZER,
  75. .handleInstanceDestructor = amfHandleInstanceDestructor
  76. };
  77. /*
  78. * Versions supported
  79. */
  80. static SaVersionT amfVersionsSupported[] = {
  81. { 'B', 1, 1 }
  82. };
  83. static struct saVersionDatabase amfVersionDatabase = {
  84. sizeof (amfVersionsSupported) / sizeof (SaVersionT),
  85. amfVersionsSupported
  86. };
  87. /*
  88. * Implementation
  89. */
  90. void amfHandleInstanceDestructor (void *instance)
  91. {
  92. }
  93. SaAisErrorT
  94. saAmfInitialize (
  95. SaAmfHandleT *amfHandle,
  96. const SaAmfCallbacksT *amfCallbacks,
  97. SaVersionT *version)
  98. {
  99. struct amfInstance *amfInstance;
  100. SaAisErrorT error = SA_AIS_OK;
  101. error = saVersionVerify (&amfVersionDatabase, (SaVersionT *)version);
  102. if (error != SA_AIS_OK) {
  103. goto error_no_destroy;
  104. }
  105. error = saHandleCreate (&amfHandleDatabase, sizeof (struct amfInstance), amfHandle);
  106. if (error != SA_AIS_OK) {
  107. goto error_no_destroy;
  108. }
  109. error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
  110. if (error != SA_AIS_OK) {
  111. goto error_destroy;
  112. }
  113. amfInstance->response_fd = -1;
  114. amfInstance->dispatch_fd = -1;
  115. error = saServiceConnectTwo (&amfInstance->response_fd,
  116. &amfInstance->dispatch_fd, AMF_SERVICE);
  117. if (error != SA_AIS_OK) {
  118. goto error_put_destroy;
  119. }
  120. memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT));
  121. pthread_mutex_init (&amfInstance->response_mutex, NULL);
  122. pthread_mutex_init (&amfInstance->dispatch_mutex, NULL);
  123. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  124. return (SA_AIS_OK);
  125. error_put_destroy:
  126. saHandleInstancePut (&amfHandleDatabase, *amfHandle);
  127. error_destroy:
  128. saHandleDestroy (&amfHandleDatabase, *amfHandle);
  129. error_no_destroy:
  130. return (error);
  131. }
  132. SaAisErrorT
  133. saAmfSelectionObjectGet (
  134. SaAmfHandleT amfHandle,
  135. SaSelectionObjectT *selectionObject)
  136. {
  137. struct amfInstance *amfInstance;
  138. SaAisErrorT error;
  139. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
  140. if (error != SA_AIS_OK) {
  141. return (error);
  142. }
  143. *selectionObject = amfInstance->dispatch_fd;
  144. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  145. return (SA_AIS_OK);
  146. }
  147. SaAisErrorT
  148. saAmfDispatch (
  149. SaAmfHandleT amfHandle,
  150. SaDispatchFlagsT dispatchFlags)
  151. {
  152. struct pollfd ufds;
  153. int timeout = -1;
  154. SaAisErrorT error;
  155. int cont = 1; /* always continue do loop except when set to 0 */
  156. int dispatch_avail;
  157. struct amfInstance *amfInstance;
  158. struct res_lib_amf_csisetcallback *res_lib_amf_csisetcallback;
  159. struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
  160. struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
  161. struct res_lib_amf_componentterminatecallback *res_lib_amf_componentterminatecallback;
  162. /*
  163. struct res_lib_amf_protectiongrouptrackcallback *res_lib_amf_protectiongrouptrackcallback;
  164. */
  165. SaAmfCallbacksT callbacks;
  166. struct res_overlay dispatch_data;
  167. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  168. (void *)&amfInstance);
  169. if (error != SA_AIS_OK) {
  170. return (error);
  171. }
  172. /*
  173. * Timeout instantly for SA_DISPATCH_ALL
  174. */
  175. if (dispatchFlags == SA_DISPATCH_ALL) {
  176. timeout = 0;
  177. }
  178. do {
  179. /*
  180. * Read data directly from socket
  181. */
  182. ufds.fd = amfInstance->dispatch_fd;
  183. ufds.events = POLLIN;
  184. ufds.revents = 0;
  185. error = saPollRetry (&ufds, 1, timeout);
  186. if (error != SA_AIS_OK) {
  187. goto error_nounlock;
  188. }
  189. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  190. error = saPollRetry (&ufds, 1, 0);
  191. if (error != SA_AIS_OK) {
  192. goto error_nounlock;
  193. }
  194. /*
  195. * Handle has been finalized in another thread
  196. */
  197. if (amfInstance->finalize == 1) {
  198. error = SA_AIS_OK;
  199. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  200. goto error_unlock;
  201. }
  202. dispatch_avail = ufds.revents & POLLIN;
  203. if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
  204. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  205. break; /* exit do while cont is 1 loop */
  206. } else
  207. if (dispatch_avail == 0) {
  208. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  209. continue; /* next poll */
  210. }
  211. if (ufds.revents & POLLIN) {
  212. /*
  213. * Queue empty, read response from socket
  214. */
  215. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.header,
  216. sizeof (struct res_header));
  217. if (error != SA_AIS_OK) {
  218. goto error_unlock;
  219. }
  220. if (dispatch_data.header.size > sizeof (struct res_header)) {
  221. error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.data,
  222. dispatch_data.header.size - sizeof (struct res_header));
  223. if (error != SA_AIS_OK) {
  224. goto error_unlock;
  225. }
  226. }
  227. } else {
  228. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  229. continue;
  230. }
  231. /*
  232. * Make copy of callbacks, message data, unlock instance, and call callback
  233. * A risk of this dispatch method is that the callback routines may
  234. * operate at the same time that amfFinalize has been called in another thread.
  235. */
  236. memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
  237. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  238. /*
  239. * Dispatch incoming response
  240. */
  241. switch (dispatch_data.header.id) {
  242. case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
  243. res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
  244. callbacks.saAmfHealthcheckCallback (
  245. res_lib_amf_healthcheckcallback->invocation,
  246. &res_lib_amf_healthcheckcallback->compName,
  247. &res_lib_amf_healthcheckcallback->key);
  248. break;
  249. case MESSAGE_RES_AMF_CSISETCALLBACK:
  250. {
  251. res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
  252. SaAmfCSIDescriptorT csi_descriptor;
  253. csi_descriptor.csiFlags = res_lib_amf_csisetcallback->csiFlags;
  254. memcpy(&csi_descriptor.csiName, &res_lib_amf_csisetcallback->csiName,
  255. sizeof(SaNameT));
  256. csi_descriptor.csiStateDescriptor = res_lib_amf_csisetcallback->csiStateDescriptor;
  257. csi_descriptor.csiAttr.number = res_lib_amf_csisetcallback->number;
  258. SaAmfCSIAttributeT* csi_attribute_array = malloc( sizeof( SaAmfCSIAttributeT ) *
  259. csi_descriptor.csiAttr.number );
  260. if( csi_attribute_array == 0) {
  261. return SA_AIS_ERR_LIBRARY;
  262. }
  263. csi_descriptor.csiAttr.attr = csi_attribute_array;
  264. char* p = res_lib_amf_csisetcallback->csi_attr_buf;
  265. int i;
  266. for (i=0; i<csi_descriptor.csiAttr.number; i++) {
  267. csi_attribute_array[i].attrName = (SaUint8T*)p;
  268. p += strlen(p) + 1;
  269. csi_attribute_array[i].attrValue = (SaUint8T*)p;
  270. p += strlen(p) + 1;
  271. }
  272. callbacks.saAmfCSISetCallback (
  273. res_lib_amf_csisetcallback->invocation,
  274. &res_lib_amf_csisetcallback->compName,
  275. res_lib_amf_csisetcallback->haState,
  276. &csi_descriptor);
  277. free(csi_attribute_array);
  278. break;
  279. }
  280. case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
  281. res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
  282. callbacks.saAmfCSIRemoveCallback (
  283. res_lib_amf_csiremovecallback->invocation,
  284. &res_lib_amf_csiremovecallback->compName,
  285. &res_lib_amf_csiremovecallback->csiName,
  286. res_lib_amf_csiremovecallback->csiFlags);
  287. break;
  288. case MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK:
  289. res_lib_amf_componentterminatecallback = (struct res_lib_amf_componentterminatecallback *)&dispatch_data;
  290. callbacks.saAmfComponentTerminateCallback (
  291. res_lib_amf_componentterminatecallback->invocation,
  292. &res_lib_amf_componentterminatecallback->compName);
  293. break;
  294. #ifdef COMPILE_OUT
  295. case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
  296. res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
  297. memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  298. res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
  299. res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
  300. callbacks.saAmfProtectionGroupTrackCallback(
  301. &res_lib_amf_protectiongrouptrackcallback->csiName,
  302. res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
  303. res_lib_amf_protectiongrouptrackcallback->numberOfItems,
  304. res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
  305. res_lib_amf_protectiongrouptrackcallback->error);
  306. #endif
  307. break;
  308. default:
  309. error = SA_AIS_ERR_LIBRARY;
  310. goto error_nounlock;
  311. break;
  312. }
  313. /*
  314. * Determine if more messages should be processed
  315. */
  316. switch (dispatchFlags) {
  317. case SA_DISPATCH_ONE:
  318. cont = 0;
  319. break;
  320. case SA_DISPATCH_ALL:
  321. break;
  322. case SA_DISPATCH_BLOCKING:
  323. break;
  324. }
  325. } while (cont);
  326. error_unlock:
  327. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  328. error_nounlock:
  329. return (error);
  330. }
  331. SaAisErrorT
  332. saAmfFinalize (
  333. SaAmfHandleT amfHandle)
  334. {
  335. struct amfInstance *amfInstance;
  336. SaAisErrorT error;
  337. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
  338. if (error != SA_AIS_OK) {
  339. return (error);
  340. }
  341. pthread_mutex_lock (&amfInstance->dispatch_mutex);
  342. pthread_mutex_lock (&amfInstance->response_mutex);
  343. /*
  344. * Another thread has already started finalizing
  345. */
  346. if (amfInstance->finalize) {
  347. pthread_mutex_unlock (&amfInstance->response_mutex);
  348. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  349. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  350. return (SA_AIS_ERR_BAD_HANDLE);
  351. }
  352. amfInstance->finalize = 1;
  353. pthread_mutex_unlock (&amfInstance->response_mutex);
  354. pthread_mutex_unlock (&amfInstance->dispatch_mutex);
  355. saHandleDestroy (&amfHandleDatabase, amfHandle);
  356. if (amfInstance->response_fd != -1) {
  357. shutdown (amfInstance->response_fd, 0);
  358. close (amfInstance->response_fd);
  359. }
  360. if (amfInstance->dispatch_fd != -1) {
  361. shutdown (amfInstance->dispatch_fd, 0);
  362. close (amfInstance->dispatch_fd);
  363. }
  364. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  365. return (error);
  366. }
  367. SaAisErrorT
  368. saAmfComponentRegister (
  369. SaAmfHandleT amfHandle,
  370. const SaNameT *compName,
  371. const SaNameT *proxyCompName)
  372. {
  373. struct amfInstance *amfInstance;
  374. SaAisErrorT error;
  375. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  376. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  377. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  378. (void *)&amfInstance);
  379. if (error != SA_AIS_OK) {
  380. return (error);
  381. }
  382. req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
  383. req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
  384. memcpy (&req_lib_amf_componentregister.compName, compName,
  385. sizeof (SaNameT));
  386. if (proxyCompName) {
  387. memcpy (&req_lib_amf_componentregister.proxyCompName,
  388. proxyCompName, sizeof (SaNameT));
  389. } else {
  390. memset (&req_lib_amf_componentregister.proxyCompName, 0,
  391. sizeof (SaNameT));
  392. }
  393. pthread_mutex_lock (&amfInstance->response_mutex);
  394. error = saSendReceiveReply (amfInstance->response_fd,
  395. &req_lib_amf_componentregister,
  396. sizeof (struct req_lib_amf_componentregister),
  397. &res_lib_amf_componentregister,
  398. sizeof (struct res_lib_amf_componentregister));
  399. pthread_mutex_unlock (&amfInstance->response_mutex);
  400. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  401. if (res_lib_amf_componentregister.header.error == SA_AIS_OK) {
  402. amfInstance->compRegistered = 1;
  403. memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
  404. }
  405. return (error == SA_AIS_OK ? res_lib_amf_componentregister.header.error : error);
  406. }
  407. SaAisErrorT
  408. saAmfComponentUnregister (
  409. SaAmfHandleT amfHandle,
  410. const SaNameT *compName,
  411. const SaNameT *proxyCompName)
  412. {
  413. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  414. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  415. struct amfInstance *amfInstance;
  416. SaAisErrorT error;
  417. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  418. (void *)&amfInstance);
  419. if (error != SA_AIS_OK) {
  420. return (error);
  421. }
  422. req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
  423. req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
  424. memcpy (&req_lib_amf_componentunregister.compName, compName,
  425. sizeof (SaNameT));
  426. if (proxyCompName) {
  427. memcpy (&req_lib_amf_componentunregister.proxyCompName,
  428. proxyCompName, sizeof (SaNameT));
  429. } else {
  430. memset (&req_lib_amf_componentunregister.proxyCompName, 0,
  431. sizeof (SaNameT));
  432. }
  433. pthread_mutex_lock (&amfInstance->response_mutex);
  434. error = saSendReceiveReply (amfInstance->response_fd,
  435. &req_lib_amf_componentunregister,
  436. sizeof (struct req_lib_amf_componentunregister),
  437. &res_lib_amf_componentunregister,
  438. sizeof (struct res_lib_amf_componentunregister));
  439. pthread_mutex_unlock (&amfInstance->response_mutex);
  440. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  441. return (error == SA_AIS_OK ? res_lib_amf_componentunregister.header.error : error);
  442. }
  443. SaAisErrorT
  444. saAmfComponentNameGet (
  445. SaAmfHandleT amfHandle,
  446. SaNameT *compName)
  447. {
  448. struct amfInstance *amfInstance;
  449. SaAisErrorT error;
  450. char *env_value;
  451. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  452. (void *)&amfInstance);
  453. if (error != SA_AIS_OK) {
  454. return (error);
  455. }
  456. pthread_mutex_lock (&amfInstance->response_mutex);
  457. error = SA_AIS_OK;
  458. env_value = getenv ("SA_AMF_COMPONENT_NAME");
  459. if (env_value == 0) {
  460. error = SA_AIS_ERR_NOT_EXIST;
  461. goto error_exit;
  462. }
  463. strncpy ((char *)compName->value, env_value, SA_MAX_NAME_LENGTH-1);
  464. compName->value[SA_MAX_NAME_LENGTH-1] = '\0';
  465. compName->length = strlen (env_value);
  466. error_exit:
  467. pthread_mutex_unlock (&amfInstance->response_mutex);
  468. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  469. return (error);
  470. }
  471. SaAisErrorT
  472. saAmfPmStart (
  473. SaAmfHandleT amfHandle,
  474. const SaNameT *compName,
  475. SaUint64T processId,
  476. SaInt32T descendentsTreeDepth,
  477. SaAmfPmErrorsT pmErrors,
  478. SaAmfRecommendedRecoveryT recommendedRecovery)
  479. {
  480. struct req_lib_amf_pmstart req_lib_amf_pmstart;
  481. struct res_lib_amf_pmstart res_lib_amf_pmstart;
  482. struct amfInstance *amfInstance;
  483. SaAisErrorT error;
  484. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  485. (void *)&amfInstance);
  486. if (error != SA_AIS_OK) {
  487. return (error);
  488. }
  489. req_lib_amf_pmstart.header.size = sizeof (struct req_lib_amf_componentunregister);
  490. req_lib_amf_pmstart.header.id = MESSAGE_REQ_AMF_PMSTART;
  491. memcpy (&req_lib_amf_pmstart.compName, compName,
  492. sizeof (SaNameT));
  493. req_lib_amf_pmstart.processId = processId;
  494. req_lib_amf_pmstart.descendentsTreeDepth = descendentsTreeDepth;
  495. req_lib_amf_pmstart.pmErrors = pmErrors;
  496. pthread_mutex_lock (&amfInstance->response_mutex);
  497. error = saSendReceiveReply (amfInstance->response_fd,
  498. &req_lib_amf_pmstart,
  499. sizeof (struct req_lib_amf_pmstart),
  500. &res_lib_amf_pmstart,
  501. sizeof (struct res_lib_amf_pmstart));
  502. pthread_mutex_unlock (&amfInstance->response_mutex);
  503. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  504. return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error);
  505. }
  506. SaAisErrorT
  507. saAmfPmStop (
  508. SaAmfHandleT amfHandle,
  509. const SaNameT *compName,
  510. SaAmfPmStopQualifierT stopQualifier,
  511. SaInt64T processId,
  512. SaAmfPmErrorsT pmErrors)
  513. {
  514. struct req_lib_amf_pmstop req_lib_amf_pmstop;
  515. struct res_lib_amf_pmstop res_lib_amf_pmstop;
  516. struct amfInstance *amfInstance;
  517. SaAisErrorT error;
  518. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  519. (void *)&amfInstance);
  520. if (error != SA_AIS_OK) {
  521. return (error);
  522. }
  523. req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop);
  524. req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP;
  525. memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT));
  526. req_lib_amf_pmstop.stopQualifier = stopQualifier;
  527. req_lib_amf_pmstop.processId = processId;
  528. req_lib_amf_pmstop.pmErrors = pmErrors;
  529. pthread_mutex_lock (&amfInstance->response_mutex);
  530. error = saSendReceiveReply (amfInstance->response_fd,
  531. &req_lib_amf_pmstop,
  532. sizeof (struct req_lib_amf_pmstop),
  533. &res_lib_amf_pmstop,
  534. sizeof (struct res_lib_amf_pmstop));
  535. pthread_mutex_unlock (&amfInstance->response_mutex);
  536. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  537. return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error);
  538. return (SA_AIS_OK);
  539. }
  540. SaAisErrorT
  541. saAmfHealthcheckStart (
  542. SaAmfHandleT amfHandle,
  543. const SaNameT *compName,
  544. const SaAmfHealthcheckKeyT *healthcheckKey,
  545. SaAmfHealthcheckInvocationT invocationType,
  546. SaAmfRecommendedRecoveryT recommendedRecovery)
  547. {
  548. struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart;
  549. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  550. struct amfInstance *amfInstance;
  551. SaAisErrorT error;
  552. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  553. (void *)&amfInstance);
  554. if (error != SA_AIS_OK) {
  555. return (error);
  556. }
  557. req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart);
  558. req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART;
  559. memcpy (&req_lib_amf_healthcheckstart.compName, compName,
  560. sizeof (SaNameT));
  561. memcpy (&req_lib_amf_healthcheckstart.healthcheckKey,
  562. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  563. req_lib_amf_healthcheckstart.invocationType = invocationType;
  564. req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery;
  565. pthread_mutex_lock (&amfInstance->response_mutex);
  566. error = saSendReceiveReply (amfInstance->response_fd,
  567. &req_lib_amf_healthcheckstart,
  568. sizeof (struct req_lib_amf_healthcheckstart),
  569. &res_lib_amf_healthcheckstart,
  570. sizeof (struct res_lib_amf_healthcheckstart));
  571. pthread_mutex_unlock (&amfInstance->response_mutex);
  572. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  573. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error);
  574. }
  575. SaAisErrorT
  576. saAmfHealthcheckConfirm (
  577. SaAmfHandleT amfHandle,
  578. const SaNameT *compName,
  579. const SaAmfHealthcheckKeyT *healthcheckKey,
  580. SaAisErrorT healthcheckResult)
  581. {
  582. struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm;
  583. struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm;
  584. struct amfInstance *amfInstance;
  585. SaAisErrorT error;
  586. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  587. (void *)&amfInstance);
  588. if (error != SA_AIS_OK) {
  589. return (error);
  590. }
  591. req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_componentunregister);
  592. req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM;
  593. memcpy (&req_lib_amf_healthcheckconfirm.compName, compName,
  594. sizeof (SaNameT));
  595. memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey,
  596. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  597. req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult;
  598. pthread_mutex_lock (&amfInstance->response_mutex);
  599. error = saSendReceiveReply (amfInstance->response_fd,
  600. &req_lib_amf_healthcheckconfirm,
  601. sizeof (struct req_lib_amf_healthcheckconfirm),
  602. &res_lib_amf_healthcheckconfirm,
  603. sizeof (struct res_lib_amf_healthcheckconfirm));
  604. pthread_mutex_unlock (&amfInstance->response_mutex);
  605. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  606. return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error);
  607. }
  608. SaAisErrorT
  609. saAmfHealthcheckStop (
  610. SaAmfHandleT amfHandle,
  611. const SaNameT *compName,
  612. const SaAmfHealthcheckKeyT *healthcheckKey)
  613. {
  614. struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop;
  615. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  616. struct amfInstance *amfInstance;
  617. SaAisErrorT error;
  618. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  619. (void *)&amfInstance);
  620. if (error != SA_AIS_OK) {
  621. return (error);
  622. }
  623. req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop);
  624. req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP;
  625. memcpy (&req_lib_amf_healthcheckstop.compName, compName,
  626. sizeof (SaNameT));
  627. memcpy (&req_lib_amf_healthcheckstop.healthcheckKey,
  628. healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  629. pthread_mutex_lock (&amfInstance->response_mutex);
  630. error = saSendReceiveReply (amfInstance->response_fd,
  631. &req_lib_amf_healthcheckstop,
  632. sizeof (struct req_lib_amf_healthcheckstop),
  633. &res_lib_amf_healthcheckstop,
  634. sizeof (struct res_lib_amf_healthcheckstop));
  635. pthread_mutex_unlock (&amfInstance->response_mutex);
  636. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  637. return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error);
  638. }
  639. SaAisErrorT
  640. saAmfHAStateGet (
  641. SaAmfHandleT amfHandle,
  642. const SaNameT *compName,
  643. const SaNameT *csiName,
  644. SaAmfHAStateT *haState)
  645. {
  646. struct amfInstance *amfInstance;
  647. struct req_lib_amf_hastateget req_lib_amf_hastateget;
  648. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  649. SaAisErrorT error;
  650. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  651. (void *)&amfInstance);
  652. if (error != SA_AIS_OK) {
  653. return (error);
  654. }
  655. pthread_mutex_lock (&amfInstance->response_mutex);
  656. req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
  657. req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget);
  658. memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT));
  659. memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT));
  660. error = saSendReceiveReply (amfInstance->response_fd,
  661. &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget),
  662. &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  663. pthread_mutex_unlock (&amfInstance->response_mutex);
  664. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  665. if (res_lib_amf_hastateget.header.error == SA_AIS_OK) {
  666. memcpy (haState, &res_lib_amf_hastateget.haState,
  667. sizeof (SaAmfHAStateT));
  668. }
  669. return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error);
  670. }
  671. SaAisErrorT
  672. saAmfCSIQuiescingComplete (
  673. SaAmfHandleT amfHandle,
  674. SaInvocationT invocation,
  675. SaAisErrorT error)
  676. {
  677. struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete;
  678. struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete;
  679. struct amfInstance *amfInstance;
  680. SaAisErrorT errorResult;
  681. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  682. (void *)&amfInstance);
  683. if (error != SA_AIS_OK) {
  684. return (error);
  685. }
  686. req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_componentunregister);
  687. req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE;
  688. req_lib_amf_csiquiescingcomplete.invocation = invocation;
  689. req_lib_amf_csiquiescingcomplete.error = error;
  690. pthread_mutex_lock (&amfInstance->response_mutex);
  691. errorResult = saSendReceiveReply (amfInstance->response_fd,
  692. &req_lib_amf_csiquiescingcomplete,
  693. sizeof (struct req_lib_amf_csiquiescingcomplete),
  694. &res_lib_amf_csiquiescingcomplete,
  695. sizeof (struct res_lib_amf_csiquiescingcomplete));
  696. pthread_mutex_unlock (&amfInstance->response_mutex);
  697. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  698. return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult);
  699. }
  700. SaAisErrorT
  701. saAmfProtectionGroupTrack (
  702. SaAmfHandleT amfHandle,
  703. const SaNameT *csiName,
  704. SaUint8T trackFlags,
  705. const SaAmfProtectionGroupNotificationT *notificationBuffer)
  706. {
  707. struct amfInstance *amfInstance;
  708. struct req_lib_amf_protectiongrouptrack req_lib_amf_protectiongrouptrack;
  709. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  710. SaAisErrorT error;
  711. req_lib_amf_protectiongrouptrack.header.size = sizeof (struct req_lib_amf_protectiongrouptrack);
  712. req_lib_amf_protectiongrouptrack.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK;
  713. memcpy (&req_lib_amf_protectiongrouptrack.csiName, csiName,
  714. sizeof (SaNameT));
  715. req_lib_amf_protectiongrouptrack.trackFlags = trackFlags;
  716. req_lib_amf_protectiongrouptrack.notificationBufferAddress = (SaAmfProtectionGroupNotificationT *)notificationBuffer;
  717. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  718. (void *)&amfInstance);
  719. if (error != SA_AIS_OK) {
  720. return (error);
  721. }
  722. pthread_mutex_lock (&amfInstance->response_mutex);
  723. error = saSendReceiveReply (amfInstance->response_fd,
  724. &req_lib_amf_protectiongrouptrack,
  725. sizeof (struct req_lib_amf_protectiongrouptrack),
  726. &res_lib_amf_protectiongrouptrack,
  727. sizeof (struct res_lib_amf_protectiongrouptrack));
  728. pthread_mutex_unlock (&amfInstance->response_mutex);
  729. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  730. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrack.header.error : error);
  731. }
  732. SaAisErrorT
  733. saAmfProtectionGroupTrackStop (
  734. SaAmfHandleT amfHandle,
  735. const SaNameT *csiName)
  736. {
  737. struct amfInstance *amfInstance;
  738. struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop;
  739. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  740. SaAisErrorT error;
  741. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  742. (void *)&amfInstance);
  743. if (error != SA_AIS_OK) {
  744. return (error);
  745. }
  746. req_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop);
  747. req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
  748. memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
  749. pthread_mutex_lock (&amfInstance->response_mutex);
  750. error = saSendReceiveReply (amfInstance->response_fd,
  751. &req_lib_amf_protectiongrouptrackstop,
  752. sizeof (struct req_lib_amf_protectiongrouptrackstop),
  753. &res_lib_amf_protectiongrouptrackstop,
  754. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  755. pthread_mutex_unlock (&amfInstance->response_mutex);
  756. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  757. return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error);
  758. }
  759. SaAisErrorT
  760. saAmfComponentErrorReport (
  761. SaAmfHandleT amfHandle,
  762. const SaNameT *erroneousComponent,
  763. SaTimeT errorDetectionTime,
  764. SaAmfRecommendedRecoveryT recommendedRecovery,
  765. SaNtfIdentifierT ntfIdentifier)
  766. {
  767. struct amfInstance *amfInstance;
  768. struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport;
  769. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  770. SaAisErrorT error;
  771. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  772. (void *)&amfInstance);
  773. if (error != SA_AIS_OK) {
  774. return (error);
  775. }
  776. req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT;
  777. req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport);
  778. memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent,
  779. sizeof (SaNameT));
  780. req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime;
  781. DPRINT (("start error report\n"));
  782. error = saSendReceiveReply (amfInstance->response_fd,
  783. &req_lib_amf_componenterrorreport,
  784. sizeof (struct req_lib_amf_componenterrorreport),
  785. &res_lib_amf_componenterrorreport,
  786. sizeof (struct res_lib_amf_componenterrorreport));
  787. DPRINT (("end error report\n"));
  788. error = res_lib_amf_componenterrorreport.header.error;
  789. pthread_mutex_unlock (&amfInstance->response_mutex);
  790. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  791. return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error);
  792. }
  793. SaAisErrorT
  794. saAmfComponentErrorClear (
  795. SaAmfHandleT amfHandle,
  796. const SaNameT *compName,
  797. SaNtfIdentifierT ntfIdentifier)
  798. {
  799. struct amfInstance *amfInstance;
  800. struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear;
  801. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  802. SaAisErrorT error;
  803. error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  804. (void *)&amfInstance);
  805. if (error != SA_AIS_OK) {
  806. return (error);
  807. }
  808. req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR;
  809. req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear);
  810. memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT));
  811. error = saSendReceiveReply (amfInstance->response_fd,
  812. &req_lib_amf_componenterrorclear,
  813. sizeof (struct req_lib_amf_componenterrorclear),
  814. &res_lib_amf_componenterrorclear,
  815. sizeof (struct res_lib_amf_componenterrorclear));
  816. pthread_mutex_unlock (&amfInstance->response_mutex);
  817. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  818. return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error);
  819. }
  820. SaAisErrorT
  821. saAmfResponse (
  822. SaAmfHandleT amfHandle,
  823. SaInvocationT invocation,
  824. SaAisErrorT error)
  825. {
  826. struct amfInstance *amfInstance;
  827. struct req_lib_amf_response req_lib_amf_response;
  828. struct res_lib_amf_response res_lib_amf_response;
  829. SaAisErrorT errorResult;
  830. errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
  831. (void *)&amfInstance);
  832. if (errorResult != SA_AIS_OK) {
  833. return (error);
  834. }
  835. req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
  836. req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response);
  837. req_lib_amf_response.invocation = invocation;
  838. req_lib_amf_response.error = error;
  839. pthread_mutex_lock (&amfInstance->response_mutex);
  840. errorResult = saSendReceiveReply (amfInstance->response_fd,
  841. &req_lib_amf_response, sizeof (struct req_lib_amf_response),
  842. &res_lib_amf_response, sizeof (struct res_lib_amf_response));
  843. pthread_mutex_unlock (&amfInstance->response_mutex);
  844. saHandleInstancePut (&amfHandleDatabase, amfHandle);
  845. return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult);
  846. }