Dependents:   SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers net.h Source File

net.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #ifndef NET_H
00025 #define NET_H
00026 
00027 class NetIf;
00028 class NetTcpSocket;
00029 class NetUdpSocket;
00030 class NetDnsRequest;
00031 
00032 #include <list>
00033 using std::list;
00034 
00035 #include "host.h"
00036 #include "ipaddr.h"
00037 #include "netif.h"
00038 #include "nettcpsocket.h"
00039 #include "netudpsocket.h"
00040 #include "netservice.h"
00041 #include "netdnsrequest.h"
00042 
00043 class Net
00044 {
00045 private:
00046   Net();
00047   ~Net();
00048 public:  
00049   static void poll(); //Poll every if & socket
00050   
00051   static NetTcpSocket* tcpSocket(NetIf& netif);
00052   static NetTcpSocket* tcpSocket(); //Socket on default if
00053   static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
00054   
00055   static NetUdpSocket* udpSocket(NetIf& netif);
00056   static NetUdpSocket* udpSocket(); //Socket on default if
00057   static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
00058   
00059   static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
00060   static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
00061 
00062   static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
00063   static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
00064   
00065   static void setDefaultIf(NetIf& netif); //Deprecated
00066   static void setDefaultIf(NetIf* pIf);
00067   static NetIf* getDefaultIf();
00068   
00069   //TODO: Factory functions like 'setupEthernet', 'setupPPP', 'setupTelit' ...
00070   #if 0
00071   enum NetErr //Generic errors
00072   {
00073     __NET_MIN = -0xFFFF;
00074     NET_OPEN, //Could not open if
00075     NET_CONNECT, //Could not connect
00076     NET_AUTH, //Could not auth
00077     NET_HW, //HW problem
00078         
00079     NET_OK = 0
00080   };
00081   
00082   static NetErr Ethernet();
00083   static NetErr PPPoverSerial(int Tx, int Rx, const char* apn, const char* user, const char* password);
00084   static NetErr Telit(int pwrSetPin, int pwrMonPin, int Tx, int Rx);
00085   #endif
00086   
00087 protected:
00088   friend class NetIf;
00089   friend class NetTcpSocket;
00090   friend class NetUdpSocket;
00091   
00092   static void registerIf(NetIf* pIf);
00093   static void unregisterIf(NetIf* pIf);
00094   
00095   static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
00096   static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);  
00097   
00098   static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
00099   static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);  
00100   
00101 private:
00102   static Net& net(); //Return inst of singleton
00103 
00104   NetIf* m_defaultIf;
00105   
00106   list<NetIf*> m_lpIf;
00107   list<NetTcpSocket*> m_lpNetTcpSocket;
00108   list<NetUdpSocket*> m_lpNetUdpSocket;
00109 };
00110 
00111 #endif