平成24年中国四国技術職員研修用

Dependencies:   MSCUsbHost NetServices RPCInterface TextLCD mbed

Committer:
yueee_yt
Date:
Sat Aug 18 07:26:48 2012 +0000
Revision:
0:fd83f3540b1a
NTP????????

Who changed what in which revision?

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