Add container handling logic
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / bt-service-main.c
index ea38343..3f1d655 100644 (file)
 #include <bincfg.h>
 #endif
 
+#include <unistd.h>
+#include <sys/socket.h>
 #include <bundle.h>
 #include <eventsystem.h>
+#include <ell/ell.h>
 
 #include "bt-internal-types.h"
 #include "bt-service-common.h"
 #include <oal-event.h>
 #include <oal-manager.h>
 
+/* ELL Start */
+struct ell_event_source {
+       GSource source;
+       GPollFD pollfd;
+};
+
+static gboolean event_prepare(GSource *source, gint *timeout)
+{
+        int r = l_main_prepare();
+        *timeout = r;
+
+        return FALSE;
+}
+
+static gboolean event_check(GSource *source)
+{
+        l_main_iterate(0);
+        return FALSE;
+}
+
+static GSourceFuncs event_funcs = {
+        .prepare = event_prepare,
+        .check = event_check,
+};
+/* ELL End */
+
 static GMainLoop *main_loop;
 static gboolean terminated = FALSE;
 static gboolean is_initialized = FALSE;
@@ -58,9 +87,7 @@ static void __on_log_glib(const gchar *log_domain, GLogLevelFlags log_level,
 
 static void __bt_release_service(void)
 {
-#ifdef TIZEN_FEATURE_BT_AVC_TARGET
        _bt_audio_deinit_absolute_volume_control();
-#endif
 
        _bt_service_le_deinit();
        _bt_deinit_hf_local_term_event_sender();
@@ -174,9 +201,6 @@ static gboolean __bt_check_bt_service(void *data)
        int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
        int flight_mode_deactivation = 0;
        int bt_off_due_to_timeout = 0;
-#if 0
-       int ps_mode_deactivation = 0;
-#endif
 
        if (_is_name_acquired() == FALSE) {
                BT_ERR("dbus name is NOT acquired yet");
@@ -197,10 +221,12 @@ static gboolean __bt_check_bt_service(void *data)
                }
        }
 
-       if (TIZEN_PROFILE_TV) {
-#if TODO_40 /* Need to add this function */
+       if (TIZEN_PROFILE_TV || TIZEN_FEATURE_ROBOT_REFERENCE) {
+/*
+#if TODO_40
                if (_bt_get_enable_timer_id() == 0)
 #endif
+*/
                        _bt_enable_adapter();
        } else if (!headed_plugin_info->plugin_headed_enabled) {
                BT_DBG("Enable adapter if headless device");
@@ -215,11 +241,6 @@ static gboolean __bt_check_bt_service(void *data)
                if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0)
                        BT_ERR("Fail to get the flight_mode_deactivation value");
 
-#if 0
-       if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_deactivation) != 0)
-               BT_ERR("Fail to get the ps_mode_deactivation value");
-#endif
-
                if (vconf_get_int(BT_OFF_DUE_TO_TIMEOUT, &bt_off_due_to_timeout) != 0)
                        BT_ERR("Fail to get BT_OFF_DUE_TO_TIMEOUT");
 
@@ -335,11 +356,9 @@ int _bt_service_initialize(void)
 
        _bt_init_request_list();
 
-#ifdef TIZEN_FEATURE_BT_AVC_TARGET
        ret = _bt_audio_init_absolute_volume_control();
        if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to init AVC");
-#endif
 
        is_initialized = TRUE;
 
@@ -349,6 +368,9 @@ int _bt_service_initialize(void)
 int main(void)
 {
        struct sigaction sa;
+       /* ELL Start */
+       struct ell_event_source *source;
+       /* ELL End */
        BT_INFO_C("### Starting the bt-service daemon");
 
        if (!TIZEN_FEATURE_BT_SUPPORTED) {
@@ -356,6 +378,11 @@ int main(void)
                return 0;
        }
 
+       if (access(CONTAINER_FILE, F_OK) == 0) {
+               BT_INFO("bt-service is not running in container");
+               return 0;
+       }
+
        memset(&sa, 0, sizeof(sa));
        sa.sa_sigaction = __bt_sigterm_handler;
        sa.sa_flags = SA_SIGINFO;
@@ -374,12 +401,29 @@ int main(void)
                return 0;
        }
 
+       /* ELL Start */
+       BT_INFO("ELL Main init");
+       l_main_init();
+       /* ELL End */
+
        bluetooth_plugin_init();
 
        g_log_set_default_handler(__on_log_glib, NULL);
 
        main_loop = g_main_loop_new(NULL, FALSE);
 
+       /* ELL Start */
+       source = (struct ell_event_source *) g_source_new(&event_funcs,
+                       sizeof(struct ell_event_source));
+
+       source->pollfd.fd = l_main_get_epoll_fd();
+       source->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+
+       g_source_add_poll((GSource *)source, &source->pollfd);
+       g_source_attach((GSource *) source,
+                       g_main_loop_get_context(main_loop));
+
+       /* ELL End */
        g_main_loop_run(main_loop);
        BT_DBG("g_main_loop_quit called!");
 
@@ -387,12 +431,20 @@ int main(void)
 
        _bt_service_unref_connection();
 
+       /* ELL Start */
+       g_source_destroy((GSource *) source);
+       /* ELL End */
+
        if (main_loop != NULL)
                g_main_loop_unref(main_loop);
 
        if (terminated == FALSE)
                __bt_release_service();
 
+       /* ELL Start */
+       l_main_exit();
+       /* ELL End */
+
        return 0;
 }