Add support for advanced service information 93/86693/1
authorYu Jiung <jiung.yu@samsung.com>
Fri, 2 Sep 2016 10:17:24 +0000 (19:17 +0900)
committerYu Jiung <jiung.yu@samsung.com>
Fri, 2 Sep 2016 10:17:28 +0000 (19:17 +0900)
Change-Id: I9103e686a0bb2365bae5d3e39d9de46352b6fc4a
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
interfaces/aspmanager-iface-service.xml
packaging/asp-manager.spec
src/asp-manager-gdbus.c
src/asp-manager.c
src/tech/asp-tech-p2p.c

index 490e85edd8476effaf1f4d34967c55b820665545..13b07f3d41cd7fdba10964583810b543b11910fb 100755 (executable)
@@ -10,6 +10,7 @@
                </method>
                <method name='CancelAdvertiseService'>
                        <arg type='u' name='adv_id' direction='in'/>
+                       <arg type='i' name='tech' direction='in'/>
                        <arg type='i' name='error_code' direction='out'/>
                </method>
                <method name='SeekService'>
index e89a1b8ff6e96ec09e158175922443a5e858b0d4..15d3de50d70ab6ba1bd203bd9ebd11b5a17c1e15 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       asp-manager
 Summary:    ASP(application service platform) manager
-Version:    0.0.1
+Version:    0.0.2
 Release:    2
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index cf9836ba21fdc1fd469c809c816c995ebdf2b993..f19e2e610971435278fe59f2dfe7c05b0a22ac93 100755 (executable)
@@ -86,19 +86,27 @@ static void __g_variant_to_g_hash_table(GVariant *variant, GHashTable* hash, boo
        GVariantIter *iter = NULL;
        GVariant* var = NULL;
        gchar *key = NULL;
-       gchar *value = NULL;
+       gchar *key_str = NULL;
+       gchar *value_str = NULL;
+       __ASP_LOG_FUNC_ENTER__;
 
        if (key_only) {
                g_variant_get(variant, "as", &iter);
-               while (g_variant_iter_loop(iter, "s", &key))
-                       g_hash_table_insert(hash, key, NULL);
+               while (g_variant_iter_loop(iter, "s", &key)) {
+                       key_str = g_strdup(key);
+                       g_hash_table_insert(hash, key_str, NULL);
+               }
        } else {
                g_variant_get(variant, "a{sv}", &iter);
                while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
-                       value = g_variant_dup_string(var, NULL);
-                       g_hash_table_insert(hash, key, value);
+
+                       key_str = g_strdup(key);
+                       value_str = g_variant_dup_string(var, NULL);
+                       g_hash_table_insert(hash, key_str, value_str);
                }
        }
