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