Committer:
mbed714
Date:
Tue Nov 09 19:32:44 2010 +0000
Revision:
3:0c324737064d
Parent:
0:98aadd37a5c5

        

Who changed what in which revision?

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