apply FSL(Flora Software License)
[framework/system/system-server.git] / ss_main.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 #include <TapiCommon.h>
22
23 #include "ss_log.h"
24 #include "ss_core.h"
25 #include "ss_sig_handler.h"
26 #include "ss_device_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         /* telephony initialize */
66         int ret = 0;
67         ret = tel_init();
68         if (ret != TAPI_API_SUCCESS) {
69                 PRT_TRACE_ERR("tapi init error : [0x%x]", ret);
70         }
71         /* Register Telephony Client */
72         ret = tel_register_app_name("slp.system.server");
73         if (ret != TAPI_API_SUCCESS) {
74                 PRT_TRACE_ERR("tapi app register error : [0x%x]", ret);
75         }
76
77         ad->sysnoti_fd = ss_sysnoti_init();
78         if (ss_noti_init() < 0)
79                 PRT_TRACE_ERR("init noti error");
80
81         ss_queue_init();
82         ss_core_init(ad);
83         ss_signal_init();
84         ss_predefine_internal_init();
85         ss_process_manager_init();
86         ss_time_manager_init();
87         ss_cpu_handler_init();
88
89         ss_lowmem_init(ad);
90         ss_lowbat_init(ad);
91         ss_usb_init();
92         ss_ta_init();
93         ss_device_change_init(ad);
94         ss_mmc_init();
95         ss_bs_init();
96         _ss_usb_storage_init();
97 }
98
99 #define SS_PIDFILE_PATH         "/var/run/.system_server.pid"
100
101 static int system_main(int argc, char **argv)
102 {
103         struct ss_main_data ad;
104
105         init_ad(&ad);
106         ad.noti_fd = heynoti_init();
107         heynoti_attach_handler(ad.noti_fd);
108         system_server_init(&ad);
109
110         ecore_main_loop_begin();
111
112         fini(&ad);
113         ecore_shutdown();
114
115         return 0;
116 }
117
118 static int elm_main(int argc, char **argv)
119 {
120         return system_main(argc, argv);
121 }
122
123 int main(int argc, char **argv)
124 {
125         writepid(SS_PIDFILE_PATH);
126         ecore_init();
127         return elm_main(argc, argv);
128 }