+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <new>
-#include <csignal>
-
-#include <glib-unix.h>
-
-#include <sensor_log.h>
-#include "server.h"
-
-#define NEW_FAIL_LIMIT 3
-
-using namespace sensor;
-
-static void handle_signal_std(int signum)
-{
- _W("Received SIGNAL(%d : %s)", signum, strsignal(signum));
-
- /* raise SIGTERM manually to call handle_signal with glib dispatcher */
- raise(SIGTERM);
-}
-
-static gboolean handle_signal(gpointer data)
-{
- long signum = (long) data;
- _W("Received SIGNAL(%ld : %s)", signum, strsignal(signum));
-
- server::stop();
-
- return G_SOURCE_REMOVE;
-}
-
-static void on_new_failed(void)
-{
- static unsigned fail_count = 0;
- _E("Failed to allocate memory");
-
- fail_count += 1;
- if (fail_count >= NEW_FAIL_LIMIT) {
- raise(SIGTERM);
- return;
- }
-}
-
-int main(int argc, char *argv[])
-{
- _I("Started");
-
- /* register signal handler with glib to prevent deadlock */
- g_unix_signal_add(SIGINT, handle_signal, (gpointer) SIGINT);
- g_unix_signal_add(SIGHUP, handle_signal, (gpointer) SIGHUP);
- g_unix_signal_add(SIGTERM, handle_signal, (gpointer) SIGTERM);
-
- /* register signal handler with std for not supported signal in glib */
- std::signal(SIGQUIT, handle_signal_std);
- std::signal(SIGABRT, handle_signal_std);
- std::signal(SIGCHLD, SIG_IGN);
- std::signal(SIGPIPE, SIG_IGN);
-
- std::set_new_handler(on_new_failed);
-
- server::run();
-
- _I("Stopped");
-
- return 0;
-}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <new>
+#include <csignal>
+
+#include <glib-unix.h>
+
+#include <sensor_log.h>
+#include "server.h"
+#include "sensord.h"
+
+#define NEW_FAIL_LIMIT 3
+
+using namespace sensor;
+
+static void handle_signal_std(int signum)
+{
+ _W("Received SIGNAL(%d : %s)", signum, strsignal(signum));
+
+ /* raise SIGTERM manually to call handle_signal with glib dispatcher */
+ raise(SIGTERM);
+}
+
+static gboolean handle_signal(gpointer data)
+{
+ long signum = (long) data;
+ _W("Received SIGNAL(%ld : %s)", signum, strsignal(signum));
+
+ sensord_exit();
+
+ return G_SOURCE_REMOVE;
+}
+
+static void on_new_failed(void)
+{
+ static unsigned fail_count = 0;
+ _E("Failed to allocate memory");
+
+ fail_count += 1;
+ if (fail_count >= NEW_FAIL_LIMIT) {
+ raise(SIGTERM);
+ return;
+ }
+}
+
+void sensord_init(void)
+{
+ /* register signal handler with glib to prevent deadlock */
+ g_unix_signal_add(SIGINT, handle_signal, (gpointer) SIGINT);
+ g_unix_signal_add(SIGHUP, handle_signal, (gpointer) SIGHUP);
+ g_unix_signal_add(SIGTERM, handle_signal, (gpointer) SIGTERM);
+
+ /* register signal handler with std for not supported signal in glib */
+ std::signal(SIGQUIT, handle_signal_std);
+ std::signal(SIGABRT, handle_signal_std);
+ std::signal(SIGCHLD, SIG_IGN);
+ std::signal(SIGPIPE, SIG_IGN);
+
+ std::set_new_handler(on_new_failed);
+
+ server::run();
+}
+
+void sensord_exit(void)
+{
+ server::stop();
+}
+
+int main(int argc, char *argv[])
+{
+ _I("Started");
+
+ sensord_init();
+
+ _I("Stopped");
+
+ return 0;
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#pragma once
+
+void sensord_init(void);
+void sensord_exit(void);