4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <sys/types.h>
25 #include <sys/inotify.h>
28 #include <Ecore_Input.h>
37 #include "amd_config.h"
38 #include "simple_util.h"
40 #include "amd_appinfo.h"
41 #include "amd_cgutil.h"
43 #include "amd_status.h"
44 #include "amd_launch.h"
45 #include "amd_request.h"
48 # define MOUNT_PATH "/sys/fs/cgroup"
52 # define AGENT_PATH "/usr/bin/daemon-manager-release-agent"
55 #define WINDOW_READY "/tmp/.wm_ready"
57 typedef struct _window_watch {
60 Ecore_Fd_Handler *win_watch_ewd;
62 static _window_watch_t *win_info_t = NULL;
64 static int __app_dead_handler(int pid, void *data);
67 extern int _status_init(struct amdmgr* amd);
69 static int __app_dead_handler(int pid, void *data)
71 _unregister_key_event(pid);
72 _status_remove_app_info_list(pid);
76 static void __start_cb(void *user_data,
77 const char *filename, const struct appinfo *ai)
79 /*struct amdmgr *amd = user_data;*/
80 const char *componet = NULL;
83 componet = appinfo_get_value(ai, AIT_COMPTYPE);
85 r = appinfo_get_boolean(ai, AIT_ONBOOT);
87 if (r == 1 && strncmp(componet, "svcapp", 6) == 0)
89 const char *pkgid = appinfo_get_value(ai, AIT_PKGID);
90 _D("start service - %s", pkgid);
96 static void _start_services(struct amdmgr *amd)
98 appinfo_foreach(amd->af, __start_cb, amd);
101 static int __booting_done_handler(int pid, void *data)
103 _start_services((struct amdmgr*)data);
108 static gboolean _check_window_ready(void)
110 if (access(WINDOW_READY, R_OK) == 0)
116 static void __window_init(void)
125 static Eina_Bool _window_cb(void *data, Ecore_Fd_Handler * fd_handler)
128 char buf[FILENAME_MAX];
130 struct inotify_event* event;
132 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) {
133 _E("An error has occurred. Stop watching this fd and quit");
134 return ECORE_CALLBACK_CANCEL;
137 fd = ecore_main_fd_handler_fd_get(fd_handler);
139 _E("ecore_main_fd_handler_fd_get error");
140 return ECORE_CALLBACK_CANCEL;
142 len = read(fd, buf, FILENAME_MAX);
144 event = (struct inotify_event*) &buf[0];
146 _D("filename : %s", event->name);
148 if (access(WINDOW_READY, R_OK) == 0) {
151 ecore_main_fd_handler_del(win_info_t->win_watch_ewd);
152 inotify_rm_watch(win_info_t->watch_fd, win_info_t->win_watch_wd);
158 return ECORE_CALLBACK_RENEW;
161 static void _register_window_init(void)
163 win_info_t = malloc(sizeof(_window_watch_t));
165 _E("Unable to allocate memory. don't init widow\n");
168 win_info_t->watch_fd = inotify_init();
169 win_info_t->win_watch_wd = inotify_add_watch(win_info_t->watch_fd, "/tmp", IN_CREATE);
170 win_info_t->win_watch_ewd = ecore_main_fd_handler_add(win_info_t->watch_fd,
171 ECORE_FD_READ, _window_cb, NULL, NULL, NULL);
174 static void _window_init(void)
176 if (_check_window_ready())
179 _register_window_init();
190 appinfo_init(&amd.af);
191 cgutil_create(MOUNT_PATH, AGENT_PATH, &amd.cg);
197 aul_listen_app_dead_signal(__app_dead_handler, NULL);
199 aul_listen_booting_done_signal(__booting_done_handler, &amd);
204 gboolean __amd_ready(gpointer user_data)
208 handle = creat("/tmp/amd_ready", S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
215 int main(int argc, char *argv[])
218 _E("AMD Initialization failed!\n");
222 g_idle_add(__amd_ready, NULL);
224 ecore_main_loop_begin();