Handle bluetooth-meshd life cycle
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / mesh / bt-service-mesh-main.c
index b7969bf..167b3ba 100644 (file)
@@ -29,6 +29,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <ell/ell.h>
+#include <actd/unit_control.h>
 
 #include "bluetooth-api.h"
 #include "bt-internal-types.h"
@@ -44,6 +45,8 @@
 
 #include <oal-mesh.h>
 
+#define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service"
+
 /* Event handlers */
 static void __bt_mesh_handle_pending_request_info(int result,
                int service_function, void *param,
@@ -668,8 +671,18 @@ static void __handle_mesh_events(int event_type,
 
 int _bt_mesh_init(void)
 {
+       int ret = UNIT_CONTROL_OK;
        oal_status_t status = OAL_STATUS_SUCCESS;
 
+       /* Launch bluetooth-meshd */
+       ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+                               MESH_SYSTEMD_SERVICE_NAME, 5000);
+
+       if (ret != UNIT_CONTROL_OK) {
+               BT_ERR("Failed to call systemact service: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
        status = mesh_enable();
        if (OAL_STATUS_SUCCESS != status) {
                BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
@@ -688,6 +701,14 @@ int _bt_mesh_init(void)
 int _bt_mesh_deinit(void)
 {
        oal_status_t status = OAL_STATUS_SUCCESS;
+       int ret = UNIT_CONTROL_OK;
+
+       /* Terminate bluetooth-meshd */
+       ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+                       MESH_SYSTEMD_SERVICE_NAME, 5000);
+
+       if (ret != UNIT_CONTROL_OK)
+               BT_ERR("Failed to call systemact service: %d", ret);
 
        status = mesh_disable();
        if (OAL_STATUS_SUCCESS != status) {