2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
6 * Author: Steven Dake (sdake@mvista.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
40 #include <sys/types.h>
41 #include <sys/socket.h>
45 #include "ais_types.h"
48 void printSaNameT (SaNameT
*name
)
52 for (i
= 0; i
< name
->length
; i
++) {
53 printf ("%c", name
->value
[i
]);
57 void setSanameT (SaNameT
*name
, char *str
) {
58 name
->length
= strlen (str
);
59 memcpy (name
->value
, str
, name
->length
);
62 static int health_flag
= -1;
63 static unsigned int healthcheck_count
= 0;
64 static unsigned int healthcheck_no
= 0;
67 void HealthcheckCallback (SaInvocationT invocation
,
68 const SaNameT
*compName
,
69 SaAmfHealthcheckT checkType
)
74 if (health_flag
== -1 || healthcheck_no
%healthcheck_count
== 0) {
75 printf ("%u HealthcheckCallback have occured for component: ",healthcheck_no
);
76 printSaNameT ((SaNameT
*)compName
);
79 res
= saAmfResponse (invocation
, SA_OK
);
81 printf ("response res is %d\n", res
);
85 void ReadinessStateSetCallback (SaInvocationT invocation
,
86 const SaNameT
*compName
,
87 SaAmfReadinessStateT readinessState
)
89 switch (readinessState
) {
90 case SA_AMF_IN_SERVICE
:
91 printf ("ReadinessStateSetCallback: '");
92 printSaNameT ((SaNameT
*)compName
);
93 printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n");
94 saAmfResponse (invocation
, SA_OK
);
96 case SA_AMF_OUT_OF_SERVICE
:
97 printf ("ReadinessStateSetCallback: '");
98 printSaNameT ((SaNameT
*)compName
);
99 printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n");
100 saAmfResponse (invocation
, SA_OK
);
102 case SA_AMF_STOPPING
:
103 printf ("ReadinessStateSetCallback: '");
104 printSaNameT ((SaNameT
*)compName
);
105 printf ("' requested to enter operational state SA_AMF_STOPPING.\n");
106 saAmfStoppingComplete (invocation
, SA_OK
);
111 void ComponentTerminateCallback (
112 SaInvocationT invocation
,
113 const SaNameT
*compName
)
115 printf ("ComponentTerminateCallback\n");
119 void CSISetCallback (
120 SaInvocationT invocation
,
121 const SaNameT
*compName
,
122 SaAmfHAStateT haState
,
123 SaAmfCSIDescriptorT
*csiDescriptor
)
126 case SA_AMF_HA_ACTIVE
:
127 printf ("CSISetCallback: '");
128 printSaNameT ((SaNameT
*)&csiDescriptor
->csiName
);
129 printf ("' for CSI '");
130 printSaNameT ((SaNameT
*)compName
);
132 printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
133 // saAmfResponse (invocation, SA_OK);
136 case SA_AMF_HA_STANDBY
:
137 printf ("CSISetCallback: '");
138 printSaNameT ((SaNameT
*)compName
);
139 printf ("' for CSI '");
140 printSaNameT ((SaNameT
*)compName
);
142 printf (" requested to enter hastate SA_AMF_STANDBY.\n");
143 // saAmfResponse (invocation, SA_OK);
149 void CSIRemoveCallback (
150 SaInvocationT invocation
,
151 const SaNameT
*compName
,
152 const SaNameT
*csiName
,
153 const SaAmfCSIFlagsT
*csiFlags
)
155 printf ("CSIRemoveCallback for component '");
156 printSaNameT ((SaNameT
*)compName
);
157 printf ("' in CSI '");
158 printSaNameT ((SaNameT
*)csiName
);
160 saAmfResponse (invocation
, SA_OK
);
163 void ProtectionGroupTrackCallback (
164 const SaNameT
*csiName
,
165 SaAmfProtectionGroupNotificationT
*notificationBuffer
,
166 SaUint32T numberOfItems
,
167 SaUint32T numberOfMembers
,
172 printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems
, (int)numberOfMembers
);
173 printf ("buffer is %p\n", notificationBuffer
);
174 for (i
= 0; i
< numberOfItems
; i
++) {
175 printf ("component name");
176 printSaNameT (¬ificationBuffer
[i
].member
.compName
);
178 printf ("\treadiness state is %d\n", notificationBuffer
[i
].member
.readinessState
);
179 printf ("\thastate %d\n", notificationBuffer
[i
].member
.haState
);
180 printf ("\tchange is %d\n", notificationBuffer
[i
].change
);
185 void ExternalComponentRestartCallback (
186 const SaInvocationT invocation
,
187 const SaNameT
*externalCompName
)
189 printf ("ExternalComponentRestartCallback\n");
192 void ExternalComponentControlCallback (
193 const SaInvocationT invocation
,
194 const SaNameT
*externalCompName
,
195 SaAmfExternalComponentActionT controlAction
)
197 printf ("ExternalComponentControlCallback\n");
200 void PendingOperationConfirmCallback (
201 const SaInvocationT invocation
,
202 const SaNameT
*compName
,
203 SaAmfPendingOperationFlagsT pendingOperationFlags
)
205 printf ("PendingOperationConfirmCallback\n");
208 void PendingOperationExpiredCallback (
209 const SaNameT
*compName
,
210 SaAmfPendingOperationFlagsT pendingOperationFlags
)
212 printf ("PendingOperationExpiredCallback\n");
216 SaAmfCallbacksT amfCallbacks
= {
217 .saAmfCSISetCallback
= CSISetCallback
,
220 SaAmfCallbacksT amfCallbacks
;
222 SaVersionT version
= { 'B', 1, 1 };
224 static struct sched_param sched_param
= {
228 void sigintr_handler (int signum
) {
233 int main (int argc
, char **argv
) {
236 SaSelectionObjectT select_fd
;
243 memset (&compName
, 0, sizeof (SaNameT
));
244 signal (SIGINT
, sigintr_handler
);
245 result
= sched_setscheduler (0, SCHED_RR
, &sched_param
);
247 printf ("couldn't set sched priority\n");
251 c
= getopt(argc
,argv
,"h:n:");
260 sscanf (optarg
,"%ud" ,&healthcheck_count
);
263 setSanameT (&compName
, optarg
);
270 result
= saAmfInitialize (&handle
, &amfCallbacks
, &version
);
271 if (result
!= SA_OK
) {
272 printf ("initialize result is %d\n", result
);
277 saAmfSelectionObjectGet (handle
, &select_fd
);
278 FD_SET (select_fd
, &read_fds
);
279 if (compName
.length
<= 0) {
280 setSanameT (&compName
, "comp_a_in_su_3");
283 result
= saAmfComponentRegister (handle
, &compName
, NULL
);
284 printf ("register result is %d (should be 1)\n", result
);
287 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
288 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
291 saAmfFinalize (handle
);