This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.

Dependents:   imu-daq-eth

Committer:
idinor
Date:
Wed Jul 20 11:45:39 2011 +0000
Revision:
0:dcf3c92487ca

        

Who changed what in which revision?

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