Core networking libraries including LwIP implementation

Dependencies:   DebugLib Socket lwip lwip-sys

Dependents:   EthernetInterface

Fork of NetworkingCoreLib by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Wed Jun 20 13:17:26 2012 +0000
Parent:
9:441d060c8861
Parent:
10:14ef6ceb4e75
Child:
12:06fa5c117973
Commit message:
Merge

Changed in this revision

--- a/main/if/IPInterface.cpp	Fri Jun 15 16:37:37 2012 +0000
+++ b/main/if/IPInterface.cpp	Wed Jun 20 13:17:26 2012 +0000
@@ -25,6 +25,8 @@
 
 #include "IPInterface.h"
 
+#include <cstring> //For strcpy
+
 
 IPInterface::IPInterface()
 {
@@ -52,3 +54,32 @@
 }
 
 /*static*/ IPInterface* IPInterface::s_pDefaultInterface = NULL;
+
+
+char* IPInterface::getIPAddress() //Get IP Address as a string ('a.b.c.d')
+{
+  if(isConnected())
+  {
+    return m_ipAddr;
+  }
+  else
+  {
+    return NULL;
+  }
+}
+
+bool IPInterface::isConnected() //Is the interface connected?
+{
+  return m_connected;
+}
+
+void IPInterface::setIPAddress(char* ipAddr)
+{
+  std::strcpy(m_ipAddr, ipAddr); //Let's trust the derived class not to buffer overflow us
+}
+
+void IPInterface::setConnected(bool connected)
+{
+  m_connected = connected;
+}
+
--- a/main/if/IPInterface.h	Fri Jun 15 16:37:37 2012 +0000
+++ b/main/if/IPInterface.h	Wed Jun 20 13:17:26 2012 +0000
@@ -36,9 +36,12 @@
     virtual ~IPInterface();
 
     //int init(); //Initialize interface; no connection should be performed at this stage
-    //int connect(); //Do connect the interface
-    //int disconnect();
+    virtual int connect() = 0; //Do connect the interface
+    virtual int disconnect() = 0;
     //It is encouraged that the derived class implement a "setup(...)" function to configure the interface before the connection
+    
+    char* getIPAddress(); //Get IP Address as a string ('a.b.c.d')
+    bool isConnected(); //Is the interface connected?
 
     static IPInterface* getDefaultInterface(); //For use by TCP, UDP sockets library
 
@@ -46,7 +49,15 @@
     void registerAsDefaultInterface(); //First come, first served
     void unregisterAsDefaultInterface(); //Must be called before inst is destroyed to avoid invalid ptr fault
 
+protected:
+    //Must be called by subclasses
+    void setIPAddress(char* ipAddr);
+    void setConnected(bool connected);
+
 private:
+    char m_ipAddr[16];
+    bool m_connected;
+
     static IPInterface* s_pDefaultInterface;
 };
 
--- a/main/if/LwIPInterface.h	Fri Jun 15 16:37:37 2012 +0000
+++ b/main/if/LwIPInterface.h	Wed Jun 20 13:17:26 2012 +0000
@@ -39,7 +39,7 @@
     virtual ~LwIPInterface();
 
     int init(); //Init LwIP-specific stuff, create the right bindings, etc
-
+    
 private:
     static void tcpipRdyCb(void* ctx); //Result of TCP/IP thread launch
     Semaphore m_rdySphre;