This is the firmware for the LaOS - Laser Open Source project. You can use it to drive a laser cutter. For hardware and more information, look at our wiki: http://wiki.laoslaser.org

Dependencies:   EthernetNetIf mbed

Committer:
fablabtruck
Date:
Fri Jun 08 09:26:40 2012 +0000
Revision:
0:3852426a5068
svn revision 379

Who changed what in which revision?

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