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