2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "include/ss_data.h"
25 #define SS_PREDEFINE_ACT_FUNC_STR "ss_predefine_action"
26 #define SS_IS_ACCESSABLE_FUNC_STR "ss_is_accessable"
27 #define SS_UI_VIEWABLE_FUNC_STR "ss_ui_viewable"
29 static Eina_List *predef_act_list;
30 static Eina_List *run_queue;
32 static struct ss_action_entry *ss_action_entry_find(char *type)
36 struct ss_action_entry *data;
38 EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) {
39 if ((data != NULL) && (!strcmp(data->type, type)))
46 int ss_action_entry_add_internal(char *type,
47 int (*predefine_action) (),
48 int (*ui_viewable) (),
49 int (*is_accessable) (int))
51 struct ss_action_entry *data;
53 data = malloc(sizeof(struct ss_action_entry));
56 PRT_TRACE_ERR("Malloc failed");
61 if (ss_action_entry_find(type) != NULL)
65 data->predefine_action = predefine_action;
66 if (data->predefine_action == NULL)
69 data->is_accessable = is_accessable;
70 data->ui_viewable = ui_viewable;
71 data->owner_pid = getpid();
72 data->type = strdup(type);
73 data->path = strdup("");
75 predef_act_list = eina_list_prepend(predef_act_list, data);
77 PRT_TRACE_ERR("[SYSMAN] add predefine action entry suceessfully - %s",
81 if (data->type != NULL)
82 PRT_TRACE_ERR("[SYSMAN] add predefine action entry -%s",
88 int ss_action_entry_add(struct sysnoti *msg)
90 struct ss_action_entry *data;
92 data = malloc(sizeof(struct ss_action_entry));
95 PRT_TRACE_ERR("Malloc failed");
99 if (ss_action_entry_find(msg->type) != NULL)
102 data->handle = dlopen(msg->path, RTLD_LAZY);
104 PRT_TRACE_ERR("cannot find such library");
108 data->predefine_action = dlsym(data->handle, SS_PREDEFINE_ACT_FUNC_STR);
109 if (data->predefine_action == NULL) {
110 PRT_TRACE_ERR("cannot find predefine_action symbol : %s",
111 SS_PREDEFINE_ACT_FUNC_STR);
115 data->is_accessable = dlsym(data->handle, SS_IS_ACCESSABLE_FUNC_STR);
116 data->ui_viewable = dlsym(data->handle, SS_UI_VIEWABLE_FUNC_STR);
117 data->owner_pid = msg->pid;
118 data->type = strdup(msg->type);
119 data->path = strdup(msg->path);
121 predef_act_list = eina_list_prepend(predef_act_list, data);
123 PRT_TRACE_ERR("[SYSMAN]add predefine action entry suceessfully - %s",
127 PRT_TRACE_ERR("[SYSMAN] FAIL predefine action entry - %s", msg->type);
132 int ss_action_entry_call_internal(char *type, int argc, ...)
136 struct ss_action_entry *data;
140 char *argv[SYSMAN_MAXARG];
142 if (argc > SYSMAN_MAXARG || type == NULL)
145 EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) {
146 if ((data != NULL) && (!strcmp(data->type, type))) {
147 va_start(argptr, argc);
148 for (i = 0; i < argc; i++) {
149 args = va_arg(argptr, char *);
151 argv[i] = strdup(args);
158 ret=ss_run_queue_add(data, argc, argv);
159 PRT_TRACE_ERR("ss_run_queue_add : %d",ret);
160 ret=ss_core_action_run();
161 PRT_TRACE_ERR("ss_core_action_run : %d",ret);
169 int ss_action_entry_call(struct sysnoti *msg, int argc, char **argv)
173 struct ss_action_entry *data;
175 EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) {
176 if ((data != NULL) && (!strcmp(data->type, msg->type))) {
177 if (data->is_accessable != NULL
178 && data->is_accessable(msg->pid) == 0) {
180 ("%d cannot call that predefine module",
185 ret=ss_run_queue_add(data, argc, argv);
186 PRT_TRACE_ERR("ss_run_queue_add : %d",ret);
187 ret=ss_core_action_run();
188 PRT_TRACE_ERR("ss_core_action_run : %d",ret);
193 PRT_TRACE_EM("[SYSMAN] cannot found action");
197 int ss_run_queue_add(struct ss_action_entry *act_entry, int argc, char **argv)
199 struct ss_run_queue_entry *rq_entry;
202 rq_entry = malloc(sizeof(struct ss_run_queue_entry));
204 if (rq_entry == NULL) {
205 PRT_TRACE_ERR("Malloc failed");
209 rq_entry->state = SS_STATE_INIT;
210 rq_entry->action_entry = act_entry;
211 rq_entry->forked_pid = 0;
212 rq_entry->argc = argc;
213 for (i = 0; i < argc; i++)
214 rq_entry->argv[i] = argv[i];
216 run_queue = eina_list_prepend(run_queue, rq_entry);
218 PRT_TRACE_EM("[SYSMAN] new action called : %s", act_entry->type);
222 int ss_run_queue_run(enum ss_run_state state,
223 int (*run_func) (void *, struct ss_run_queue_entry *),
228 struct ss_run_queue_entry *rq_entry;
230 EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) {
231 if ((rq_entry != NULL) && (rq_entry->state == state))
232 run_func(user_data, rq_entry);
238 struct ss_run_queue_entry *ss_run_queue_find_bypid(int pid)
242 struct ss_run_queue_entry *rq_entry;
244 EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) {
245 if ((rq_entry != NULL) && (rq_entry->forked_pid == pid))
252 int ss_run_queue_del(struct ss_run_queue_entry *entry)
256 struct ss_run_queue_entry *rq_entry;
259 EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) {
260 if ((rq_entry != NULL) && (rq_entry == entry)) {
261 run_queue = eina_list_remove(run_queue, rq_entry);
262 PRT_TRACE_EM("[SYSMAN] action deleted : %s",
263 rq_entry->action_entry->type);
264 for (i = 0; i < rq_entry->argc; i++) {
265 if (rq_entry->argv[i])
266 free(rq_entry->argv[i]);
275 int ss_run_queue_del_bypid(int pid)
279 struct ss_run_queue_entry *rq_entry;
282 EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) {
283 if ((rq_entry != NULL) && (rq_entry->forked_pid == pid)) {
284 run_queue = eina_list_remove(run_queue, rq_entry);
285 PRT_TRACE_EM("[SYSMAN] action deleted : %s",
286 rq_entry->action_entry->type);
287 for (i = 0; i < rq_entry->argc; i++) {
288 if (rq_entry->argv[i])
289 free(rq_entry->argv[i]);