Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

Revision:
0:ea85c4bb5e1f
Child:
1:6ec9998427ad
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/internal/types/ScanResultList.cpp	Mon Aug 11 09:58:24 2014 +0000
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2014, ACKme Networks
+ * All Rights Reserved.
+ *
+ * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
+ * the contents of this file may not be disclosed to third parties, copied
+ * or duplicated in any form, in whole or in part, without the prior
+ * written permission of ACKme Networks.
+ */
+
+#include <assert.h>
+#include "Wiconnect.h"
+#include "types/ScanResult.h"
+
+
+
+/*************************************************************************************************/
+ScanResultList::ScanResultList(int bufferLen_, void *buffer_)
+{
+    assert((bufferLen_ == 0 && buffer_ == NULL) || (bufferLen_ != 0 && buffer_ != NULL));
+    count = 0;
+    listHead = listTail = NULL;
+    buffer = (uint8_t*)buffer_;
+    bufferPtr = buffer;
+    bufferLen = bufferLen_;
+}
+
+/*************************************************************************************************/
+ScanResultList::~ScanResultList()
+{
+    if(buffer == NULL)
+    {
+        ScanResult* result = listHead;
+        while(result != NULL)
+        {
+            ScanResult* tmp = result;
+            result = result->next;
+            delete tmp;
+        }
+    }
+}
+
+/*************************************************************************************************/
+WiconnectResult ScanResultList::add(const char *channelStr, const char *rssiStr, const char* macStr, const char *rateStr, const char *secStr, const char *ssidStr)
+{
+    WiconnectResult result;
+    ScanResult *res;
+
+    if(buffer == NULL)
+    {
+        res = new ScanResult();
+        if(res == NULL)
+        {
+            return WICONNECT_NULL_BUFFER;
+        }
+    }
+    else
+    {
+        if(bufferLen < sizeof(ScanResult))
+        {
+            return WICONNECT_OVERFLOW;
+        }
+        res = (ScanResult*)bufferPtr;
+        memset(res, 0, sizeof(ScanResult));
+        bufferLen -= sizeof(ScanResult);
+        bufferPtr += sizeof(ScanResult);
+    }
+
+    if(WICONNECT_FAILED(result, res->init(channelStr, rssiStr, macStr, rateStr, secStr, ssidStr)))
+    {
+        if(buffer == NULL)
+        {
+            delete res;
+        }
+    }
+    else
+    {
+        if(listHead == NULL)
+        {
+            listHead = listTail = res;
+        }
+        else
+        {
+            res->previous = listTail;
+            listTail->next = res;
+            listTail = res;
+        }
+        ++count;
+    }
+
+    return result;
+}
+
+/*************************************************************************************************/
+const ScanResult* ScanResultList::getListHead() const
+{
+    return listHead;
+}
+
+/*************************************************************************************************/
+int ScanResultList::getCount() const
+{
+    return count;
+}
+
+/*************************************************************************************************/
+const ScanResult* ScanResultList::getResult(int i) const
+{
+    if(i >= count)
+        return NULL;
+
+    ScanResult* result = listHead;
+    while(i-- != 0)
+        result = result->next;
+
+    return result;
+}
+
+/*************************************************************************************************/
+const ScanResult* ScanResultList::operator [](int i) const
+{
+    return getResult(i);
+}
+
+
+
+
+
+