Implement lazy mount
[apps/native/starter.git] / src / wearable / starter.c
1 /*
2  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <Elementary.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <vconf.h>
27 #include <signal.h>
28 #include <dd-deviced.h>
29 #include <Ecore_Wayland.h>
30 #include <malloc.h>
31
32 #include <lazy_mount.h>
33 #include <systemd/sd-daemon.h>
34
35 #include "hw_key.h"
36 #include "util.h"
37 #include "hourly_alert.h"
38 #include "dbus_util.h"
39 #include "clock_mgr.h"
40 #include "status.h"
41 #include "home_mgr.h"
42 #include "process_mgr.h"
43
44 int errno;
45
46
47
48 static struct {
49         int lcd_status;
50 } s_starter = {
51         .lcd_status = -1,
52 };
53
54
55
56 static void _signal_handler(int signum, siginfo_t *info, void *unused)
57 {
58     _D("_signal_handler : Terminated...");
59     elm_exit();
60 }
61
62
63
64 static int _power_off_cb(status_active_key_e key, void *data)
65 {
66         int val = status_active_get()->sysman_power_off_status;
67
68         if (val > VCONFKEY_SYSMAN_POWER_OFF_POPUP) {
69                 _E("power off status : %d", val);
70             elm_exit();
71         }
72
73         return 1;
74 }
75
76
77
78 static int _change_language_cb(status_active_key_e key, void *data)
79 {
80         _D("%s, %d", __func__, __LINE__);
81
82         if (status_active_get()->langset) {
83                 elm_language_set(status_active_get()->langset);
84         }
85
86         return 1;
87 }
88
89
90
91 static int _change_sequence_cb(status_active_key_e key, void *data)
92 {
93         int seq = status_active_get()->starter_sequence;
94
95         if (seq == 1) {
96                 home_mgr_launch_home_first();
97         }
98
99         return 1;
100 }
101
102
103
104 static void _on_lcd_changed_receive(void *data, DBusMessage *msg)
105 {
106         int lcd_on = 0;
107         int lcd_off = 0;
108
109         _D("LCD signal is received");
110
111         lcd_on = dbus_message_is_signal(msg, DEVICED_INTERFACE_DISPLAY, MEMBER_LCD_ON);
112         lcd_off = dbus_message_is_signal(msg, DEVICED_INTERFACE_DISPLAY, MEMBER_LCD_OFF);
113
114         if (lcd_on) {
115                 _W("LCD on");
116                 s_starter.lcd_status = 1;
117         } else if(lcd_off) {
118                 _W("LCD off");
119                 s_starter.lcd_status = 0;
120         } else {
121                 _E("%s dbus_message_is_signal error", DEVICED_INTERFACE_DISPLAY);
122         }
123 }
124
125
126
127 static void _init(void)
128 {
129         struct sigaction act;
130         char err_buf[128] = {0,};
131         int ret = 0;
132
133         memset(&act,0x00,sizeof(struct sigaction));
134         act.sa_sigaction = _signal_handler;
135         act.sa_flags = SA_SIGINFO;
136
137         ret = sigemptyset(&act.sa_mask);
138         if (ret < 0) {
139                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
140                         _E("Failed to sigemptyset[%d / %s]", errno, err_buf);
141                 }
142         }
143         ret = sigaddset(&act.sa_mask, SIGTERM);
144         if (ret < 0) {
145                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
146                         _E("Failed to sigaddset[%d / %s]", errno, err_buf);
147                 }
148         }
149         ret = sigaction(SIGTERM, &act, NULL);
150         if (ret < 0) {
151                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
152                         _E("Failed to sigaction[%d / %s]", errno, err_buf);
153                 }
154         }
155
156         status_register();
157         status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
158         status_active_register_cb(STATUS_ACTIVE_KEY_LANGSET, _change_language_cb, NULL);
159
160         /* Tells the service manager that service startup is finished */
161         sd_notify(0, "READY=1");
162
163         home_mgr_launch_home();
164
165         dbus_util_receive_lcd_status(_on_lcd_changed_receive, NULL);
166
167         home_mgr_init();
168         clock_mgr_init();
169         hourly_alert_init();
170         hw_key_create_window();
171 }
172
173
174
175 static void _fini(void)
176 {
177         hw_key_destroy_window();
178         hourly_alert_fini();
179         clock_mgr_fini();
180         home_mgr_fini();
181
182         status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
183         status_active_unregister_cb(STATUS_ACTIVE_KEY_LANGSET, _change_language_cb);
184         status_active_unregister_cb(STATUS_ACTIVE_KEY_STARTER_SEQUENCE, _change_sequence_cb);
185         status_unregister();
186 }
187
188
189
190 int main(int argc, char *argv[])
191 {
192         int ret = 0;
193
194         _D("starter is launched..!!");
195
196         ret = elm_init(argc, argv);
197         if (ret != 1) {
198                 _E("elm_init() failed : %d", ret);
199                 return -1;
200         }
201
202         ret = ecore_wl_init(NULL);
203         if (ret == 0) {
204                 _E("ecore_wl_init() failed : %d", ret);
205                 elm_shutdown();
206                 return -1;
207         }
208
209         _init();
210
211         /*
212          * Release free memory from top of the heap
213          */
214         malloc_trim(0);
215
216         elm_run();
217
218         _fini();
219         elm_shutdown();
220
221         return 0;
222 }