d25449a51d76cd3285c507cec5f3d936e2e914a8
[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 "hw_key.h"
33 #include "util.h"
34 #include "hourly_alert.h"
35 #include "dbus_util.h"
36 #include "clock_mgr.h"
37 #include "status.h"
38 #include "home_mgr.h"
39 #include "process_mgr.h"
40
41 int errno;
42
43
44
45 static struct {
46         int lcd_status;
47 } s_starter = {
48         .lcd_status = -1,
49 };
50
51
52
53 static void _signal_handler(int signum, siginfo_t *info, void *unused)
54 {
55     _D("_signal_handler : Terminated...");
56     elm_exit();
57 }
58
59
60
61 static int _power_off_cb(status_active_key_e key, void *data)
62 {
63         int val = status_active_get()->sysman_power_off_status;
64
65         if (val > VCONFKEY_SYSMAN_POWER_OFF_POPUP) {
66                 _E("power off status : %d", val);
67             elm_exit();
68         }
69
70         return 1;
71 }
72
73
74
75 static int _change_language_cb(status_active_key_e key, void *data)
76 {
77         _D("%s, %d", __func__, __LINE__);
78
79         if (status_active_get()->langset) {
80                 elm_language_set(status_active_get()->langset);
81         }
82
83         return 1;
84 }
85
86
87
88 static int _change_sequence_cb(status_active_key_e key, void *data)
89 {
90         int seq = status_active_get()->starter_sequence;
91
92         if (seq == 1) {
93                 home_mgr_launch_home_first();
94         }
95
96         return 1;
97 }
98
99
100
101 static void _on_lcd_changed_receive(void *data, DBusMessage *msg)
102 {
103         int lcd_on = 0;
104         int lcd_off = 0;
105
106         _D("LCD signal is received");
107
108         lcd_on = dbus_message_is_signal(msg, DEVICED_INTERFACE_DISPLAY, MEMBER_LCD_ON);
109         lcd_off = dbus_message_is_signal(msg, DEVICED_INTERFACE_DISPLAY, MEMBER_LCD_OFF);
110
111         if (lcd_on) {
112                 _W("LCD on");
113                 s_starter.lcd_status = 1;
114         } else if(lcd_off) {
115                 _W("LCD off");
116                 s_starter.lcd_status = 0;
117         } else {
118                 _E("%s dbus_message_is_signal error", DEVICED_INTERFACE_DISPLAY);
119         }
120 }
121
122
123
124 static void _init(void)
125 {
126         struct sigaction act;
127         char err_buf[128] = {0,};
128
129         memset(&act,0x00,sizeof(struct sigaction));
130         act.sa_sigaction = _signal_handler;
131         act.sa_flags = SA_SIGINFO;
132
133         int ret = sigemptyset(&act.sa_mask);
134         if (ret < 0) {
135                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
136                         _E("Failed to sigemptyset[%d / %s]", errno, err_buf);
137                 }
138         }
139         ret = sigaddset(&act.sa_mask, SIGTERM);
140         if (ret < 0) {
141                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
142                         _E("Failed to sigaddset[%d / %s]", errno, err_buf);
143                 }
144         }
145         ret = sigaction(SIGTERM, &act, NULL);
146         if (ret < 0) {
147                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
148                         _E("Failed to sigaction[%d / %s]", errno, err_buf);
149                 }
150         }
151
152         status_register();
153         status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
154         status_active_register_cb(STATUS_ACTIVE_KEY_LANGSET, _change_language_cb, NULL);
155
156         home_mgr_launch_home();
157
158         dbus_util_receive_lcd_status(_on_lcd_changed_receive, NULL);
159
160         home_mgr_init();
161         clock_mgr_init();
162         hourly_alert_init();
163         hw_key_create_window();
164 }
165
166
167
168 static void _fini(void)
169 {
170         hw_key_destroy_window();
171         hourly_alert_fini();
172         clock_mgr_fini();
173         home_mgr_fini();
174
175         status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
176         status_active_unregister_cb(STATUS_ACTIVE_KEY_LANGSET, _change_language_cb);
177         status_active_unregister_cb(STATUS_ACTIVE_KEY_STARTER_SEQUENCE, _change_sequence_cb);
178         status_unregister();
179 }
180
181
182
183 int main(int argc, char *argv[])
184 {
185         int ret = 0;
186
187         _D("starter is launched..!!");
188
189         ret = elm_init(argc, argv);
190         if (ret != 1) {
191                 _E("elm_init() failed : %d", ret);
192                 return -1;
193         }
194
195         ret = ecore_wl_init(NULL);
196         if (ret == 0) {
197                 _E("ecore_wl_init() failed : %d", ret);
198                 elm_shutdown();
199                 return -1;
200         }
201
202         _init();
203
204         /*
205          * Release free memory from top of the heap
206          */
207         malloc_trim(0);
208
209         elm_run();
210
211         _fini();
212         elm_shutdown();
213
214         return 0;
215 }