Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

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