service.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2006 MontaVista Software, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@mvista.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <assert.h>
  39. #include "../lcr/lcr_ifact.h"
  40. #include "swab.h"
  41. #include "service.h"
  42. #include "mainconfig.h"
  43. #include "util.h"
  44. #include "logsys.h"
  45. LOGSYS_DECLARE_SUBSYS ("SERV", LOG_INFO);
  46. struct default_service {
  47. char *name;
  48. int ver;
  49. };
  50. static struct default_service default_services[] = {
  51. {
  52. .name = "openais_evs",
  53. .ver = 0,
  54. },
  55. {
  56. .name = "openais_clm",
  57. .ver = 0,
  58. },
  59. {
  60. .name = "openais_amf",
  61. .ver = 0,
  62. },
  63. {
  64. .name = "openais_ckpt",
  65. .ver = 0,
  66. },
  67. {
  68. .name = "openais_evt",
  69. .ver = 0,
  70. },
  71. {
  72. .name = "openais_lck",
  73. .ver = 0,
  74. },
  75. {
  76. .name = "openais_msg",
  77. .ver = 0,
  78. },
  79. {
  80. .name = "openais_cfg",
  81. .ver = 0,
  82. },
  83. {
  84. .name = "openais_cpg",
  85. .ver = 0,
  86. }
  87. };
  88. struct openais_service_handler *ais_service[SERVICE_HANDLER_MAXIMUM_COUNT];
  89. /*
  90. * Adds a service handler to the object database
  91. */
  92. int openais_service_objdb_add (
  93. struct objdb_iface_ver0 *objdb,
  94. char *name,
  95. int version)
  96. {
  97. unsigned int object_handle;
  98. objdb->object_create (OBJECT_PARENT_HANDLE, &object_handle,
  99. "service", strlen ("service"));
  100. objdb->object_key_create (object_handle, "name", strlen ("name"),
  101. name, strlen (name) + 1);
  102. objdb->object_key_create (object_handle, "ver", strlen ("ver"),
  103. &version, sizeof (version));
  104. return (0);
  105. }
  106. static int service_handler_config (
  107. struct openais_service_handler *handler,
  108. struct objdb_iface_ver0 *objdb)
  109. {
  110. int res = 0;
  111. /* Already loaded? */
  112. if (ais_service[handler->id] != NULL)
  113. return 0;
  114. log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name);
  115. ais_service[handler->id] = handler;
  116. if (ais_service[handler->id]->config_init_fn) {
  117. res = ais_service[handler->id]->config_init_fn (objdb);
  118. }
  119. return (res);
  120. }
  121. /*
  122. * adds the default services to the object database
  123. */
  124. int openais_service_default_objdb_set (struct objdb_iface_ver0 *objdb)
  125. {
  126. int i;
  127. unsigned int object_service_handle;
  128. char *value = NULL;
  129. /* Load default services unless they have been explicitly disabled */
  130. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  131. if (objdb->object_find (
  132. OBJECT_PARENT_HANDLE,
  133. "aisexec",
  134. strlen ("aisexec"),
  135. &object_service_handle) == 0) {
  136. if ( ! objdb->object_key_get (object_service_handle,
  137. "defaultservices",
  138. strlen ("defaultservices"),
  139. (void *)&value,
  140. NULL)) {
  141. if (value && strcmp (value, "no") == 0) {
  142. return 0;
  143. }
  144. }
  145. }
  146. for (i = 0; i < sizeof (default_services) / sizeof (struct default_service); i++) {
  147. openais_service_objdb_add (objdb, default_services[i].name, default_services[i].ver);
  148. }
  149. return (0);
  150. }
  151. /*
  152. * Links dynamic services into the executive
  153. */
  154. int openais_service_link_all (struct objdb_iface_ver0 *objdb)
  155. {
  156. char *service_name;
  157. char *service_ver;
  158. unsigned int object_service_handle;
  159. int ret;
  160. unsigned int handle;
  161. struct openais_service_handler_iface_ver0 *iface_ver0;
  162. void *iface_ver0_p;
  163. unsigned int ver_int;
  164. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  165. while (objdb->object_find (
  166. OBJECT_PARENT_HANDLE,
  167. "service",
  168. strlen ("service"),
  169. &object_service_handle) == 0) {
  170. objdb->object_key_get (object_service_handle,
  171. "name",
  172. strlen ("name"),
  173. (void *)&service_name,
  174. NULL);
  175. ret = objdb->object_key_get (object_service_handle,
  176. "ver",
  177. strlen ("ver"),
  178. (void *)&service_ver,
  179. NULL);
  180. ver_int = atoi (service_ver);
  181. /*
  182. * reference the interface and register it
  183. */
  184. iface_ver0_p = NULL;
  185. lcr_ifact_reference (
  186. &handle,
  187. service_name,
  188. ver_int,
  189. &iface_ver0_p,
  190. (void *)0);
  191. iface_ver0 = (struct openais_service_handler_iface_ver0 *)iface_ver0_p;
  192. if (iface_ver0 == 0) {
  193. log_printf(LOG_LEVEL_ERROR, "openais component %s did not load.\n", service_name);
  194. openais_exit_error (AIS_DONE_DYNAMICLOAD);
  195. } else {
  196. log_printf(LOG_LEVEL_NOTICE, "openais component %s loaded.\n", service_name);
  197. }
  198. service_handler_config (
  199. iface_ver0->openais_get_service_handler_ver0(), objdb);
  200. }
  201. return (0);
  202. }
  203. int openais_service_init_all (int service_count,
  204. struct objdb_iface_ver0 *objdb)
  205. {
  206. int i;
  207. int res=0;
  208. for (i = 0; i < service_count; i++) {
  209. if (ais_service[i] && ais_service[i]->exec_init_fn) {
  210. log_printf (LOG_LEVEL_NOTICE, "Initialising service handler '%s'\n", ais_service[i]->name);
  211. res = ais_service[i]->exec_init_fn (objdb);
  212. if (res != 0) {
  213. break;
  214. }
  215. }
  216. }
  217. return (res);
  218. }