Dependents: SNMPAgent HTTPServer think_speak_a cyassl-client ... more
LPC1768/if/net/netdnsrequest.h@0:0f6c82fcde82, 2010-12-09 (annotated)
- Committer:
- mamezu
- Date:
- Thu Dec 09 01:33:56 2010 +0000
- Revision:
- 0:0f6c82fcde82
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mamezu | 0:0f6c82fcde82 | 1 | |
mamezu | 0:0f6c82fcde82 | 2 | /* |
mamezu | 0:0f6c82fcde82 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
mamezu | 0:0f6c82fcde82 | 4 | |
mamezu | 0:0f6c82fcde82 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
mamezu | 0:0f6c82fcde82 | 6 | of this software and associated documentation files (the "Software"), to deal |
mamezu | 0:0f6c82fcde82 | 7 | in the Software without restriction, including without limitation the rights |
mamezu | 0:0f6c82fcde82 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
mamezu | 0:0f6c82fcde82 | 9 | copies of the Software, and to permit persons to whom the Software is |
mamezu | 0:0f6c82fcde82 | 10 | furnished to do so, subject to the following conditions: |
mamezu | 0:0f6c82fcde82 | 11 | |
mamezu | 0:0f6c82fcde82 | 12 | The above copyright notice and this permission notice shall be included in |
mamezu | 0:0f6c82fcde82 | 13 | all copies or substantial portions of the Software. |
mamezu | 0:0f6c82fcde82 | 14 | |
mamezu | 0:0f6c82fcde82 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
mamezu | 0:0f6c82fcde82 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
mamezu | 0:0f6c82fcde82 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
mamezu | 0:0f6c82fcde82 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
mamezu | 0:0f6c82fcde82 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mamezu | 0:0f6c82fcde82 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
mamezu | 0:0f6c82fcde82 | 21 | THE SOFTWARE. |
mamezu | 0:0f6c82fcde82 | 22 | */ |
mamezu | 0:0f6c82fcde82 | 23 | |
mamezu | 0:0f6c82fcde82 | 24 | #ifndef NETDNSREQUEST_H |
mamezu | 0:0f6c82fcde82 | 25 | #define NETDNSREQUEST_H |
mamezu | 0:0f6c82fcde82 | 26 | |
mamezu | 0:0f6c82fcde82 | 27 | //class Socket; |
mamezu | 0:0f6c82fcde82 | 28 | class Host; |
mamezu | 0:0f6c82fcde82 | 29 | //class NetService; |
mamezu | 0:0f6c82fcde82 | 30 | class NetDnsRequest; |
mamezu | 0:0f6c82fcde82 | 31 | |
mamezu | 0:0f6c82fcde82 | 32 | #include "netservice.h" |
mamezu | 0:0f6c82fcde82 | 33 | #include "ipaddr.h" |
mamezu | 0:0f6c82fcde82 | 34 | #include "host.h" |
mamezu | 0:0f6c82fcde82 | 35 | |
mamezu | 0:0f6c82fcde82 | 36 | enum NetDnsReply |
mamezu | 0:0f6c82fcde82 | 37 | { |
mamezu | 0:0f6c82fcde82 | 38 | NETDNS_PRTCL, |
mamezu | 0:0f6c82fcde82 | 39 | NETDNS_NOTFOUND, //Hostname is unknown |
mamezu | 0:0f6c82fcde82 | 40 | NETDNS_ERROR, //Problem with DNS Service |
mamezu | 0:0f6c82fcde82 | 41 | //... |
mamezu | 0:0f6c82fcde82 | 42 | NETDNS_FOUND, |
mamezu | 0:0f6c82fcde82 | 43 | }; |
mamezu | 0:0f6c82fcde82 | 44 | |
mamezu | 0:0f6c82fcde82 | 45 | class NetDnsRequest : public NetService |
mamezu | 0:0f6c82fcde82 | 46 | { |
mamezu | 0:0f6c82fcde82 | 47 | public: |
mamezu | 0:0f6c82fcde82 | 48 | NetDnsRequest(const char* hostname); |
mamezu | 0:0f6c82fcde82 | 49 | NetDnsRequest(Host* pHost); |
mamezu | 0:0f6c82fcde82 | 50 | virtual ~NetDnsRequest(); |
mamezu | 0:0f6c82fcde82 | 51 | |
mamezu | 0:0f6c82fcde82 | 52 | class CDummy; |
mamezu | 0:0f6c82fcde82 | 53 | template<class T> |
mamezu | 0:0f6c82fcde82 | 54 | //Linker bug : Must be defined here :( |
mamezu | 0:0f6c82fcde82 | 55 | void setOnReply( T* pItem, void (T::*pMethod)(NetDnsReply) ) |
mamezu | 0:0f6c82fcde82 | 56 | { |
mamezu | 0:0f6c82fcde82 | 57 | m_pCbItem = (CDummy*) pItem; |
mamezu | 0:0f6c82fcde82 | 58 | m_pCbMeth = (void (CDummy::*)(NetDnsReply)) pMethod; |
mamezu | 0:0f6c82fcde82 | 59 | } |
mamezu | 0:0f6c82fcde82 | 60 | |
mamezu | 0:0f6c82fcde82 | 61 | //Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet |
mamezu | 0:0f6c82fcde82 | 62 | // virtual DnsErr pollState() = 0; |
mamezu | 0:0f6c82fcde82 | 63 | virtual void poll() = 0; //NetService fn |
mamezu | 0:0f6c82fcde82 | 64 | |
mamezu | 0:0f6c82fcde82 | 65 | void getResult(IpAddr* pIp); |
mamezu | 0:0f6c82fcde82 | 66 | |
mamezu | 0:0f6c82fcde82 | 67 | virtual void close(); |
mamezu | 0:0f6c82fcde82 | 68 | |
mamezu | 0:0f6c82fcde82 | 69 | protected: |
mamezu | 0:0f6c82fcde82 | 70 | void onReply(NetDnsReply reply); //Must be called by impl when the request completes |
mamezu | 0:0f6c82fcde82 | 71 | |
mamezu | 0:0f6c82fcde82 | 72 | IpAddr m_ip; |
mamezu | 0:0f6c82fcde82 | 73 | char* m_hostname; |
mamezu | 0:0f6c82fcde82 | 74 | |
mamezu | 0:0f6c82fcde82 | 75 | private: |
mamezu | 0:0f6c82fcde82 | 76 | CDummy* m_pCbItem; |
mamezu | 0:0f6c82fcde82 | 77 | void (CDummy::*m_pCbMeth)(NetDnsReply); |
mamezu | 0:0f6c82fcde82 | 78 | |
mamezu | 0:0f6c82fcde82 | 79 | Host* m_pHost; |
mamezu | 0:0f6c82fcde82 | 80 | |
mamezu | 0:0f6c82fcde82 | 81 | bool m_closed; |
mamezu | 0:0f6c82fcde82 | 82 | }; |
mamezu | 0:0f6c82fcde82 | 83 | |
mamezu | 0:0f6c82fcde82 | 84 | #endif |