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