Add handle for payload
authorAbhay agarwal <ay.agarwal@samsung.com>
Thu, 28 Nov 2019 11:37:18 +0000 (17:07 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 30 Dec 2019 07:45:56 +0000 (16:45 +0900)
Signed-off-by: Abhay agarwal <ay.agarwal@samsung.com>
13 files changed:
CMakeLists.txt
include/user-awareness-private.h
include/user-awareness.h
src/user-awareness-device.c
src/user-awareness-payload.c [new file with mode: 0644]
src/user-awareness-service.c
src/user-awareness-users.c
test/CMakeLists.txt
test/uat-devices.c
test/uat-main.c
test/uat-payload.c [new file with mode: 0644]
test/uat-service.c
test/uat-users.c

index e39a147167b744de3a871812fdeb585395087c13..80cbb51168e937f01d850c30c1cfc85c9c2f45d7 100644 (file)
@@ -55,6 +55,7 @@ SET(SRCS
        src/user-awareness-users.c
        src/user-awareness-util.c
        src/user-awareness-event-handler.c
+       src/user-awareness-payload.c
 )
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
index bd83179af28a1f1953995a440ccca825a5e83da1..7e047f7995e07620490c23123c3b73f2f7edbed9 100644 (file)
@@ -69,7 +69,6 @@ extern "C" {
                return UA_ERROR_NOT_FOUND; \
        }
 
-
 /**
  * @brief Prints arg.
  * @since_tizen 5.5
@@ -77,6 +76,13 @@ extern "C" {
 #define UA_PRINT_DEVICE_HANDLE(arg) \
                UA_INFO("Device Handle [%p]", #arg); \
 
+/**
+ * @brief Prints arg.
+ * @since_tizen 5.5
+ */
+#define UA_PRINT_PAYLOAD_HANDLE(arg) \
+               UA_INFO("Payload Handle [%p]", #arg); \
+
 /**
  * @brief Prints arg.
  * @since_tizen 5.5
@@ -289,12 +295,14 @@ typedef enum {
  * @since_tizen 5.5
  */
 typedef struct {
+       ua_payload_h handle; /**< Payload handle */
        char primary_key; /**< primary key for manufacturer data */
-       char device_icon; /**< device icon for manufacturer data */
        char secondary_key; /**< secondary_key for manufacturer data */
+       char device_icon; /**< device icon for manufacturer data */
        char *device_uid; /**< device_uid for manufacturer data */
        char *bt_mac; /**< bt mac address of device */
-} ua_ble_payload_s;
+       gboolean isadded; /**< Is the payload addition completed? */
+} ua_payload_info_s;
 
 /**
  * @brief Device info data structure.
@@ -316,7 +324,6 @@ typedef struct {
        gboolean create_by_app; /**< Did app add this device information? */
        gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
        unsigned long long last_seen; /**< The time of last presence */
-       ua_ble_payload_s *payload; /**< BLE payload to filter device*/
 } ua_dev_info_s;
 
 /**
@@ -471,9 +478,9 @@ void _ua_free_ua_service_info_s(gpointer data);
  * @pre
  * @post
  *
- * @see _ua_free_ua_ble_payload_s()
+ * @see _ua_free_ua_payload_info_s()
  */
-void _ua_create_ua_ble_payload_s(ua_ble_payload_s **payload_handle);
+void _ua_create_ua_payload_info_s(ua_payload_info_s **payload_handle);
 
 /**
  * @brief Destroys a payload handle.
@@ -485,9 +492,9 @@ void _ua_create_ua_ble_payload_s(ua_ble_payload_s **payload_handle);
  * @pre
  * @post
  *
- * @see _ua_create_ua_ble_payload_s()
+ * @see _ua_create_ua_payload_info_s()
  */
-void _ua_free_ua_ble_payload_s(gpointer data);
+void _ua_free_ua_payload_info_s(gpointer data);
 
 /**
  * @brief Return payload handle from uam_ble_payload_s.
@@ -500,12 +507,12 @@ void _ua_free_ua_ble_payload_s(gpointer data);
  * @pre
  * @post
  *
- * @see _ua_free_ua_ble_payload_s()
+ * @see _ua_free_ua_payload_info_s()
  */
-ua_ble_payload_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload);
+ua_payload_info_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload);
 
 /**
- * @brief Creates payload handle of uam_ble_payload_s type from ua_ble_payload_s.
+ * @brief Creates payload handle of uam_ble_payload_s type from ua_payload_info_s.
  * @since_tizen 5.5
  *
  * @param[in] payload Payload handle.
@@ -515,7 +522,7 @@ ua_ble_payload_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload);
  * @pre
  * @post
  */
-void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, ua_ble_payload_s *payload);
+void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, ua_payload_info_s *payload);
 
 /**
  * @brief Returns a cloned copy of payload handle.
@@ -528,7 +535,7 @@ void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, ua_ble_payload_
  * @pre
  * @post
  */
