Add 'MESH_CONNECTED_EVENT' event handler
authorJiwan Kim <ji-wan.kim@samsung.com>
Wed, 7 Jun 2017 02:22:09 +0000 (11:22 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:09:10 +0000 (11:09 +0900)
- Handle 'mesh_connected' signal

include/mesh.h
src/mesh_dbus.c
test/main.c

index 28df4d9bf6a8a4304c2a7ea334196394b89c2e7d..0d6d2514277e569b0d958439ffa1d43e33af4b7c 100644 (file)
@@ -108,6 +108,7 @@ typedef enum {
        MESH_LEFT_NETWORK_EVENT = 0x03, /**< This event comes after left the current mesh network */
        MESH_STATION_JOIN_EVENT = 0x04, /**< This event takes place when new station joined */
        MESH_STATION_LEFT_EVENT = 0x05, /**< This event takes place when existing station left */
+       MESH_CONNECTED_EVENT = 0x06, /**< This event comes after all network connection sequence finished */
 } mesh_event_e;
 
 /**
@@ -117,7 +118,7 @@ typedef enum {
  * @since_tizen 4.0
  */
 typedef struct {
-       unsigned int result; /**< The result of creating or joining mesh network */
+       int result; /**< The result of creating or joining mesh network */
 } mesh_mesh_enabled_event_s;
 
 /**
@@ -130,6 +131,16 @@ typedef struct {
        char bssid[MAX_BSSID_LEN]; /**< The BSSID of the station that generated the event */
 } mesh_other_station_event_s;
 
+/**
+ * @brief The structure type for the MESH_CONNECTED_EVENT callback data.
+ * @details The result of connecting mesh network.
+ *
+ * @since_tizen 4.0
+ */
+typedef struct {
+       int result; /**< The result of connecting mesh network. */
+} mesh_connected_event_s;
+
 /**
  * @brief The structure type for response data of mesh_event_cb.
  * @details This function can receive events from the devices in the network.
@@ -139,8 +150,9 @@ typedef struct {
  */
 typedef struct {
        union {
-               mesh_mesh_enabled_event_s *mesh_enable; /**< The result of enabling zigbee system service. */
+               mesh_mesh_enabled_event_s *mesh_enable; /**< The result of enabling mesh system service. */
                mesh_other_station_event_s *sta_info; /**< This event comes from other stations. */
+               mesh_connected_event_s *connected_result; /**< The result of mesh network connection. */
        } data;
 } mesh_event_data_s;
 
index ff793261baec54c98467ec2457f1859daf2e5a71..9792e5002bc5084bb06f0115bc41fbd1a7f2471d 100644 (file)
@@ -291,21 +291,34 @@ static void _mesh_signal_handler(GDBusConnection *connection,
 
        if (0 == g_strcmp0(signal_name, "mesh_enabled")) {
                int result = MESH_ERROR_NONE;
+               mesh_event_data_s ev;
+
                g_variant_get(parameters, "(i)", &result);
-               result = __convert_service_error_type(result);
 
-               mesh_event_data_s ev;
                ev.data.mesh_enable = calloc(1, sizeof(mesh_mesh_enabled_event_s));
                RETM_IF(NULL == ev.data.mesh_enable, "Failed to memory allocation !");
-               ev.data.mesh_enable->result = result;
+               ev.data.mesh_enable->result = __convert_service_error_type(result);
+
                h->event_handler(MESH_MESH_ENABLED_EVENT, &ev);
-               g_free(ev.data.mesh_enable);
+               free(ev.data.mesh_enable);
        } else if (0 == g_strcmp0(signal_name, "scan_done")) {
                h->event_handler(MESH_SCAN_DONE_EVENT, NULL);
        } else if (0 == g_strcmp0(signal_name, "joined_network")) {
                h->event_handler(MESH_JOIN_NETWORK_EVENT, NULL);
        } else if (0 == g_strcmp0(signal_name, "left_network")) {
                h->event_handler(MESH_LEFT_NETWORK_EVENT, NULL);
+       } else if (0 == g_strcmp0(signal_name, "mesh_connected")) {
+               int result = MESH_ERROR_NONE;
+               mesh_event_data_s ev;
+
+               g_variant_get(parameters, "(i)", &result);
+
+               ev.data.connected_result = calloc(1, sizeof(mesh_connected_event_s));
+               RETM_IF(NULL == ev.data.connected_result, "Failed to memory allocation !");
+               ev.data.connected_result->result = __convert_service_error_type(result);
+
+               h->event_handler(MESH_CONNECTED_EVENT, &ev);
+               free(ev.data.connected_result);
        } else if (0 == g_strcmp0(signal_name, "sta_joined")) {
                char *bssid = NULL;
                mesh_event_data_s ev;
@@ -372,6 +385,15 @@ static void _mesh_subscribe_event(mesh_h handle)
        h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
        LOGD("subscribed for left_network signal %d", id);
 
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME,
+                       "mesh_connected", MESH_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL);
+       if (0 == id) {
+               LOGE("g_dbus_connection_signal_subscribe(mesh_connected) Fail(%d)", errno);
+               return;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOGD("subscribed for mesh_connected signal %d", id);
 
        id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME,
                        "sta_joined", MESH_OBJECT_PATH, NULL,
index 76aeb561098a86f00876e243ede4b88c9dcfd0cf..06b1be6bccff9b3fb4be0437a549db358def655a 100644 (file)
@@ -68,6 +68,7 @@ static const char* _mesh_event_to_string(mesh_event_e e)
        CASE_TO_STR(MESH_LEFT_NETWORK_EVENT)
        CASE_TO_STR(MESH_STATION_JOIN_EVENT)
        CASE_TO_STR(MESH_STATION_LEFT_EVENT)
+       CASE_TO_STR(MESH_CONNECTED_EVENT)
        default :
                return "MESH_EVENT_UNKNOWN";
        }
@@ -97,6 +98,10 @@ void event_cb(mesh_event_e event_type, mesh_event_data_s* event)
                case MESH_STATION_LEFT_EVENT: {
                        msgp("  A Station Left = %s", event->data.sta_info->bssid);
                } break;
+               case MESH_CONNECTED_EVENT: {
+                       msgp("  Connection sequence finished [%s]",
+                               mesh_error_to_string(event->data.connected_result->result));
+               } break;
        }
 }