Dependents:   SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1

Committer:
donatien
Date:
Mon May 24 10:23:42 2010 +0000
Revision:
0:3717b703f76d
Child:
1:e52ec2a24c6a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:3717b703f76d 1 #ifndef NET_H
donatien 0:3717b703f76d 2 #define NET_H
donatien 0:3717b703f76d 3
donatien 0:3717b703f76d 4 class NetIf;
donatien 0:3717b703f76d 5 class NetTcpSocket;
donatien 0:3717b703f76d 6 class NetUdpSocket;
donatien 0:3717b703f76d 7 class NetDnsRequest;
donatien 0:3717b703f76d 8
donatien 0:3717b703f76d 9 #include <list>
donatien 0:3717b703f76d 10 using std::list;
donatien 0:3717b703f76d 11
donatien 0:3717b703f76d 12 #include "host.h"
donatien 0:3717b703f76d 13 #include "ipaddr.h"
donatien 0:3717b703f76d 14 #include "netif.h"
donatien 0:3717b703f76d 15 #include "nettcpsocket.h"
donatien 0:3717b703f76d 16 #include "netudpsocket.h"
donatien 0:3717b703f76d 17 #include "netservice.h"
donatien 0:3717b703f76d 18 #include "netdnsrequest.h"
donatien 0:3717b703f76d 19
donatien 0:3717b703f76d 20 class Net
donatien 0:3717b703f76d 21 {
donatien 0:3717b703f76d 22 private:
donatien 0:3717b703f76d 23 Net();
donatien 0:3717b703f76d 24 ~Net();
donatien 0:3717b703f76d 25 public:
donatien 0:3717b703f76d 26 static void poll(); //Poll every if & socket
donatien 0:3717b703f76d 27
donatien 0:3717b703f76d 28 static NetTcpSocket* tcpSocket(NetIf& netif);
donatien 0:3717b703f76d 29 static NetTcpSocket* tcpSocket(); //Socket on default if
donatien 0:3717b703f76d 30 static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
donatien 0:3717b703f76d 31
donatien 0:3717b703f76d 32 static NetUdpSocket* udpSocket(NetIf& netif);
donatien 0:3717b703f76d 33 static NetUdpSocket* udpSocket(); //Socket on default if
donatien 0:3717b703f76d 34 static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
donatien 0:3717b703f76d 35
donatien 0:3717b703f76d 36 static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
donatien 0:3717b703f76d 37 static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
donatien 0:3717b703f76d 38
donatien 0:3717b703f76d 39 static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
donatien 0:3717b703f76d 40 static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
donatien 0:3717b703f76d 41
donatien 0:3717b703f76d 42 static void setDefaultIf(NetIf& netif); //Deprecated
donatien 0:3717b703f76d 43 static void setDefaultIf(NetIf* pIf);
donatien 0:3717b703f76d 44 static NetIf* getDefaultIf();
donatien 0:3717b703f76d 45
donatien 0:3717b703f76d 46 //TODO: Factory functions like 'setupEthernet', 'setupPPP', 'setupTelit' ...
donatien 0:3717b703f76d 47 #if 0
donatien 0:3717b703f76d 48 enum NetErr //Generic errors
donatien 0:3717b703f76d 49 {
donatien 0:3717b703f76d 50 __NET_MIN = -0xFFFF;
donatien 0:3717b703f76d 51 NET_OPEN, //Could not open if
donatien 0:3717b703f76d 52 NET_CONNECT, //Could not connect
donatien 0:3717b703f76d 53 NET_AUTH, //Could not auth
donatien 0:3717b703f76d 54 NET_HW, //HW problem
donatien 0:3717b703f76d 55
donatien 0:3717b703f76d 56 NET_OK = 0
donatien 0:3717b703f76d 57 };
donatien 0:3717b703f76d 58
donatien 0:3717b703f76d 59 static NetErr Ethernet();
donatien 0:3717b703f76d 60 static NetErr PPPoverSerial(int Tx, int Rx, const char* apn, const char* user, const char* password);
donatien 0:3717b703f76d 61 static NetErr Telit(int pwrSetPin, int pwrMonPin, int Tx, int Rx);
donatien 0:3717b703f76d 62 #endif
donatien 0:3717b703f76d 63
donatien 0:3717b703f76d 64 protected:
donatien 0:3717b703f76d 65 friend class NetIf;
donatien 0:3717b703f76d 66 friend class NetTcpSocket;
donatien 0:3717b703f76d 67 friend class NetUdpSocket;
donatien 0:3717b703f76d 68
donatien 0:3717b703f76d 69 static void registerIf(NetIf* pIf);
donatien 0:3717b703f76d 70 static void unregisterIf(NetIf* pIf);
donatien 0:3717b703f76d 71
donatien 0:3717b703f76d 72 static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
donatien 0:3717b703f76d 73 static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);
donatien 0:3717b703f76d 74
donatien 0:3717b703f76d 75 static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
donatien 0:3717b703f76d 76 static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);
donatien 0:3717b703f76d 77
donatien 0:3717b703f76d 78 private:
donatien 0:3717b703f76d 79 static Net& net(); //Return inst of singleton
donatien 0:3717b703f76d 80
donatien 0:3717b703f76d 81 NetIf* m_defaultIf;
donatien 0:3717b703f76d 82
donatien 0:3717b703f76d 83 list<NetIf*> m_lpIf;
donatien 0:3717b703f76d 84 list<NetTcpSocket*> m_lpNetTcpSocket;
donatien 0:3717b703f76d 85 list<NetUdpSocket*> m_lpNetUdpSocket;
donatien 0:3717b703f76d 86 };
donatien 0:3717b703f76d 87
donatien 0:3717b703f76d 88 #endif