Patch to add new api to logsys to get priority names from subsystem names.
[openais.git] / lib / amf.c
blob35e20c85f077864af571ea7bb5faed952d9a0e46
2 /*
3 * Copyright (c) 2002-2005 MontaVista Software, Inc.
5 * All rights reserved.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
36 #include <stdio.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <errno.h>
41 #include <signal.h>
42 #include <pthread.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <sys/select.h>
46 #include <sys/un.h>
48 #include <saAis.h>
49 #include <saAmf.h>
50 #include <ipc_gen.h>
51 #include <ipc_amf.h>
52 #include <ais_util.h>
55 struct res_overlay {
56 mar_res_header_t header __attribute__((aligned(8)));
57 char data[4096];
61 * Data structure for instance data
63 struct amfInstance {
64 int response_fd;
65 int dispatch_fd;
66 SaAmfCallbacksT callbacks;
67 SaNameT compName;
68 int compRegistered;
69 int finalize;
70 pthread_mutex_t response_mutex;
71 pthread_mutex_t dispatch_mutex;
74 static void amfHandleInstanceDestructor (void *);
77 * All instances in one database
79 static struct saHandleDatabase amfHandleDatabase = {
80 .handleCount = 0,
81 .handles = 0,
82 .mutex = PTHREAD_MUTEX_INITIALIZER,
83 .handleInstanceDestructor = amfHandleInstanceDestructor
87 * Versions supported
89 static SaVersionT amfVersionsSupported[] = {
90 { 'B', 1, 1 }
93 static struct saVersionDatabase amfVersionDatabase = {
94 sizeof (amfVersionsSupported) / sizeof (SaVersionT),
95 amfVersionsSupported
99 * Implementation
102 void amfHandleInstanceDestructor (void *instance)
104 struct amfInstance *amfInstance = instance;
106 pthread_mutex_destroy (&amfInstance->response_mutex);
107 pthread_mutex_destroy (&amfInstance->dispatch_mutex);
110 SaAisErrorT
111 saAmfInitialize (
112 SaAmfHandleT *amfHandle,
113 const SaAmfCallbacksT *amfCallbacks,
114 SaVersionT *version)
116 struct amfInstance *amfInstance;
117 SaAisErrorT error = SA_AIS_OK;
119 error = saVersionVerify (&amfVersionDatabase, (SaVersionT *)version);
120 if (error != SA_AIS_OK) {
121 goto error_no_destroy;
124 error = saHandleCreate (&amfHandleDatabase, sizeof (struct amfInstance), amfHandle);
125 if (error != SA_AIS_OK) {
126 goto error_no_destroy;
129 error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance);
130 if (error != SA_AIS_OK) {
131 goto error_destroy;
134 amfInstance->response_fd = -1;
136 amfInstance->dispatch_fd = -1;
138 error = saServiceConnect (&amfInstance->response_fd,
139 &amfInstance->dispatch_fd, AMF_SERVICE);
140 if (error != SA_AIS_OK) {
141 goto error_put_destroy;
144 memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT));
146 pthread_mutex_init (&amfInstance->response_mutex, NULL);
148 pthread_mutex_init (&amfInstance->dispatch_mutex, NULL);
150 saHandleInstancePut (&amfHandleDatabase, *amfHandle);
152 return (SA_AIS_OK);
154 error_put_destroy:
155 saHandleInstancePut (&amfHandleDatabase, *amfHandle);
156 error_destroy:
157 saHandleDestroy (&amfHandleDatabase, *amfHandle);
158 error_no_destroy:
159 return (error);
162 SaAisErrorT
163 saAmfSelectionObjectGet (
164 SaAmfHandleT amfHandle,
165 SaSelectionObjectT *selectionObject)
167 struct amfInstance *amfInstance;
168 SaAisErrorT error;
170 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
171 if (error != SA_AIS_OK) {
172 return (error);
175 *selectionObject = amfInstance->dispatch_fd;
177 saHandleInstancePut (&amfHandleDatabase, amfHandle);
178 return (SA_AIS_OK);
182 SaAisErrorT
183 saAmfDispatch (
184 SaAmfHandleT amfHandle,
185 SaDispatchFlagsT dispatchFlags)
187 struct pollfd ufds;
188 int timeout = -1;
189 SaAisErrorT error;
190 int cont = 1; /* always continue do loop except when set to 0 */
191 int dispatch_avail;
192 struct amfInstance *amfInstance;
193 struct res_lib_amf_csisetcallback *res_lib_amf_csisetcallback;
195 struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
196 struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
197 struct res_lib_amf_componentterminatecallback *res_lib_amf_componentterminatecallback;
198 SaAmfCallbacksT callbacks;
199 struct res_overlay dispatch_data;
201 if (dispatchFlags != SA_DISPATCH_ONE &&
202 dispatchFlags != SA_DISPATCH_ALL &&
203 dispatchFlags != SA_DISPATCH_BLOCKING) {
205 return (SA_AIS_ERR_INVALID_PARAM);
208 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
209 (void *)&amfInstance);
210 if (error != SA_AIS_OK) {
211 return (error);
215 * Timeout instantly for SA_DISPATCH_ALL
217 if (dispatchFlags == SA_DISPATCH_ALL) {
218 timeout = 0;
221 do {
223 * Read data directly from socket
225 ufds.fd = amfInstance->dispatch_fd;
226 ufds.events = POLLIN;
227 ufds.revents = 0;
229 error = saPollRetry (&ufds, 1, timeout);
230 if (error != SA_AIS_OK) {
231 goto error_put;
234 pthread_mutex_lock (&amfInstance->dispatch_mutex);
237 * Handle has been finalized in another thread
239 if (amfInstance->finalize == 1) {
240 error = SA_AIS_OK;
241 goto error_unlock;
244 if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
245 error = SA_AIS_ERR_BAD_HANDLE;
246 goto error_unlock;
249 dispatch_avail = ufds.revents & POLLIN;
250 if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
251 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
252 break; /* exit do while cont is 1 loop */
253 } else
254 if (dispatch_avail == 0) {
255 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
256 continue; /* next poll */
259 if (ufds.revents & POLLIN) {
261 * Queue empty, read response from socket
263 error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.header,
264 sizeof (mar_res_header_t));
266 if (error != SA_AIS_OK) {
268 goto error_unlock;
270 if (dispatch_data.header.size > sizeof (mar_res_header_t)) {
272 error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.data,
273 dispatch_data.header.size - sizeof (mar_res_header_t));
275 if (error != SA_AIS_OK) {
277 goto error_unlock;
280 } else {
281 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
283 continue;
287 * Make copy of callbacks, message data, unlock instance, and call callback
288 * A risk of this dispatch method is that the callback routines may
289 * operate at the same time that amfFinalize has been called in another thread.
292 memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT));
293 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
296 * Dispatch incoming response
299 switch (dispatch_data.header.id) {
301 case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK:
302 res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data;
304 callbacks.saAmfHealthcheckCallback (
305 res_lib_amf_healthcheckcallback->invocation,
306 &res_lib_amf_healthcheckcallback->compName,
307 &res_lib_amf_healthcheckcallback->key);
308 break;
310 case MESSAGE_RES_AMF_CSISETCALLBACK:
312 SaAmfCSIDescriptorT csi_descriptor;
313 SaAmfCSIAttributeT *csi_attribute_array;
314 char *attr_buf;
315 int i;
317 res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data;
320 csi_descriptor.csiFlags = res_lib_amf_csisetcallback->csiFlags;
321 memcpy(&csi_descriptor.csiName, &res_lib_amf_csisetcallback->csiName,
322 sizeof(SaNameT));
323 csi_descriptor.csiStateDescriptor = res_lib_amf_csisetcallback->csiStateDescriptor;
324 csi_descriptor.csiAttr.number = res_lib_amf_csisetcallback->number;
326 csi_attribute_array = malloc (sizeof (SaAmfCSIAttributeT) *
327 csi_descriptor.csiAttr.number);
329 if (csi_attribute_array == 0) {
330 return SA_AIS_ERR_LIBRARY;
332 csi_descriptor.csiAttr.attr = csi_attribute_array;
334 attr_buf = res_lib_amf_csisetcallback->csi_attr_buf;
336 for (i = 0; i < csi_descriptor.csiAttr.number; i++) {
337 csi_attribute_array[i].attrName = (SaUint8T*)attr_buf;
339 attr_buf += strlen(attr_buf) + 1;
340 csi_attribute_array[i].attrValue = (SaUint8T*)attr_buf;
342 attr_buf += strlen(attr_buf) + 1;
345 callbacks.saAmfCSISetCallback (
346 res_lib_amf_csisetcallback->invocation,
347 &res_lib_amf_csisetcallback->compName,
348 res_lib_amf_csisetcallback->haState,
349 &csi_descriptor);
351 if (csi_attribute_array != NULL) {
352 free(csi_attribute_array);
354 break;
356 case MESSAGE_RES_AMF_CSIREMOVECALLBACK:
357 res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data;
358 callbacks.saAmfCSIRemoveCallback (
359 res_lib_amf_csiremovecallback->invocation,
360 &res_lib_amf_csiremovecallback->compName,
361 &res_lib_amf_csiremovecallback->csiName,
362 res_lib_amf_csiremovecallback->csiFlags);
363 break;
365 case MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK:
366 res_lib_amf_componentterminatecallback = (struct res_lib_amf_componentterminatecallback *)&dispatch_data;
367 callbacks.saAmfComponentTerminateCallback (
368 res_lib_amf_componentterminatecallback->invocation,
369 &res_lib_amf_componentterminatecallback->compName);
370 break;
372 #ifdef COMPILE_OUT
373 case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK:
374 res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data;
375 memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
376 res_lib_amf_protectiongrouptrackcallback->notificationBuffer,
377 res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT));
378 callbacks.saAmfProtectionGroupTrackCallback(
379 &res_lib_amf_protectiongrouptrackcallback->csiName,
380 res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress,
381 res_lib_amf_protectiongrouptrackcallback->numberOfItems,
382 res_lib_amf_protectiongrouptrackcallback->numberOfMembers,
383 res_lib_amf_protectiongrouptrackcallback->error);
384 #endif
385 break;
386 default:
387 error = SA_AIS_ERR_LIBRARY;
388 goto error_put;
389 break;
393 * Determine if more messages should be processed
395 switch (dispatchFlags) {
396 case SA_DISPATCH_ONE:
397 cont = 0;
398 break;
399 case SA_DISPATCH_ALL:
400 break;
401 case SA_DISPATCH_BLOCKING:
402 break;
404 } while (cont);
406 error_unlock:
407 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
408 error_put:
409 saHandleInstancePut (&amfHandleDatabase, amfHandle);
411 return (error);
414 SaAisErrorT
415 saAmfFinalize (
416 SaAmfHandleT amfHandle)
418 struct amfInstance *amfInstance;
419 SaAisErrorT error;
421 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance);
422 if (error != SA_AIS_OK) {
423 return (error);
426 pthread_mutex_lock (&amfInstance->dispatch_mutex);
428 pthread_mutex_lock (&amfInstance->response_mutex);
431 * Another thread has already started finalizing
433 if (amfInstance->finalize) {
434 pthread_mutex_unlock (&amfInstance->response_mutex);
435 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
436 saHandleInstancePut (&amfHandleDatabase, amfHandle);
437 return (SA_AIS_ERR_BAD_HANDLE);
440 amfInstance->finalize = 1;
442 pthread_mutex_unlock (&amfInstance->response_mutex);
444 pthread_mutex_unlock (&amfInstance->dispatch_mutex);
446 saHandleDestroy (&amfHandleDatabase, amfHandle);
448 if (amfInstance->response_fd != -1) {
449 shutdown (amfInstance->response_fd, 0);
450 close (amfInstance->response_fd);
452 if (amfInstance->dispatch_fd != -1) {
453 shutdown (amfInstance->dispatch_fd, 0);
454 close (amfInstance->dispatch_fd);
457 saHandleInstancePut (&amfHandleDatabase, amfHandle);
459 return (error);
462 SaAisErrorT
463 saAmfComponentRegister (
464 SaAmfHandleT amfHandle,
465 const SaNameT *compName,
466 const SaNameT *proxyCompName)
468 struct amfInstance *amfInstance;
469 SaAisErrorT error;
470 struct req_lib_amf_componentregister req_lib_amf_componentregister;
471 struct res_lib_amf_componentregister res_lib_amf_componentregister;
473 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
474 (void *)&amfInstance);
475 if (error != SA_AIS_OK) {
476 return (error);
479 req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister);
480 req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER;
481 memcpy (&req_lib_amf_componentregister.compName, compName,
482 sizeof (SaNameT));
483 if (proxyCompName) {
484 memcpy (&req_lib_amf_componentregister.proxyCompName,
485 proxyCompName, sizeof (SaNameT));
486 } else {
487 memset (&req_lib_amf_componentregister.proxyCompName, 0,
488 sizeof (SaNameT));
491 pthread_mutex_lock (&amfInstance->response_mutex);
493 error = saSendReceiveReply (amfInstance->response_fd,
494 &req_lib_amf_componentregister,
495 sizeof (struct req_lib_amf_componentregister),
496 &res_lib_amf_componentregister,
497 sizeof (struct res_lib_amf_componentregister));
499 pthread_mutex_unlock (&amfInstance->response_mutex);
501 saHandleInstancePut (&amfHandleDatabase, amfHandle);
503 if (res_lib_amf_componentregister.header.error == SA_AIS_OK) {
504 amfInstance->compRegistered = 1;
505 memcpy (&amfInstance->compName, compName, sizeof (SaNameT));
507 return (error == SA_AIS_OK ? res_lib_amf_componentregister.header.error : error);
510 SaAisErrorT
511 saAmfComponentUnregister (
512 SaAmfHandleT amfHandle,
513 const SaNameT *compName,
514 const SaNameT *proxyCompName)
516 struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
517 struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
518 struct amfInstance *amfInstance;
519 SaAisErrorT error;
521 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
522 (void *)&amfInstance);
523 if (error != SA_AIS_OK) {
524 return (error);
527 req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister);
528 req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER;
529 memcpy (&req_lib_amf_componentunregister.compName, compName,
530 sizeof (SaNameT));
531 if (proxyCompName) {
532 memcpy (&req_lib_amf_componentunregister.proxyCompName,
533 proxyCompName, sizeof (SaNameT));
534 } else {
535 memset (&req_lib_amf_componentunregister.proxyCompName, 0,
536 sizeof (SaNameT));
539 pthread_mutex_lock (&amfInstance->response_mutex);
541 error = saSendReceiveReply (amfInstance->response_fd,
542 &req_lib_amf_componentunregister,
543 sizeof (struct req_lib_amf_componentunregister),
544 &res_lib_amf_componentunregister,
545 sizeof (struct res_lib_amf_componentunregister));
547 pthread_mutex_unlock (&amfInstance->response_mutex);
549 saHandleInstancePut (&amfHandleDatabase, amfHandle);
551 return (error == SA_AIS_OK ? res_lib_amf_componentunregister.header.error : error);
554 SaAisErrorT
555 saAmfComponentNameGet (
556 SaAmfHandleT amfHandle,
557 SaNameT *compName)
559 struct amfInstance *amfInstance;
560 SaAisErrorT error;
561 char *env_value;
563 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
564 (void *)&amfInstance);
565 if (error != SA_AIS_OK) {
566 return (error);
569 pthread_mutex_lock (&amfInstance->response_mutex);
571 error = SA_AIS_OK;
573 env_value = getenv ("SA_AMF_COMPONENT_NAME");
574 if (env_value == 0) {
575 error = SA_AIS_ERR_NOT_EXIST;
576 goto error_exit;
579 strncpy ((char *)compName->value, env_value, SA_MAX_NAME_LENGTH-1);
580 compName->value[SA_MAX_NAME_LENGTH-1] = '\0';
581 compName->length = strlen (env_value);
583 error_exit:
584 pthread_mutex_unlock (&amfInstance->response_mutex);
586 saHandleInstancePut (&amfHandleDatabase, amfHandle);
588 return (error);
591 SaAisErrorT
592 saAmfPmStart (
593 SaAmfHandleT amfHandle,
594 const SaNameT *compName,
595 SaUint64T processId,
596 SaInt32T descendentsTreeDepth,
597 SaAmfPmErrorsT pmErrors,
598 SaAmfRecommendedRecoveryT recommendedRecovery)
600 struct req_lib_amf_pmstart req_lib_amf_pmstart;
601 struct res_lib_amf_pmstart res_lib_amf_pmstart;
602 struct amfInstance *amfInstance;
603 SaAisErrorT error;
605 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
606 (void *)&amfInstance);
607 if (error != SA_AIS_OK) {
608 return (error);
611 req_lib_amf_pmstart.header.size = sizeof (struct req_lib_amf_pmstart);
612 req_lib_amf_pmstart.header.id = MESSAGE_REQ_AMF_PMSTART;
613 memcpy (&req_lib_amf_pmstart.compName, compName,
614 sizeof (SaNameT));
615 req_lib_amf_pmstart.processId = processId;
616 req_lib_amf_pmstart.descendentsTreeDepth = descendentsTreeDepth;
617 req_lib_amf_pmstart.pmErrors = pmErrors;
618 req_lib_amf_pmstart.recommendedRecovery = recommendedRecovery;
620 pthread_mutex_lock (&amfInstance->response_mutex);
622 error = saSendReceiveReply (amfInstance->response_fd,
623 &req_lib_amf_pmstart,
624 sizeof (struct req_lib_amf_pmstart),
625 &res_lib_amf_pmstart,
626 sizeof (struct res_lib_amf_pmstart));
628 pthread_mutex_unlock (&amfInstance->response_mutex);
630 saHandleInstancePut (&amfHandleDatabase, amfHandle);
632 return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error);
635 SaAisErrorT
636 saAmfPmStop (
637 SaAmfHandleT amfHandle,
638 const SaNameT *compName,
639 SaAmfPmStopQualifierT stopQualifier,
640 SaInt64T processId,
641 SaAmfPmErrorsT pmErrors)
643 struct req_lib_amf_pmstop req_lib_amf_pmstop;
644 struct res_lib_amf_pmstop res_lib_amf_pmstop;
645 struct amfInstance *amfInstance;
646 SaAisErrorT error;
648 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
649 (void *)&amfInstance);
650 if (error != SA_AIS_OK) {
651 return (error);
654 req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop);
655 req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP;
656 memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT));
657 req_lib_amf_pmstop.stopQualifier = stopQualifier;
658 req_lib_amf_pmstop.processId = processId;
659 req_lib_amf_pmstop.pmErrors = pmErrors;
661 pthread_mutex_lock (&amfInstance->response_mutex);
663 error = saSendReceiveReply (amfInstance->response_fd,
664 &req_lib_amf_pmstop,
665 sizeof (struct req_lib_amf_pmstop),
666 &res_lib_amf_pmstop,
667 sizeof (struct res_lib_amf_pmstop));
669 pthread_mutex_unlock (&amfInstance->response_mutex);
671 saHandleInstancePut (&amfHandleDatabase, amfHandle);
673 return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error);
674 return (SA_AIS_OK);
677 SaAisErrorT
678 saAmfHealthcheckStart (
679 SaAmfHandleT amfHandle,
680 const SaNameT *compName,
681 const SaAmfHealthcheckKeyT *healthcheckKey,
682 SaAmfHealthcheckInvocationT invocationType,
683 SaAmfRecommendedRecoveryT recommendedRecovery)
685 struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart;
686 struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
687 struct amfInstance *amfInstance;
688 SaAisErrorT error;
690 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
691 (void *)&amfInstance);
692 if (error != SA_AIS_OK) {
693 return (error);
696 req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart);
697 req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART;
698 memcpy (&req_lib_amf_healthcheckstart.compName, compName,
699 sizeof (SaNameT));
700 memcpy (&req_lib_amf_healthcheckstart.healthcheckKey,
701 healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
702 req_lib_amf_healthcheckstart.invocationType = invocationType;
703 req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery;
705 pthread_mutex_lock (&amfInstance->response_mutex);
707 error = saSendReceiveReply (amfInstance->response_fd,
708 &req_lib_amf_healthcheckstart,
709 sizeof (struct req_lib_amf_healthcheckstart),
710 &res_lib_amf_healthcheckstart,
711 sizeof (struct res_lib_amf_healthcheckstart));
713 pthread_mutex_unlock (&amfInstance->response_mutex);
715 saHandleInstancePut (&amfHandleDatabase, amfHandle);
717 return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error);
720 SaAisErrorT
721 saAmfHealthcheckConfirm (
722 SaAmfHandleT amfHandle,
723 const SaNameT *compName,
724 const SaAmfHealthcheckKeyT *healthcheckKey,
725 SaAisErrorT healthcheckResult)
727 struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm;
728 struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm;
729 struct amfInstance *amfInstance;
730 SaAisErrorT error;
732 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
733 (void *)&amfInstance);
734 if (error != SA_AIS_OK) {
735 return (error);
738 req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_healthcheckconfirm);
739 req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM;
740 memcpy (&req_lib_amf_healthcheckconfirm.compName, compName,
741 sizeof (SaNameT));
742 memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey,
743 healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
744 req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult;
746 pthread_mutex_lock (&amfInstance->response_mutex);
748 error = saSendReceiveReply (amfInstance->response_fd,
749 &req_lib_amf_healthcheckconfirm,
750 sizeof (struct req_lib_amf_healthcheckconfirm),
751 &res_lib_amf_healthcheckconfirm,
752 sizeof (struct res_lib_amf_healthcheckconfirm));
754 pthread_mutex_unlock (&amfInstance->response_mutex);
756 saHandleInstancePut (&amfHandleDatabase, amfHandle);
758 return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error);
761 SaAisErrorT
762 saAmfHealthcheckStop (
763 SaAmfHandleT amfHandle,
764 const SaNameT *compName,
765 const SaAmfHealthcheckKeyT *healthcheckKey)
767 struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop;
768 struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
769 struct amfInstance *amfInstance;
770 SaAisErrorT error;
772 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
773 (void *)&amfInstance);
774 if (error != SA_AIS_OK) {
775 return (error);
778 req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop);
779 req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP;
780 memcpy (&req_lib_amf_healthcheckstop.compName, compName,
781 sizeof (SaNameT));
782 memcpy (&req_lib_amf_healthcheckstop.healthcheckKey,
783 healthcheckKey, sizeof (SaAmfHealthcheckKeyT));
785 pthread_mutex_lock (&amfInstance->response_mutex);
787 error = saSendReceiveReply (amfInstance->response_fd,
788 &req_lib_amf_healthcheckstop,
789 sizeof (struct req_lib_amf_healthcheckstop),
790 &res_lib_amf_healthcheckstop,
791 sizeof (struct res_lib_amf_healthcheckstop));
793 pthread_mutex_unlock (&amfInstance->response_mutex);
795 saHandleInstancePut (&amfHandleDatabase, amfHandle);
797 return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error);
801 SaAisErrorT
802 saAmfHAStateGet (
803 SaAmfHandleT amfHandle,
804 const SaNameT *compName,
805 const SaNameT *csiName,
806 SaAmfHAStateT *haState)
808 struct amfInstance *amfInstance;
809 struct req_lib_amf_hastateget req_lib_amf_hastateget;
810 struct res_lib_amf_hastateget res_lib_amf_hastateget;
811 SaAisErrorT error;
813 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
814 (void *)&amfInstance);
815 if (error != SA_AIS_OK) {
816 return (error);
819 pthread_mutex_lock (&amfInstance->response_mutex);
821 req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET;
822 req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget);
823 memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT));
824 memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT));
826 error = saSendReceiveReply (amfInstance->response_fd,
827 &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget),
828 &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
830 pthread_mutex_unlock (&amfInstance->response_mutex);
832 saHandleInstancePut (&amfHandleDatabase, amfHandle);
834 if (res_lib_amf_hastateget.header.error == SA_AIS_OK) {
835 memcpy (haState, &res_lib_amf_hastateget.haState,
836 sizeof (SaAmfHAStateT));
838 return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error);
841 SaAisErrorT
842 saAmfCSIQuiescingComplete (
843 SaAmfHandleT amfHandle,
844 SaInvocationT invocation,
845 SaAisErrorT error)
847 struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete;
848 struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete;
849 struct amfInstance *amfInstance;
850 SaAisErrorT errorResult;
852 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
853 (void *)&amfInstance);
854 if (error != SA_AIS_OK) {
855 return (error);
858 req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_csiquiescingcomplete);
859 req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE;
860 req_lib_amf_csiquiescingcomplete.invocation = invocation;
861 req_lib_amf_csiquiescingcomplete.error = error;
863 pthread_mutex_lock (&amfInstance->response_mutex);
865 errorResult = saSendReceiveReply (amfInstance->response_fd,
866 &req_lib_amf_csiquiescingcomplete,
867 sizeof (struct req_lib_amf_csiquiescingcomplete),
868 &res_lib_amf_csiquiescingcomplete,
869 sizeof (struct res_lib_amf_csiquiescingcomplete));
871 pthread_mutex_unlock (&amfInstance->response_mutex);
873 saHandleInstancePut (&amfHandleDatabase, amfHandle);
875 return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult);
878 SaAisErrorT
879 saAmfProtectionGroupTrack (
880 SaAmfHandleT amfHandle,
881 const SaNameT *csiName,
882 SaUint8T trackFlags,
883 SaAmfProtectionGroupNotificationBufferT *notificationBuffer)
885 struct amfInstance *amfInstance;
886 struct req_lib_amf_protectiongrouptrack req_lib_amf_protectiongrouptrack;
887 struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
888 SaAisErrorT error;
890 req_lib_amf_protectiongrouptrack.header.size = sizeof (struct req_lib_amf_protectiongrouptrack);
891 req_lib_amf_protectiongrouptrack.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK;
892 memcpy (&req_lib_amf_protectiongrouptrack.csiName, csiName,
893 sizeof (SaNameT));
894 req_lib_amf_protectiongrouptrack.trackFlags = trackFlags;
895 req_lib_amf_protectiongrouptrack.notificationBufferAddress = (SaAmfProtectionGroupNotificationBufferT *)notificationBuffer;
897 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
898 (void *)&amfInstance);
899 if (error != SA_AIS_OK) {
900 return (error);
903 pthread_mutex_lock (&amfInstance->response_mutex);
905 error = saSendReceiveReply (amfInstance->response_fd,
906 &req_lib_amf_protectiongrouptrack,
907 sizeof (struct req_lib_amf_protectiongrouptrack),
908 &res_lib_amf_protectiongrouptrack,
909 sizeof (struct res_lib_amf_protectiongrouptrack));
911 pthread_mutex_unlock (&amfInstance->response_mutex);
913 saHandleInstancePut (&amfHandleDatabase, amfHandle);
915 return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrack.header.error : error);
918 SaAisErrorT
919 saAmfProtectionGroupTrackStop (
920 SaAmfHandleT amfHandle,
921 const SaNameT *csiName)
923 struct amfInstance *amfInstance;
924 struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop;
925 struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
926 SaAisErrorT error;
928 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
929 (void *)&amfInstance);
930 if (error != SA_AIS_OK) {
931 return (error);
934 req_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop);
935 req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP;
936 memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT));
938 pthread_mutex_lock (&amfInstance->response_mutex);
940 error = saSendReceiveReply (amfInstance->response_fd,
941 &req_lib_amf_protectiongrouptrackstop,
942 sizeof (struct req_lib_amf_protectiongrouptrackstop),
943 &res_lib_amf_protectiongrouptrackstop,
944 sizeof (struct res_lib_amf_protectiongrouptrackstop));
946 pthread_mutex_unlock (&amfInstance->response_mutex);
948 saHandleInstancePut (&amfHandleDatabase, amfHandle);
950 return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error);
953 SaAisErrorT
954 saAmfComponentErrorReport (
955 SaAmfHandleT amfHandle,
956 const SaNameT *erroneousComponent,
957 SaTimeT errorDetectionTime,
958 SaAmfRecommendedRecoveryT recommendedRecovery,
959 SaNtfIdentifierT ntfIdentifier)
961 struct amfInstance *amfInstance;
962 struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport;
963 struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
964 SaAisErrorT error;
966 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
967 (void *)&amfInstance);
968 if (error != SA_AIS_OK) {
969 return (error);
972 req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT;
973 req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport);
974 memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent,
975 sizeof (SaNameT));
976 req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime;
977 req_lib_amf_componenterrorreport.recommendedRecovery = recommendedRecovery;
978 DPRINT (("start error report\n"));
979 error = saSendReceiveReply (amfInstance->response_fd,
980 &req_lib_amf_componenterrorreport,
981 sizeof (struct req_lib_amf_componenterrorreport),
982 &res_lib_amf_componenterrorreport,
983 sizeof (struct res_lib_amf_componenterrorreport));
984 DPRINT (("end error report\n"));
986 error = res_lib_amf_componenterrorreport.header.error;
988 pthread_mutex_unlock (&amfInstance->response_mutex);
990 saHandleInstancePut (&amfHandleDatabase, amfHandle);
992 return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error);
995 SaAisErrorT
996 saAmfComponentErrorClear (
997 SaAmfHandleT amfHandle,
998 const SaNameT *compName,
999 SaNtfIdentifierT ntfIdentifier)
1001 struct amfInstance *amfInstance;
1002 struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear;
1003 struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
1004 SaAisErrorT error;
1006 error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
1007 (void *)&amfInstance);
1008 if (error != SA_AIS_OK) {
1009 return (error);
1012 req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR;
1013 req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear);
1014 memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT));
1016 error = saSendReceiveReply (amfInstance->response_fd,
1017 &req_lib_amf_componenterrorclear,
1018 sizeof (struct req_lib_amf_componenterrorclear),
1019 &res_lib_amf_componenterrorclear,
1020 sizeof (struct res_lib_amf_componenterrorclear));
1022 pthread_mutex_unlock (&amfInstance->response_mutex);
1024 saHandleInstancePut (&amfHandleDatabase, amfHandle);
1026 return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error);
1029 SaAisErrorT
1030 saAmfResponse (
1031 SaAmfHandleT amfHandle,
1032 SaInvocationT invocation,
1033 SaAisErrorT error)
1035 struct amfInstance *amfInstance;
1036 struct req_lib_amf_response req_lib_amf_response;
1037 struct res_lib_amf_response res_lib_amf_response;
1038 SaAisErrorT errorResult;
1040 errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
1041 (void *)&amfInstance);
1042 if (errorResult != SA_AIS_OK) {
1043 return (errorResult);
1046 req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE;
1047 req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response);
1048 req_lib_amf_response.invocation = invocation;
1049 req_lib_amf_response.error = error;
1051 pthread_mutex_lock (&amfInstance->response_mutex);
1053 errorResult = saSendReceiveReply (amfInstance->response_fd,
1054 &req_lib_amf_response, sizeof (struct req_lib_amf_response),
1055 &res_lib_amf_response, sizeof (struct res_lib_amf_response));
1057 pthread_mutex_unlock (&amfInstance->response_mutex);
1059 saHandleInstancePut (&amfHandleDatabase, amfHandle);
1061 return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult);