naze-shippai-suru-noka

Dependencies:   TextLCD mbed pop3

Files at this revision

API Documentation at this revision

Comitter:
kogure7
Date:
Tue Nov 01 11:58:29 2011 +0000
Parent:
0:85a5c0651795
Commit message:

Changed in this revision

core/host.h Show annotated file Show diff for this revision Revisions of this file
core/ipaddr.h Show annotated file Show diff for this revision Revisions of this file
core/net.h Show annotated file Show diff for this revision Revisions of this file
core/netservice.h Show annotated file Show diff for this revision Revisions of this file
pop3.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/host.h	Tue Nov 01 11:58:29 2011 +0000
@@ -0,0 +1,109 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef HOST_H
+#define HOST_H
+
+#include "ipaddr.h"
+#include <string.h>
+
+///Host information container
+/**
+This class is a container for data relative to a connection:
+- IP Address
+- Port number
+- Host Name
+*/
+class Host 
+{
+public:
+  ///Initiliazes host with null values
+  Host() : m_ip(0,0,0,0), m_port(0), m_name(NULL)
+  {
+    
+  }
+  
+  ///Initializes host
+  Host(const IpAddr& ip, const int& port, const char* name="" ) : m_ip(ip), m_port(port), m_name(NULL)
+  {
+    setName(name); 
+  }
+  
+  ~Host()
+  {
+    if(m_name)
+    {
+      delete[] m_name;
+    }
+  }
+  
+  ///Returns IP address
+  const IpAddr& getIp() const
+  {
+    return m_ip;
+  }
+  
+  ///Returns port number
+  const int& getPort() const
+  {
+    return m_port;
+  }
+  
+  ///Returns host name
+  const char* getName() const
+  {
+    return m_name;
+  }
+  
+  ///Sets IP address
+  void setIp(const IpAddr& ip)
+  {
+    m_ip = ip;
+  }
+  
+  ///Sets port number
+  void setPort(int port)
+  {
+    m_port = port;
+  }
+  
+  ///Sets host name
+  void setName(const char* name)
+  {
+    if(m_name)
+      delete[] m_name;
+    int len = strlen(name);
+    if(len)
+    {
+      m_name = new char[len+1];
+      strcpy(m_name, name);
+    }
+  }
+  
+private:
+  IpAddr m_ip;
+  int m_port;
+  char* m_name;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/ipaddr.h	Tue Nov 01 11:58:29 2011 +0000
@@ -0,0 +1,98 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef IPADDR_H
+#define IPADDR_H
+
+#include "netCfg.h"
+#if NET_LWIP_STACK
+typedef struct ip_addr ip_addr_t;
+#endif
+
+#include "stdint.h"
+
+///IP Address container
+/**
+This class is a container for an IPv4 address.
+*/
+class IpAddr //Basically a C++ frontend to ip_addr_t
+{
+public:
+  #if NET_LWIP_STACK
+  IpAddr(ip_addr_t* pIp);
+  #endif
+  
+  ///Initializes IP address with provided values
+  IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3);
+  
+  ///Initializes IP address with null values 
+  IpAddr();
+
+  #if NET_LWIP_STACK
+  ip_addr_t getStruct() const;
+  #endif
+  
+  ///Returns IP address byte #
+  uint8_t operator[](unsigned int i) const;
+  
+  ///Compares too addresses
+  /**
+  @return true if the two addresses are equal
+  */
+  bool isEq(const IpAddr& b) const;
+  
+  ///Compares too addresses
+  /**
+  @return true if the two addresses are equal
+  */
+  bool operator==(const IpAddr& b) const;
+ 
+  ///Compares too addresses
+  /**
+  @return true if the two addresses are different
+  */ 
+  bool operator!=(const IpAddr& b) const;
+  
+  ///Checks whether the address is null
+  /**
+  @return true if the address is null
+  */
+  bool isNull() const;
+  
+  ///Checks whether the address is a broadcast address
+  /**
+  @return true if the address is a broadcast address
+  */
+  bool isBroadcast() const;
+
+  ///Checks whether the address is a multicast address
+  /**
+  @return true if the address is a multicast address
+  */
+  bool isMulticast() const;
+  
+private:
+  uint8_t m_ip[4];
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/net.h	Tue Nov 01 11:58:29 2011 +0000
@@ -0,0 +1,101 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef NET_H
+#define NET_H
+
+class NetIf;
+class NetTcpSocket;
+class NetUdpSocket;
+class NetDnsRequest;
+
+#include <list>
+using std::list;
+
+/*
+#include "host.h"
+#include "ipaddr.h"
+#include "netservice.h"
+#include "if/net/netif.h"
+#include "if/net/nettcpsocket.h"
+#include "if/net/netudpsocket.h"
+#include "if/net/netdnsrequest.h"
+*/
+
+class Host;
+class NetIf;
+class NetTcpSocket;
+class NetUdpSocket;
+class NetDnsRequest;
+
+class Net
+{
+private:
+  Net();
+  ~Net();
+public:  
+  static void poll(); //Poll every if & socket
+  
+  static NetTcpSocket* tcpSocket(NetIf& netif);
+  static NetTcpSocket* tcpSocket(); //Socket on default if
+  static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
+  
+  static NetUdpSocket* udpSocket(NetIf& netif);
+  static NetUdpSocket* udpSocket(); //Socket on default if
+  static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
+  
+  static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
+  static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
+
+  static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
+  static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
+  
+  static void setDefaultIf(NetIf& netif); //Deprecated
+  static void setDefaultIf(NetIf* pIf);
+  static NetIf* getDefaultIf();
+  
+protected:
+  friend class NetIf;
+  friend class NetTcpSocket;
+  friend class NetUdpSocket;
+  
+  static void registerIf(NetIf* pIf);
+  static void unregisterIf(NetIf* pIf);
+  
+  static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
+  static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);  
+  
+  static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
+  static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);  
+  
+private:
+  static Net& net(); //Return inst of singleton
+
+  NetIf* m_defaultIf;
+  
+  list<NetIf*> m_lpIf;
+  list<NetTcpSocket*> m_lpNetTcpSocket;
+  list<NetUdpSocket*> m_lpNetUdpSocket;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/netservice.h	Tue Nov 01 11:58:29 2011 +0000
@@ -0,0 +1,67 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+/**
+\file Net Service base class header file
+*/
+
+#ifndef NETSERVICE_H
+#define NETSERVICE_H
+
+#include <list>
+using std::list;
+
+///Net Service base class
+/**
+Each connection-oriented object can register as service (by inheriting this class), so that it is polled regularly.
+It notifies the pool when the connection is terminated so that it can be destroyed.
+*/
+class NetService
+{
+public:
+  ///Instantiates a new service
+  /**
+  @param owned If true the object is owned by the pool and will be destroyed on closure.
+  */
+  NetService(bool owned = true); //Is owned by the pool?
+  virtual ~NetService();
+
+  ///This method can be inherited so that it is called on each @a Net::poll() call.
+  virtual void poll();
+ 
+  static void servicesPoll(); //Poll all registered services & destroy closed ones
+
+protected:
+  ///This flags the service as to be destructed if owned by the pool.
+  void close();
+  
+private:
+  bool m_closed;
+  bool m_removed;
+  bool m_owned;
+  
+  static list<NetService*>& lpServices(); //Helper to prevent static initialization fiasco  
+
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pop3.lib	Tue Nov 01 11:58:29 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hlipka/code/pop3/#3e29a3a6f3bb