testamf4.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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"); saAmfStoppingComplete (invocation, SA_OK);
  92. break;
  93. }
  94. }
  95. void ComponentTerminateCallback (
  96. SaInvocationT invocation,
  97. const SaNameT *compName)
  98. {
  99. printf ("ComponentTerminateCallback\n");
  100. }
  101. void CSISetCallback (
  102. SaInvocationT invocation,
  103. const SaNameT *compName,
  104. const SaNameT *csiName,
  105. SaAmfCSIFlagsT csiFlags,
  106. SaAmfHAStateT *haState,
  107. SaNameT *activeCompName,
  108. SaAmfCSITransitionDescriptorT transitionDescriptor)
  109. {
  110. switch (*haState) {
  111. case SA_AMF_ACTIVE:
  112. printf ("CSISetCallback: '");
  113. printSaNameT ((SaNameT *)compName);
  114. printf ("' for CSI '");
  115. printSaNameT ((SaNameT *)compName);
  116. printf ("'");
  117. printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
  118. saAmfResponse (invocation, SA_OK);
  119. break;
  120. case SA_AMF_STANDBY:
  121. printf ("CSISetCallback: '");
  122. printSaNameT ((SaNameT *)compName);
  123. printf ("' for CSI '");
  124. printSaNameT ((SaNameT *)compName);
  125. printf ("'");
  126. printf (" requested to enter hastate SA_AMF_STANDBY.\n");
  127. saAmfResponse (invocation, SA_OK);
  128. break;
  129. case SA_AMF_QUIESCED:
  130. printf ("CSISetCallback: '");
  131. printSaNameT ((SaNameT *)compName);
  132. printf ("' for CSI '");
  133. printSaNameT ((SaNameT *)compName);
  134. printf ("'");
  135. printf (" requested to enter hastate SA_AMF_QUIESCED.\n");
  136. saAmfResponse (invocation, SA_OK);
  137. break;
  138. }
  139. }
  140. void CSIRemoveCallback (
  141. SaInvocationT invocation,
  142. const SaNameT *compName,
  143. const SaNameT *csiName,
  144. const SaAmfCSIFlagsT *csiFlags)
  145. {
  146. printf ("CSIRemoveCallback for component '");
  147. printSaNameT ((SaNameT *)compName);
  148. printf ("' in CSI '");
  149. printSaNameT ((SaNameT *)csiName);
  150. printf ("'\n");
  151. saAmfResponse (invocation, SA_OK);
  152. }
  153. void ProtectionGroupTrackCallback (
  154. const SaNameT *csiName,
  155. SaAmfProtectionGroupNotificationT *notificationBuffer,
  156. SaUint32T numberOfItems,
  157. SaUint32T numberOfMembers,
  158. SaErrorT error)
  159. {
  160. int i;
  161. printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers);
  162. printf ("buffer is %p\n", notificationBuffer);
  163. for (i = 0; i < numberOfItems; i++) {
  164. printf ("component name");
  165. printSaNameT (&notificationBuffer[i].member.compName);
  166. printf ("\n");
  167. printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState);
  168. printf ("\thastate %d\n", notificationBuffer[i].member.haState);
  169. printf ("\tchange is %d\n", notificationBuffer[i].change);
  170. }
  171. }
  172. void ExternalComponentRestartCallback (
  173. const SaInvocationT invocation,
  174. const SaNameT *externalCompName)
  175. {
  176. printf ("ExternalComponentRestartCallback\n");
  177. }
  178. void ExternalComponentControlCallback (
  179. const SaInvocationT invocation,
  180. const SaNameT *externalCompName,
  181. SaAmfExternalComponentActionT controlAction)
  182. {
  183. printf ("ExternalComponentControlCallback\n");
  184. }
  185. void PendingOperationConfirmCallback (
  186. const SaInvocationT invocation,
  187. const SaNameT *compName,
  188. SaAmfPendingOperationFlagsT pendingOperationFlags)
  189. {
  190. printf ("PendingOperationConfirmCallback\n");
  191. }
  192. void PendingOperationExpiredCallback (
  193. const SaNameT *compName,
  194. SaAmfPendingOperationFlagsT pendingOperationFlags)
  195. {
  196. printf ("PendingOperationExpiredCallback\n");
  197. }
  198. SaAmfCallbacksT amfCallbacks = {
  199. HealthcheckCallback,
  200. ReadinessStateSetCallback,
  201. ComponentTerminateCallback,
  202. CSISetCallback,
  203. CSIRemoveCallback,
  204. ProtectionGroupTrackCallback,
  205. ExternalComponentRestartCallback,
  206. ExternalComponentControlCallback,
  207. PendingOperationConfirmCallback,
  208. PendingOperationExpiredCallback
  209. };
  210. SaVersionT version = { 'A', 1, 1 };
  211. int main (void) {
  212. SaAmfHandleT handle;
  213. int result;
  214. int select_fd;
  215. fd_set read_fds;
  216. SaNameT compName;
  217. result = saAmfInitialize (&handle, &amfCallbacks, &version);
  218. if (result != SA_OK) {
  219. printf ("initialize result is %d\n", result);
  220. exit (1);
  221. }
  222. FD_ZERO (&read_fds);
  223. saAmfSelectionObjectGet (&handle, &select_fd);
  224. FD_SET (select_fd, &read_fds);
  225. setSanameT (&compName, "comp_b_in_su_y");
  226. result = saAmfComponentRegister (&handle, &compName, NULL);
  227. printf ("register result is %d (should be 1)\n", result);
  228. do {
  229. select (select_fd + 1, &read_fds, 0, 0, 0);
  230. saAmfDispatch (&handle, SA_DISPATCH_ALL);
  231. } while (result);
  232. saAmfFinalize (&handle);
  233. exit (0);
  234. }