change usb control process name to usb-server
[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
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         _ss_usb_storage_init();
86 }
87
88 #define SS_PIDFILE_PATH         "/var/run/.system_server.pid"
89
90 static int system_main(int argc, char **argv)
91 {
92         struct ss_main_data ad;
93
94         init_ad(&ad);
95         ad.noti_fd = heynoti_init();
96         heynoti_attach_handler(ad.noti_fd);
97         system_server_init(&ad);
98
99         ecore_main_loop_begin();
100
101         fini(&ad);
102         ecore_shutdown();
103
104         return 0;
105 }
106
107 static int elm_main(int argc, char **argv)
108 {
109         return system_main(argc, argv);
110 }
111
112 int main(int argc, char **argv)
113 {
114         writepid(SS_PIDFILE_PATH);
115         ecore_init();
116         return elm_main(argc, argv);
117 }