Add API to get payloads list
authorAbhay agarwal <ay.agarwal@samsung.com>
Thu, 12 Dec 2019 09:55:02 +0000 (15:25 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 30 Dec 2019 07:29:55 +0000 (16:29 +0900)
Signed-off-by: Abhay agarwal <ay.agarwal@samsung.com>
include/ua-internal.h
ua-api/src/ua-api.c
ua-daemon/include/ua-manager-core.h
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-request-handler.c

index 71afe94..b9e7156 100644 (file)
@@ -85,6 +85,7 @@ extern "C" {
        REQUEST(UAM_REQUEST_ADD_IBEACON_ADV) \
        REQUEST(UAM_REQUEST_ADD_PAYLOAD) \
        REQUEST(UAM_REQUEST_ADD_PAYLOAD_TO_SERVICE) \
+       REQUEST(UAM_REQUEST_GET_PAYLOADS) \
        REQUEST(UAM_REQUEST_MAX)
 
 #define GENERATE_REQUEST_ENUM(ENUM) ENUM,
index ed751e7..8d2a20b 100644 (file)
@@ -1491,3 +1491,40 @@ UAM_EXPORT_API int _uam_service_add_payload(const char *service,
        FUNC_EXIT;
        return ret;
 }
+
+UAM_EXPORT_API int _uam_get_added_payloads(GPtrArray **payload_list)
+{
+       FUNC_ENTRY;
+       int ret;
+
+       UAM_VALIDATE_INPUT_PARAMETER(payload_list);
+
+       UAM_INIT_PARAMS();
+       UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       ret = _uam_sync_request(UAM_REQUEST_GET_PAYLOADS,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+       if (UAM_ERROR_NONE == ret && NULL != out_param) {
+               int i;
+               int count;
+
+               count = (out_param->len)/sizeof(uam_ble_payload_s);
+               if (0 == count)
+                       UAM_INFO("No registered payloads");
+
+               for (i = 0; i < count; i++) {
+                       uam_ble_payload_s *payload_info = NULL;
+                       uam_ble_payload_s *info;
+
+                       info = &g_array_index(out_param, uam_ble_payload_s, i);
+                       payload_info = g_memdup(info, sizeof(uam_ble_payload_s));
+                       if (payload_info)
+                               g_ptr_array_add(*payload_list, (gpointer)payload_info);
+               }
+       }
+
+       UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       FUNC_EXIT;
+       return ret;
+}
index 1a2f15f..295876b 100644 (file)
@@ -73,7 +73,7 @@ typedef struct {
        char secondary_key; /** Purpose */
        char *device_uid; /** DEVICE_UID */
        char *bt_mac; /** BT MAC Address */
-} uam_db_ble_payload_t;
+} uam_db_payload_info_t;
 
 typedef struct {
        uam_tech_type_e tech_type; /**< Connectivity type */
@@ -259,6 +259,8 @@ int _uam_core_add_payload(uam_ble_payload_s *payload, const char *device_id,
 int _uam_core_service_add_payload(uam_ble_payload_s *payload,
                const char *svc_name);
 
+int _uam_core_get_payloads(int *count, uam_ble_payload_s **payload_list);
+
 #ifdef __cplusplus
 }
 #endif
index 8b18cb2..f6405d5 100644 (file)
@@ -49,6 +49,7 @@ static GSList *users; /* List of users - uam_db_user_info_t */
 static GSList *devices; /* List of devices - uam_db_device_info_t */
 static GSList *services; /* List of services -  uam_db_service_info_t */
 static GSList *svc_devs; /* List of service device mapping -  uam_svc_dev_info_t */
+static GSList *payloads; /* List of payloads - uam_db_payload_info_t */
 
 static GSList *monitors; /* List of monitoring apps - uam_monitor_info_t */
 static GSList *scanners; /* List of scanning apps -  uam_scanner_info_t */
@@ -266,23 +267,6 @@ static void __uam_core_copy_addr(uam_device_info_s *device, uam_db_address_info_
        }
 }
 
-/*
-static void __uam_copy_payload_info(uam_ble_payload_s *dev_payload, uam_db_ble_payload_t *payload)
-{
-       if (payload) {
-               dev_payload->primary_key = payload->primary_key;
-               dev_payload->device_icon = payload->device_icon;
-               dev_payload->secondary_key = payload->secondary_key;
-               if (payload->device_uid)
-                       memcpy(dev_payload->device_uid,
-                       payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN);
-               if (payload->bt_mac)
-                       memcpy(dev_payload->bt_mac,
-                       payload->bt_mac, UAM_BT_MAC_ADDRESS_STRING_LEN);
-       }
-}
-*/
-
 static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_info_s *device)
 {
        FUNC_ENTRY;
@@ -3874,12 +3858,44 @@ void _uam_core_handle_status_changed(unsigned int sensor, void *info)
        FUNC_EXIT;
 }
 
+static void __uam_copy_db_payload_info(uam_ble_payload_s *dst_payload,
+       uam_db_payload_info_t *src_payload)
+{
+       if (src_payload) {
+               dst_payload->primary_key = src_payload->primary_key;
+               dst_payload->device_icon = src_payload->device_icon;
+               dst_payload->secondary_key = src_payload->secondary_key;
+               if (src_payload->device_uid)
+                       memcpy(dst_payload->device_uid,
+                       src_payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN);
+               if (src_payload->bt_mac)
+                       memcpy(dst_payload->bt_mac,
+                       src_payload->bt_mac, UAM_BT_MAC_ADDRESS_STRING_LEN);
+       }
+}
+
+static void __uam_copy_uam_payload_info(
+               uam_db_payload_info_t *dst_payload, uam_ble_payload_s *src_payload)
+{
+       if (src_payload) {
+               dst_payload = g_new0(uam_db_payload_info_t, 1);
+               dst_payload->primary_key = src_payload->primary_key;
+               dst_payload->device_icon = src_payload->device_icon;
+               dst_payload->secondary_key = src_payload->secondary_key;
+               dst_payload->device_uid = g_memdup(&(src_payload->device_uid),
+                                       UAM_BLE_PAYLOAD_DEVICE_UID_LEN);
+               dst_payload->bt_mac = g_memdup(&(src_payload->bt_mac),
+                                       UAM_BT_MAC_ADDRESS_STRING_LEN);
+       }
+}
+
 int _uam_core_add_payload(uam_ble_payload_s *payload,
                const char *device_id, int tech_type)
 {
        FUNC_ENTRY;
        int ret = UAM_ERROR_NONE;
        uam_db_tech_info_t *tech_info;
+       uam_db_payload_info_t *db_payload;
        char *mac;
 
        retv_if(NULL == payload, UAM_ERROR_INVALID_PARAMETER);
@@ -3887,6 +3903,8 @@ int _uam_core_add_payload(uam_ble_payload_s *payload,
        retv_if(UAM_TECH_TYPE_NONE >= tech_type, UAM_ERROR_INVALID_PARAMETER);
        retv_if(UAM_TECH_TYPE_MAX <= tech_type, UAM_ERROR_INVALID_PARAMETER);
 
+       // <TO-DO> check if payload already exist
+
        tech_info = __uam_core_get_dev_tech_info(device_id, tech_type);
        retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER);
        mac = __get_mac_addr(tech_info);
@@ -3898,6 +3916,9 @@ int _uam_core_add_payload(uam_ble_payload_s *payload,
                return ret;
        }
 
+       __uam_copy_uam_payload_info(db_payload, payload);
+       payloads = g_slist_append(payloads, db_payload);
+
        FUNC_EXIT;
        return UAM_ERROR_NONE;
 }
@@ -3913,12 +3934,16 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload,
        retv_if(NULL == payload, UAM_ERROR_INVALID_PARAMETER);
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
 
+       // <TO-DO> check if payload exist
+       // <TO-DO> check if service exist
+       // <TO-DO> check if device-service exist
+
        /* Retrieve service from list */
        l = g_slist_find_custom(services, svc_name, __compare_svc_name);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        service = l->data;
 
-       /*** Add payload to database ***/
+       /*** Add payload service mapping to database ***/
        ret = _uam_db_update_device_service_payload_info(payload, service->name);
        if (UAM_ERROR_NONE != ret) {
                UAM_ERR("_uam_db_update_device_service_payload_info failed");
@@ -3928,3 +3953,29 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload,
        FUNC_EXIT;
        return UAM_ERROR_NONE;
 }
+
+int _uam_core_get_payloads(int *count, uam_ble_payload_s **payload_list)
+{
+       FUNC_ENTRY;
+       guint size;
+       GSList *l;
+
+       size = g_slist_length(payloads);
+       *payload_list = g_new0(uam_ble_payload_s, size);
+       *count = 0;
+
+       /* fetch payloads list from DB */
+       for (l = payloads; l; l = g_slist_next(l)) {
+               uam_db_payload_info_t *db_info = l->data;
+
+               if (!db_info || !db_info->device_uid)
+                       continue;
+
+               __uam_copy_db_payload_info(&(*payload_list)[*count], db_info);
+               *count += 1;
+       }
+
+       UAM_INFO("Count: %d", *count);
+       FUNC_EXIT;
+       return UAM_ERROR_NONE;
+}
index c5133ec..cf149af 100644 (file)
@@ -720,6 +720,22 @@ static int __uam_manager_sync_request_handler(
                result = _uam_core_service_add_payload(&payload, svc_name);
                break;
        }
+       case UAM_REQUEST_GET_PAYLOADS: {
+               int count = 0;
+               uam_ble_payload_s *payloads = NULL;
+
+               result = _uam_core_get_payloads(&count, &payloads);
+               if (UAM_ERROR_NONE == result) {
+                       int indx;
+
+                       for (indx = 0; indx < count; indx++)
+                               g_array_append_vals(*out_param1,
+                                               &(payloads[indx]), sizeof(uam_ble_payload_s));
+
+                       g_free(payloads);
+               }
+               break;
+       }
        default:
                UAM_WARN("UnSupported function [%s(0x%4.4X)]",
                                _uam_manager_request_to_str(function), function);
@@ -919,6 +935,7 @@ static gboolean __uam_manager_is_sync_function(int function)
        case UAM_REQUEST_ADD_IBEACON_ADV:
        case UAM_REQUEST_ADD_PAYLOAD:
        case UAM_REQUEST_ADD_PAYLOAD_TO_SERVICE:
+       case UAM_REQUEST_GET_PAYLOADS:
                return TRUE;
        default:
                return FALSE;