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