Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / tizen / caedrutils.c
index 70073ae..72df325 100644 (file)
 #include <bluetooth.h>
 
 #include "logger.h"
+#include "uarraylist.h"
+
+/**
+ * Pending devices list for data transfer.
+ */
+static u_arraylist_t *g_deviceStateList = NULL;
 
 bool CAEDRIsServiceSupported(const char **serviceUUID, int32_t serviceCount,
                                  const char *matchService)
@@ -54,5 +60,69 @@ bool CAEDRIsServiceSupported(const char **serviceUUID, int32_t serviceCount,
     return false;
 }
 
+CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress)
+{
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "CAEDRGetDeviceInfoFromAddress");
 
+    if (!remoteAddress)
+    {
+        OIC_LOG(ERROR, EDR_ADAPTER_TAG, "remoteAddress is null");
+        return NULL;
+    }
+
+    uint32_t length = u_arraylist_length(g_deviceStateList);
+    for (uint32_t index = 0; index < length; index++)
+    {
+        CAConnectedDeviceInfo_t* deviceInfo =
+                (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
+        if (!deviceInfo)
+        {
+            OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "deviceInfo object is null");
+            continue;
+        }
+
+        if (!strcmp((const char*) deviceInfo->address, remoteAddress))
+        {
+            return deviceInfo;
+        }
+    }
+    return NULL;
+}
+
+CAResult_t CAEDRAddDeviceInfoToList(const char *remoteAddress, CAConnectedDeviceInfo_t *deviceInfo)
+{
+    if (!remoteAddress)
+    {
+        OIC_LOG(ERROR, EDR_ADAPTER_TAG, "remoteAddress is null");
+        return CA_STATUS_INVALID_PARAM;
+    }
+
+    if (!deviceInfo)
+    {
+        OIC_LOG(ERROR, EDR_ADAPTER_TAG, "deviceInfo is null");
+        return CA_STATUS_INVALID_PARAM;
+    }
+
+    for (int i = 0; i < CA_MACADDR_SIZE; i++)
+    {
+        deviceInfo->address[i] = (uint8_t) remoteAddress[i];
+    }
+
+    if (!g_deviceStateList)
+    {
+        g_deviceStateList = u_arraylist_create();
+        if (!g_deviceStateList)
+        {
+            OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create Device list");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (!u_arraylist_add(g_deviceStateList, (void *) deviceInfo))
+    {
+        OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Add Device to list");
+        return CA_STATUS_FAILED;
+    }
 
+    return CA_STATUS_OK;
+}
\ No newline at end of file