4 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 * @desc Module helper functions
27 #include "resourced.h"
32 static GSList *modules_list;
34 void add_module(const struct module_ops *module)
36 ret_msg_if(!module, "Invalid module handler\n");
37 if (module->priority == MODULE_PRIORITY_HIGH)
38 modules_list = g_slist_prepend(modules_list, (gpointer)module);
40 modules_list = g_slist_append(modules_list, (gpointer)module);
43 void remove_module(const struct module_ops *module)
45 modules_list = g_slist_remove(modules_list, (gpointer)module);
48 const struct module_ops *find_module(const char *name)
51 const struct module_ops *module;
53 gslist_for_each_item(iter, modules_list) {
54 module = (struct module_ops *)iter->data;
55 if (!strcmp(module->name, name))
61 void modules_check_runtime_support(void *data)
64 const struct module_ops *module;
65 int ret_code = RESOURCED_ERROR_NONE;
67 gslist_for_each_item(iter, modules_list) {
68 module = (const struct module_ops *)iter->data;
69 _D("check runtime support [%s] module\n", module->name);
71 if (!module->check_runtime_support)
74 ret_code = module->check_runtime_support((void *)module);
75 if (ret_code != RESOURCED_ERROR_NONE) {
76 _E("%s module check failed", module->name);
77 remove_module(module);
83 void modules_init(void *data)
86 const struct module_ops *module;
87 int ret_code = RESOURCED_ERROR_NONE;
89 gslist_for_each_item(iter, modules_list) {
90 module = (struct module_ops *)iter->data;
91 _D("Initialize [%s] module\n", module->name);
93 ret_code = module->init(data);
95 _E("Fail to initialize [%s] module\n", module->name);
99 void modules_exit(void *data)
102 /* Deinitialize in reverse order */
103 GSList *reverse_list = g_slist_reverse(modules_list);
104 const struct module_ops *module;
105 int ret_code = RESOURCED_ERROR_NONE;
107 gslist_for_each_item(iter, reverse_list) {
108 module = (struct module_ops *)iter->data;
109 _D("Deinitialize [%s] module\n", module->name);
111 ret_code = module->exit(data);
113 _E("Fail to deinitialize [%s] module\n", module->name);