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