Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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