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/types/SocketIrqHandlerMap.h	Mon Aug 11 09:58:24 2014 +0000
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "Wiconnect.h"
+#include "types/PinIrqHandler.h"
+
+namespace wiconnect
+{
+
+class SocketIrqHandlerMap
+{
+public:
+    /*************************************************************************************************/
+    SocketIrqHandlerMap()
+    {
+        memset(handlers, 0, sizeof(handlers));
+    }
+
+    /*************************************************************************************************/
+    ~SocketIrqHandlerMap()
+    {
+        for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i)
+        {
+            if(handlers[i] != NULL)
+            {
+                handlers[i]->~PinIrqHandler();
+            }
+        }
+    }
+
+    /*************************************************************************************************/
+    bool pinIsRegistered(Pin pin)
+    {
+        for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i)
+        {
+            if(handlers[i] != NULL && handlers[i]->irqPin == pin)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /*************************************************************************************************/
+    WiconnectResult registerHandler(Pin pin, const Callback &callback)
+    {
+        if(pinIsRegistered(pin))
+        {
+            return WICONNECT_DUPLICATE;
+        }
+
+        PinIrqHandler *handler = NULL;
+
+        for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i)
+        {
+            if(handlers[i] == NULL)
+            {
+                handler = (PinIrqHandler*)&handlerBuffers[i];
+                handlers[i] = handler;
+            }
+        }
+
+        if(handler == NULL)
+        {
+            return WICONNECT_NOT_FOUND;
+        }
+
+        *handler = PinIrqHandler(pin, callback);
+
+        return WICONNECT_SUCCESS;
+    }
+
+    /*************************************************************************************************/
+    WiconnectResult unregisterHandler(Pin pin)
+    {
+        for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i)
+        {
+            if(handlers[i] != NULL && handlers[i]->irqPin == pin)
+            {
+                handlers[i]->~PinIrqHandler();
+                handlers[i] = NULL;
+                return WICONNECT_SUCCESS;
+            }
+        }
+
+        return WICONNECT_NOT_FOUND;
+    }
+
+private:
+    PinIrqHandler *handlers[WICONNECT_MAX_PIN_IRQ_HANDLERS];
+    PinIrqHandlerBuffer handlerBuffers[WICONNECT_MAX_PIN_IRQ_HANDLERS];
+};
+
+
+
+}
+