-ua_ble_payload_s* _ua_payload_clone(ua_ble_payload_s *org_payload);
+ua_payload_info_s* _ua_payload_clone(ua_payload_info_s *org_payload);
 
 /**
  * @brief Add a device handle to internal device-list.
index 6229bbc47dc627306dc23c3a2ee06d8b7aae9f92..21fdc2dcd0d12d24f56e94bb151cbc53225e91cd 100644 (file)
@@ -290,6 +290,13 @@ typedef void *ua_service_h;
  */
 typedef void *ua_device_h;
 
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief The handle of payload information.
+ * @since_tizen 5.5
+ */
+typedef void *ua_payload_h;
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Callback to be invoked if a sensor state changed (ready <-> not ready).
@@ -2618,156 +2625,185 @@ int ua_device_get_discriminant(
  * @see ua_device_set_os_info()
  * @see ua_device_set_wifi_ipv4_address()
  * @see ua_device_set_discriminant()
- * @see ua_device_set_payload_primary_key()
- * @see ua_device_set_payload_device_icon()
- * @see ua_device_set_payload_secondary_key()
- * @see ua_device_set_payload_device_uid()
  */
 int ua_device_update(
                ua_device_h device_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Sets BLE payload primary_key for device.
+ * @brief Gets device handle by MAC address.
  * @since_tizen 5.5
  *
- * @param[in] handle The device handle.
- * @param[in] primary_key The BLE payload primary_key.
+ * @remarks The @a device_handle should not be released.
+ * @remarks The @a device_handle can be used only in the function.
+ *
+ * @param[in] mac The device's MAC address
+ * @param[out] device_handle The device handle
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_device_get_payload_primary_key()
  */
-int ua_device_set_payload_primary_key(
-               ua_device_h handle,
-               const char primary_key);
+int ua_device_get_by_mac_address(
+               const char *mac,
+               ua_device_h *device_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Sets BLE payload device_icon for device.
+ * @brief Gets device handle by device ID.
  * @since_tizen 5.5
  *
- * @param[in] handle The device handle.
- * @param[in] device_icon The BLE payload device_icon.
+ * @remarks The @a device_handle should not be released.
+ * @remarks The @a device_handle can be used only in the function.
+ *
+ * @param[in] device_id The device ID
+ * @param[in] mac_type The device's MAC type
+ * @param[out] device_handle The device handle.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_device_get_payload_device_icon()
  */
-int ua_device_set_payload_device_icon(
-               ua_device_h handle,
-               const char device_icon);
+int ua_device_get_by_device_id(
+               const char *device_id,
+               ua_mac_type_e mac_type,
+               ua_device_h * device_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Sets BLE payload secondary_key for device.
+ * @brief Removes the device by MAC address.
  * @since_tizen 5.5
  *
- * @param[in] handle The device handle.
- * @param[in] secondary_key The BLE payload secondary_key.
+ * @param[in] mac The device's MAC address.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
+ * @retcal #UA_ERROR_RESOURCE_BUSY Remove done. but another service uses thie device.
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_device_get_payload_secondary_key()
+ * @see ua_user_remove_device_by_device_id()
  */
-int ua_device_set_payload_secondary_key(
-               ua_device_h handle,
-               const char secondary_key);
+int ua_user_remove_device_by_mac_address(
+               const char *mac);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Sets BLE payload DEVICE_UID for device.
+ * @brief Removes the device ID.
  * @since_tizen 5.5
  *
- * @remarks The @a device_uid is expected to be exact 17 bytes long data
- *          and may have intermediate NULLs
+ * @param[in] device_id The device ID.
+ * @param[in] mac_type The device's MAC address type.
  *
- * @param[in] handle The device handle.
- * @param[in] device_uid_len The BLE payload DEVICE_UID's length.
- * @param[in] device_uid The BLE payload DEVICE_UID.
+ * @return  0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retcal #UA_ERROR_RESOURCE_BUSY Remove done. but another service uses thie device.
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_user_remove_device_by_mac_address()
+ */
+int ua_user_remove_device_by_device_id(
+               const char *device_id,
+               ua_mac_type_e mac_type);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Retrieves the device handle of all the registered devices.
+ * @since_tizen 5.5
+ *
+ * @param[in] foreach_cb Callback function to be invoked with all device handle.
+ * @param[in] user_data The user data to be passed when callback is called.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_device_get_payload_device_uid()
+ * @see ua_registered_dev_cb()
  */
-int ua_device_set_payload_device_uid(
-               ua_device_h handle,
-               unsigned int device_uid_len,
-               const char *device_uid);
+int ua_device_foreach_added(
+               ua_registered_dev_cb foreach_cb,
+               void *user_data);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Sets iBeacon adevertising data.
+ * @brief Retrieves the device handle of all the registered devices for one specific user.
  * @since_tizen 5.5
  *
- * @param[in] adv_len The iBeacon adevertising data's length.
- * @param[in] ibeacon_adv The iBeacon adevertising data.
+ * @param[in] user_handle The user handle.
+ * @param[in] foreach_cb Callback function to be invoked with user device handle.
+ * @param[in] user_data The user data to be passed when callback is called.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
+ *
+ * @see ua_registered_dev_cb()
  */
-int ua_add_ibeacon_adv_data(
-               unsigned int adv_len,
-               const char *ibeacon_adv);
+int ua_device_foreach_added_by_user(
+               ua_user_h user_handle,
+               ua_registered_dev_cb foreach_cb,
+               void *user_data);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets device's BLE payload primary_key.
+ * @brief Creates the payload handle.
  * @since_tizen 5.5
  *
- * @param[in] handle The device handle.
- * @param[out] primary_key The BLE payload primary_key.
+ * @remarks The @a payload_handle should be destroyed by using #ua_payload_destroy().
+ *
+ * @param[out] payload_handle The payload handle
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_device_set_payload_primary_key()
+ * @see ua_payload_destroy()
  */
-int ua_device_get_payload_primary_key(
-               ua_device_h handle,
-               char *primary_key);
+int ua_payload_create(
+               ua_payload_h * payload_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets device's BLE payload device_icon.
+ * @brief Destroys the payload handle.
  * @since_tizen 5.5
  *
- * @param[in] handle The device handle.
- * @param[out] device_icon The BLE payload device_icon.
+ * @remarks Payload context will removed and all allocated memory (if any) will be released.
+ *
+ * @param[in] payload_handle The payload handle
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
@@ -2777,19 +2813,18 @@ int ua_device_get_payload_primary_key(
  * @pre
  * @post
  *
- * @see ua_device_set_payload_device_icon()
+ * @see ua_payload_create()
  */
-int ua_device_get_payload_device_icon(
-               ua_device_h handle,
-               char *device_icon);
+int ua_payload_destroy(
+               ua_payload_h payload_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets device's BLE payload secondary_key.
+ * @brief Sets BLE payload primary_key for device.
  * @since_tizen 5.5
  *
- * @param[in] handle The device handle.
- * @param[out] secondary_key The BLE payload secondary_key.
+ * @param[in] handle The payload handle.
+ * @param[in] primary_key The BLE payload primary_key.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
@@ -2799,21 +2834,41 @@ int ua_device_get_payload_device_icon(
  * @pre
  * @post
  *
- * @see ua_device_set_payload_secondary_key()
+ * @see ua_payload_get_primary_key()
  */
-int ua_device_get_payload_secondary_key(
-               ua_device_h handle,
-               char *secondary_key);
+int ua_payload_set_primary_key(
+               ua_payload_h handle,
+               const char primary_key);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets device's BLE payload DEVICE_UID.
+ * @brief Sets BLE payload device_icon for device.
  * @since_tizen 5.5
  *
- * @remarks You must release @a device_uid using g_free().
+ * @param[in] handle The payload handle.
+ * @param[in] device_icon The BLE payload device_icon.
  *
- * @param[in] handle The device handle.
- * @param[out] device_uid The BLE payload DEVICE_UID.
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ *
+ * @see ua_payload_get_device_icon()
+ */
+int ua_payload_set_device_icon(
+               ua_payload_h handle,
+               const char device_icon);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sets BLE payload secondary_key for device.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The payload handle.
+ * @param[in] secondary_key The BLE payload secondary_key.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
@@ -2823,155 +2878,169 @@ int ua_device_get_payload_secondary_key(
  * @pre
  * @post
  *
- * @see ua_device_set_payload_device_uid()
+ * @see ua_payload_get_secondary_key()
  */
-int ua_device_get_payload_device_uid(
-               ua_device_h handle,
-               char **device_uid);
+int ua_payload_set_secondary_key(
+               ua_payload_h handle,
+               const char secondary_key);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets device handle by MAC address.
+ * @brief Sets BLE payload DEVICE_UID for device.
  * @since_tizen 5.5
  *
- * @remarks The @a device_handle should not be released.
- * @remarks The @a device_handle can be used only in the function.
+ * @remarks The @a device_uid is expected to be exact 17 bytes long data
+ *          and may have intermediate NULLs
  *
- * @param[in] mac The device's MAC address
- * @param[out] device_handle The device handle
+ * @param[in] handle The payload handle.
+ * @param[in] device_uid_len The BLE payload DEVICE_UID's length.
+ * @param[in] device_uid The BLE payload DEVICE_UID.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
+ * @see ua_payload_get_device_uid()
  */
-int ua_device_get_by_mac_address(
-               const char *mac,
-               ua_device_h *device_handle);
+int ua_payload_set_device_uid(
+               ua_payload_h handle,
+               unsigned int device_uid_len,
+               const char *device_uid);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets device handle by device ID.
+ * @brief Sets iBeacon adevertising data.
  * @since_tizen 5.5
  *
- * @remarks The @a device_handle should not be released.
- * @remarks The @a device_handle can be used only in the function.
+ * @param[in] adv_len The iBeacon adevertising data's length.
+ * @param[in] ibeacon_adv The iBeacon adevertising data.
  *
- * @param[in] device_id The device ID
- * @param[in] mac_type The device's MAC type
- * @param[out] device_handle The device handle.
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+int ua_add_ibeacon_adv_data(
+               unsigned int adv_len,
+               const char *ibeacon_adv);
+
+/**
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Gets device's BLE payload primary_key.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The payload handle.
+ * @param[out] primary_key The BLE payload primary_key.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
+ * @see ua_payload_set_primary_key()
  */
-int ua_device_get_by_device_id(
-               const char *device_id,
-               ua_mac_type_e mac_type,
-               ua_device_h * device_handle);
+int ua_payload_get_primary_key(
+               ua_payload_h handle,
+               char *primary_key);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Removes the device by MAC address.
+ * @brief Gets device's BLE payload device_icon.
  * @since_tizen 5.5
  *
- * @param[in] mac The device's MAC address.
+ * @param[in] handle The payload handle.
+ * @param[out] device_icon The BLE payload device_icon.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
- * @retcal #UA_ERROR_RESOURCE_BUSY Remove done. but another service uses thie device.
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_user_remove_device_by_device_id()
+ * @see ua_payload_set_device_icon()
  */
-int ua_user_remove_device_by_mac_address(
-               const char *mac);
+int ua_payload_get_device_icon(
+               ua_payload_h handle,
+               char *device_icon);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Removes the device ID.
+ * @brief Gets device's BLE payload secondary_key.
  * @since_tizen 5.5
  *
- * @param[in] device_id The device ID.
- * @param[in] mac_type The device's MAC address type.
+ * @param[in] handle The payload handle.
+ * @param[out] secondary_key The BLE payload secondary_key.
  *
- * @return  0 on success, otherwise a negative error value
+ * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
- * @retcal #UA_ERROR_RESOURCE_BUSY Remove done. but another service uses thie device.
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_user_remove_device_by_mac_address()
+ * @see ua_payload_set_secondary_key()
  */
-int ua_user_remove_device_by_device_id(
-               const char *device_id,
-               ua_mac_type_e mac_type);
+int ua_payload_get_secondary_key(
+               ua_payload_h handle,
+               char *secondary_key);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Retrieves the device handle of all the registered devices.
+ * @brief Gets device's BLE payload DEVICE_UID.
  * @since_tizen 5.5
  *
- * @param[in] foreach_cb Callback function to be invoked with all device handle.
- * @param[in] user_data The user data to be passed when callback is called.
+ * @remarks You must release @a device_uid using g_free().
+ *
+ * @param[in] handle The payload handle.
+ * @param[out] device_uid The BLE payload DEVICE_UID.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_registered_dev_cb()
+ * @see ua_payload_set_device_uid()
  */
-int ua_device_foreach_added(
-               ua_registered_dev_cb foreach_cb,
-               void *user_data);
+int ua_payload_get_device_uid(
+               ua_payload_h handle,
+               char **device_uid);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Retrieves the device handle of all the registered devices for one specific user.
+ * @brief Adds device's payload.
  * @since_tizen 5.5
  *
- * @param[in] user_handle The user handle.
- * @param[in] foreach_cb Callback function to be invoked with user device handle.
- * @param[in] user_data The user data to be passed when callback is called.
+ * @param[in] payload_handle The payload handle.
+ * @param[in] device_handle The device handle.
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_registered_dev_cb()
  */
-int ua_device_foreach_added_by_user(
-               ua_user_h user_handle,
-               ua_registered_dev_cb foreach_cb,
-               void *user_data);
+int ua_payload_add(
+               ua_payload_h payload_handle,
+               ua_device_h device_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
index 1c1f9b265136ef4004deee53624edc97d6d1bd50..c1bf68082adbcffe5c2a12920986997bf6268529 100644 (file)
@@ -178,141 +178,6 @@ ua_dev_info_s* _ua_get_device_info_from_uam(uam_device_info_s *uam_info)
        return dev;
 }
 
-void _ua_create_ua_ble_payload_s(ua_ble_payload_s **payload_handle)
-{
-       FUNC_ENTRY;
-       ua_ble_payload_s *payload = NULL;
-
-       ret_if(NULL == payload_handle);
-
-       payload = g_malloc0(sizeof(ua_ble_payload_s));
-       if (!payload) {
-               UA_ERR("g_malloc0 failed");
-               *payload_handle = NULL;
-               return;
-       }
-
-       payload->primary_key = 13;
-       payload->device_icon = 1;
-       payload->secondary_key = 1;
-       payload->device_uid = NULL;
-       payload->bt_mac = NULL;
-
-       *payload_handle = payload;
-       FUNC_EXIT;
-}
-
-void _ua_free_ua_ble_payload_s(gpointer data)
-{
-       FUNC_ENTRY;
-       ua_ble_payload_s *payload = data;
-
-       ret_if(NULL == payload);
-
-       g_free(payload->device_uid);
-       g_free(payload->bt_mac);
-
-       g_free(payload);
-       FUNC_EXIT;
-}
-
-ua_ble_payload_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload)
-{
-       FUNC_ENTRY;
-       ua_ble_payload_s *payload = NULL;
-
-       retv_if(NULL == uam_payload, NULL);
-
-       payload = g_malloc0(sizeof(ua_ble_payload_s));
-       if (!payload) {
-               UA_ERR("g_malloc0 failed");
-               return NULL;
-       }
-
-       payload->primary_key = uam_payload->primary_key;
-       payload->device_icon = uam_payload->device_icon;
-       payload->secondary_key = uam_payload->secondary_key;
-
-       payload->device_uid = g_memdup(uam_payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
-       if (!payload->device_uid) {
-               UA_ERR("g_malloc0 failed");
-               _ua_free_ua_ble_payload_s(payload);
-               return NULL;
-       }
-
-       payload->bt_mac = g_strdup(uam_payload->bt_mac);
-       if (!payload->bt_mac) {
-               UA_ERR("g_malloc0 failed");
-               _ua_free_ua_ble_payload_s(payload);
-               return NULL;
-       }
-
-       FUNC_EXIT;
-       return payload;
-}
-
-void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload,
-       ua_ble_payload_s *payload)
-{
-       FUNC_ENTRY;
-       memset(uam_payload, 0, sizeof(uam_ble_payload_s));
-
-       if (NULL == payload) {
-               uam_payload->primary_key = 13;
-               uam_payload->device_icon = 1;
-               uam_payload->secondary_key = 1;
-               UA_DBG("(NULL == payload) return");
-               return;
-       }
-
-       uam_payload->primary_key = payload->primary_key;
-       uam_payload->device_icon = payload->device_icon;
-       uam_payload->secondary_key = payload->secondary_key;
-
-       if (payload->device_uid)
-               memcpy(uam_payload->device_uid, payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
-
-       if (payload->bt_mac)
-               g_strlcpy(uam_payload->bt_mac, payload->bt_mac, UA_BT_MAC_MAX_LEN);
-
-       FUNC_EXIT;
-}
-
-ua_ble_payload_s* _ua_payload_clone(ua_ble_payload_s *org_payload)
-{
-       FUNC_ENTRY;
-       ua_ble_payload_s *payload = NULL;
-
-       retv_if(NULL == org_payload, NULL);
-
-       payload = g_malloc0(sizeof(ua_ble_payload_s));
-       if (!payload) {
-               UA_ERR("g_malloc0 failed");
-               return NULL;
-       }
-
-       payload->primary_key = org_payload->primary_key;
-       payload->device_icon = org_payload->device_icon;
-       payload->secondary_key = org_payload->secondary_key;
-
-       payload->device_uid = g_memdup(org_payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
-       if (!payload->device_uid && org_payload->device_uid) {
-               UA_ERR("g_malloc0 failed");
-               _ua_free_ua_ble_payload_s(payload);
-               return NULL;
-       }
-
-       payload->bt_mac = g_strdup(org_payload->bt_mac);
-       if (!payload->bt_mac && org_payload->bt_mac) {
-               UA_ERR("g_malloc0 failed");
-               _ua_free_ua_ble_payload_s(payload);
-               return NULL;
-       }
-
-       FUNC_EXIT;
-       return payload;
-}
-
 void _ua_free_ua_device_info_t(gpointer data)
 {
        FUNC_ENTRY;
@@ -325,7 +190,6 @@ void _ua_free_ua_device_info_t(gpointer data)
        g_free(device->ipv4);
        g_free(device->ipv6); // LCOV_EXCL_LINE
        g_free(device->device_id);
-       _ua_free_ua_ble_payload_s(device->payload);
 
        g_free(device);
        FUNC_EXIT;
@@ -459,7 +323,6 @@ int ua_device_create(ua_device_h *device_handle)
        device->os = UA_OS_TYPE_NOT_DEFINE;
        device->isadded = false;
        device->discriminant = true;
-       device->payload = NULL;
 
        /* Add device to list of devices */
        *device_handle = (ua_device_h)device;
@@ -678,119 +541,6 @@ int ua_device_set_discriminant(
        return UA_ERROR_NONE;
 }
 
-int ua_device_set_payload_primary_key(
-               ua_device_h handle,
-               const char primary_key)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               _ua_create_ua_ble_payload_s(&device->payload);
-               if (!device->payload) {
-                       UA_ERR("_ua_create_ua_ble_payload_s() failed");
-                       return UA_ERROR_OUT_OF_MEMORY;
-               }
-       }
-
-       device->payload->primary_key = primary_key;
-
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_device_icon(
-               ua_device_h handle,
-               const char device_icon)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               _ua_create_ua_ble_payload_s(&device->payload);
-               if (!device->payload) {
-                       UA_ERR("_ua_create_ua_ble_payload_s() failed");
-                       return UA_ERROR_OUT_OF_MEMORY;
-               }
-       }
-
-       device->payload->device_icon = device_icon;
-
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_secondary_key(
-               ua_device_h handle,
-               const char secondary_key)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               _ua_create_ua_ble_payload_s(&device->payload);
-               if (!device->payload) {
-                       UA_ERR("_ua_create_ua_ble_payload_s() failed");
-                       return UA_ERROR_OUT_OF_MEMORY;
-               }
-       }
-
-       device->payload->secondary_key = secondary_key;
-
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
-int ua_device_set_payload_device_uid(
-               ua_device_h handle,
-               unsigned int device_uid_len,
-               const char *device_uid)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_VALIDATE_INPUT_PARAMETER(device_uid);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-       retv_if(device_uid_len != UA_BLE_PAYLOAD_DEVICE_UID_LEN, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               _ua_create_ua_ble_payload_s(&device->payload);
-               if (!device->payload) {
-                       UA_ERR("_ua_create_ua_ble_payload_s() failed");
-                       return UA_ERROR_OUT_OF_MEMORY;
-               }
-       }
-
-       g_free(device->payload->device_uid);
-       device->payload->device_uid = NULL;
-
-       device->payload->device_uid = g_malloc0(UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
-       if (device->payload->device_uid == NULL) {
-               UA_ERR("g_malloc0 failed");
-               _ua_free_ua_ble_payload_s((gpointer)device->payload);
-               return UA_ERROR_OUT_OF_MEMORY;
-       }
-
-       memcpy(device->payload->device_uid, device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN);
-
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
 int ua_device_get_mac_address(
                ua_device_h device_handle,
                char **mac_address)
@@ -966,111 +716,6 @@ int ua_device_get_last_presence(
        return UA_ERROR_NONE;
 }
 
-int ua_device_get_payload_primary_key(
-               ua_device_h handle,
-               char *primary_key)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_VALIDATE_INPUT_PARAMETER(primary_key);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               *primary_key = 0x00;
-               UA_DBG("payload(primary_key) is not found");
-               goto done;
-       }
-
-       *primary_key = device->payload->primary_key;
-
-done:
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
-int ua_device_get_payload_device_icon(
-               ua_device_h handle,
-               char *device_icon)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_VALIDATE_INPUT_PARAMETER(device_icon);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               *device_icon = 0x00;
-               UA_DBG("payload(device_icon) is not found");
-               goto done;
-       }
-
-       *device_icon = device->payload->device_icon;
-
-done:
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-int ua_device_get_payload_secondary_key(
-               ua_device_h handle,
-               char *secondary_key)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_VALIDATE_INPUT_PARAMETER(secondary_key);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload) {
-               *secondary_key = 0x00;
-               UA_DBG("payload(secondary_key) is not found");
-               goto done;
-       }
-
-       *secondary_key = device->payload->secondary_key;
-
-done:
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
-int ua_device_get_payload_device_uid(
-               ua_device_h handle,
-               char **device_uid)
-{
-       FUNC_ENTRY;
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-       UA_VALIDATE_INPUT_PARAMETER(device_uid);
-       UA_PRINT_DEVICE_HANDLE(handle);
-       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
-
-       if (!device->payload || !device->payload->device_uid) {
-               *device_uid = NULL;
-               UA_DBG("payload(device_uid) is not found");
-               goto done;
-       }
-
-       *device_uid = g_memdup(device->payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN);
-       if (*device_uid == NULL) {
-               /* LCOV_EXCL_START */
-               UA_ERR("g_memdup failed");
-               return UA_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-
-done:
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
 int ua_device_get_by_mac_address(
                const char *mac,
                ua_device_h *device_handle)
@@ -1140,14 +785,6 @@ int ua_device_get_by_mac_address(
                return UA_ERROR_OUT_OF_MEMORY;
        }
 
-       dev->payload = _ua_get_payload_from_uam(&uam_dev.payload);
-       if (dev->payload == NULL) {
-               UA_ERR("_ua_get_payload_from_uam() failed");
-               *device_handle = NULL;
-               _ua_free_ua_device_info_t((gpointer)dev);
-               return UA_ERROR_OUT_OF_MEMORY;
-       }
-
        dev->type = _to_ua_mac_type(uam_dev.type);
        dev->pairing_required = FALSE;
        dev->discriminant= uam_dev.discriminant;
@@ -1239,14 +876,6 @@ int ua_device_get_by_device_id(
                return UA_ERROR_OUT_OF_MEMORY;
        }
 
-       dev->payload = _ua_get_payload_from_uam(&uam_dev.payload);
-       if (dev->payload == NULL) {
-               UA_ERR("_ua_get_payload_from_uam() failed");
-               *device_handle = NULL;
-               _ua_free_ua_device_info_t((gpointer)dev);
-               return UA_ERROR_OUT_OF_MEMORY;
-       }
-
        dev->type = _to_ua_mac_type(uam_dev.type);
        dev->pairing_required = FALSE;
        dev->os = uam_dev.operating_system;
@@ -1291,8 +920,6 @@ int ua_device_update(ua_device_h device_handle)
        if (device->ipv4)
                g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
 
-       _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
-
        ret = _ua_get_error_code(_uam_is_device_registered(&uam_device, &is_registered));
        if (UA_ERROR_NONE != ret) {
                /* LCOV_EXCL_START */
@@ -1368,13 +995,6 @@ int ua_device_clone(ua_device_h *cloned,
                return UA_ERROR_OUT_OF_MEMORY;
        }
 
-       device->payload = _ua_payload_clone(org_device->payload);
-       if (device->payload == NULL && org_device->payload) {
-               UA_ERR("g_malloc0 failed");
-               _ua_free_ua_device_info_t((gpointer)device);
-               return UA_ERROR_OUT_OF_MEMORY;
-       }
-
        device->isadded = org_device->isadded;
        device->type = org_device->type;
        device->os = org_device->os;
@@ -1491,14 +1111,6 @@ int ua_device_foreach_added(
                                goto done;
                        }
 
-                       device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
-                       if (device_info->payload == NULL) {
-                               UA_ERR("_ua_get_payload_from_uam() failed");
-                               ret = UA_ERROR_OUT_OF_MEMORY;
-                               _ua_free_ua_device_info_t((gpointer)device_info);
-                               goto done;
-                       }
-
                        device_info->isadded = true;
                        device_info->handle = (ua_device_h)device_info;
                        device_info->type = _to_ua_mac_type(ptr->type);
@@ -1604,14 +1216,6 @@ int ua_device_foreach_added_by_user(
                                goto done;
                        }
 
-                       device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
-                       if (device_info->payload == NULL) {
-                               UA_ERR("_ua_get_payload_from_uam() failed");
-                               ret = UA_ERROR_OUT_OF_MEMORY;
-                               _ua_free_ua_device_info_t((gpointer)device_info);
-                               goto done;
-                       }
-
                        device_info->isadded = true;
                        device_info->handle = (ua_device_h)device_info;
                        device_info->type = _to_ua_mac_type(ptr->type);
diff --git a/src/user-awareness-payload.c b/src/user-awareness-payload.c
new file mode 100644 (file)
index 0000000..71b8a27
--- /dev/null
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <ua-api.h>
+
+#include <user-awareness.h>
+#include <user-awareness-log.h>
+#include <user-awareness-private.h>
+#include <user-awareness-util.h>
+
+GSList *ua_payload_list;
+
+int ua_payload_create(ua_payload_h *payload_handle)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = NULL;
+
+       UA_VALIDATE_INPUT_PARAMETER(payload_handle);
+
+       payload = g_malloc0(sizeof(ua_payload_info_s));
+       if (!payload) {
+               /* LCOV_EXCL_START */
+               UA_ERR("g_malloc0 failed");
+               return UA_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
+
+       payload->primary_key = 13;
+       payload->device_icon = 1;
+       payload->secondary_key = 1;
+       payload->device_uid = NULL;
+       payload->bt_mac = NULL;
+       payload->isadded = false;
+
+       /* Add payload to list of payloads*/
+       *payload_handle = (ua_payload_h)payload;
+       payload->handle = *payload_handle;
+
+       ua_payload_list = g_slist_append(ua_payload_list, payload);
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+void _ua_free_ua_payload_info_s(gpointer data)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = data;
+
+       ret_if(NULL == payload);
+
+       g_free(payload->device_uid);
+       g_free(payload->bt_mac);
+
+       g_free(payload);
+       FUNC_EXIT;
+}
+
+int ua_payload_destroy(ua_payload_h handle)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = (ua_payload_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_VALIDATE_HANDLE(handle, ua_payload_list);
+
+       /* Do not remove from list if payload is added to database */
+       if (payload->isadded) {
+               /* LCOV_EXCL_START */
+               return UA_ERROR_NONE;
+               /* LCOV_EXCL_STOP */
+       }
+
+       ua_payload_list = g_slist_remove(ua_payload_list, payload);
+       _ua_free_ua_payload_info_s(payload);
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_payload_set_primary_key(
+               ua_payload_h handle,
+               const char primary_key)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = (ua_payload_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_PRINT_PAYLOAD_HANDLE(handle);
+
+       payload->primary_key = primary_key;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_payload_set_device_icon(
+               ua_device_h handle,
+               const char device_icon)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = (ua_payload_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_PRINT_PAYLOAD_HANDLE(handle);
+
+       payload->device_icon = device_icon;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_payload_set_secondary_key(
+               ua_device_h handle,
+               const char secondary_key)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = (ua_payload_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_PRINT_PAYLOAD_HANDLE(handle);
+
+       payload->secondary_key = secondary_key;
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_payload_set_device_uid(
+               ua_device_h handle,
+               unsigned int device_uid_len,
+               const char *device_uid)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = (ua_payload_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_VALIDATE_INPUT_PARAMETER(device_uid);
+       UA_PRINT_PAYLOAD_HANDLE(handle);
+
+       retv_if(device_uid_len != UA_BLE_PAYLOAD_DEVICE_UID_LEN, UA_ERROR_INVALID_PARAMETER);
+
+       g_free(payload->device_uid);
+       payload->device_uid = NULL;
+
+       payload->device_uid = g_malloc0(UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
+       if (payload->device_uid == NULL) {
+               UA_ERR("g_malloc0 failed");
+               _ua_free_ua_payload_info_s((gpointer)payload);
+               return UA_ERROR_OUT_OF_MEMORY;
+       }
+
+       memcpy(payload->device_uid, device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN);
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload,
+       ua_payload_info_s *payload)
+{
+       FUNC_ENTRY;
+       memset(uam_payload, 0, sizeof(uam_ble_payload_s));
+
+       if (NULL == payload) {
+               uam_payload->primary_key = 13;
+               uam_payload->device_icon = 1;
+               uam_payload->secondary_key = 1;
+               UA_DBG("(NULL == payload) return");
+               return;
+       }
+
+       uam_payload->primary_key = payload->primary_key;
+       uam_payload->device_icon = payload->device_icon;
+       uam_payload->secondary_key = payload->secondary_key;
+
+       if (payload->device_uid)
+               memcpy(uam_payload->device_uid, payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
+
+       if (payload->bt_mac)
+               g_strlcpy(uam_payload->bt_mac, payload->bt_mac, UA_BT_MAC_MAX_LEN);
+
+       FUNC_EXIT;
+}
+
+int ua_payload_add(ua_payload_h payload_handle, ua_device_h device_handle)
+{
+       FUNC_ENTRY;
+       int ret;
+       uam_ble_payload_s uam_payload;
+
+       ua_payload_info_s* payload_info = (ua_payload_info_s*)payload_handle;
+       ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(payload_handle);
+       UA_VALIDATE_INPUT_PARAMETER(device_handle);
+
+       UA_DBG("device_info->device_id [%s], device_info->mac [%s], device_info->type [%d]",
+               dev_info->device_id, dev_info->mac, dev_info->type);
+
+       UA_IS_EXIST(_ua_get_device_from_list(dev_info->device_id, dev_info->mac, dev_info->type));
+       retv_if(dev_info->isadded == FALSE, UA_ERROR_NOT_REGISTERED);
+       retv_if(payload_info->device_uid == NULL, UA_ERROR_INVALID_PARAMETER);
+
+       _ua_get_uam_payload_from_ua(&uam_payload, payload_info);
+
+       ret = _ua_get_error_code(_uam_request_add_payload(&uam_payload, dev_info->device_id,
+                                                       _ua_to_uam_tech_type(dev_info->type)));
+       if (UA_ERROR_NONE != ret) {
+               UA_ERR("_uam_payload_add returned %s",
+                               _ua_get_error_string(ret));
+               return ret;
+       }
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+/*
+ua_payload_info_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = NULL;
+
+       retv_if(NULL == uam_payload, NULL);
+
+       payload = g_malloc0(sizeof(ua_payload_info_s));
+       if (!payload) {
+               UA_ERR("g_malloc0 failed");
+               return NULL;
+       }
+
+       payload->primary_key = uam_payload->primary_key;
+       payload->device_icon = uam_payload->device_icon;
+       payload->secondary_key = uam_payload->secondary_key;
+
+       payload->device_uid = g_memdup(uam_payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
+       if (!payload->device_uid) {
+               UA_ERR("g_malloc0 failed");
+               _ua_free_ua_payload_info_s(payload);
+               return NULL;
+       }
+
+       payload->bt_mac = g_strdup(uam_payload->bt_mac);
+       if (!payload->bt_mac) {
+               UA_ERR("g_malloc0 failed");
+               _ua_free_ua_payload_info_s(payload);
+               return NULL;
+       }
+
+       FUNC_EXIT;
+       return payload;
+}
+
+ua_payload_info_s* _ua_payload_clone(ua_payload_info_s *org_payload)
+{
+       FUNC_ENTRY;
+       ua_payload_info_s *payload = NULL;
+
+       retv_if(NULL == org_payload, NULL);
+
+       payload = g_malloc0(sizeof(ua_payload_info_s));
+       if (!payload) {
+               UA_ERR("g_malloc0 failed");
+               return NULL;
+       }
+
+       payload->primary_key = org_payload->primary_key;
+       payload->device_icon = org_payload->device_icon;
+       payload->secondary_key = org_payload->secondary_key;
+
+       payload->device_uid = g_memdup(org_payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN + 1);
+       if (!payload->device_uid && org_payload->device_uid) {
+               UA_ERR("g_malloc0 failed");
+               _ua_free_ua_payload_info_s(payload);
+               return NULL;
+       }
+
+       payload->bt_mac = g_strdup(org_payload->bt_mac);
+       if (!payload->bt_mac && org_payload->bt_mac) {
+               UA_ERR("g_malloc0 failed");
+               _ua_free_ua_payload_info_s(payload);
+               return NULL;
+       }
+
+       FUNC_EXIT;
+       return payload;
+}
+*/
+/*
+int ua_payload_get_primary_key(
+               ua_device_h handle,
+               char *primary_key)
+{
+       FUNC_ENTRY;
+       ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_VALIDATE_INPUT_PARAMETER(primary_key);
+       UA_PRINT_DEVICE_HANDLE(handle);
+       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+       if (!device->payload) {
+               *primary_key = 0x00;
+               UA_DBG("payload(primary_key) is not found");
+               goto done;
+       }
+
+       *primary_key = device->payload->primary_key;
+
+done:
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_payload_get_device_icon(
+               ua_device_h handle,
+               char *device_icon)
+{
+       FUNC_ENTRY;
+       ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_VALIDATE_INPUT_PARAMETER(device_icon);
+       UA_PRINT_DEVICE_HANDLE(handle);
+       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+       if (!device->payload) {
+               *device_icon = 0x00;
+               UA_DBG("payload(device_icon) is not found");
+               goto done;
+       }
+
+       *device_icon = device->payload->device_icon;
+
+done:
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+int ua_payload_get_secondary_key(
+               ua_device_h handle,
+               char *secondary_key)
+{
+       FUNC_ENTRY;
+       ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_VALIDATE_INPUT_PARAMETER(secondary_key);
+       UA_PRINT_DEVICE_HANDLE(handle);
+       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+       if (!device->payload) {
+               *secondary_key = 0x00;
+               UA_DBG("payload(secondary_key) is not found");
+               goto done;
+       }
+
+       *secondary_key = device->payload->secondary_key;
+
+done:
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+
+int ua_payload_get_device_uid(
+               ua_device_h handle,
+               char **device_uid)
+{
+       FUNC_ENTRY;
+       ua_dev_info_s *device = (ua_dev_info_s *)handle;
+
+       UA_VALIDATE_INPUT_PARAMETER(handle);
+       UA_VALIDATE_INPUT_PARAMETER(device_uid);
+       UA_PRINT_DEVICE_HANDLE(handle);
+       retv_if(device->type != UA_MAC_TYPE_BLE, UA_ERROR_INVALID_PARAMETER);
+
+       if (!device->payload || !device->payload->device_uid) {
+               *device_uid = NULL;
+               UA_DBG("payload(device_uid) is not found");
+               goto done;
+       }
+
+       *device_uid = g_memdup(device->payload->device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN);
+       if (*device_uid == NULL) {
+               // LCOV_EXCL_START
+               UA_ERR("g_memdup failed");
+               return UA_ERROR_OUT_OF_MEMORY;
+               // LCOV_EXCL_START
+       }
+
+done:
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
+*/
index 957b98258e2b749bd8f18e802d81984a13caa2a6..c7e3dc451672d15e8cb722378c53ebca6e5ee796 100644 (file)
@@ -934,14 +934,6 @@ int ua_service_foreach_added_devices(
                                goto done;
                        }
 
-                       device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
-                       if (device_info->payload == NULL) {
-                               UA_ERR("_ua_get_payload_from_uam() failed");
-                               ret = UA_ERROR_OUT_OF_MEMORY;
-                               _ua_free_ua_device_info_t((gpointer)device_info);
-                               goto done;
-                       }
-
                        device_info->isadded = true;
                        device_info->handle = (ua_device_h)device_info;
                        device_info->type = _to_ua_mac_type(ptr->type);
index 51c3a5d0434a3c04da1d96bc9162ea68d8bd2c6d..d65aee380f1fba78109be626cdf4b0dd9c851727 100644 (file)
@@ -946,8 +946,6 @@ int ua_user_add_device(ua_user_h user_handle, ua_device_h device_handle,
        if (device->ipv4)
                g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
 
-       _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
-
        ret = _ua_get_error_code(_uam_request_add_device(user->account, &uam_device));
        if (UA_ERROR_NONE != ret) {
                /* LCOV_EXCL_START */
@@ -1007,9 +1005,6 @@ int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle)
        if (device->ipv4)
                g_strlcpy(uam_device.ipv4_addr, device->ipv4, UA_IPV4_ADDRESS_STRING_LEN);
 
-//TODO lk, do we need this info to be filled
-       _ua_get_uam_payload_from_ua(&uam_device.payload, device->payload);
-
        ret = _ua_get_error_code(_uam_request_remove_device(user->account, &uam_device));
 
        if (UA_ERROR_NONE != ret) {
@@ -1134,14 +1129,6 @@ int ua_user_foreach_added_devices(
                                goto done;
                        }
 
-                       device_info->payload = _ua_get_payload_from_uam(&ptr->payload);
-                       if (device_info->payload == NULL) {
-                               UA_ERR("_ua_get_payload_from_uam() failed");
-                               ret = UA_ERROR_OUT_OF_MEMORY;
-                               _ua_free_ua_device_info_t((gpointer)device_info);
-                               goto done;
-                       }
-
                        device_info->isadded = true;
                        device_info->handle = (ua_device_h)device_info;
                        device_info->type = _to_ua_mac_type(ptr->type);
index 90a5e494947c9ffb34260a3a9cfe79c0dbdd1e9a..4509bb0bacb963b4e85ec946ac71514351e34801 100644 (file)
@@ -21,6 +21,7 @@ SET(TEST_SRCS
        uat-sensors.c
        uat-service.c
        uat-detections.c
+       uat-payload.c
 )
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
index 6009a0ca64f15013d590f8be4be30d12e3b591ab..be54b56e8115d352ace70419e0ae844a3c17b445 100644 (file)
@@ -43,10 +43,6 @@ static char g_bss_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< BSSID of the selected
 static char g_discriminant[MENU_DATA_SIZE + 1] = {"1",}; /**< Discrimniant for a device */
 static char g_ipv4_address_str[MENU_DATA_SIZE + 1] = {0,}; /**< IPv4 of the selected device */
 static char g_is_paring_required_str[MENU_DATA_SIZE + 1] = {0,}; /**< Is paring required for the selected device */
-static char g_payload_primary_key[MENU_DATA_SIZE + 1] = {0,}; /**< payload primary_key for the selected device */
-static char g_payload_device_icon[MENU_DATA_SIZE + 1] = {0,}; /**< payload device_icon for the selected device */
-static char g_payload_secondary_key[MENU_DATA_SIZE + 1] = {0,}; /**< payload secondary_key for the selected device */
-static char g_payload_device_uid_str[MENU_DATA_SIZE + 1] = {0,}; /**< payload device_uid for the selected device */
 
 char g_selected_device_idx[MENU_DATA_SIZE + 1] = {0,}; /**< Selected device id */
 extern char g_service_str[MENU_DATA_SIZE + 1];  /**< Service name string */
@@ -70,10 +66,6 @@ static bool __foreach_added_device_cb(
        bool required = false;
        unsigned long long last_seen = 0;
        bool discriminant = false;
-       char primary_key = 0;
-       char device_icon = 0;
-       char secondary_key = 0;
-       char *device_uid = NULL;
 
        if (!device_handle) {
                msgr("device_handle is NULL");
@@ -136,24 +128,6 @@ static bool __foreach_added_device_cb(
        if (UA_ERROR_NONE == ret_temp)
                msgb("Last present at : %llu", last_seen);
 
-       ret_temp = ua_device_get_payload_primary_key(handle, &primary_key);
-       if (UA_ERROR_NONE == ret_temp)
-               msgb("payload primary_key : %d[hex: 0x%X]", primary_key, primary_key);
-
-       ret_temp = ua_device_get_payload_device_icon(handle, &device_icon);
-       if (UA_ERROR_NONE == ret_temp)
-               msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon);
-
-       ret_temp = ua_device_get_payload_secondary_key(handle, &secondary_key);
-       if (UA_ERROR_NONE == ret_temp)
-               msgb("payload secondary_key : %d[hex: 0x%X]", secondary_key, secondary_key);
-
-       ret_temp = ua_device_get_payload_device_uid(handle, &device_uid);
-       if (UA_ERROR_NONE == ret_temp) {
-               uat_print_device_uid(device_uid);
-               g_free(device_uid);
-       }
-
        g_device_list = g_slist_append(g_device_list, handle);
 
        return true;
@@ -170,10 +144,6 @@ void uat_update_device_info(void)
        char *ipv4 = NULL;
        bool required = false;
        bool discriminant = false;
-       char primary_key = 0;
-       char device_icon = 0;
-       char secondary_key = 0;
-       char *device_uid = NULL;
 
        check_if(NULL == g_device_h);
 
@@ -232,52 +202,8 @@ void uat_update_device_info(void)
                        required ? "YES" : "NO ", sizeof("YES"));
        }
 
-       ret = ua_device_get_payload_primary_key(g_device_h, &primary_key);
-       if (UA_ERROR_NONE == ret)
-               snprintf(g_payload_primary_key, MENU_DATA_SIZE + 1, "%u",
-                       (unsigned int)primary_key);
-
-       ret = ua_device_get_payload_device_icon(g_device_h, &device_icon);
-       if (UA_ERROR_NONE == ret)
-               snprintf(g_payload_device_icon, MENU_DATA_SIZE + 1, "%u",
-                       (unsigned int)device_icon);
-
-       ret = ua_device_get_payload_secondary_key(g_device_h, &secondary_key);
-       if (UA_ERROR_NONE == ret)
-               snprintf(g_payload_secondary_key, MENU_DATA_SIZE + 1, "%u",
-                       (unsigned int)secondary_key);
-
-       ret = ua_device_get_payload_device_uid(g_device_h, &device_uid);
-       memset(g_payload_device_uid_str, 0, MENU_DATA_SIZE + 1);
-       if (UA_ERROR_NONE == ret && device_uid) {
-               memcpy(g_payload_device_uid_str, device_uid, UA_BLE_PAYLOAD_DEVICE_UID_LEN);
-               g_free(device_uid);
-       }
 }
 
-
-#ifndef SUPPORT_STRING_DEVICE_UID
-static int _scan_payload_device_uid_str(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-       int temp = 0;
-
-       msg("Input 17 bytes device_uid, each byte is 0 to 255 value");
-       memset(g_payload_device_uid_str, 0, MENU_DATA_SIZE + 1);
-
-       for (int i = 0; i < UA_BLE_PAYLOAD_DEVICE_UID_LEN; i++) {
-               ret = fscanf(stdin, "%d", &temp);
-               if(!ret)
-                       msg(" - fscanf ret: %d", ret);
-
-               g_payload_device_uid_str[i] = (unsigned char)temp;
-       }
-
-       return RET_SUCCESS;
-}
-#endif /* SUPPORT_STRING_DEVICE_UID */
-
 static int run_ua_device_create(
        MManager *mm, struct menu_data *menu)
 {
@@ -456,78 +382,6 @@ static int run_ua_device_set_wifi_ipv4_address(
        return RET_SUCCESS;
 }
 
-static int run_ua_device_set_payload_primary_key(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-       char primary_key = 0;
-
-       msg("ua_device_set_payload_primary_key");
-
-       if (strlen(g_payload_primary_key))
-               primary_key = (unsigned char)strtol(g_payload_primary_key, NULL, 10);
-
-       ret = ua_device_set_payload_primary_key(g_device_h, primary_key);
-
-       msg(" - ua_device_set_payload_primary_key() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_ua_device_set_payload_device_icon(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-       char device_icon = 0;
-
-       msg("ua_device_set_payload_device_icon");
-
-       if (strlen(g_payload_device_icon))
-               device_icon = (unsigned char)strtol(g_payload_device_icon, NULL, 10);
-
-       ret = ua_device_set_payload_device_icon(g_device_h, device_icon);
-
-       msg(" - ua_device_set_payload_device_icon() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_ua_device_set_payload_secondary_key(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-       char secondary_key = 0;
-
-       msg("ua_device_set_payload_secondary_key");
-
-       if (strlen(g_payload_secondary_key))
-               secondary_key = (unsigned char)strtol(g_payload_secondary_key, NULL, 10);
-
-       ret = ua_device_set_payload_secondary_key(g_device_h, secondary_key);
-
-       msg(" - ua_device_set_payload_secondary_key() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_ua_device_set_payload_device_uid(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-
-       msg("ua_device_set_payload_device_uid");
-
-       ret = ua_device_set_payload_device_uid(g_device_h, UA_BLE_PAYLOAD_DEVICE_UID_LEN, g_payload_device_uid_str);
-
-       msg(" - ua_device_set_payload_device_uid() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
 static int run_ua_device_get_by_mac_address(
        MManager *mm, struct menu_data *menu)
 {
@@ -659,42 +513,6 @@ static struct menu_data menu_ua_discrminiant[] = {
        { NULL, NULL, },
 };
 
-static struct menu_data menu_ua_device_set_payload_primary_key[] = {
-       { "1", "Service_ID (0 to 255)",
-               NULL, NULL, g_payload_primary_key },
-       { "2", "run", NULL,
-               run_ua_device_set_payload_primary_key, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_ua_device_set_payload_device_icon[] = {
-       { "1", "device_icon (0 to 255)",
-               NULL, NULL, g_payload_device_icon },
-       { "2", "run", NULL,
-               run_ua_device_set_payload_device_icon, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_ua_device_set_payload_secondary_key[] = {
-       { "1", "Purpose (0 to 255)",
-               NULL, NULL, g_payload_secondary_key },
-       { "2", "run", NULL,
-               run_ua_device_set_payload_secondary_key, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_ua_device_set_payload_device_uid[] = {
-       { "1", "DEVICE_UID (Max. 17 bytes)",
-#ifdef SUPPORT_STRING_DEVICE_UID
-               NULL, NULL, g_payload_device_uid_str },
-#else
-               NULL, _scan_payload_device_uid_str, NULL },
-#endif
-       { "2", "run", NULL,
-               run_ua_device_set_payload_device_uid, NULL },
-       { NULL, NULL, },
-};
-
 static struct menu_data menu_ua_devlist_by_mac[] = {
        { "1", "MAC",
                NULL, NULL, g_mac_addr_str },
@@ -730,14 +548,6 @@ struct menu_data menu_ua_devices[] = {
                menu_ua_discrminiant, NULL, g_discriminant},
        { "8", "ua_device_set_wifi_ipv4_address",
                menu_ua_ipv4_address, NULL, g_ipv4_address_str },
-       { "9", "ua_device_set_payload_primary_key",
-               menu_ua_device_set_payload_primary_key, NULL, g_payload_primary_key },
-       { "10", "ua_device_set_payload_device_icon",
-               menu_ua_device_set_payload_device_icon, NULL, g_payload_device_icon },
-       { "11", "ua_device_set_payload_secondary_key",
-               menu_ua_device_set_payload_secondary_key, NULL, g_payload_secondary_key },
-       { "12", "ua_device_set_payload_device_uid",
-               menu_ua_device_set_payload_device_uid, NULL, g_payload_device_uid_str },
        { "13", "ua_device_get_wifi_bssid",
                NULL, run_ua_device_get_wifi_bssid, NULL },
        { "14", "ua_device_get_by_mac_address",
index 0552467704ab60de33fbf411fccb7608af07b0a4..a925f65c15c3b9649a7eeabb2fc4d259e2d69222 100644 (file)
@@ -37,6 +37,7 @@ extern struct menu_data menu_ua_init[];
 extern struct menu_data menu_ua_devices[];
 extern struct menu_data menu_ua_users[];
 extern struct menu_data menu_ua_services[];
+extern struct menu_data menu_ua_payloads[];
 extern struct menu_data menu_ua_sensors[];
 extern struct menu_data menu_ua_detections[];
 
@@ -47,6 +48,7 @@ static struct menu_data menu_main[] = {
        { "4", "Services", menu_ua_services, NULL, NULL },
        { "5", "Sensors", menu_ua_sensors, NULL, NULL },
        { "6", "Detection", menu_ua_detections, NULL, NULL },
+       { "7", "Payload", menu_ua_payloads, NULL, NULL },
        { NULL, NULL, },
 };
 
diff --git a/test/uat-payload.c b/test/uat-payload.c
new file mode 100644 (file)
index 0000000..2e062f8
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "uat-common.h"
+
+extern ua_device_h g_device_h; /**< Device handle */
+ua_payload_h g_payload_h = NULL; /**< Payload handle */
+
+static char g_payload_primary_key[MENU_DATA_SIZE + 1] = {0,}; /**< payload primary_key for the selected device */
+static char g_payload_device_icon[MENU_DATA_SIZE + 1] = {0,}; /**< payload device_icon for the selected device */
+static char g_payload_secondary_key[MENU_DATA_SIZE + 1] = {0,}; /**< payload secondary_key for the selected device */
+static char g_payload_device_uid_str[MENU_DATA_SIZE + 1] = {0,}; /**< payload device_uid for the selected device */
+
+static int run_ua_payload_create(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+
+       msg("ua_payload_create");
+
+       if (g_payload_h) {
+               ua_payload_destroy(g_payload_h);
+               g_payload_h = NULL;
+       }
+
+       ret = ua_payload_create(&g_payload_h);
+
+       msg(" - ua_payload_create() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_ua_payload_destroy(MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+
+       msg("ua_payload_destroy");
+
+       ret = ua_payload_destroy(g_payload_h);
+       g_payload_h = NULL;
+
+       msg(" - ua_payload_destroy() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+#ifndef SUPPORT_STRING_DEVICE_UID
+static int _scan_payload_device_uid_str(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+       int temp = 0;
+
+       msg("Input 17 bytes device_uid, each byte is 0 to 255 value");
+       memset(g_payload_device_uid_str, 0, MENU_DATA_SIZE + 1);
+
+       for (int i = 0; i < UA_BLE_PAYLOAD_DEVICE_UID_LEN; i++) {
+               ret = fscanf(stdin, "%d", &temp);
+               if(!ret)
+                       msg(" - fscanf ret: %d", ret);
+
+               g_payload_device_uid_str[i] = (unsigned char)temp;
+       }
+
+       return RET_SUCCESS;
+}
+#endif /* SUPPORT_STRING_DEVICE_UID */
+
+static int run_ua_payload_set_primary_key(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+       char primary_key = 0;
+
+       msg("ua_payload_set_primary_key");
+
+       if (strlen(g_payload_primary_key))
+               primary_key = (unsigned char)strtol(g_payload_primary_key, NULL, 10);
+
+       ret = ua_payload_set_primary_key(g_payload_h, primary_key);
+
+       msg(" - ua_payload_set_primary_key() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_ua_payload_set_device_icon(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+       char device_icon = 0;
+
+       msg("ua_payload_set_device_icon");
+
+       if (strlen(g_payload_device_icon))
+               device_icon = (unsigned char)strtol(g_payload_device_icon, NULL, 10);
+
+       ret = ua_payload_set_device_icon(g_payload_h, device_icon);
+
+       msg(" - ua_payload_set_device_icon() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_ua_payload_set_secondary_key(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+       char secondary_key = 0;
+
+       msg("ua_payload_set_secondary_key");
+
+       if (strlen(g_payload_secondary_key))
+               secondary_key = (unsigned char)strtol(g_payload_secondary_key, NULL, 10);
+
+       ret = ua_payload_set_secondary_key(g_payload_h, secondary_key);
+
+       msg(" - ua_payload_set_secondary_key() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_ua_payload_set_device_uid(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+
+       msg("ua_payload_set_device_uid");
+
+       ret = ua_payload_set_device_uid(g_payload_h,
+               UA_BLE_PAYLOAD_DEVICE_UID_LEN, g_payload_device_uid_str);
+
+       msg(" - ua_payload_set_device_uid() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+static int run_ua_payload_add(
+       MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+
+       msg("ua_payload_add");
+
+       check_if(NULL == g_payload_h);
+
+       ret = ua_payload_add(g_payload_h, g_device_h);
+
+       msg(" - ua_payload_add() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
+static struct menu_data menu_ua_payload_set_primary_key[] = {
+       { "1", "Primary Key (0 to 255)",
+               NULL, NULL, g_payload_primary_key },
+       { "2", "run", NULL,
+               run_ua_payload_set_primary_key, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_ua_payload_set_device_icon[] = {
+       { "1", "device_icon (0 to 255)",
+               NULL, NULL, g_payload_device_icon },
+       { "2", "run", NULL,
+               run_ua_payload_set_device_icon, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_ua_payload_set_secondary_key[] = {
+       { "1", "Purpose (0 to 255)",
+               NULL, NULL, g_payload_secondary_key },
+       { "2", "run", NULL,
+               run_ua_payload_set_secondary_key, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_ua_payload_set_device_uid[] = {
+       { "1", "DEVICE_UID (Max. 17 bytes)",
+#ifdef SUPPORT_STRING_DEVICE_UID
+               NULL, NULL, g_payload_device_uid_str },
+#else
+               NULL, _scan_payload_device_uid_str, NULL },
+#endif
+       { "2", "run", NULL,
+               run_ua_payload_set_device_uid, NULL },
+       { NULL, NULL, },
+};
+
+struct menu_data menu_ua_payloads[] = {
+       { "1", "ua_payload_create",
+               NULL, run_ua_payload_create, NULL },
+       { "2", "ua_payload_destroy",
+               NULL, run_ua_payload_destroy, NULL },
+       { "3", "ua_payload_set_primary_key",
+               menu_ua_payload_set_primary_key, NULL, g_payload_primary_key },
+       { "4", "ua_payload_set_device_icon",
+               menu_ua_payload_set_device_icon, NULL, g_payload_device_icon },
+       { "5", "ua_payload_set_secondary_key",
+               menu_ua_payload_set_secondary_key, NULL, g_payload_secondary_key },
+       { "6", "ua_payload_set_device_uid",
+               menu_ua_payload_set_device_uid, NULL, g_payload_device_uid_str },
+       { "7", ANSI_COLOR_LIGHTGREEN "ua_payload_add" ANSI_COLOR_NORMAL,
+               NULL, run_ua_payload_add, NULL },
+       { NULL, NULL, },
+};
index 66f7ce00c60f9f0baee955a6edccf04ccdddc19d..fdb10b0fe94293c69b4513f35c830655f32bc3a7 100644 (file)
@@ -191,10 +191,6 @@ static bool _service_foreach_added_device_cb(
        bool required = false;
        bool discriminant = false;
        unsigned long long last_seen = 0;
-       char primary_key = 0;
-       char device_icon = 0;
-       char secondary_key = 0;
-       char *device_uid = NULL;
 
        if (!service_handle) {
                msgr("service_handle is NULL");
@@ -268,24 +264,6 @@ static bool _service_foreach_added_device_cb(
        if (UA_ERROR_NONE == ret_temp)
                msgb("Last present at : %llu", last_seen);
 
-       ret_temp = ua_device_get_payload_primary_key(handle, &primary_key);
-       if (UA_ERROR_NONE == ret_temp)
-               msgb("payload primary_key : %d[hex: 0x%X]", primary_key, primary_key);
-
-       ret_temp = ua_device_get_payload_device_icon(handle, &device_icon);
-       if (UA_ERROR_NONE == ret_temp)
-               msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon);
-
-       ret_temp = ua_device_get_payload_secondary_key(handle, &secondary_key);
-       if (UA_ERROR_NONE == ret_temp)
-               msgb("payload secondary_key : %d[hex: 0x%X]", secondary_key, secondary_key);
-
-       ret_temp = ua_device_get_payload_device_uid(handle, &device_uid);
-       if (UA_ERROR_NONE == ret_temp) {
-               uat_print_device_uid(device_uid);
-               g_free(device_uid);
-       }
-
        g_device_list = g_slist_append(g_device_list, handle);
 
        return true;
index 4f2bdcc8266c76fa835af9a8fa08522625d89e16..e1d5a3777682ff77e443efbf5e507cd5c74c8d8a 100644 (file)
@@ -206,10 +206,6 @@ static bool _user_foreach_added_device_cb(ua_device_h device_handle,
        bool required = false;
        unsigned long long last_seen = 0;
        bool discriminant = false;
-       char primary_key = 0;
-       char device_icon = 0;
-       char secondary_key = 0;
-       char *device_uid = NULL;
 
        if (!device_handle) {
                msgr("device_handle is NULL");
@@ -273,24 +269,6 @@ static bool _user_foreach_added_device_cb(ua_device_h device_handle,
        if (UA_ERROR_NONE == ret_temp)
                msgc("Last present at : %llu", last_seen);
 
-       ret_temp = ua_device_get_payload_primary_key(handle, &primary_key);
-       if (UA_ERROR_NONE == ret_temp)
-               msgc("payload primary_key : %d[hex: 0x%X]", primary_key, primary_key);
-
-       ret_temp = ua_device_get_payload_device_icon(handle, &device_icon);
-       if (UA_ERROR_NONE == ret_temp)
-               msgc("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon);
-
-       ret_temp = ua_device_get_payload_secondary_key(handle, &secondary_key);
-       if (UA_ERROR_NONE == ret_temp)
-               msgc("payload secondary_key : %d[hex: 0x%X]", secondary_key, secondary_key);
-
-       ret_temp = ua_device_get_payload_device_uid(handle, &device_uid);
-       if (UA_ERROR_NONE == ret_temp) {
-               uat_print_device_uid(device_uid);
-               g_free(device_uid);
-       }
-
        g_device_list = g_slist_append(g_device_list, handle);
 
        return true;