Daniel Peter / NetServices
Committer:
mbed714
Date:
Wed Sep 29 19:48:03 2010 +0000
Revision:
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 /** \file
mbed714 0:98aadd37a5c5 25 DNS Request header file
mbed714 0:98aadd37a5c5 26 */
mbed714 0:98aadd37a5c5 27
mbed714 0:98aadd37a5c5 28 #ifndef DNSREQUEST_H
mbed714 0:98aadd37a5c5 29 #define DNSREQUEST_H
mbed714 0:98aadd37a5c5 30
mbed714 0:98aadd37a5c5 31 #include "core/net.h"
mbed714 0:98aadd37a5c5 32 #include "core/ipaddr.h"
mbed714 0:98aadd37a5c5 33 #include "core/host.h"
mbed714 0:98aadd37a5c5 34 //Essentially it is a safe interface to NetDnsRequest
mbed714 0:98aadd37a5c5 35
mbed714 0:98aadd37a5c5 36 ///DNS Request error codes
mbed714 0:98aadd37a5c5 37 enum DNSRequestErr
mbed714 0:98aadd37a5c5 38 {
mbed714 0:98aadd37a5c5 39 __DNS_MIN = -0xFFFF,
mbed714 0:98aadd37a5c5 40 DNS_SETUP, ///<DNSRequest not properly configured
mbed714 0:98aadd37a5c5 41 DNS_IF, ///<Interface has problems, does not exist or is not initialized
mbed714 0:98aadd37a5c5 42 DNS_MEM, ///<Not enough mem
mbed714 0:98aadd37a5c5 43 DNS_INUSE, ///<Interface / Port is in use
mbed714 0:98aadd37a5c5 44 DNS_PROCESSING, ///<Request has not completed
mbed714 0:98aadd37a5c5 45 //...
mbed714 0:98aadd37a5c5 46 DNS_OK = 0 ///<Success
mbed714 0:98aadd37a5c5 47 };
mbed714 0:98aadd37a5c5 48
mbed714 0:98aadd37a5c5 49 ///DNS Request Result Events
mbed714 0:98aadd37a5c5 50 enum DNSReply
mbed714 0:98aadd37a5c5 51 {
mbed714 0:98aadd37a5c5 52 DNS_PRTCL,
mbed714 0:98aadd37a5c5 53 DNS_NOTFOUND, ///Hostname is unknown
mbed714 0:98aadd37a5c5 54 DNS_ERROR, ///Problem with DNS Service
mbed714 0:98aadd37a5c5 55 //...
mbed714 0:98aadd37a5c5 56 DNS_FOUND,
mbed714 0:98aadd37a5c5 57 };
mbed714 0:98aadd37a5c5 58
mbed714 0:98aadd37a5c5 59 class NetDnsRequest;
mbed714 0:98aadd37a5c5 60 enum NetDnsReply;
mbed714 0:98aadd37a5c5 61
mbed714 0:98aadd37a5c5 62 ///This is a simple DNS Request class
mbed714 0:98aadd37a5c5 63 /**
mbed714 0:98aadd37a5c5 64 This class exposes an API to deal with DNS Requests
mbed714 0:98aadd37a5c5 65 */
mbed714 0:98aadd37a5c5 66 class DNSRequest
mbed714 0:98aadd37a5c5 67 {
mbed714 0:98aadd37a5c5 68 public:
mbed714 0:98aadd37a5c5 69 ///Creates a new request
mbed714 0:98aadd37a5c5 70 DNSRequest();
mbed714 0:98aadd37a5c5 71
mbed714 0:98aadd37a5c5 72 ///Terminates and closes request
mbed714 0:98aadd37a5c5 73 ~DNSRequest();
mbed714 0:98aadd37a5c5 74
mbed714 0:98aadd37a5c5 75 ///Resolves an hostname
mbed714 0:98aadd37a5c5 76 /**
mbed714 0:98aadd37a5c5 77 @param hostname : hostname to resolve
mbed714 0:98aadd37a5c5 78 */
mbed714 0:98aadd37a5c5 79 DNSRequestErr resolve(const char* hostname);
mbed714 0:98aadd37a5c5 80
mbed714 0:98aadd37a5c5 81 ///Resolves an hostname
mbed714 0:98aadd37a5c5 82 /**
mbed714 0:98aadd37a5c5 83 @param host : hostname to resolve, the result will be stored in the IpAddr field of this object
mbed714 0:98aadd37a5c5 84 */
mbed714 0:98aadd37a5c5 85 DNSRequestErr resolve(Host* pHost);
mbed714 0:98aadd37a5c5 86
mbed714 0:98aadd37a5c5 87 ///Setups callback
mbed714 0:98aadd37a5c5 88 /**
mbed714 0:98aadd37a5c5 89 The callback function will be called on result.
mbed714 0:98aadd37a5c5 90 @param pMethod : callback function
mbed714 0:98aadd37a5c5 91 */
mbed714 0:98aadd37a5c5 92 void setOnReply( void (*pMethod)(DNSReply) );
mbed714 0:98aadd37a5c5 93
mbed714 0:98aadd37a5c5 94 class CDummy;
mbed714 0:98aadd37a5c5 95 ///Setups callback
mbed714 0:98aadd37a5c5 96 /**
mbed714 0:98aadd37a5c5 97 The callback function will be called on result.
mbed714 0:98aadd37a5c5 98 @param pItem : instance of class on which to execute the callback method
mbed714 0:98aadd37a5c5 99 @param pMethod : callback method
mbed714 0:98aadd37a5c5 100 */
mbed714 0:98aadd37a5c5 101 template<class T>
mbed714 0:98aadd37a5c5 102 void setOnReply( T* pItem, void (T::*pMethod)(DNSReply) )
mbed714 0:98aadd37a5c5 103 {
mbed714 0:98aadd37a5c5 104 m_pCbItem = (CDummy*) pItem;
mbed714 0:98aadd37a5c5 105 m_pCbMeth = (void (CDummy::*)(DNSReply)) pMethod;
mbed714 0:98aadd37a5c5 106 }
mbed714 0:98aadd37a5c5 107
mbed714 0:98aadd37a5c5 108 ///Gets IP address once it has been resolved
mbed714 0:98aadd37a5c5 109 /**
mbed714 0:98aadd37a5c5 110 @param pIp : pointer to an IpAddr instance in which to store the resolved IP address
mbed714 0:98aadd37a5c5 111 */
mbed714 0:98aadd37a5c5 112 DNSRequestErr getResult(IpAddr* pIp);
mbed714 0:98aadd37a5c5 113
mbed714 0:98aadd37a5c5 114 ///Closes DNS Request before completion
mbed714 0:98aadd37a5c5 115 DNSRequestErr close();
mbed714 0:98aadd37a5c5 116
mbed714 0:98aadd37a5c5 117 protected:
mbed714 0:98aadd37a5c5 118 void onNetDnsReply(NetDnsReply r);
mbed714 0:98aadd37a5c5 119 DNSRequestErr checkInst();
mbed714 0:98aadd37a5c5 120
mbed714 0:98aadd37a5c5 121 private:
mbed714 0:98aadd37a5c5 122 NetDnsRequest* m_pNetDnsRequest;
mbed714 0:98aadd37a5c5 123
mbed714 0:98aadd37a5c5 124 CDummy* m_pCbItem;
mbed714 0:98aadd37a5c5 125 void (CDummy::*m_pCbMeth)(DNSReply);
mbed714 0:98aadd37a5c5 126
mbed714 0:98aadd37a5c5 127 void (*m_pCb)(DNSReply);
mbed714 0:98aadd37a5c5 128
mbed714 0:98aadd37a5c5 129 };
mbed714 0:98aadd37a5c5 130
mbed714 0:98aadd37a5c5 131 #endif