From: Cheoleun Moon Date: Mon, 10 Feb 2020 01:23:04 +0000 (+0900) Subject: Implement UpdateSubscribe command X-Git-Tag: submit/tizen/20200403.050222~2^2~68^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=115e5d8d043de8576c4f8b77173aaec6b69ec163;p=platform%2Fcore%2Fapi%2Fwifi-aware.git Implement UpdateSubscribe command --- diff --git a/include/wifi-aware.h b/include/wifi-aware.h index 47832eb..1fefe05 100644 --- a/include/wifi-aware.h +++ b/include/wifi-aware.h @@ -126,7 +126,7 @@ typedef void *wifi_aware_publish_h; * @brief Handle for Wi-Fi Aware configuration. * @since_tizen 6.0 */ -typedef void *wifi_aware_subscribe_config_h; +typedef void *wifi_aware_subscribe_h; /** * @brief Handle for Wi-Fi Aware peer. @@ -158,9 +158,9 @@ int wifi_aware_initialize(wifi_aware_h *wifi_aware); int wifi_aware_deinitialize(wifi_aware_h wifi_aware); /** - * @brief Create a configuration for Publish request. + * @brief Create a Publish request. * @since_tizen 6.0 - * @param[out] config + * @param[out] publish * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE * @see wifi_aware_publish_destroy @@ -168,9 +168,9 @@ int wifi_aware_deinitialize(wifi_aware_h wifi_aware); int wifi_aware_publish_create(wifi_aware_publish_h *publish); /** - * @brief Destroy a configuration for Publish request. + * @brief Destroy a Publish request. * @since_tizen 6.0 - * @param[in] config + * @param[in] publish * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE * @see wifi_aware_publish_create @@ -178,27 +178,27 @@ int wifi_aware_publish_create(wifi_aware_publish_h *publish); int wifi_aware_publish_destroy(wifi_aware_publish_h publish); /** - * @brief Create a configuration for Subscribe request. + * @brief Create a Subscribe request. * @since_tizen 6.0 - * @param[out] config + * @param[out] subscribe * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE - * @see wifi_aware_subscribe_config_destroy + * @see wifi_aware_subscribe_destroy */ -int wifi_aware_subscribe_config_create(wifi_aware_subscribe_config_h *config); +int wifi_aware_subscribe_create(wifi_aware_subscribe_h *subscribe); /** - * @brief Destroy a configuration for Subscribe request. + * @brief Destroy a Subscribe request. * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE - * @see wifi_aware_subscribe_config_create + * @see wifi_aware_subscribe_create */ -int wifi_aware_subscribe_config_destroy(wifi_aware_subscribe_config_h config); +int wifi_aware_subscribe_destroy(wifi_aware_subscribe_h subscribe); /** - * @brief + * @brief * @since_tizen 6.0 * @param[in] publish * @param[in] ttl @@ -274,86 +274,86 @@ int wifi_aware_publish_set_enable_ranging(wifi_aware_publish_h publish, bool ena // subscribe_config /** - * @brief + * @brief * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] ttl * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_ttl(wifi_aware_subscribe_config_h config, unsigned short ttl); +int wifi_aware_subscribe_set_ttl(wifi_aware_subscribe_h subscribe, unsigned short ttl); /** * @brief * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] subscribe_type * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_type(wifi_aware_subscribe_config_h config, wifi_aware_subscribe_type_e subscribe_type); +int wifi_aware_subscribe_set_type(wifi_aware_subscribe_h subscribe, wifi_aware_subscribe_type_e subscribe_type); /** * @brief Set the name of the service. The length should be less than or equal to 255 * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] service_name UTF-8 name which identifies the service * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_service_name(wifi_aware_subscribe_config_h config, const char *service_name); +int wifi_aware_subscribe_set_service_name(wifi_aware_subscribe_h subscribe, const char *service_name); /** - * @brief + * @brief * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] service_specific_info * @param[in] len * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_service_specific_info(wifi_aware_subscribe_config_h config, unsigned char *service_specific_info, size_t len); +int wifi_aware_subscribe_set_service_specific_info(wifi_aware_subscribe_h subscribe, unsigned char *service_specific_info, size_t len); /** - * @brief + * @brief * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] match_filter An ordered sequence of pairs * @param[in] len * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_match_filter(wifi_aware_subscribe_config_h config, unsigned char *match_filter, size_t len); +int wifi_aware_subscribe_set_match_filter(wifi_aware_subscribe_h subscribe, unsigned char *match_filter, size_t len); /** - * @brief + * @brief * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] distance * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_max_distance(wifi_aware_subscribe_config_h config, int distance); +int wifi_aware_subscribe_set_max_distance(wifi_aware_subscribe_h subscribe, int distance); /** - * @brief + * @brief * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] distance * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_min_distance(wifi_aware_subscribe_config_h config, int distance); +int wifi_aware_subscribe_set_min_distance(wifi_aware_subscribe_h subscribe, int distance); /** * @brief TODO (Need decision to add) Set whether notifying a termination of the service or not. * @since_tizen 6.0 - * @param[in] config + * @param[in] subscribe * @param[in] enable * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe_config_set_enable_termination_event(wifi_aware_subscribe_config_h config, bool enable); +int wifi_aware_subscribe_set_enable_termination_event(wifi_aware_subscribe_h subscribe, bool enable); /** @@ -369,11 +369,10 @@ typedef void(*wifi_aware_enabled_cb)(wifi_aware_error_e error, void *user_data); /** * @brief Enable Wi-Fi Aware functions. * If Wi-Fi Aware is already enabled, the callback to return success is immediately invoked. - * TODO (Need to fix the following policy) For an enable request when already enabled, @a config will be applied. * @remarks If the enable request is sucessfully done, the application can get the MAC address. + * TODO: Does an application need to know MAC address (NMI)? * @since_tizen 6.0 * @param[in] wifi_aware The handle for the Wi-Fi aware - * @param[in] config TODO: Need a decision whether to allow configuration for enable * @param[in] callback The result of enable request is asynchrously delivered * @param[in] user_data User data * @return 0 on success, otherwise a negative error value @@ -382,7 +381,6 @@ typedef void(*wifi_aware_enabled_cb)(wifi_aware_error_e error, void *user_data); int wifi_aware_enable(wifi_aware_h wifi_aware, wifi_aware_enabled_cb callback, void *user_data); - /** * @brief This callback delivers the result of a Publish request. * If the request is successfully done, @a publish_id is set to the Wi-Fi Aware service. @@ -417,7 +415,7 @@ int wifi_aware_start_publish(wifi_aware_h wifi_aware, * @brief Cancel a published Wi-Fi Aware service so that it cannot be found. * @since_tizen 6.0 * @param[in] wifi_aware - * @param[in] publish_id + * @param[in] publish * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ @@ -427,7 +425,6 @@ int wifi_aware_cancel_publish(wifi_aware_h wifi_aware, wifi_aware_publish_h publ * @brief Update the configuration for a Wi-Fi Aware service that has already been published. * @since_tizen 6.0 * @param[in] wifi_aware - * @param[in] publish_id * @param[in] publish * @param[in] callback * @param[in] user_data @@ -448,31 +445,44 @@ int wifi_aware_update_publish(wifi_aware_h wifi_aware, * @retval #WIFI_AWARE_ERROR_NONE */ typedef void(*wifi_aware_subscribed_cb)(wifi_aware_error_e error, - unsigned int subscribe_id, void *user_data); + wifi_aware_subscribe_h subscribe, void *user_data); /** - * @brief Start to find Wi-Fi Aware services with configuration. + * @brief Start to find Wi-Fi Aware services. * @since_tizen 6.0 * @param[in] wifi_aware - * @param[in] config + * @param[in] subscribe * @param[in] callback * @param[in] user_data * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_subscribe(wifi_aware_h wifi_aware, wifi_aware_subscribe_config_h config, +int wifi_aware_start_subscribe(wifi_aware_h wifi_aware, wifi_aware_subscribe_h subscribe, wifi_aware_subscribed_cb callback, void *user_data); /** * @brief Stop finding Wi-Fi Aware services. * @since_tizen 6.0 * @param[in] wifi_aware - * @param[in] subscribe_id + * @param[in] subscribe * @return 0 on success, otherwise a negative error value * @retval #WIFI_AWARE_ERROR_NONE */ -int wifi_aware_cancel_subscribe(wifi_aware_h wifi_aware, - unsigned int subscribe_id); +int wifi_aware_cancel_subscribe(wifi_aware_h wifi_aware, wifi_aware_subscribe_h subscribe); + +/** + * @brief Update the configuration for a Wi-Fi Aware service that has already been subscribed. + * @since_tizen 6.0 + * @param[in] wifi_aware + * @param[in] subscribe + * @param[in] callback + * @param[in] user_data + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_AWARE_ERROR_NONE + */ +int wifi_aware_update_subscribe(wifi_aware_h wifi_aware, + wifi_aware_subscribe_h subscribe, + wifi_aware_subscribed_cb callback, void *user_data); /** * @brief diff --git a/src/wifi-aware-gdbus.c b/src/wifi-aware-gdbus.c index ed46004..a19cd11 100644 --- a/src/wifi-aware-gdbus.c +++ b/src/wifi-aware-gdbus.c @@ -29,6 +29,7 @@ #include "wifi-aware.h" #include "wifi-aware-private.h" #include "wifi-aware-publish-private.h" +#include "wifi-aware-subscribe-private.h" #include "wifi-aware-utils.h" #include "wifi-aware-gdbus.h" @@ -314,6 +315,27 @@ static GVariant *__create_cancel_subscribe_request_param(int client_id, unsigned return g_variant_new("(iu)", client_id, sub_id); } +static GVariant *__create_update_subscribe_request_param(int client_id, + unsigned int sub_id, wifi_aware_subscribe_request_s *req) +{ + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "ttl", g_variant_new("q", req->ttl)); + g_variant_builder_add(builder, "{sv}", "subscribe_type", g_variant_new("y", req->subscribe_type)); + g_variant_builder_add(builder, "{sv}", "service_name", g_variant_new("s", req->service_name)); + g_variant_builder_add(builder, "{sv}", "specific_info", g_variant_new("s", req->specific_info)); + g_variant_builder_add(builder, "{sv}", "specific_info_len", g_variant_new("q", req->specific_info_len)); + g_variant_builder_add(builder, "{sv}", "match_filter", g_variant_new("s", req->match_filter)); + g_variant_builder_add(builder, "{sv}", "match_filter_len", g_variant_new("q", req->match_filter_len)); + g_variant_builder_add(builder, "{sv}", "enable_termination_event", g_variant_new("b", req->enable_termination_event)); + + params = g_variant_new("(iua{sv})", client_id, sub_id, builder); + g_variant_builder_unref(builder); + return params; +} + int wifi_aware_gdbus_enable(wifi_aware_h wifi_aware, wifi_aware_enable_request_s *req, GAsyncReadyCallback cb) { @@ -381,7 +403,7 @@ int wifi_aware_gdbus_cancel_publish(wifi_aware_publish_h publish, int client_id) unsigned int pub_id = _wifi_aware_publish_get_id(publish); if (pub_id == 0) { - WIFI_AWARE_LOGE("Invalid Publish Id."); + WIFI_AWARE_LOGE("Invalid Publish Id"); return WIFI_AWARE_ERROR_INVALID_PARAMETER; } @@ -430,12 +452,12 @@ int wifi_aware_gdbus_update_publish(wifi_aware_publish_h publish, int client_id, return ret; } -int wifi_aware_gdbus_subscribe(wifi_aware_h wifi_aware, int client_id, - wifi_aware_subscribe_request_s *req, GAsyncReadyCallback cb) +int wifi_aware_gdbus_subscribe(wifi_aware_subscribe_h subscribe, int client_id, GAsyncReadyCallback cb) { __WIFI_AWARE_FUNC_ENTER__; GVariant *params = NULL; int ret = WIFI_AWARE_ERROR_NONE; + wifi_aware_subscribe_request_s *req = _wifi_aware_subscribe_get_request(subscribe); params = __create_subscribe_request_param(client_id, req); DBUS_DEBUG_VARIANT(params); @@ -443,7 +465,7 @@ int wifi_aware_gdbus_subscribe(wifi_aware_h wifi_aware, int client_id, ret = __wifi_aware_dbus_method_call_async( WIFI_AWARE_DISCOVERY_INTERFACE, WIFI_AWARE_DISCOVERY_PATH, - "Subscribe", params, cb, wifi_aware); + "Subscribe", params, cb, subscribe); RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Subscribe failed"); @@ -460,13 +482,18 @@ static int __handle_cancel_subscribe_reply(GVariant *reply) return error; } -int wifi_aware_gdbus_cancel_subscribe(wifi_aware_h wifi_aware, int client_id, - unsigned int sub_id) +int wifi_aware_gdbus_cancel_subscribe(wifi_aware_subscribe_h subscribe, int client_id) { __WIFI_AWARE_FUNC_ENTER__; GVariant *params = NULL; GVariant *reply = NULL; int ret = WIFI_AWARE_ERROR_NONE; + unsigned int sub_id = _wifi_aware_subscribe_get_id(subscribe); + + if (sub_id == 0) { + WIFI_AWARE_LOGE("Invalid Subscribe Id"); + return WIFI_AWARE_ERROR_INVALID_PARAMETER; + } params = __create_cancel_subscribe_request_param(client_id, sub_id); DBUS_DEBUG_VARIANT(params); @@ -485,3 +512,31 @@ int wifi_aware_gdbus_cancel_subscribe(wifi_aware_h wifi_aware, int client_id, __WIFI_AWARE_FUNC_EXIT__; return ret; } + +int wifi_aware_gdbus_update_subscribe(wifi_aware_subscribe_h subscribe, int client_id, GAsyncReadyCallback cb) +{ + __WIFI_AWARE_FUNC_ENTER__; + GVariant *params = NULL; + int ret = WIFI_AWARE_ERROR_NONE; + wifi_aware_subscribe_request_s *req = _wifi_aware_subscribe_get_request(subscribe); + unsigned int sub_id = _wifi_aware_subscribe_get_id(subscribe); + + if (sub_id == 0) { + WIFI_AWARE_LOGE("Invalid Publish Id."); + return WIFI_AWARE_ERROR_INVALID_PARAMETER; + } + + params = __create_update_subscribe_request_param(client_id, sub_id, req); + DBUS_DEBUG_VARIANT(params); + + ret = __wifi_aware_dbus_method_call_async( + WIFI_AWARE_DISCOVERY_INTERFACE, + WIFI_AWARE_DISCOVERY_PATH, + "UpdateSubscribe", params, cb, subscribe); + + RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Subscribe failed"); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + diff --git a/src/wifi-aware-private.c b/src/wifi-aware-private.c index 26175cd..bdeab78 100644 --- a/src/wifi-aware-private.c +++ b/src/wifi-aware-private.c @@ -33,6 +33,7 @@ #include "wifi-aware-peer.h" #include "wifi-aware-private.h" #include "wifi-aware-publish-private.h" +#include "wifi-aware-subscribe-private.h" #include "wifi-aware-utils.h" typedef struct { @@ -154,6 +155,12 @@ bool _wifi_aware_handle_is_valid(wifi_aware_h wifi_aware) return true; } +static int __get_client_id(wifi_aware_h wifi_aware) +{ + wifi_aware_s *aware = (wifi_aware_s *)wifi_aware; + return aware->client_id; +} + static wifi_aware_error_e __parse_enable_reply(GVariant *reply, wifi_aware_s *aware) { int error; @@ -199,10 +206,7 @@ static void __publish_request_reply(GObject *src, GAsyncResult *res, gpointer us conn = G_DBUS_CONNECTION(src); reply = g_dbus_connection_call_finish(conn, res, &dbus_error); - if (reply == NULL) { - WIFI_AWARE_LOGE("reply is NULL"); - return; - } + RET_IF(reply == NULL, "reply is NULL"); if (dbus_error != NULL) { WIFI_AWARE_LOGE("Publish Request failure: %s", dbus_error->message); @@ -211,7 +215,7 @@ static void __publish_request_reply(GObject *src, GAsyncResult *res, gpointer us } else { g_variant_get(reply, "(ui)", &publish_id, &error); - WIFI_AWARE_LOGI("Publish ID: %u error: %d", publish_id, error); + WIFI_AWARE_LOGI("Publish ID: %u, error: %d", publish_id, error); } _wifi_aware_publish_set_id(publish, publish_id); @@ -223,7 +227,7 @@ static void __subscribe_request_reply(GObject *src, GAsyncResult *res, gpointer GDBusConnection *conn = NULL; GError *dbus_error = NULL; GVariant *reply = NULL; - wifi_aware_s *aware = (wifi_aware_s *)user_data; + wifi_aware_subscribe_h subscribe = (wifi_aware_subscribe_h)user_data; wifi_aware_error_e error = WIFI_AWARE_ERROR_NONE; unsigned int subscribe_id = -1; @@ -231,6 +235,7 @@ static void __subscribe_request_reply(GObject *src, GAsyncResult *res, gpointer conn = G_DBUS_CONNECTION(src); reply = g_dbus_connection_call_finish(conn, res, &dbus_error); + RET_IF(reply == NULL, "reply is NULL"); if (dbus_error != NULL) { WIFI_AWARE_LOGE("Subscribe Request failure: %s", dbus_error->message); @@ -239,11 +244,11 @@ static void __subscribe_request_reply(GObject *src, GAsyncResult *res, gpointer } else { g_variant_get(reply, "(ui)", &subscribe_id, &error); - WIFI_AWARE_LOGI("Subscribe ID: %u", subscribe_id); + WIFI_AWARE_LOGI("Subscribe ID: %u, error: %d", subscribe_id, error); } - if (aware->subscribed_cb) - aware->subscribed_cb(error, subscribe_id, aware->subscribed_cb_data); + _wifi_aware_subscribe_set_id(subscribe, subscribe_id); + _wifi_aware_subscribe_invoke_callback(error, subscribe); } int _wifi_aware_handle_create(wifi_aware_h *wifi_aware) @@ -319,38 +324,47 @@ int _wifi_aware_enable_request(wifi_aware_h wifi_aware) int _wifi_aware_publish_request(wifi_aware_h wifi_aware, wifi_aware_publish_h publish) { - wifi_aware_s *aware = (wifi_aware_s *)wifi_aware; - return wifi_aware_gdbus_publish(publish, aware->client_id, __publish_request_reply); + return wifi_aware_gdbus_publish(publish, + __get_client_id(wifi_aware), + __publish_request_reply); } int _wifi_aware_cancel_publish_request(wifi_aware_h wifi_aware, wifi_aware_publish_h publish) { - wifi_aware_s *aware = (wifi_aware_s *)wifi_aware; - return wifi_aware_gdbus_cancel_publish(publish, aware->client_id); + return wifi_aware_gdbus_cancel_publish(publish, + __get_client_id(wifi_aware)); } int _wifi_aware_update_publish_request(wifi_aware_h wifi_aware, wifi_aware_publish_h publish) { - wifi_aware_s *aware = (wifi_aware_s *)wifi_aware; - return wifi_aware_gdbus_update_publish(publish, aware->client_id, __publish_request_reply); + return wifi_aware_gdbus_update_publish(publish, + __get_client_id(wifi_aware), + __publish_request_reply); } int _wifi_aware_subscribe_request(wifi_aware_h wifi_aware, - wifi_aware_subscribe_config_h config) + wifi_aware_subscribe_h subscribe) { - wifi_aware_s *aware = (wifi_aware_s *)wifi_aware; - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; - return wifi_aware_gdbus_subscribe(wifi_aware, aware->client_id, - req, __subscribe_request_reply); + return wifi_aware_gdbus_subscribe(subscribe, + __get_client_id(wifi_aware), + __subscribe_request_reply); } int _wifi_aware_cancel_subscribe_request(wifi_aware_h wifi_aware, - unsigned int sub_id) + wifi_aware_subscribe_h subscribe) { - wifi_aware_s *aware = (wifi_aware_s *)wifi_aware; - return wifi_aware_gdbus_cancel_subscribe(wifi_aware, aware->client_id, sub_id); + return wifi_aware_gdbus_cancel_subscribe(subscribe, + __get_client_id(wifi_aware)); +} + +int _wifi_aware_update_subscribe_request(wifi_aware_h wifi_aware, + wifi_aware_subscribe_h subscribe) +{ + return wifi_aware_gdbus_update_subscribe(subscribe, + __get_client_id(wifi_aware), + __subscribe_request_reply); } void _set_discovery_result_cb(wifi_aware_h wifi_aware, diff --git a/src/wifi-aware-publish.c b/src/wifi-aware-publish.c index d1b44d8..03b6615 100644 --- a/src/wifi-aware-publish.c +++ b/src/wifi-aware-publish.c @@ -32,6 +32,7 @@ #include "wifi-aware-gdbus.h" #include "wifi-aware-log.h" #include "wifi-aware-private.h" +#include "wifi-aware-publish-private.h" #include "wifi-aware-utils.h" typedef struct { @@ -289,4 +290,3 @@ API int wifi_aware_update_publish(wifi_aware_h wifi_aware, __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } - diff --git a/src/wifi-aware-subscribe.c b/src/wifi-aware-subscribe.c index b5867fb..5e670f2 100644 --- a/src/wifi-aware-subscribe.c +++ b/src/wifi-aware-subscribe.c @@ -28,18 +28,32 @@ #include "wifi-aware.h" -#include "wifi-aware-config.h" +#include "wifi-aware-handle.h" #include "wifi-aware-gdbus.h" #include "wifi-aware-log.h" #include "wifi-aware-private.h" +#include "wifi-aware-subscribe-private.h" #include "wifi-aware-utils.h" +typedef struct { + uint32_t subscribe_id; + wifi_aware_subscribe_request_s req; -static void __wifi_aware_subscribe_config_set_default_values( - wifi_aware_subscribe_config_h *config) + wifi_aware_subscribed_cb subscribed_cb; + void *subscribed_cb_data; +} wifi_aware_subscribe_s; + +static void __add_subscribed_callback(wifi_aware_subscribe_h subscribe, + wifi_aware_subscribed_cb callback, void *user_data) +{ + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + handle->subscribed_cb = callback; + handle->subscribed_cb_data = user_data; +} + +static void __wifi_aware_subscribe_set_default_values( + wifi_aware_subscribe_request_s *req) { - wifi_aware_subscribe_request_s *req = - (wifi_aware_subscribe_request_s *)config; req->ttl = 0; req->subscribe_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE; //memset(req->specific_info[WIFI_AWARE_MAX_SERVICE_SPECIFIC_INFO_LEN], 0, WIFI_AWARE_MAX_SERVICE_SPECIFIC_INFO_LEN); @@ -49,72 +63,108 @@ static void __wifi_aware_subscribe_config_set_default_values( req->enable_termination_event = false; } -API int wifi_aware_subscribe_config_create( - wifi_aware_subscribe_config_h *config) +wifi_aware_subscribe_request_s *_wifi_aware_subscribe_get_request(wifi_aware_subscribe_h subscribe) +{ + RET_VAL_IF(subscribe == NULL, NULL, "wifi_aware_subscribe_h is NULL"); + + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + return &(handle->req); +} + +unsigned int _wifi_aware_subscribe_get_id(wifi_aware_subscribe_h subscribe) +{ + RET_VAL_IF(subscribe == NULL, 0, "wifi_aware_subscribe_h is NULL"); + + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + return handle->subscribe_id; +} + +void _wifi_aware_subscribe_invoke_callback(wifi_aware_error_e error, wifi_aware_subscribe_h subscribe) +{ + RET_IF(subscribe == NULL, "wifi_aware_subscribe_h is NULL"); + + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + if (handle->subscribed_cb) + handle->subscribed_cb(error, subscribe, handle->subscribed_cb_data); +} + +void _wifi_aware_subscribe_set_id(wifi_aware_subscribe_h subscribe, unsigned int subscribe_id) +{ + RET_IF(subscribe == NULL, "wifi_aware_subscribe_h is NULL"); + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + handle->subscribe_id = subscribe_id; +} + +API int wifi_aware_subscribe_create( + wifi_aware_subscribe_h *subscribe) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - *config = g_try_malloc0(sizeof(wifi_aware_subscribe_request_s)); - __wifi_aware_subscribe_config_set_default_values(config); + wifi_aware_subscribe_s *handle = + (wifi_aware_subscribe_s *) g_try_malloc0(sizeof(wifi_aware_subscribe_s)); + RET_VAL_IF(handle == NULL, WIFI_AWARE_ERROR_OUT_OF_MEMORY, "Out of memory"); + + __wifi_aware_subscribe_set_default_values(&handle->req); + *subscribe = (wifi_aware_subscribe_h)handle; __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_destroy( - wifi_aware_subscribe_config_h config) +API int wifi_aware_subscribe_destroy( + wifi_aware_subscribe_h subscribe) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - g_free(config); + g_free(subscribe); __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_set_ttl( - wifi_aware_subscribe_config_h config, +API int wifi_aware_subscribe_set_ttl( + wifi_aware_subscribe_h subscribe, unsigned short ttl) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; - req->ttl = ttl; + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + handle->req.ttl = ttl; __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_set_type( - wifi_aware_subscribe_config_h config, +API int wifi_aware_subscribe_set_type( + wifi_aware_subscribe_h subscribe, wifi_aware_subscribe_type_e subscribe_type) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; - req->subscribe_type = subscribe_type; + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + handle->req.subscribe_type = subscribe_type; __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_set_service_name( - wifi_aware_subscribe_config_h config, +API int wifi_aware_subscribe_set_service_name( + wifi_aware_subscribe_h subscribe, const char *service_name) { __WIFI_AWARE_FUNC_ENTER__; int len = 0; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; len = strlen(service_name); if (len > WIFI_AWARE_MAX_SERVICE_NAME_LEN) { WIFI_AWARE_LOGE("The length of service_name should be equal to or less than %d", @@ -122,61 +172,61 @@ API int wifi_aware_subscribe_config_set_service_name( return WIFI_AWARE_ERROR_INVALID_PARAMETER; } - strncpy(req->service_name, service_name, WIFI_AWARE_MAX_SERVICE_NAME_LEN); + strncpy(handle->req.service_name, service_name, WIFI_AWARE_MAX_SERVICE_NAME_LEN); __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_set_service_specific_info( - wifi_aware_subscribe_config_h config, +API int wifi_aware_subscribe_set_service_specific_info( + wifi_aware_subscribe_h subscribe, unsigned char *service_specific_info, size_t len) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; - memcpy(req->specific_info, service_specific_info, len); - req->specific_info_len = len; + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + memcpy(handle->req.specific_info, service_specific_info, len); + handle->req.specific_info_len = len; __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_set_match_filter( - wifi_aware_subscribe_config_h config, +API int wifi_aware_subscribe_set_match_filter( + wifi_aware_subscribe_h subscribe, unsigned char *match_filter, size_t len) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; - memcpy(req->match_filter, match_filter, len); - req->match_filter_len = len; + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + memcpy(handle->req.match_filter, match_filter, len); + handle->req.match_filter_len = len; __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe_config_set_enable_termination_event( - wifi_aware_subscribe_config_h config, +API int wifi_aware_subscribe_set_enable_termination_event( + wifi_aware_subscribe_h subscribe, bool enable) { __WIFI_AWARE_FUNC_ENTER__; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - wifi_aware_subscribe_request_s *req = (wifi_aware_subscribe_request_s *)config; - req->enable_termination_event = enable; + wifi_aware_subscribe_s *handle = (wifi_aware_subscribe_s *)subscribe; + handle->req.enable_termination_event = enable; __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_subscribe(wifi_aware_h wifi_aware, - wifi_aware_subscribe_config_h config, +API int wifi_aware_start_subscribe(wifi_aware_h wifi_aware, + wifi_aware_subscribe_h subscribe, wifi_aware_subscribed_cb callback, void *user_data) { __WIFI_AWARE_FUNC_ENTER__; @@ -184,19 +234,18 @@ API int wifi_aware_subscribe(wifi_aware_h wifi_aware, CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi_aware); - RET_VAL_IF(config == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_config_h is NULL"); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); - _add_subscribed_callback(wifi_aware, callback, user_data); + __add_subscribed_callback(wifi_aware, callback, user_data); - ret = _wifi_aware_subscribe_request(wifi_aware, config); + ret = _wifi_aware_subscribe_request(wifi_aware, subscribe); RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "_wifi_aware_subscribe_request"); __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } -API int wifi_aware_cancel_subscribe(wifi_aware_h wifi_aware, - unsigned int subscribe_id) +API int wifi_aware_cancel_subscribe(wifi_aware_h wifi_aware, wifi_aware_subscribe_h subscribe) { __WIFI_AWARE_FUNC_ENTER__; int ret = WIFI_AWARE_ERROR_NONE; @@ -204,13 +253,33 @@ API int wifi_aware_cancel_subscribe(wifi_aware_h wifi_aware, CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi_aware); - ret = _wifi_aware_cancel_subscribe_request(wifi_aware, subscribe_id); + ret = _wifi_aware_cancel_subscribe_request(wifi_aware, subscribe); RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "_wifi_aware_cancel_subscribe_request"); __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } +API int wifi_aware_update_subscribe(wifi_aware_h wifi_aware, + wifi_aware_subscribe_h subscribe, + wifi_aware_subscribed_cb callback, void *user_data) +{ + __WIFI_AWARE_FUNC_ENTER__; + int ret = WIFI_AWARE_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi_aware); + RET_VAL_IF(subscribe == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "wifi_aware_subscribe_h is NULL"); + + __add_subscribed_callback(subscribe, callback, user_data); + + ret = _wifi_aware_update_subscribe_request(wifi_aware, subscribe); + RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "_wifi_aware_update_subscribe_request"); + + __WIFI_AWARE_FUNC_EXIT__; + return WIFI_AWARE_ERROR_NONE; +} + API int wifi_aware_set_discovery_result_cb(wifi_aware_h wifi_aware, wifi_aware_discovery_result_cb callback, void *user_data) { diff --git a/test/wifi-aware-test.c b/test/wifi-aware-test.c index 0032337..ddac669 100644 --- a/test/wifi-aware-test.c +++ b/test/wifi-aware-test.c @@ -144,7 +144,7 @@ static char *g_menu_str[] = { static GMainLoop *g_main_loop_p; static wifi_aware_h g_wifi_aware_handle = NULL; static wifi_aware_publish_h g_publish_handle = NULL; -static unsigned int g_sub_id; +static wifi_aware_subscribe_h g_subscribe_handle = NULL; /***************************************************************************** * Local Functions Definition @@ -385,7 +385,7 @@ static int __set_match_filter(unsigned char match_filter[MAX_MATCH_FILTER_LEN + return total_len; } -static void __set_publish_config(wifi_aware_publish_h config) +static void __set_publish_config(wifi_aware_publish_h publish) { int ret = 0; int publish_type = 0; @@ -400,21 +400,21 @@ static void __set_publish_config(wifi_aware_publish_h config) if (ret < 0) return; - ret = wifi_aware_publish_set_type(config, + ret = wifi_aware_publish_set_type(publish, publish_type ? WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED : WIFI_AWARE_PUBLISH_TYPE_SOLICITED); if (ret != WIFI_AWARE_ERROR_NONE) return; strncpy(service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN); - ret = wifi_aware_publish_set_service_name(config, + ret = wifi_aware_publish_set_service_name(publish, service_name); if (ret != WIFI_AWARE_ERROR_NONE) return; len = strlen(PUB_SSI); memcpy(specific_info, PUB_SSI, len); - ret = wifi_aware_publish_set_service_specific_info(config, + ret = wifi_aware_publish_set_service_specific_info(publish, specific_info, len); if (ret != WIFI_AWARE_ERROR_NONE) return; @@ -428,7 +428,7 @@ static void __set_publish_config(wifi_aware_publish_h config) return; } __print_match_filter(match_filter, len); - ret = wifi_aware_publish_set_match_filter(config, match_filter, len); + ret = wifi_aware_publish_set_match_filter(publish, match_filter, len); if (ret != WIFI_AWARE_ERROR_NONE) return; } @@ -437,21 +437,21 @@ static void __set_publish_config(wifi_aware_publish_h config) void test_publish() { int ret = 0; - wifi_aware_publish_h config = NULL; + wifi_aware_publish_h publish = NULL; RET_IF_LOOP_IS_NULL(); RET_IF_HANDLE_IS_NULL(); - ret = wifi_aware_publish_create(&config); + ret = wifi_aware_publish_create(&publish); __print_result(ret, "wifi_aware_publish_create"); - __set_publish_config(config); + __set_publish_config(publish); - g_publish_handle = config; - ret = wifi_aware_start_publish(g_wifi_aware_handle, config, __published_cb, NULL); + g_publish_handle = publish; + ret = wifi_aware_start_publish(g_wifi_aware_handle, publish, __published_cb, NULL); __print_result(ret, "wifi_aware_publish"); - //ret = wifi_aware_publish_destroy(config); + //ret = wifi_aware_publish_destroy(publish); //__print_result(ret, "wifi_aware_publish_destroy"); } @@ -483,7 +483,6 @@ void test_update_publish() { int ret = 0; char service_name[MAX_SERVICE_NAME_LEN + 1] = {0, }; - size_t len = 0; RET_IF_LOOP_IS_NULL(); RET_IF_HANDLE_IS_NULL(); @@ -503,12 +502,10 @@ void test_update_publish() __print_result(ret, "wifi_aware_update_publish"); } -static void __subscribed_cb(wifi_aware_error_e error, unsigned int subscribe_id, void *user_data) +static void __subscribed_cb(wifi_aware_error_e error, wifi_aware_subscribe_h subscribe, void *user_data) { - g_sub_id = subscribe_id; - if (error == WIFI_AWARE_ERROR_NONE) - printf("Subscribe Request is success. Subscirbe ID: %u\n", subscribe_id); + printf("Subscribe Request is success. Subscirbe ID: [*]\n"); else printf("Subscirbe Request fails. Error: %s\n", __print_error(error)); } @@ -523,7 +520,7 @@ static void __discovery_result_cb(unsigned int subscribe_id, wifi_aware_peer_h p __print_byte_array(service_specific_info, service_specific_info_len); } -static void __set_subscribe_config(wifi_aware_subscribe_config_h config) +static void __set_subscribe_config(wifi_aware_subscribe_h subscribe) { int ret = 0; int subscribe_type = 0; @@ -538,21 +535,21 @@ static void __set_subscribe_config(wifi_aware_subscribe_config_h config) if (ret < 0) return; - ret = wifi_aware_subscribe_config_set_type(config, + ret = wifi_aware_subscribe_set_type(subscribe, subscribe_type ? WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE : WIFI_AWARE_SUBSCRIBE_TYPE_ACTIVE); if (ret != WIFI_AWARE_ERROR_NONE) return; strncpy(service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN); - ret = wifi_aware_subscribe_config_set_service_name(config, + ret = wifi_aware_subscribe_set_service_name(subscribe, service_name); if (ret != WIFI_AWARE_ERROR_NONE) return; len = strlen(SUB_SSI); memcpy(specific_info, SUB_SSI, len); - ret = wifi_aware_subscribe_config_set_service_specific_info(config, + ret = wifi_aware_subscribe_set_service_specific_info(subscribe, specific_info, len); if (ret != WIFI_AWARE_ERROR_NONE) return; @@ -565,7 +562,7 @@ static void __set_subscribe_config(wifi_aware_subscribe_config_h config) printf("Not set match filter\n"); return; } - ret = wifi_aware_subscribe_config_set_match_filter(config, match_filter, len); + ret = wifi_aware_subscribe_set_match_filter(subscribe, match_filter, len); if (ret != WIFI_AWARE_ERROR_NONE) return; } @@ -574,7 +571,7 @@ static void __set_subscribe_config(wifi_aware_subscribe_config_h config) void test_subscribe() { int ret = 0; - wifi_aware_subscribe_config_h config = NULL; + wifi_aware_subscribe_h subscribe = NULL; RET_IF_LOOP_IS_NULL(); RET_IF_HANDLE_IS_NULL(); @@ -582,16 +579,16 @@ void test_subscribe() ret = wifi_aware_set_discovery_result_cb(g_wifi_aware_handle, __discovery_result_cb, NULL); __print_result(ret, "wifi_aware_set_discovery_result_cb"); - ret = wifi_aware_subscribe_config_create(&config); - __print_result(ret, "wifi_aware_subscribe_config_create"); + ret = wifi_aware_subscribe_create(&subscribe); + __print_result(ret, "wifi_aware_subscribe_create"); - __set_subscribe_config(config); + __set_subscribe_config(subscribe); - ret = wifi_aware_subscribe(g_wifi_aware_handle, config, __subscribed_cb, NULL); + ret = wifi_aware_start_subscribe(g_wifi_aware_handle, subscribe, __subscribed_cb, NULL); __print_result(ret, "wifi_aware_subscribe"); - ret = wifi_aware_subscribe_config_destroy(config); - __print_result(ret, "wifi_aware_subscribe_config_destroy"); + ret = wifi_aware_subscribe_destroy(subscribe); + __print_result(ret, "wifi_aware_subscribe_destroy"); } void test_cancel_subscribe() @@ -601,12 +598,12 @@ void test_cancel_subscribe() RET_IF_LOOP_IS_NULL(); RET_IF_HANDLE_IS_NULL(); - if (g_sub_id < 1) { + if (g_subscribe_handle == NULL) { printf("subscribe should be done\n"); return; } - ret = wifi_aware_cancel_subscribe(g_wifi_aware_handle, g_sub_id); + ret = wifi_aware_cancel_subscribe(g_wifi_aware_handle, g_subscribe_handle); __print_result(ret, "wifi_aware_cancel_subscribe"); }