Dependents:   SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1

if/net/netdnsrequest.h

Committer:
donatien
Date:
2010-05-24
Revision:
0:3717b703f76d
Child:
1:e52ec2a24c6a

File content as of revision 0:3717b703f76d:

#ifndef NETDNSREQUEST_H
#define NETDNSREQUEST_H

//class Socket;
class Host;
//class NetService;
class NetDnsRequest;

#include "netservice.h"
#include "ipaddr.h"
#include "host.h"

enum NetDnsReply
{
  NETDNS_PRTCL,
  NETDNS_NOTFOUND, //Hostname is unknown
  NETDNS_ERROR, //Problem with DNS Service
  //...
  NETDNS_FOUND,
};

class NetDnsRequest : public NetService
{
public:
  NetDnsRequest(const char* hostname);
  NetDnsRequest(Host* pHost);
  virtual ~NetDnsRequest();
  
  class CDummy;
  template<class T> 
  //Linker bug : Must be defined here :(
  void setOnReply( T* pItem, void (T::*pMethod)(NetDnsReply) )
  {
    m_pCbItem = (CDummy*) pItem;
    m_pCbMeth = (void (CDummy::*)(NetDnsReply)) pMethod;
  }
  
  //Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet
 // virtual DnsErr pollState() = 0;
  virtual void poll() = 0; //NetService fn
  
  void getResult(IpAddr* pIp);
  
  virtual void close();
  
protected:
  void onReply(NetDnsReply reply); //Must be called by impl when the request completes
  
  IpAddr m_ip;
  char* m_hostname;

private:  
  CDummy* m_pCbItem;
  void (CDummy::*m_pCbMeth)(NetDnsReply);
  
  Host* m_pHost;
  
  bool m_closed;
};

#endif