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