From: Yu Jiung Date: Fri, 2 Sep 2016 10:17:24 +0000 (+0900) Subject: Add support for advanced service information X-Git-Tag: submit/tizen/20170424.082918~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efd7c7cfa3f21397f95228a308aa7b5eca07732f;p=platform%2Fcore%2Fconnectivity%2Fasp-manager.git Add support for advanced service information Change-Id: I9103e686a0bb2365bae5d3e39d9de46352b6fc4a Signed-off-by: Yu jiung --- diff --git a/interfaces/aspmanager-iface-service.xml b/interfaces/aspmanager-iface-service.xml index 490e85e..13b07f3 100755 --- a/interfaces/aspmanager-iface-service.xml +++ b/interfaces/aspmanager-iface-service.xml @@ -10,6 +10,7 @@ + diff --git a/packaging/asp-manager.spec b/packaging/asp-manager.spec index e89a1b8..15d3de5 100755 --- a/packaging/asp-manager.spec +++ b/packaging/asp-manager.spec @@ -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 diff --git a/src/asp-manager-gdbus.c b/src/asp-manager-gdbus.c index cf9836b..f19e2e6 100755 --- a/src/asp-manager-gdbus.c +++ b/src/asp-manager-gdbus.c @@ -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) { diff --git a/src/asp-manager.c b/src/asp-manager.c index 77b2204..bf69055 100755 --- a/src/asp-manager.c +++ b/src/asp-manager.c @@ -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); } diff --git a/src/tech/asp-tech-p2p.c b/src/tech/asp-tech-p2p.c index e0dba81..85c7682 100755 --- a/src/tech/asp-tech-p2p.c +++ b/src/tech/asp-tech-p2p.c @@ -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; }