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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers netdnsrequest.h Source File

netdnsrequest.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #ifndef NETDNSREQUEST_H
00025 #define NETDNSREQUEST_H
00026 
00027 //class Socket;
00028 class Host;
00029 //class NetService;
00030 class NetDnsRequest;
00031 
00032 #include "netservice.h"
00033 #include "ipaddr.h"
00034 #include "host.h"
00035 
00036 enum NetDnsReply
00037 {
00038   NETDNS_PRTCL,
00039   NETDNS_NOTFOUND, //Hostname is unknown
00040   NETDNS_ERROR, //Problem with DNS Service
00041   //...
00042   NETDNS_FOUND,
00043 };
00044 
00045 class NetDnsRequest : public NetService
00046 {
00047 public:
00048   NetDnsRequest(const char* hostname);
00049   NetDnsRequest(Host* pHost);
00050   virtual ~NetDnsRequest();
00051   
00052   class CDummy;
00053   template<class T> 
00054   //Linker bug : Must be defined here :(
00055   void setOnReply( T* pItem, void (T::*pMethod)(NetDnsReply) )
00056   {
00057     m_pCbItem = (CDummy*) pItem;
00058     m_pCbMeth = (void (CDummy::*)(NetDnsReply)) pMethod;
00059   }
00060   
00061   //Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet
00062  // virtual DnsErr pollState() = 0;
00063   virtual void poll() = 0; //NetService fn
00064   
00065   void getResult(IpAddr* pIp);
00066   
00067   virtual void close();
00068   
00069 protected:
00070   void onReply(NetDnsReply reply); //Must be called by impl when the request completes
00071   
00072   IpAddr m_ip;
00073   char* m_hostname;
00074 
00075 private:  
00076   CDummy* m_pCbItem;
00077   void (CDummy::*m_pCbMeth)(NetDnsReply);
00078   
00079   Host* m_pHost;
00080   
00081   bool m_closed;
00082 };
00083 
00084 #endif