ZG2100 Network interface source

Committer:
donatien
Date:
Fri Aug 06 10:46:03 2010 +0000
Revision:
4:e00281c7453d
Parent:
1:3a7c15057192

        

Who changed what in which revision?

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