2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
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.
41 #include <sys/types.h>
42 #include <sys/socket.h>
46 #include "ais_types.h"
49 void printSaNameT (SaNameT
*name
)
53 for (i
= 0; i
< name
->length
; i
++) {
54 printf ("%c", name
->value
[i
]);
58 void setSanameT (SaNameT
*name
, char *str
) {
59 name
->length
= strlen (str
);
60 memcpy (name
->value
, str
, name
->length
);
63 static int health_flag
= -1;
64 static unsigned int healthcheck_count
= 0;
65 static unsigned int healthcheck_no
= 0;
68 void HealthcheckCallback (SaInvocationT invocation
,
69 const SaNameT
*compName
,
70 SaAmfHealthcheckT checkType
)
75 if (health_flag
== -1 || healthcheck_no
%healthcheck_count
== 0) {
76 printf ("%u HealthcheckCallback have occured for component: ",healthcheck_no
);
77 printSaNameT ((SaNameT
*)compName
);
80 res
= saAmfResponse (invocation
, SA_OK
);
82 printf ("response res is %d\n", res
);
86 void ReadinessStateSetCallback (SaInvocationT invocation
,
87 const SaNameT
*compName
,
88 SaAmfReadinessStateT readinessState
)
90 switch (readinessState
) {
91 case SA_AMF_IN_SERVICE
:
92 printf ("ReadinessStateSetCallback: '");
93 printSaNameT ((SaNameT
*)compName
);
94 printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n");
95 saAmfResponse (invocation
, SA_OK
);
97 case SA_AMF_OUT_OF_SERVICE
:
98 printf ("ReadinessStateSetCallback: '");
99 printSaNameT ((SaNameT
*)compName
);
100 printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n");
101 saAmfResponse (invocation
, SA_OK
);
103 case SA_AMF_STOPPING
:
104 printf ("ReadinessStateSetCallback: '");
105 printSaNameT ((SaNameT
*)compName
);
106 printf ("' requested to enter operational state SA_AMF_STOPPING.\n");
107 saAmfStoppingComplete (invocation
, SA_OK
);
112 void ComponentTerminateCallback (
113 SaInvocationT invocation
,
114 const SaNameT
*compName
)
116 printf ("ComponentTerminateCallback\n");
120 void CSISetCallback (
121 SaInvocationT invocation
,
122 const SaNameT
*compName
,
123 SaAmfHAStateT haState
,
124 SaAmfCSIDescriptorT
*csiDescriptor
)
127 case SA_AMF_HA_ACTIVE
:
128 printf ("CSISetCallback: '");
129 printSaNameT ((SaNameT
*)&csiDescriptor
->csiName
);
130 printf ("' for CSI '");
131 printSaNameT ((SaNameT
*)compName
);
133 printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
134 // saAmfResponse (invocation, SA_OK);
137 case SA_AMF_HA_STANDBY
:
138 printf ("CSISetCallback: '");
139 printSaNameT ((SaNameT
*)compName
);
140 printf ("' for CSI '");
141 printSaNameT ((SaNameT
*)compName
);
143 printf (" requested to enter hastate SA_AMF_STANDBY.\n");
144 // saAmfResponse (invocation, SA_OK);
150 void CSIRemoveCallback (
151 SaInvocationT invocation
,
152 const SaNameT
*compName
,
153 const SaNameT
*csiName
,
154 const SaAmfCSIFlagsT
*csiFlags
)
156 printf ("CSIRemoveCallback for component '");
157 printSaNameT ((SaNameT
*)compName
);
158 printf ("' in CSI '");
159 printSaNameT ((SaNameT
*)csiName
);
161 saAmfResponse (invocation
, SA_OK
);
164 void ProtectionGroupTrackCallback (
165 const SaNameT
*csiName
,
166 SaAmfProtectionGroupNotificationT
*notificationBuffer
,
167 SaUint32T numberOfItems
,
168 SaUint32T numberOfMembers
,
173 printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems
, (int)numberOfMembers
);
174 printf ("buffer is %p\n", notificationBuffer
);
175 for (i
= 0; i
< numberOfItems
; i
++) {
176 printf ("component name");
177 printSaNameT (¬ificationBuffer
[i
].member
.compName
);
179 printf ("\treadiness state is %d\n", notificationBuffer
[i
].member
.readinessState
);
180 printf ("\thastate %d\n", notificationBuffer
[i
].member
.haState
);
181 printf ("\tchange is %d\n", notificationBuffer
[i
].change
);
186 void ExternalComponentRestartCallback (
187 const SaInvocationT invocation
,
188 const SaNameT
*externalCompName
)
190 printf ("ExternalComponentRestartCallback\n");
193 void ExternalComponentControlCallback (
194 const SaInvocationT invocation
,
195 const SaNameT
*externalCompName
,
196 SaAmfExternalComponentActionT controlAction
)
198 printf ("ExternalComponentControlCallback\n");
201 void PendingOperationConfirmCallback (
202 const SaInvocationT invocation
,
203 const SaNameT
*compName
,
204 SaAmfPendingOperationFlagsT pendingOperationFlags
)
206 printf ("PendingOperationConfirmCallback\n");
209 void PendingOperationExpiredCallback (
210 const SaNameT
*compName
,
211 SaAmfPendingOperationFlagsT pendingOperationFlags
)
213 printf ("PendingOperationExpiredCallback\n");
217 SaAmfCallbacksT amfCallbacks
= {
218 .saAmfCSISetCallback
= CSISetCallback
,
221 SaAmfCallbacksT amfCallbacks
;
223 SaVersionT version
= { 'B', 1, 1 };
225 static struct sched_param sched_param
= {
229 void sigintr_handler (int signum
) {
234 int main (int argc
, char **argv
) {
237 SaSelectionObjectT select_fd
;
244 memset (&compName
, 0, sizeof (SaNameT
));
245 signal (SIGINT
, sigintr_handler
);
246 result
= sched_setscheduler (0, SCHED_RR
, &sched_param
);
248 printf ("couldn't set sched priority\n");
252 c
= getopt(argc
,argv
,"h:n:");
261 sscanf (optarg
,"%ud" ,&healthcheck_count
);
264 setSanameT (&compName
, optarg
);
271 result
= saAmfInitialize (&handle
, &amfCallbacks
, &version
);
272 if (result
!= SA_OK
) {
273 printf ("initialize result is %d\n", result
);
278 saAmfSelectionObjectGet (handle
, &select_fd
);
279 FD_SET (select_fd
, &read_fds
);
280 if (compName
.length
<= 0) {
281 setSanameT (&compName
, "comp_b_in_su_3");
284 result
= saAmfComponentRegister (handle
, &compName
, NULL
);
285 printf ("register result is %d (should be 1)\n", result
);
288 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
289 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
292 saAmfFinalize (handle
);