Mesh: Create & attach ELL main loop
authorAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 18:13:57 +0000 (23:43 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 18:13:57 +0000 (23:43 +0530)
This patch primarily attaches bt-service
with ELL mainloop and also initializes OAL

Change-Id: I2cb5d5afe77051160e530ffb74d44de409d35e18
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-service/services/adapter/bt-service-core-adapter.c
bt-service/services/bt-service-main.c
bt-service/services/include/bt-service-mesh-main.h [new file with mode: 0644]

index 691bf16..cf409a0 100644 (file)
@@ -47,6 +47,7 @@
 #include <bt-hal-agent.h>
 #endif
 #include <bt-hal-hf-client.h>
+#include <bt-hal-mesh.h>
 
 #define enum_prop_to_hal(prop, hal_prop, type) do { \
        static type e; \
@@ -309,6 +310,11 @@ static const void *get_profile_interface(const char *profile_id)
        if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
                return bt_get_a2dp_sink_interface();
 
+       if (!strcmp(profile_id, BT_PROFILE_MESH_ID)) {
+               INFO("Mesh: Get MESH Stack Interface");
+               return bt_get_mesh_interface();
+       }
+
        return NULL;
 }
 
index f17dbff..ecf4aca 100644 (file)
@@ -35,6 +35,7 @@
 #include "bt-service-common.h"
 #include "bt-service-util.h"
 #include "bt-service-main.h"
+#include "bt-service-mesh-main.h"
 #include "bt-service-core-adapter.h"
 #include "bt-service-core-device.h"
 #include "bt-service-event-receiver.h"
@@ -1307,6 +1308,10 @@ int _bt_init_profiles()
        if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_audio_initialize(BT_HFP_MODULE) Failed");
 
+       /* Mesh Init */
+       ret = _bt_mesh_init();
+       if (ret != BLUETOOTH_ERROR_NONE)
+               BT_ERR("Mesh Initialization Failed!!");
        return BLUETOOTH_ERROR_NONE;
 }
 
index ea38343..782eaf2 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;
@@ -349,6 +378,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) {
@@ -374,12 +406,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 +436,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;
 }
 
diff --git a/bt-service/services/include/bt-service-mesh-main.h b/bt-service/services/include/bt-service-mesh-main.h
new file mode 100644 (file)
index 0000000..33ec0d1
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * @author: Anupam Roy <anupam.r@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef BT_SERVICE_MESH_MAIN_H_
+#define BT_SERVICE_MESH_MAIN_H_
+
+#include <glib.h>
+#include <sys/types.h>
+#include "bluetooth-api.h"
+#include "bluetooth-mesh-api.h"
+#include <json-c/json.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _bt_mesh_init(void);
+
+int _bt_mesh_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* BT_SERVICE_MESH_MAIN_H_ */