2 * Copyright (c) 2006 MontaVista Software, Inc.
3 * Copyright (c) 2006-2007 Red Hat, Inc.
7 * Author: Steven Dake (sdake@redhat.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
40 #include "../lcr/lcr_ifact.h"
45 #include "mainconfig.h"
49 LOGSYS_DECLARE_SUBSYS ("SERV", LOG_INFO
);
51 struct default_service
{
56 static struct default_service default_services
[] = {
58 .name
= "openais_evs",
62 .name
= "openais_clm",
66 .name
= "openais_amf",
70 .name
= "openais_ckpt",
74 .name
= "openais_evt",
78 .name
= "openais_lck",
82 .name
= "openais_msg",
86 .name
= "openais_cfg",
90 .name
= "openais_cpg",
94 .name
= "openais_confdb",
99 struct openais_service_handler
*ais_service
[SERVICE_HANDLER_MAXIMUM_COUNT
];
101 static unsigned int default_services_requested (struct objdb_iface_ver0
*objdb
)
103 unsigned int object_service_handle
;
107 * Don't link default services if they have been disabled
109 objdb
->object_find_reset (OBJECT_PARENT_HANDLE
);
110 if (objdb
->object_find (
111 OBJECT_PARENT_HANDLE
,
114 &object_service_handle
) == 0) {
116 if ( ! objdb
->object_key_get (object_service_handle
,
118 strlen ("defaultservices"),
122 if (value
&& strcmp (value
, "no") == 0) {
130 unsigned int openais_service_link_and_init (
131 struct objdb_iface_ver0
*objdb
,
133 unsigned int service_ver
)
135 struct openais_service_handler_iface_ver0
*iface_ver0
;
138 struct openais_service_handler
*service
;
140 unsigned int object_handle
;
143 * reference the service interface
146 lcr_ifact_reference (
153 iface_ver0
= (struct openais_service_handler_iface_ver0
*)iface_ver0_p
;
155 if (iface_ver0
== 0) {
156 log_printf(LOG_LEVEL_ERROR
, "Service failed to load '%s'.\n", service_name
);
164 service
= iface_ver0
->openais_get_service_handler_ver0();
166 ais_service
[service
->id
] = service
;
167 if (service
->config_init_fn
) {
168 res
= service
->config_init_fn (objdb
);
171 if (service
->exec_init_fn
) {
172 res
= service
->exec_init_fn (objdb
);
176 * Store service in object database
178 objdb
->object_create (OBJECT_PARENT_HANDLE
,
183 objdb
->object_key_create (object_handle
,
187 strlen (service_name
) + 1);
189 objdb
->object_key_create (object_handle
,
193 sizeof (service_ver
));
195 res
= objdb
->object_key_create (object_handle
,
201 objdb
->object_key_create (object_handle
,
203 strlen ("service_id"),
205 sizeof (service
->id
));
207 log_printf (LOG_LEVEL_NOTICE
, "Service initialized '%s'\n", service
->name
);
211 extern unsigned int openais_service_unlink_and_exit (
212 struct objdb_iface_ver0
*objdb
,
214 unsigned int service_ver
)
216 unsigned int object_service_handle
;
217 char *found_service_name
;
218 unsigned int *found_service_ver
;
219 unsigned int *found_service_handle
;
220 unsigned short *service_id
;
223 objdb
->object_find_reset (OBJECT_PARENT_HANDLE
);
224 while (objdb
->object_find (
225 OBJECT_PARENT_HANDLE
,
228 &object_service_handle
) == 0) {
230 objdb
->object_key_get (object_service_handle
,
233 (void *)&found_service_name
,
236 objdb
->object_key_get (object_service_handle
,
239 (void *)&found_service_ver
,
243 * If service found and linked exit it
245 if ((strcmp (service_name
, found_service_name
) == 0) &&
246 (service_ver
== *found_service_ver
)) {
248 res
= objdb
->object_key_get (object_service_handle
,
251 (void *)&found_service_handle
,
254 res
= objdb
->object_key_get (object_service_handle
,
256 strlen ("service_id"),
260 if (ais_service
[*service_id
]->exec_exit_fn
) {
261 ais_service
[*service_id
]->exec_exit_fn (objdb
);
263 ais_service
[*service_id
] = NULL
;
265 res
= lcr_ifact_release (*found_service_handle
);
266 objdb
->object_destroy (object_service_handle
);
274 * Links default services into the executive
276 unsigned int openais_service_defaults_link_and_init (struct objdb_iface_ver0
*objdb
)
280 if (default_services_requested (objdb
) == 0) {
284 i
< sizeof (default_services
) / sizeof (struct default_service
); i
++) {
286 openais_service_link_and_init (
288 default_services
[i
].name
,
289 default_services
[i
].ver
);