+       __ASP_LOG_FUNC_EXIT__;
+       return;
 }
 
 static gboolean __asp_manager_gdbus_advertise_service(AspService *object,
@@ -156,6 +164,7 @@ static gboolean __asp_manager_gdbus_advertise_service(AspService *object,
        }
 
        result = asp_service_advertise(&service, 0);
+       g_hash_table_remove_all(service.service_info_map);
        if (result < 0) {
                ASP_LOGE("Failed to advertise service");
                ASP_RETURN_SERVICE_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
@@ -222,6 +231,7 @@ static gboolean __asp_manager_gdbus_service_status_change(AspService *object,
        }
 
        result = asp_service_advertise(&service, 1);
+       g_hash_table_remove_all(service.service_info_map);
        if (result < 0) {
                ASP_LOGE("Failed to change service status");
                ASP_RETURN_SERVICE_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
@@ -239,6 +249,7 @@ out:
 static gboolean __asp_manager_gdbus_cancel_advertise_service(AspService *object,
                GDBusMethodInvocation *invocation,
                const guint adv_id,
+               const guint tech,
                const gboolean *user_data)
 {
        __ASP_LOG_FUNC_ENTER__;
@@ -262,6 +273,7 @@ static gboolean __asp_manager_gdbus_cancel_advertise_service(AspService *object,
 
        memset(&service, 0x0, sizeof(asp_service_advertise_s));
        service.adv_id = adv_id;
+       service.discovery_tech = tech;
        result = asp_service_cancel_advertise(&service);
        if (result < 0) {
                ASP_LOGE("Failed to cancel advertise service");
@@ -318,6 +330,7 @@ static gboolean __asp_manager_gdbus_seek_service(AspService *object,
        }
 
        result = asp_service_seek(&service, &search_id);
+       g_hash_table_remove_all(service.service_info_map);
        if (result < 0) {
                ASP_LOGE("Failed to seek service");
                ASP_RETURN_SERVICE_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
@@ -349,12 +362,6 @@ static gboolean __asp_manager_gdbus_cancel_seek_service(AspService *object,
                goto out;
        }
 
-       if (search_id == 0) {
-               ASP_LOGE("Invalid parameter");
-               ASP_RETURN_SERVICE_ERR(invocation, -ASP_ERROR_INVALIED_PARAMS);
-               goto out;
-       }
-
        memset(&service, 0x0, sizeof(asp_service_seek_s));
        service.search_id = search_id;
        result = asp_service_cancel_seek(&service);
@@ -593,7 +600,7 @@ static gboolean __asp_manager_gdbus_confirm_session(AspSession *object,
        ASP_LOGD("session ID [%u] session mac [%s]", session_id, session_mac);
 
        macaddr_atoe(session_mac, mac_addr);
-       if(pin_str != NULL)
+       if (pin_str != NULL)
                pin = (guint32)atoi(pin_str);
        res = asp_session_confirm_session(mac_addr, session_id, confirmed, pin);
        if (!res) {
index 77b22047674b1376382fe7347dd2586762ba4fa5..bf690557b871b44aca473e65dc0aa3b3205eca93 100755 (executable)
@@ -64,7 +64,7 @@ static void __session_request_cb(gint32 error_code, guint8 *session_mac,
        gchar session_mac_str[MACSTR_LEN + 1] = {0,};
        gchar pin_str[MACSTR_LEN + 1] = {0,};
 
-       if(info_length != 0) {
+       if (info_length != 0) {
                session_info_str = g_try_malloc0(info_length + 1);
                memcpy(session_info_str, session_info, info_length);
        }
index e0dba8119494d8e7b5daf4217cb4794dea885511..85c7682565b54f9aa5f099d360dfb4c575f94c7b 100755 (executable)
@@ -221,8 +221,10 @@ static GVariant *__g_hash_table_to_g_variant(GHashTable *hash)
        gpointer key, value;
 
        g_hash_table_iter_init(&iter, hash);
-       while (g_hash_table_iter_next(&iter, &key, &value))
+       while (g_hash_table_iter_next(&iter, &key, &value)) {
+               ASP_LOGD("%s %s", key, value);
                g_variant_builder_add(&builder, "{sv}", key, g_variant_new_string(value));
+       }
 
        return g_variant_builder_end(&builder);
 }
@@ -231,7 +233,7 @@ static GVariant *__g_hash_keys_to_g_variant(GHashTable *hash)
 {
        GVariantBuilder builder;
 
-       g_variant_builder_init(&builder, G_VARIANT_TYPE("(as)"));
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
 
        GHashTableIter iter;
        gpointer key, value;
@@ -296,6 +298,48 @@ void asp_tech_p2p_process_deactivation(GDBusConnection *connection,
        return;
 }
 
+static void __service_info_to_g_hash(const gchar *service_info,
+               GHashTable *service_info_map)
+{
+       const gchar *key = NULL;
+       const gchar *value = NULL;
+       gsize pos = 0;
+       gsize key_length = 0;
+       gsize value_length = 0;
+       gsize info_length = 0;
+
+       info_length = strlen(service_info);
+
+       while (service_info[pos] != '\0' && pos < info_length) {
+               key = &service_info[pos];
+               while (service_info[pos] != '=' && pos < info_length) {
+                       key_length++;
+                       pos++;
+               }
+
+               if (pos >= info_length - 1) {
+                       g_hash_table_replace(service_info_map, g_strndup(key, key_length),
+                                       g_strdup(""));
+                       break;
+               }
+
+               pos++;
+               value = &service_info[pos];
+               while (service_info[pos] != ',' && pos < info_length) {
+                       value_length++;
+                       pos++;
+               }
+
+               g_hash_table_replace(service_info_map, g_strndup(key, key_length),
+                               g_strndup(value, value_length));
+               ASP_LOGD("Insert (%s, %s) to hash.", key, value);
+
+               if (service_info[pos] == ',' && pos == info_length)
+                       break;
+       }
+       return;
+}
+
 void asp_tech_p2p_process_search_result(GDBusConnection *connection,
                const gchar *object_path, GVariant *parameters)
 {
@@ -303,6 +347,7 @@ void asp_tech_p2p_process_search_result(GDBusConnection *connection,
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
+       GHashTable *service_info_map = NULL;
        asp_event_data event;
        const gchar *service_mac = NULL;
        const gchar *key = NULL;
@@ -312,7 +357,6 @@ void asp_tech_p2p_process_search_result(GDBusConnection *connection,
        guint32 advertisement_id = 0;
        guint32 config_method = 0;
        gchar *instance_name = NULL;
-       gchar *service_info = NULL;
        guint8 status = 0;
 
        if (!parameters) {
@@ -338,7 +382,12 @@ void asp_tech_p2p_process_search_result(GDBusConnection *connection,
                        instance_name = g_strdup(str);
                } else if (!g_strcmp0(key, "status")) {
                        g_variant_get(var, "y", &status);
-               }  else {
+               }  else if (!g_strcmp0(key, "service_info")) {
+                       g_variant_get(var, "&s", &str);
+                       service_info_map = g_hash_table_new_full(g_str_hash,
+                                       g_str_equal, g_free, g_free);
+                       __service_info_to_g_hash(str, service_info_map);
+               }   else {
                                ;/* Do Nothing */
                }
        }
@@ -351,12 +400,12 @@ void asp_tech_p2p_process_search_result(GDBusConnection *connection,
        memcpy(event.search_result.service_mac, service_mac, MACSTR_LEN + 1);
        event.search_result.device_name = device_name;
        event.search_result.instance_name = instance_name;
-       event.search_result.service_info = NULL;
+       event.search_result.service_info = service_info_map;
        asp_manager_event(NULL, ASP_EVENT_SEARCH_RESULT, &event);
 
        g_free(device_name);
        g_free(instance_name);
-       g_free(service_info);
+       g_hash_table_remove_all(service_info_map);
 
        __ASP_LOG_FUNC_EXIT__;
        return;
@@ -556,7 +605,7 @@ void asp_tech_p2p_process_session_peer_ip(GDBusConnection *connection,
                }
        }
 
-       if(peer_ip == NULL) {
+       if (peer_ip == NULL) {
                ASP_LOGE("Invalid peer IP address");
                return;
        }