sensord: support get_data() API simply
[platform/core/system/sensord.git] / src / server / main.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <unistd.h>
21 #include <sensor_log.h>
22 #include <dbus_util.h>
23 #include <new>
24 #include <csignal>
25
26 #include "server.h"
27
28 #define NEW_FAIL_LIMIT 3
29
30 using namespace sensor;
31
32 static void on_signal(int signum)
33 {
34         _W("Received SIGNAL(%d : %s)", signum, strsignal(signum));
35         server::stop();
36 }
37
38 static void on_new_failed(void)
39 {
40         static unsigned fail_count = 0;
41         _E("Failed to allocate memory");
42
43         fail_count += 1;
44         if (fail_count >= NEW_FAIL_LIMIT) {
45                 raise(SIGTERM);
46                 return;
47         }
48
49         usleep(100000);
50 }
51
52 int main(int argc, char *argv[])
53 {
54         _I("Started");
55         std::signal(SIGINT, on_signal);
56         std::signal(SIGHUP, on_signal);
57         std::signal(SIGTERM, on_signal);
58         std::signal(SIGQUIT, on_signal);
59         std::signal(SIGABRT, on_signal);
60         std::signal(SIGCHLD, SIG_IGN);
61         std::signal(SIGPIPE, SIG_IGN);
62
63         std::set_new_handler(on_new_failed);
64
65         init_dbus();
66
67         server::run();
68
69         fini_dbus();
70
71         _I("Stopped");
72
73         return 0;
74 }