service.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 "service.h"
  41. #include "mainconfig.h"
  42. #include "util.h"
  43. #define LOG_SERVICE LOG_SERVICE_SERV
  44. #include "print.h"
  45. struct default_service {
  46. char *name;
  47. int ver;
  48. };
  49. static struct default_service default_services[] = {
  50. {
  51. .name = "openais_evs",
  52. .ver = 0,
  53. },
  54. {
  55. .name = "openais_clm",
  56. .ver = 0,
  57. },
  58. {
  59. .name = "openais_amf",
  60. .ver = 0,
  61. },
  62. {
  63. .name = "openais_ckpt",
  64. .ver = 0,
  65. },
  66. {
  67. .name = "openais_evt",
  68. .ver = 0,
  69. },
  70. {
  71. .name = "openais_lck",
  72. .ver = 0,
  73. },
  74. {
  75. .name = "openais_msg",
  76. .ver = 0,
  77. },
  78. {
  79. .name = "openais_cfg",
  80. .ver = 0,
  81. },
  82. {
  83. .name = "openais_cpg",
  84. .ver = 0,
  85. }
  86. };
  87. struct openais_service_handler *ais_service[128];
  88. /*
  89. * Adds a service handler to the object database
  90. */
  91. int openais_service_objdb_add (
  92. struct objdb_iface_ver0 *objdb,
  93. char *name,
  94. int version)
  95. {
  96. unsigned int object_handle;
  97. objdb->object_create (OBJECT_PARENT_HANDLE, &object_handle,
  98. "service", strlen ("service"));
  99. objdb->object_key_create (object_handle, "name", strlen ("name"),
  100. name, strlen (name) + 1);
  101. objdb->object_key_create (object_handle, "ver", strlen ("ver"),
  102. &version, sizeof (version));
  103. return (0);
  104. }
  105. static int service_handler_register (
  106. struct openais_service_handler *handler,
  107. struct openais_config *config)
  108. {
  109. int res = 0;
  110. assert (ais_service[handler->id] == NULL);
  111. log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name);
  112. ais_service[handler->id] = handler;
  113. if (ais_service[handler->id]->config_init_fn) {
  114. res = ais_service[handler->id]->config_init_fn (config);
  115. }
  116. //TODO error correction
  117. log_printf (LOG_LEVEL_NOTICE, "Initializing service handler '%s'\n", handler->name);
  118. if (ais_service[handler->id]->exec_init_fn) {
  119. res = ais_service[handler->id]->exec_init_fn (config);
  120. }
  121. return (res);
  122. }
  123. /*
  124. * adds the default services to the object database
  125. */
  126. int openais_service_default_objdb_set (struct objdb_iface_ver0 *objdb)
  127. {
  128. int i;
  129. for (i = 0; i < sizeof (default_services) / sizeof (struct default_service); i++) {
  130. openais_service_objdb_add (objdb, default_services[i].name, default_services[i].ver);
  131. }
  132. return (0);
  133. }
  134. /*
  135. * Links dynamic services into the executive
  136. */
  137. int openais_service_link_all (struct objdb_iface_ver0 *objdb,
  138. struct openais_config *openais_config)
  139. {
  140. char *service_name;
  141. unsigned char *service_ver;
  142. unsigned int object_service_handle;
  143. int ret;
  144. unsigned int handle;
  145. struct openais_service_handler_iface_ver0 *iface_ver0;
  146. unsigned int ver_int;
  147. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  148. while (objdb->object_find (
  149. OBJECT_PARENT_HANDLE,
  150. "service",
  151. strlen ("service"),
  152. &object_service_handle) == 0) {
  153. objdb->object_key_get (object_service_handle,
  154. "name",
  155. strlen ("name"),
  156. (void *)&service_name,
  157. NULL);
  158. ret = objdb->object_key_get (object_service_handle,
  159. "ver",
  160. strlen ("ver"),
  161. (void *)&service_ver,
  162. NULL);
  163. ver_int = atoi (service_ver);
  164. /*
  165. * reference the interfafce and register it
  166. */
  167. lcr_ifact_reference (
  168. &handle,
  169. service_name,
  170. ver_int,
  171. (void **)&iface_ver0,
  172. (void *)0);
  173. if (iface_ver0 == 0) {
  174. log_printf(LOG_LEVEL_ERROR, "openais component %s did not load.\n", service_name);
  175. openais_exit_error (AIS_DONE_DYNAMICLOAD);
  176. } else {
  177. log_printf(LOG_LEVEL_NOTICE, "openais component %s loaded.\n", service_name);
  178. }
  179. service_handler_register (
  180. iface_ver0->openais_get_service_handler_ver0(), openais_config);
  181. }
  182. return (0);
  183. }