Dependencies:   mbed

Committer:
gbeardall
Date:
Mon Oct 17 10:39:17 2011 +0000
Revision:
0:715023d993d6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gbeardall 0:715023d993d6 1
gbeardall 0:715023d993d6 2 /*
gbeardall 0:715023d993d6 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
gbeardall 0:715023d993d6 4
gbeardall 0:715023d993d6 5 Permission is hereby granted, free of charge, to any person obtaining a copy
gbeardall 0:715023d993d6 6 of this software and associated documentation files (the "Software"), to deal
gbeardall 0:715023d993d6 7 in the Software without restriction, including without limitation the rights
gbeardall 0:715023d993d6 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gbeardall 0:715023d993d6 9 copies of the Software, and to permit persons to whom the Software is
gbeardall 0:715023d993d6 10 furnished to do so, subject to the following conditions:
gbeardall 0:715023d993d6 11
gbeardall 0:715023d993d6 12 The above copyright notice and this permission notice shall be included in
gbeardall 0:715023d993d6 13 all copies or substantial portions of the Software.
gbeardall 0:715023d993d6 14
gbeardall 0:715023d993d6 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gbeardall 0:715023d993d6 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gbeardall 0:715023d993d6 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gbeardall 0:715023d993d6 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gbeardall 0:715023d993d6 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gbeardall 0:715023d993d6 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gbeardall 0:715023d993d6 21 THE SOFTWARE.
gbeardall 0:715023d993d6 22 */
gbeardall 0:715023d993d6 23
gbeardall 0:715023d993d6 24 #ifndef NETDNSREQUEST_H
gbeardall 0:715023d993d6 25 #define NETDNSREQUEST_H
gbeardall 0:715023d993d6 26
gbeardall 0:715023d993d6 27 //class Socket;
gbeardall 0:715023d993d6 28 class Host;
gbeardall 0:715023d993d6 29 //class NetService;
gbeardall 0:715023d993d6 30 class NetDnsRequest;
gbeardall 0:715023d993d6 31
gbeardall 0:715023d993d6 32 #include "netservice.h"
gbeardall 0:715023d993d6 33 #include "ipaddr.h"
gbeardall 0:715023d993d6 34 #include "host.h"
gbeardall 0:715023d993d6 35
gbeardall 0:715023d993d6 36 enum NetDnsReply
gbeardall 0:715023d993d6 37 {
gbeardall 0:715023d993d6 38 NETDNS_PRTCL,
gbeardall 0:715023d993d6 39 NETDNS_NOTFOUND, //Hostname is unknown
gbeardall 0:715023d993d6 40 NETDNS_ERROR, //Problem with DNS Service
gbeardall 0:715023d993d6 41 //...
gbeardall 0:715023d993d6 42 NETDNS_FOUND,
gbeardall 0:715023d993d6 43 };
gbeardall 0:715023d993d6 44
gbeardall 0:715023d993d6 45 class NetDnsRequest : public NetService
gbeardall 0:715023d993d6 46 {
gbeardall 0:715023d993d6 47 public:
gbeardall 0:715023d993d6 48 NetDnsRequest(const char* hostname);
gbeardall 0:715023d993d6 49 NetDnsRequest(Host* pHost);
gbeardall 0:715023d993d6 50 virtual ~NetDnsRequest();
gbeardall 0:715023d993d6 51
gbeardall 0:715023d993d6 52 class CDummy;
gbeardall 0:715023d993d6 53 template<class T>
gbeardall 0:715023d993d6 54 //Linker bug : Must be defined here :(
gbeardall 0:715023d993d6 55 void setOnReply( T* pItem, void (T::*pMethod)(NetDnsReply) )
gbeardall 0:715023d993d6 56 {
gbeardall 0:715023d993d6 57 m_pCbItem = (CDummy*) pItem;
gbeardall 0:715023d993d6 58 m_pCbMeth = (void (CDummy::*)(NetDnsReply)) pMethod;
gbeardall 0:715023d993d6 59 }
gbeardall 0:715023d993d6 60
gbeardall 0:715023d993d6 61 //Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet
gbeardall 0:715023d993d6 62 // virtual DnsErr pollState() = 0;
gbeardall 0:715023d993d6 63 virtual void poll() = 0; //NetService fn
gbeardall 0:715023d993d6 64
gbeardall 0:715023d993d6 65 void getResult(IpAddr* pIp);
gbeardall 0:715023d993d6 66
gbeardall 0:715023d993d6 67 virtual void close();
gbeardall 0:715023d993d6 68
gbeardall 0:715023d993d6 69 protected:
gbeardall 0:715023d993d6 70 void onReply(NetDnsReply reply); //Must be called by impl when the request completes
gbeardall 0:715023d993d6 71
gbeardall 0:715023d993d6 72 IpAddr m_ip;
gbeardall 0:715023d993d6 73 char* m_hostname;
gbeardall 0:715023d993d6 74
gbeardall 0:715023d993d6 75 private:
gbeardall 0:715023d993d6 76 CDummy* m_pCbItem;
gbeardall 0:715023d993d6 77 void (CDummy::*m_pCbMeth)(NetDnsReply);
gbeardall 0:715023d993d6 78
gbeardall 0:715023d993d6 79 Host* m_pHost;
gbeardall 0:715023d993d6 80
gbeardall 0:715023d993d6 81 bool m_closed;
gbeardall 0:715023d993d6 82 };
gbeardall 0:715023d993d6 83
gbeardall 0:715023d993d6 84 #endif