4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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.
23 #include "predefine.h"
33 struct _internal_msg {
38 static int core_pipe[2];
39 Ecore_Fd_Handler *g_pipe_efd = NULL;
41 static int __pipe_start(struct main_data *ad);
42 static int __pipe_stop(int fd);
44 static int _core_action_run(void *user_data,
45 struct run_queue_entry *rq_entry)
47 struct action_entry *act_entry = rq_entry->action_entry;
51 rq_entry->state = STATE_RUNNING;
52 ret = act_entry->predefine_action(rq_entry->argc, rq_entry->argv);
55 _E("predefine action failed");
58 snprintf(tmp, sizeof(tmp), "/proc/%d/status", ret);
59 if (access(tmp, R_OK) == 0)
60 rq_entry->forked_pid = ret;
67 rq_entry->forked_pid = -1;
68 rq_entry->state = STATE_DONE;
69 core_action_clear(-1);
73 static Eina_Bool core_pipe_cb(void *userdata, Ecore_Fd_Handler * fd_handler)
75 struct main_data *ad = (struct main_data *)userdata;
76 struct _internal_msg p_msg;
79 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) {
80 _E("ecore_main_fd_handler_active_get error , return");
84 while (retry_count < 5) {
85 r = read(core_pipe[0], &p_msg, sizeof(struct _internal_msg));
88 _D("Re-read for error(EINTR)");
92 __pipe_stop(core_pipe[0]);
93 __pipe_stop(core_pipe[1]);
94 _D("restart pipe fd");
102 switch (p_msg.type) {
104 run_queue_run(STATE_INIT, _core_action_run, ad);
107 run_queue_del_bypid(p_msg.pid);
113 int core_action_run()
115 struct _internal_msg p_msg;
117 p_msg.type = CORE_ACT_RUN;
119 write(core_pipe[1], &p_msg, sizeof(struct _internal_msg));
124 int core_action_clear(int pid)
126 struct _internal_msg p_msg;
128 p_msg.type = CORE_ACT_CLEAR;
130 write(core_pipe[1], &p_msg, sizeof(struct _internal_msg));
135 static int __pipe_start(struct main_data *ad)
137 if (pipe(core_pipe) < 0) {
138 _E("pipe cannot create");
142 g_pipe_efd = ecore_main_fd_handler_add(core_pipe[0], ECORE_FD_READ,
143 core_pipe_cb, ad, NULL, NULL);
145 _E("error ecore_main_fd_handler_add");
151 static int __pipe_stop(int fd)
154 ecore_main_fd_handler_del(g_pipe_efd);
163 static void core_init(void *data)
165 struct main_data *ad = (struct main_data*)data;
167 __pipe_stop(core_pipe[0]);
168 __pipe_stop(core_pipe[1]);
170 if (__pipe_start(ad) == -1)
171 _E("fail pipe control fd init");
174 static const struct device_ops core_device_ops = {
175 .priority = DEVICE_PRIORITY_NORMAL,
180 DEVICE_OPS_REGISTER(&core_device_ops)