#include <oal-mesh.h>
#define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service"
+#define MESH_LAUNCH_DELAY 500
+
+static guint launch_timer = 0;
/* Event handlers */
static void __bt_mesh_handle_pending_request_info(int result,
continue;
switch (service_function) {
+ case BT_MESH_INIT: {
+ BT_INFO("Mesh: Request: BT_MESH_INIT Sender: [%s] result[%d]",
+ req_info->sender, result);
+ out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+ _bt_service_method_return(req_info->context,
+ out_param, result);
+ _bt_free_info_from_invocation_list(req_info);
+ break;
+ }
case BT_MESH_NETWORK_CREATE: {
char uuid_str[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
bluetooth_mesh_node_t *node;
}
}
-int _bt_mesh_init(void)
+static int __bt_meshd_launch()
{
int ret = UNIT_CONTROL_OK;
- oal_status_t status = OAL_STATUS_SUCCESS;
-
- /* Launch bluetooth-meshd */
+ BT_INFO("Mesh: Launch Meshd");
ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
MESH_SYSTEMD_SERVICE_NAME, 5000);
BT_ERR("Failed to call systemact service: %d", ret);
return BLUETOOTH_ERROR_INTERNAL;
}
+ BT_INFO("Mesh: Launch Meshd successful");
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_mesh_enable()
+{
+ oal_status_t status = OAL_STATUS_SUCCESS;
+ BT_INFO("Mesh: Set dbus callbacks");
status = mesh_enable();
if (OAL_STATUS_SUCCESS != status) {
- BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
+ BT_ERR("Mesh: Failed to enable mesh interface, status: %d",
status);
return BLUETOOTH_ERROR_INTERNAL;
}
return BLUETOOTH_ERROR_NONE;
}
+static gboolean __bt_mesh_launch_timer_expired_cb(gpointer data)
+{
+ BT_INFO("Mesh: Enable Mesh dbus");
+ int ret = BLUETOOTH_ERROR_NONE;
+ ret = __bt_mesh_enable();
+ if (BLUETOOTH_ERROR_NONE != ret)
+ BT_ERR("Mesh: Mesh enable failed: %d", ret);
+
+ /* Handle DBUS Context return */
+ BT_INFO("Mesh: Handle DBUS Context return");
+ __bt_mesh_handle_pending_request_info(ret,
+ BT_MESH_INIT,
+ NULL, 0);
+ return FALSE;
+}
+
+int _bt_mesh_init(void)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ if (launch_timer > 0) {
+ BT_INFO("Mesh: BT_MESH_INIT in progress");
+ return ret;
+ }
+
+ /* Launch bluetooth-meshd */
+ ret = __bt_meshd_launch();
+ if (BLUETOOTH_ERROR_NONE != ret) {
+ BT_ERR("Mesh: Meshd launch failed: %d", ret);
+ return ret;
+ }
+
+ /* wait for half a second*/
+ launch_timer = g_timeout_add(MESH_LAUNCH_DELAY,
+ (GSourceFunc)__bt_mesh_launch_timer_expired_cb,
+ NULL);
+
+ return ret;
+}
+
int _bt_mesh_deinit(void)
{
oal_status_t status = OAL_STATUS_SUCCESS;