ZG2100 Network interface source

Committer:
donatien
Date:
Fri Aug 06 10:46:03 2010 +0000
Revision:
4:e00281c7453d
Parent:
1:3a7c15057192

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 1:3a7c15057192 1
donatien 1:3a7c15057192 2 /*
donatien 1:3a7c15057192 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
donatien 1:3a7c15057192 4
donatien 1:3a7c15057192 5 Permission is hereby granted, free of charge, to any person obtaining a copy
donatien 1:3a7c15057192 6 of this software and associated documentation files (the "Software"), to deal
donatien 1:3a7c15057192 7 in the Software without restriction, including without limitation the rights
donatien 1:3a7c15057192 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donatien 1:3a7c15057192 9 copies of the Software, and to permit persons to whom the Software is
donatien 1:3a7c15057192 10 furnished to do so, subject to the following conditions:
donatien 1:3a7c15057192 11
donatien 1:3a7c15057192 12 The above copyright notice and this permission notice shall be included in
donatien 1:3a7c15057192 13 all copies or substantial portions of the Software.
donatien 1:3a7c15057192 14
donatien 1:3a7c15057192 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 1:3a7c15057192 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 1:3a7c15057192 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 1:3a7c15057192 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 1:3a7c15057192 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 1:3a7c15057192 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donatien 1:3a7c15057192 21 THE SOFTWARE.
donatien 1:3a7c15057192 22 */
donatien 1:3a7c15057192 23
donatien 1:3a7c15057192 24 #ifndef NET_H
donatien 1:3a7c15057192 25 #define NET_H
donatien 1:3a7c15057192 26
donatien 1:3a7c15057192 27 class NetIf;
donatien 1:3a7c15057192 28 class NetTcpSocket;
donatien 1:3a7c15057192 29 class NetUdpSocket;
donatien 1:3a7c15057192 30 class NetDnsRequest;
donatien 1:3a7c15057192 31
donatien 1:3a7c15057192 32 #include <list>
donatien 1:3a7c15057192 33 using std::list;
donatien 1:3a7c15057192 34
donatien 1:3a7c15057192 35 /*
donatien 1:3a7c15057192 36 #include "host.h"
donatien 1:3a7c15057192 37 #include "ipaddr.h"
donatien 1:3a7c15057192 38 #include "netservice.h"
donatien 1:3a7c15057192 39 #include "if/net/netif.h"
donatien 1:3a7c15057192 40 #include "if/net/nettcpsocket.h"
donatien 1:3a7c15057192 41 #include "if/net/netudpsocket.h"
donatien 1:3a7c15057192 42 #include "if/net/netdnsrequest.h"
donatien 1:3a7c15057192 43 */
donatien 1:3a7c15057192 44
donatien 1:3a7c15057192 45 class Host;
donatien 1:3a7c15057192 46 class NetIf;
donatien 1:3a7c15057192 47 class NetTcpSocket;
donatien 1:3a7c15057192 48 class NetUdpSocket;
donatien 1:3a7c15057192 49 class NetDnsRequest;
donatien 1:3a7c15057192 50
donatien 1:3a7c15057192 51 class Net
donatien 1:3a7c15057192 52 {
donatien 1:3a7c15057192 53 private:
donatien 1:3a7c15057192 54 Net();
donatien 1:3a7c15057192 55 ~Net();
donatien 1:3a7c15057192 56 public:
donatien 1:3a7c15057192 57 static void poll(); //Poll every if & socket
donatien 1:3a7c15057192 58
donatien 1:3a7c15057192 59 static NetTcpSocket* tcpSocket(NetIf& netif);
donatien 1:3a7c15057192 60 static NetTcpSocket* tcpSocket(); //Socket on default if
donatien 1:3a7c15057192 61 static void releaseTcpSocket(NetTcpSocket* pNetTcpSocket);
donatien 1:3a7c15057192 62
donatien 1:3a7c15057192 63 static NetUdpSocket* udpSocket(NetIf& netif);
donatien 1:3a7c15057192 64 static NetUdpSocket* udpSocket(); //Socket on default if
donatien 1:3a7c15057192 65 static void releaseUdpSocket(NetUdpSocket* pNetUdpSocket);
donatien 1:3a7c15057192 66
donatien 1:3a7c15057192 67 static NetDnsRequest* dnsRequest(const char* hostname, NetIf& netif);
donatien 1:3a7c15057192 68 static NetDnsRequest* dnsRequest(const char* hostname); //Create a new NetDnsRequest object from default if
donatien 1:3a7c15057192 69
donatien 1:3a7c15057192 70 static NetDnsRequest* dnsRequest(Host* pHost, NetIf& netif);
donatien 1:3a7c15057192 71 static NetDnsRequest* dnsRequest(Host* pHost); //Create a new NetDnsRequest object from default if
donatien 1:3a7c15057192 72
donatien 1:3a7c15057192 73 static void setDefaultIf(NetIf& netif); //Deprecated
donatien 1:3a7c15057192 74 static void setDefaultIf(NetIf* pIf);
donatien 1:3a7c15057192 75 static NetIf* getDefaultIf();
donatien 1:3a7c15057192 76
donatien 1:3a7c15057192 77 protected:
donatien 1:3a7c15057192 78 friend class NetIf;
donatien 1:3a7c15057192 79 friend class NetTcpSocket;
donatien 1:3a7c15057192 80 friend class NetUdpSocket;
donatien 1:3a7c15057192 81
donatien 1:3a7c15057192 82 static void registerIf(NetIf* pIf);
donatien 1:3a7c15057192 83 static void unregisterIf(NetIf* pIf);
donatien 1:3a7c15057192 84
donatien 1:3a7c15057192 85 static void registerNetTcpSocket(NetTcpSocket* pNetTcpSocket);
donatien 1:3a7c15057192 86 static void unregisterNetTcpSocket(NetTcpSocket* pNetTcpSocket);
donatien 1:3a7c15057192 87
donatien 1:3a7c15057192 88 static void registerNetUdpSocket(NetUdpSocket* pNetUdpSocket);
donatien 1:3a7c15057192 89 static void unregisterNetUdpSocket(NetUdpSocket* pNetUdpSocket);
donatien 1:3a7c15057192 90
donatien 1:3a7c15057192 91 private:
donatien 1:3a7c15057192 92 static Net& net(); //Return inst of singleton
donatien 1:3a7c15057192 93
donatien 1:3a7c15057192 94 NetIf* m_defaultIf;
donatien 1:3a7c15057192 95
donatien 1:3a7c15057192 96 list<NetIf*> m_lpIf;
donatien 1:3a7c15057192 97 list<NetTcpSocket*> m_lpNetTcpSocket;
donatien 1:3a7c15057192 98 list<NetUdpSocket*> m_lpNetUdpSocket;
donatien 1:3a7c15057192 99 };
donatien 1:3a7c15057192 100
donatien 1:3a7c15057192 101 #endif