3721a6eab6c659ea7f6c4a774fa368dcd61453a6
[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 "ss_device_plugin.h"
36 #include "include/ss_data.h"
37
38 static void fini(struct ss_main_data *ad)
39 {
40 }
41
42 static void init_ad(struct ss_main_data *ad)
43 {
44         memset(ad, 0x0, sizeof(struct ss_main_data));
45 }
46
47 static void writepid(char *pidpath)
48 {
49         FILE *fp;
50
51         fp = fopen(pidpath, "w");
52         if (fp != NULL) {
53                 fprintf(fp, "%d", getpid());
54                 fclose(fp);
55         }
56 }
57
58 static void system_server_init(struct ss_main_data *ad)
59 {
60         if (0 > _ss_devman_plugin_init()) {
61                 PRT_TRACE_ERR("Device Manager Plugin Initialize failed");
62                 exit (-1);
63         }
64
65         ad->sysnoti_fd = ss_sysnoti_init();
66         if (ss_noti_init() < 0)
67                 PRT_TRACE_ERR("init noti error");
68
69         ss_queue_init();
70         ss_core_init(ad);
71         ss_signal_init();
72         ss_predefine_internal_init();
73         ss_process_manager_init();
74         ss_time_manager_init();
75         ss_cpu_handler_init();
76
77         ss_lowmem_init(ad);
78         ss_lowbat_init(ad);
79         ss_usb_init();
80         ss_ta_init();
81         ss_pmon_init(ad);
82         ss_device_change_init(ad);
83         ss_mmc_init();
84         ss_bs_init();
85 }
86
87 #define SS_PIDFILE_PATH         "/var/run/.system_server.pid"
88
89 static int system_main(int argc, char **argv)
90 {
91         struct ss_main_data ad;
92
93         init_ad(&ad);
94         if ((ad.noti_fd = heynoti_init()) < 0) {
95                 PRT_TRACE_ERR("Hey Notification Initialize failed");
96                 fini(&ad);
97                 return 0;
98         }
99         if (heynoti_attach_handler(ad.noti_fd) != 0) {
100                 PRT_TRACE_ERR("fail to attach hey noti handler");
101                 fini(&ad);
102                 return 0;
103         }
104         system_server_init(&ad);
105
106         ecore_main_loop_begin();
107
108         fini(&ad);
109         ecore_shutdown();
110
111         return 0;
112 }
113
114 static int elm_main(int argc, char **argv)
115 {
116         return system_main(argc, argv);
117 }
118
119 int main(int argc, char **argv)
120 {
121         writepid(SS_PIDFILE_PATH);
122         ecore_init();
123         return elm_main(argc, argv);
124 }