testamf3.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (c) 2002-2003 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 <stdlib.h>
  36. #include <errno.h>
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <sys/un.h>
  40. #include "ais_types.h"
  41. #include "ais_amf.h"
  42. void printSaClmNodeAddressT (SaClmNodeAddressT *nodeAddress) {
  43. int i;
  44. for (i = 0; i < nodeAddress->length; i++) {
  45. printf ("%d.", nodeAddress->value[i]);
  46. }
  47. }
  48. void printSaNameT (SaNameT *name)
  49. {
  50. int i;
  51. for (i = 0; i < name->length; i++) {
  52. printf ("%c", name->value[i]);
  53. }
  54. }
  55. void setSanameT (SaNameT *name, char *str) {
  56. name->length = strlen (str);
  57. memcpy (name->value, str, name->length);
  58. }
  59. int healthcheck_count = 0;
  60. void HealthcheckCallback (SaInvocationT invocation,
  61. const SaNameT *compName,
  62. SaAmfHealthcheckT checkType)
  63. {
  64. // if (healthcheck_count++ % 20 == 19) {
  65. printf ("20 HealthcheckCallback have occured for component: ");
  66. printSaNameT ((SaNameT *)compName);
  67. printf ("\n");
  68. // }
  69. saAmfResponse (invocation, SA_OK);
  70. }
  71. void ReadinessStateSetCallback (SaInvocationT invocation,
  72. const SaNameT *compName,
  73. SaAmfReadinessStateT readinessState)
  74. {
  75. switch (readinessState) {
  76. case SA_AMF_IN_SERVICE:
  77. printf ("ReadinessStateSetCallback: '");
  78. printSaNameT ((SaNameT *)compName);
  79. printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n");
  80. saAmfResponse (invocation, SA_OK);
  81. break;
  82. case SA_AMF_OUT_OF_SERVICE:
  83. printf ("ReadinessStateSetCallback: '");
  84. printSaNameT ((SaNameT *)compName);
  85. printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n");
  86. saAmfResponse (invocation, SA_OK);
  87. break;
  88. case SA_AMF_STOPPING:
  89. printf ("ReadinessStateSetCallback: '");
  90. printSaNameT ((SaNameT *)compName);
  91. printf ("' requested to enter operational state SA_AMF_STOPPING.\n");
  92. saAmfStoppingComplete (invocation, SA_OK);
  93. break;
  94. }
  95. }
  96. void ComponentTerminateCallback (
  97. SaInvocationT invocation,
  98. const SaNameT *compName)
  99. {
  100. printf ("ComponentTerminateCallback\n");
  101. }
  102. void CSISetCallback (
  103. SaInvocationT invocation,
  104. const SaNameT *compName,
  105. const SaNameT *csiName,
  106. SaAmfCSIFlagsT csiFlags,
  107. SaAmfHAStateT *haState,
  108. SaNameT *activeCompName,
  109. SaAmfCSITransitionDescriptorT transitionDescriptor)
  110. {
  111. switch (*haState) {
  112. case SA_AMF_ACTIVE:
  113. printf ("CSISetCallback: '");
  114. printSaNameT ((SaNameT *)compName);
  115. printf ("' for CSI '");
  116. printSaNameT ((SaNameT *)compName);
  117. printf ("'");
  118. printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
  119. saAmfResponse (invocation, SA_OK);
  120. break;
  121. case SA_AMF_STANDBY:
  122. printf ("CSISetCallback: '");
  123. printSaNameT ((SaNameT *)compName);
  124. printf ("' for CSI '");
  125. printSaNameT ((SaNameT *)compName);
  126. printf ("'");
  127. printf (" requested to enter hastate SA_AMF_STANDBY.\n");
  128. saAmfResponse (invocation, SA_OK);
  129. break;
  130. case SA_AMF_QUIESCED:
  131. printf ("CSISetCallback: '");
  132. printSaNameT ((SaNameT *)compName);
  133. printf ("' for CSI '");
  134. printSaNameT ((SaNameT *)compName);
  135. printf ("'");
  136. printf (" requested to enter hastate SA_AMF_QUIESCED.\n");
  137. saAmfResponse (invocation, SA_OK);
  138. break;
  139. }
  140. }
  141. void CSIRemoveCallback (
  142. SaInvocationT invocation,
  143. const SaNameT *compName,
  144. const SaNameT *csiName,
  145. const SaAmfCSIFlagsT *csiFlags)
  146. {
  147. printf ("CSIRemoveCallback for component '");
  148. printSaNameT ((SaNameT *)compName);
  149. printf ("' in CSI '");
  150. printSaNameT ((SaNameT *)csiName);
  151. printf ("'\n");
  152. saAmfResponse (invocation, SA_OK);
  153. }
  154. void ProtectionGroupTrackCallback (
  155. const SaNameT *csiName,
  156. SaAmfProtectionGroupNotificationT *notificationBuffer,
  157. SaUint32T numberOfItems,
  158. SaUint32T numberOfMembers,
  159. SaErrorT error)
  160. {
  161. int i;
  162. printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers);
  163. printf ("buffer is %p\n", notificationBuffer);
  164. for (i = 0; i < numberOfItems; i++) {
  165. printf ("component name");
  166. printSaNameT (&notificationBuffer[i].member.compName);
  167. printf ("\n");
  168. printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState);
  169. printf ("\thastate %d\n", notificationBuffer[i].member.haState);
  170. printf ("\tchange is %d\n", notificationBuffer[i].change);
  171. }
  172. }
  173. void ExternalComponentRestartCallback (
  174. const SaInvocationT invocation,
  175. const SaNameT *externalCompName)
  176. {
  177. printf ("ExternalComponentRestartCallback\n");
  178. }
  179. void ExternalComponentControlCallback (
  180. const SaInvocationT invocation,
  181. const SaNameT *externalCompName,
  182. SaAmfExternalComponentActionT controlAction)
  183. {
  184. printf ("ExternalComponentControlCallback\n");
  185. }
  186. void PendingOperationConfirmCallback (
  187. const SaInvocationT invocation,
  188. const SaNameT *compName,
  189. SaAmfPendingOperationFlagsT pendingOperationFlags)
  190. {
  191. printf ("PendingOperationConfirmCallback\n");
  192. }
  193. void PendingOperationExpiredCallback (
  194. const SaNameT *compName,
  195. SaAmfPendingOperationFlagsT pendingOperationFlags)
  196. {
  197. printf ("PendingOperationExpiredCallback\n");
  198. }
  199. SaAmfCallbacksT amfCallbacks = {
  200. HealthcheckCallback,
  201. ReadinessStateSetCallback,
  202. ComponentTerminateCallback,
  203. CSISetCallback,
  204. CSIRemoveCallback,
  205. ProtectionGroupTrackCallback,
  206. ExternalComponentRestartCallback,
  207. ExternalComponentControlCallback,
  208. PendingOperationConfirmCallback,
  209. PendingOperationExpiredCallback
  210. };
  211. SaVersionT version = { 'A', 1, 1 };
  212. int main (void) {
  213. SaAmfHandleT handle;
  214. int result;
  215. int select_fd;
  216. fd_set read_fds;
  217. SaNameT compName;
  218. result = saAmfInitialize (&handle, &amfCallbacks, &version);
  219. if (result != SA_OK) {
  220. printf ("initialize result is %d\n", result);
  221. exit (1);
  222. }
  223. FD_ZERO (&read_fds);
  224. saAmfSelectionObjectGet (&handle, &select_fd);
  225. FD_SET (select_fd, &read_fds);
  226. setSanameT (&compName, "comp_a_in_su_y");
  227. result = saAmfComponentRegister (&handle, &compName, NULL);
  228. printf ("register result is %d (should be 1)\n", result);
  229. do {
  230. select (select_fd + 1, &read_fds, 0, 0, 0);
  231. saAmfDispatch (&handle, SA_DISPATCH_ALL);
  232. } while (result);
  233. saAmfFinalize (&handle);
  234. exit (0);
  235. }