Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:479ce5546098 1
sherckuith 0:479ce5546098 2 /*
sherckuith 0:479ce5546098 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
sherckuith 0:479ce5546098 4
sherckuith 0:479ce5546098 5 Permission is hereby granted, free of charge, to any person obtaining a copy
sherckuith 0:479ce5546098 6 of this software and associated documentation files (the "Software"), to deal
sherckuith 0:479ce5546098 7 in the Software without restriction, including without limitation the rights
sherckuith 0:479ce5546098 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
sherckuith 0:479ce5546098 9 copies of the Software, and to permit persons to whom the Software is
sherckuith 0:479ce5546098 10 furnished to do so, subject to the following conditions:
sherckuith 0:479ce5546098 11
sherckuith 0:479ce5546098 12 The above copyright notice and this permission notice shall be included in
sherckuith 0:479ce5546098 13 all copies or substantial portions of the Software.
sherckuith 0:479ce5546098 14
sherckuith 0:479ce5546098 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
sherckuith 0:479ce5546098 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
sherckuith 0:479ce5546098 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
sherckuith 0:479ce5546098 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
sherckuith 0:479ce5546098 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sherckuith 0:479ce5546098 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
sherckuith 0:479ce5546098 21 THE SOFTWARE.
sherckuith 0:479ce5546098 22 */
sherckuith 0:479ce5546098 23
sherckuith 0:479ce5546098 24 /** \file
sherckuith 0:479ce5546098 25 DNS Request header file
sherckuith 0:479ce5546098 26 */
sherckuith 0:479ce5546098 27
sherckuith 0:479ce5546098 28 #ifndef DNSREQUEST_H
sherckuith 0:479ce5546098 29 #define DNSREQUEST_H
sherckuith 0:479ce5546098 30
sherckuith 0:479ce5546098 31 #include "core/net.h"
sherckuith 0:479ce5546098 32 #include "core/ipaddr.h"
sherckuith 0:479ce5546098 33 #include "core/host.h"
sherckuith 0:479ce5546098 34 //Essentially it is a safe interface to NetDnsRequest
sherckuith 0:479ce5546098 35
sherckuith 0:479ce5546098 36 ///DNS Request error codes
sherckuith 0:479ce5546098 37 enum DNSRequestErr
sherckuith 0:479ce5546098 38 {
sherckuith 0:479ce5546098 39 __DNS_MIN = -0xFFFF,
sherckuith 0:479ce5546098 40 DNS_SETUP, ///<DNSRequest not properly configured
sherckuith 0:479ce5546098 41 DNS_IF, ///<Interface has problems, does not exist or is not initialized
sherckuith 0:479ce5546098 42 DNS_MEM, ///<Not enough mem
sherckuith 0:479ce5546098 43 DNS_INUSE, ///<Interface / Port is in use
sherckuith 0:479ce5546098 44 DNS_PROCESSING, ///<Request has not completed
sherckuith 0:479ce5546098 45 //...
sherckuith 0:479ce5546098 46 DNS_OK = 0 ///<Success
sherckuith 0:479ce5546098 47 };
sherckuith 0:479ce5546098 48
sherckuith 0:479ce5546098 49 ///DNS Request Result Events
sherckuith 0:479ce5546098 50 enum DNSReply
sherckuith 0:479ce5546098 51 {
sherckuith 0:479ce5546098 52 DNS_PRTCL,
sherckuith 0:479ce5546098 53 DNS_NOTFOUND, ///Hostname is unknown
sherckuith 0:479ce5546098 54 DNS_ERROR, ///Problem with DNS Service
sherckuith 0:479ce5546098 55 //...
sherckuith 0:479ce5546098 56 DNS_FOUND,
sherckuith 0:479ce5546098 57 };
sherckuith 0:479ce5546098 58
sherckuith 0:479ce5546098 59 class NetDnsRequest;
sherckuith 0:479ce5546098 60 enum NetDnsReply;
sherckuith 0:479ce5546098 61
sherckuith 0:479ce5546098 62 ///This is a simple DNS Request class
sherckuith 0:479ce5546098 63 /**
sherckuith 0:479ce5546098 64 This class exposes an API to deal with DNS Requests
sherckuith 0:479ce5546098 65 */
sherckuith 0:479ce5546098 66 class DNSRequest
sherckuith 0:479ce5546098 67 {
sherckuith 0:479ce5546098 68 public:
sherckuith 0:479ce5546098 69 ///Creates a new request
sherckuith 0:479ce5546098 70 DNSRequest();
sherckuith 0:479ce5546098 71
sherckuith 0:479ce5546098 72 ///Terminates and closes request
sherckuith 0:479ce5546098 73 ~DNSRequest();
sherckuith 0:479ce5546098 74
sherckuith 0:479ce5546098 75 ///Resolves an hostname
sherckuith 0:479ce5546098 76 /**
sherckuith 0:479ce5546098 77 @param hostname : hostname to resolve
sherckuith 0:479ce5546098 78 */
sherckuith 0:479ce5546098 79 DNSRequestErr resolve(const char* hostname);
sherckuith 0:479ce5546098 80
sherckuith 0:479ce5546098 81 ///Resolves an hostname
sherckuith 0:479ce5546098 82 /**
sherckuith 0:479ce5546098 83 @param host : hostname to resolve, the result will be stored in the IpAddr field of this object
sherckuith 0:479ce5546098 84 */
sherckuith 0:479ce5546098 85 DNSRequestErr resolve(Host* pHost);
sherckuith 0:479ce5546098 86
sherckuith 0:479ce5546098 87 ///Setups callback
sherckuith 0:479ce5546098 88 /**
sherckuith 0:479ce5546098 89 The callback function will be called on result.
sherckuith 0:479ce5546098 90 @param pMethod : callback function
sherckuith 0:479ce5546098 91 */
sherckuith 0:479ce5546098 92 void setOnReply( void (*pMethod)(DNSReply) );
sherckuith 0:479ce5546098 93
sherckuith 0:479ce5546098 94 class CDummy;
sherckuith 0:479ce5546098 95 ///Setups callback
sherckuith 0:479ce5546098 96 /**
sherckuith 0:479ce5546098 97 The callback function will be called on result.
sherckuith 0:479ce5546098 98 @param pItem : instance of class on which to execute the callback method
sherckuith 0:479ce5546098 99 @param pMethod : callback method
sherckuith 0:479ce5546098 100 */
sherckuith 0:479ce5546098 101 template<class T>
sherckuith 0:479ce5546098 102 void setOnReply( T* pItem, void (T::*pMethod)(DNSReply) )
sherckuith 0:479ce5546098 103 {
sherckuith 0:479ce5546098 104 m_pCbItem = (CDummy*) pItem;
sherckuith 0:479ce5546098 105 m_pCbMeth = (void (CDummy::*)(DNSReply)) pMethod;
sherckuith 0:479ce5546098 106 }
sherckuith 0:479ce5546098 107
sherckuith 0:479ce5546098 108 ///Gets IP address once it has been resolved
sherckuith 0:479ce5546098 109 /**
sherckuith 0:479ce5546098 110 @param pIp : pointer to an IpAddr instance in which to store the resolved IP address
sherckuith 0:479ce5546098 111 */
sherckuith 0:479ce5546098 112 DNSRequestErr getResult(IpAddr* pIp);
sherckuith 0:479ce5546098 113
sherckuith 0:479ce5546098 114 ///Closes DNS Request before completion
sherckuith 0:479ce5546098 115 DNSRequestErr close();
sherckuith 0:479ce5546098 116
sherckuith 0:479ce5546098 117 protected:
sherckuith 0:479ce5546098 118 void onNetDnsReply(NetDnsReply r);
sherckuith 0:479ce5546098 119 DNSRequestErr checkInst();
sherckuith 0:479ce5546098 120
sherckuith 0:479ce5546098 121 private:
sherckuith 0:479ce5546098 122 NetDnsRequest* m_pNetDnsRequest;
sherckuith 0:479ce5546098 123
sherckuith 0:479ce5546098 124 CDummy* m_pCbItem;
sherckuith 0:479ce5546098 125 void (CDummy::*m_pCbMeth)(DNSReply);
sherckuith 0:479ce5546098 126
sherckuith 0:479ce5546098 127 void (*m_pCb)(DNSReply);
sherckuith 0:479ce5546098 128
sherckuith 0:479ce5546098 129 };
sherckuith 0:479ce5546098 130
sherckuith 0:479ce5546098 131 #endif