Add wifi_aware_peer_clone and wifi_aware_peer_destroy APIs
authorCheoleun Moon <chleun.moon@samsung.com>
Wed, 18 Mar 2020 12:38:58 +0000 (21:38 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Wed, 18 Mar 2020 12:38:58 +0000 (21:38 +0900)
include/wifi-aware.h
src/include/wifi-aware-peer.h
src/wifi-aware-peer.c
src/wifi-aware.c

index 68aeca1..86c958b 100644 (file)
@@ -631,6 +631,25 @@ int wifi_aware_session_set_message_received_cb(wifi_aware_session_h session,
 int wifi_aware_session_unset_message_received_cb(wifi_aware_session_h session);
 
 /**
+ * @brief
+ * @since_tizen 6.0
+ * @param[out] cloned
+ * @param[in] origin
+ * @return     0 on success, otherwise a negative error value
+ * @retval     #WIFI_AWARE_ERROR_NONE
+ */
+int wifi_aware_peer_clone(wifi_aware_peer_h *cloned, wifi_aware_peer_h origin);
+
+/**
+ * @brief
+ * @since_tizen 6.0
+ * @param[in] peer
+ * @return     0 on success, otherwise a negative error value
+ * @retval     #WIFI_AWARE_ERROR_NONE
+ */
+int wifi_aware_peer_destroy(wifi_aware_peer_h peer);
+
+/**
  * @brief Get the MAC address (NAN Management Interface) of Wi-Fi Aware peer.
  * @remarks @a mac should be freed using free().
  * @since_tizen 6.0
index 23a7fb3..c4e2bac 100644 (file)
@@ -28,6 +28,7 @@ extern "C" {
 #define WIFI_AWARE_MAC_ADDRESS_LEN 6
 int _wifi_aware_peer_create(wifi_aware_peer_h *peer, unsigned int peer_id);
 void _wifi_aware_peer_destroy(wifi_aware_peer_h peer);
+int _wifi_aware_peer_clone(wifi_aware_peer_h *cloned, wifi_aware_peer_h origin);
 int _wifi_aware_peer_add(GHashTable *peer_map, wifi_aware_peer_h peer);
 int _wifi_aware_peer_remove(GHashTable *peer_map, wifi_aware_peer_h peer);
 wifi_aware_peer_h _wifi_aware_get_peer(GHashTable *peer_map, unsigned int peer_id);
index 19a7819..5432529 100644 (file)
@@ -43,6 +43,16 @@ void _wifi_aware_peer_destroy(wifi_aware_peer_h peer)
        g_free((wifi_aware_peer_s *)peer);
 }
 
+int _wifi_aware_peer_clone(wifi_aware_peer_h *cloned, wifi_aware_peer_h origin)
+{
+       wifi_aware_peer_s *cloned_handle = (wifi_aware_peer_s *)g_try_malloc0(sizeof(wifi_aware_peer_s));
+       RET_VAL_IF(cloned_handle == NULL, WIFI_AWARE_ERROR_OUT_OF_MEMORY, "g_try_malloc0 failed");
+
+       memcpy(cloned_handle, origin, sizeof(wifi_aware_peer_s));
+       *cloned = cloned_handle;
+       return WIFI_AWARE_ERROR_NONE;
+}
+
 int _wifi_aware_peer_add(GHashTable *peer_map, wifi_aware_peer_h peer)
 {
        wifi_aware_peer_s *peer_handle = (wifi_aware_peer_s *)peer;
index 33dd687..eb80dec 100644 (file)
@@ -587,6 +587,28 @@ API int wifi_aware_session_unset_message_received_cb(wifi_aware_session_h sessio
        return WIFI_AWARE_ERROR_NONE;
 }
 
+API int wifi_aware_peer_clone(wifi_aware_peer_h *cloned, wifi_aware_peer_h origin)
+{
+       __WIFI_AWARE_FUNC_ENTER__;
+       CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE);
+       RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized");
+       RET_VAL_IF(cloned == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "cloned is NULL");
+       RET_VAL_IF(origin == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "origin is NULL");
+
+       return _wifi_aware_peer_clone(cloned, origin);
+}
+
+API int wifi_aware_peer_destroy(wifi_aware_peer_h peer)
+{
+       __WIFI_AWARE_FUNC_ENTER__;
+       CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE);
+       RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized");
+       RET_VAL_IF(peer == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Peer is NULL");
+
+       _wifi_aware_peer_destroy(peer);
+       return WIFI_AWARE_ERROR_NONE;
+}
+
 API int wifi_aware_peer_get_mac(wifi_aware_peer_h peer, unsigned char **mac)
 {
        __WIFI_AWARE_FUNC_ENTER__;