merge with master
[platform/core/system/system-server.git] / ss_main.c
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
18 #include <stdio.h>
19 #include <fcntl.h>
20 #include <heynoti.h>
21
22 #include "ss_log.h"
23 #include "ss_core.h"
24 #include "ss_sig_handler.h"
25 #include "ss_device_handler.h"
26 #include "ss_pmon_handler.h"
27 #include "ss_sysnoti.h"
28 #include "ss_noti.h"
29 #include "ss_queue.h"
30 #include "ss_predefine.h"
31 #include "ss_bs.h"
32 #include "ss_procmgr.h"
33 #include "ss_timemgr.h"
34 #include "ss_cpu_handler.h"
35 #include "include/ss_data.h"
36
37 #define SS_PIDFILE_PATH         "/var/run/.system_server.pid"
38
39 static void fini(struct ss_main_data *ad)
40 {
41         // try to remove pid file
42         unlink(SS_PIDFILE_PATH);
43 }
44
45 static void init_ad(struct ss_main_data *ad)
46 {
47         memset(ad, 0x0, sizeof(struct ss_main_data));
48 }
49
50 static void writepid(char *pidpath)
51 {
52         FILE *fp;
53
54         fp = fopen(pidpath, "w");
55         if (fp != NULL) {
56                 fprintf(fp, "%d", getpid());
57                 fclose(fp);
58         }
59 }
60
61 static void system_server_init(struct ss_main_data *ad)
62 {
63         ad->sysnoti_fd = ss_sysnoti_init();
64         if (ss_noti_init() < 0)
65                 PRT_TRACE_ERR("init noti error");
66
67         ss_queue_init();
68         ss_core_init(ad);
69         ss_signal_init();
70         ss_predefine_internal_init();
71         ss_process_manager_init();
72         ss_time_manager_init();
73         ss_cpu_handler_init();
74
75         ss_lowmem_init(ad);
76         ss_lowbat_init(ad);
77         ss_usb_init();
78         ss_ta_init();
79         ss_pmon_init(ad);
80         ss_device_change_init(ad);
81         ss_mmc_init();
82         ss_bs_init();
83 }
84
85 static int system_main(int argc, char **argv)
86 {
87         struct ss_main_data ad;
88
89         init_ad(&ad);
90         if ((ad.noti_fd = heynoti_init()) < 0) {
91                 PRT_TRACE_ERR("Hey Notification Initialize failed");
92                 fini(&ad);
93                 return 0;
94         }
95         if (heynoti_attach_handler(ad.noti_fd) != 0) {
96                 PRT_TRACE_ERR("fail to attach hey noti handler");
97                 fini(&ad);
98                 return 0;
99         }
100         system_server_init(&ad);
101
102         ecore_main_loop_begin();
103
104         fini(&ad);
105         ecore_shutdown();
106
107         return 0;
108 }
109
110 static int elm_main(int argc, char **argv)
111 {
112         return system_main(argc, argv);
113 }
114
115 int main(int argc, char **argv)
116 {
117         writepid(SS_PIDFILE_PATH);
118         ecore_init();
119         return elm_main(argc, argv);
120 }