Committer:
zoot661
Date:
Tue May 29 09:49:18 2012 +0000
Revision:
0:f993b6d8b1d8

        

Who changed what in which revision?

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