cfg.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (c) 2005-2006 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 <sys/types.h>
  35. #include <sys/uio.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <netinet/in.h>
  39. #include <arpa/inet.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include <string.h>
  47. #include "../include/saAis.h"
  48. #include "../include/openaisCfg.h"
  49. #include "../include/ipc_gen.h"
  50. #include "../include/ipc_cfg.h"
  51. #include "../include/list.h"
  52. #include "../include/queue.h"
  53. #include "../lcr/lcr_comp.h"
  54. #include "totempg.h"
  55. #include "aispoll.h"
  56. #include "mempool.h"
  57. #include "util.h"
  58. #include "handlers.h"
  59. #define LOG_SERVICE LOG_SERVICE_AMF
  60. #include "print.h"
  61. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  62. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  63. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  64. static int cfg_confchg_fn (
  65. enum totem_configuration_type configuration_type,
  66. struct in_addr *member_list, int member_list_entries,
  67. struct in_addr *left_list, int left_list_entries,
  68. struct in_addr *joined_list, int joined_list_entries,
  69. struct memb_ring_id *ring_id);
  70. static int cfg_exit_fn (struct conn_info *conn_info);
  71. static int cfg_exec_init_fn (struct openais_config *);
  72. static int cfg_init_two_fn (struct conn_info *conn_info);
  73. static int message_handler_req_lib_cfg_statetrackstart (struct conn_info *conn_info, void *message);
  74. static int message_handler_req_lib_cfg_statetrackstop (struct conn_info *conn_info, void *message);
  75. static int message_handler_req_lib_cfg_administrativestateset (struct conn_info *conn_info, void *message);
  76. static int message_handler_req_lib_cfg_administrativestateget (struct conn_info *conn_info, void *message);
  77. /*
  78. * Service Handler Definition
  79. */
  80. struct libais_handler cfg_libais_handlers[] =
  81. {
  82. { /* 0 */
  83. .libais_handler_fn = message_handler_req_lib_cfg_statetrackstart,
  84. .response_size = sizeof (struct res_lib_cfg_statetrackstart),
  85. .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
  86. .flow_control = FLOW_CONTROL_REQUIRED
  87. },
  88. { /* 1 */
  89. .libais_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  90. .response_size = sizeof (struct res_lib_cfg_statetrackstop),
  91. .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
  92. .flow_control = FLOW_CONTROL_REQUIRED
  93. },
  94. { /* 2 */
  95. .libais_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  96. .response_size = sizeof (struct res_lib_cfg_administrativestateset),
  97. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
  98. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  99. },
  100. { /* 3 */
  101. .libais_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  102. .response_size = sizeof (struct res_lib_cfg_administrativestateget),
  103. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
  104. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  105. }
  106. };
  107. int (*cfg_aisexec_handler_fns[]) (void *, struct in_addr source_addr, int endian_conversion_required) = {
  108. /*
  109. message_handler_req_exec_cfg_componentregister,
  110. message_handler_req_exec_cfg_componentunregister,
  111. message_handler_req_exec_cfg_componenterrorreport,
  112. message_handler_req_exec_cfg_componenterrorclear,
  113. */
  114. };
  115. /*
  116. * Exports the interface for the service
  117. */
  118. struct service_handler cfg_service_handler = {
  119. .name = "openais configuration service",
  120. .id = CFG_SERVICE,
  121. .libais_handlers = cfg_libais_handlers,
  122. .libais_handlers_count = sizeof (cfg_libais_handlers) / sizeof (struct libais_handler),
  123. .aisexec_handler_fns = cfg_aisexec_handler_fns,
  124. .aisexec_handler_fns_count = sizeof (cfg_aisexec_handler_fns) / sizeof (int (*)),
  125. .confchg_fn = cfg_confchg_fn,
  126. .libais_init_two_fn = cfg_init_two_fn,
  127. .libais_exit_fn = cfg_exit_fn,
  128. .exec_init_fn = cfg_exec_init_fn,
  129. };
  130. #ifdef BUILD_DYNAMIC
  131. struct service_handler *cfg_get_handler_ver0 (void);
  132. struct aisexec_iface_ver0 cfg_service_handler_iface = {
  133. .test = NULL,
  134. .get_handler_ver0 = cfg_get_handler_ver0
  135. };
  136. struct lcr_iface openais_cfg_ver0[1] = {
  137. {
  138. .name = "openais_cfg",
  139. .version = 0,
  140. .versions_replace = 0,
  141. .versions_replace_count = 0,
  142. .dependencies = 0,
  143. .dependency_count = 0,
  144. .constructor = NULL,
  145. .destructor = NULL,
  146. .interfaces = (void **)&cfg_service_handler_iface,
  147. }
  148. };
  149. struct lcr_comp cfg_comp_ver0 = {
  150. .iface_count = 1,
  151. .ifaces = openais_cfg_ver0
  152. };
  153. extern int lcr_comp_get (struct lcr_comp **component)
  154. {
  155. *component = &cfg_comp_ver0;
  156. return (0);
  157. }
  158. struct service_handler *cfg_get_handler_ver0 (void)
  159. {
  160. return (&cfg_service_handler);
  161. }
  162. #endif /* BUILD_DYNAMIC */
  163. /* IMPL */
  164. static int cfg_exec_init_fn (struct openais_config *openais_config)
  165. {
  166. return (0);
  167. }
  168. static int cfg_confchg_fn (
  169. enum totem_configuration_type configuration_type,
  170. struct in_addr *member_list, int member_list_entries,
  171. struct in_addr *left_list, int left_list_entries,
  172. struct in_addr *joined_list, int joined_list_entries,
  173. struct memb_ring_id *ring_id)
  174. {
  175. return (0);
  176. }
  177. int cfg_exit_fn (struct conn_info *conn_info)
  178. {
  179. return (0);
  180. }
  181. static int cfg_init_two_fn (struct conn_info *conn_info)
  182. {
  183. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize configuration service.\n");
  184. list_init (&conn_info->conn_list);
  185. return (0);
  186. }
  187. /*
  188. * Library Interface Implementation
  189. */
  190. static int message_handler_req_lib_cfg_statetrackstart (struct conn_info *conn_info, void *message)
  191. {
  192. struct req_lib_cfg_statetrackstart *req_lib_cfg_statetrackstart = (struct req_lib_cfg_statetrackstart *)message;
  193. log_printf (LOG_LEVEL_FROM_LIB,
  194. "Handle : message_handler_req_lib_cfg_statetrackstart()\n");
  195. return (0);
  196. }
  197. static int message_handler_req_lib_cfg_statetrackstop (struct conn_info *conn_info, void *message)
  198. {
  199. struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  200. log_printf (LOG_LEVEL_FROM_LIB,
  201. "Handle : message_handler_req_lib_cfg_administrativestateget()\n");
  202. return (0);
  203. }
  204. static int message_handler_req_lib_cfg_administrativestateset (struct conn_info *conn_info, void *message)
  205. {
  206. struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  207. log_printf (LOG_LEVEL_FROM_LIB,
  208. "Handle : message_handler_req_lib_cfg_administrativestateset()\n");
  209. return (0);
  210. }
  211. static int message_handler_req_lib_cfg_administrativestateget (struct conn_info *conn_info, void *message)
  212. {
  213. struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  214. log_printf (LOG_LEVEL_FROM_LIB,
  215. "Handle : message_handler_req_lib_cfg_administrativestateget()\n");
  216. return (0);
  217. }