Measure system

Dependencies:   EthernetNetIf mbed RF12B

Committer:
benecsj
Date:
Thu Mar 10 19:56:45 2011 +0000
Revision:
1:b26ab2467b1a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benecsj 1:b26ab2467b1a 1
benecsj 1:b26ab2467b1a 2 /*
benecsj 1:b26ab2467b1a 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
benecsj 1:b26ab2467b1a 4
benecsj 1:b26ab2467b1a 5 Permission is hereby granted, free of charge, to any person obtaining a copy
benecsj 1:b26ab2467b1a 6 of this software and associated documentation files (the "Software"), to deal
benecsj 1:b26ab2467b1a 7 in the Software without restriction, including without limitation the rights
benecsj 1:b26ab2467b1a 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
benecsj 1:b26ab2467b1a 9 copies of the Software, and to permit persons to whom the Software is
benecsj 1:b26ab2467b1a 10 furnished to do so, subject to the following conditions:
benecsj 1:b26ab2467b1a 11
benecsj 1:b26ab2467b1a 12 The above copyright notice and this permission notice shall be included in
benecsj 1:b26ab2467b1a 13 all copies or substantial portions of the Software.
benecsj 1:b26ab2467b1a 14
benecsj 1:b26ab2467b1a 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
benecsj 1:b26ab2467b1a 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
benecsj 1:b26ab2467b1a 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
benecsj 1:b26ab2467b1a 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
benecsj 1:b26ab2467b1a 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
benecsj 1:b26ab2467b1a 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
benecsj 1:b26ab2467b1a 21 THE SOFTWARE.
benecsj 1:b26ab2467b1a 22 */
benecsj 1:b26ab2467b1a 23
benecsj 1:b26ab2467b1a 24 #ifndef HOST_H
benecsj 1:b26ab2467b1a 25 #define HOST_H
benecsj 1:b26ab2467b1a 26
benecsj 1:b26ab2467b1a 27 #include "ipaddr.h"
benecsj 1:b26ab2467b1a 28 #include <string.h>
benecsj 1:b26ab2467b1a 29
benecsj 1:b26ab2467b1a 30 ///Host information container
benecsj 1:b26ab2467b1a 31 /**
benecsj 1:b26ab2467b1a 32 This class is a container for data relative to a connection:
benecsj 1:b26ab2467b1a 33 - IP Address
benecsj 1:b26ab2467b1a 34 - Port number
benecsj 1:b26ab2467b1a 35 - Host Name
benecsj 1:b26ab2467b1a 36 */
benecsj 1:b26ab2467b1a 37 class Host
benecsj 1:b26ab2467b1a 38 {
benecsj 1:b26ab2467b1a 39 public:
benecsj 1:b26ab2467b1a 40 ///Initiliazes host with null values
benecsj 1:b26ab2467b1a 41 Host() : m_ip(0,0,0,0), m_port(0), m_name(NULL)
benecsj 1:b26ab2467b1a 42 {
benecsj 1:b26ab2467b1a 43
benecsj 1:b26ab2467b1a 44 }
benecsj 1:b26ab2467b1a 45
benecsj 1:b26ab2467b1a 46 ///Initializes host
benecsj 1:b26ab2467b1a 47 Host(const IpAddr& ip, const int& port, const char* name="" ) : m_ip(ip), m_port(port), m_name(NULL)
benecsj 1:b26ab2467b1a 48 {
benecsj 1:b26ab2467b1a 49 setName(name);
benecsj 1:b26ab2467b1a 50 }
benecsj 1:b26ab2467b1a 51
benecsj 1:b26ab2467b1a 52 ~Host()
benecsj 1:b26ab2467b1a 53 {
benecsj 1:b26ab2467b1a 54 if(m_name)
benecsj 1:b26ab2467b1a 55 {
benecsj 1:b26ab2467b1a 56 delete[] m_name;
benecsj 1:b26ab2467b1a 57 }
benecsj 1:b26ab2467b1a 58 }
benecsj 1:b26ab2467b1a 59
benecsj 1:b26ab2467b1a 60 ///Returns IP address
benecsj 1:b26ab2467b1a 61 const IpAddr& getIp() const
benecsj 1:b26ab2467b1a 62 {
benecsj 1:b26ab2467b1a 63 return m_ip;
benecsj 1:b26ab2467b1a 64 }
benecsj 1:b26ab2467b1a 65
benecsj 1:b26ab2467b1a 66 ///Returns port number
benecsj 1:b26ab2467b1a 67 const int& getPort() const
benecsj 1:b26ab2467b1a 68 {
benecsj 1:b26ab2467b1a 69 return m_port;
benecsj 1:b26ab2467b1a 70 }
benecsj 1:b26ab2467b1a 71
benecsj 1:b26ab2467b1a 72 ///Returns host name
benecsj 1:b26ab2467b1a 73 const char* getName() const
benecsj 1:b26ab2467b1a 74 {
benecsj 1:b26ab2467b1a 75 return m_name;
benecsj 1:b26ab2467b1a 76 }
benecsj 1:b26ab2467b1a 77
benecsj 1:b26ab2467b1a 78 ///Sets IP address
benecsj 1:b26ab2467b1a 79 void setIp(const IpAddr& ip)
benecsj 1:b26ab2467b1a 80 {
benecsj 1:b26ab2467b1a 81 m_ip = ip;
benecsj 1:b26ab2467b1a 82 }
benecsj 1:b26ab2467b1a 83
benecsj 1:b26ab2467b1a 84 ///Sets port number
benecsj 1:b26ab2467b1a 85 void setPort(int port)
benecsj 1:b26ab2467b1a 86 {
benecsj 1:b26ab2467b1a 87 m_port = port;
benecsj 1:b26ab2467b1a 88 }
benecsj 1:b26ab2467b1a 89
benecsj 1:b26ab2467b1a 90 ///Sets host name
benecsj 1:b26ab2467b1a 91 void setName(const char* name)
benecsj 1:b26ab2467b1a 92 {
benecsj 1:b26ab2467b1a 93 if(m_name)
benecsj 1:b26ab2467b1a 94 delete[] m_name;
benecsj 1:b26ab2467b1a 95 int len = strlen(name);
benecsj 1:b26ab2467b1a 96 if(len)
benecsj 1:b26ab2467b1a 97 {
benecsj 1:b26ab2467b1a 98 m_name = new char[len+1];
benecsj 1:b26ab2467b1a 99 strcpy(m_name, name);
benecsj 1:b26ab2467b1a 100 }
benecsj 1:b26ab2467b1a 101 }
benecsj 1:b26ab2467b1a 102
benecsj 1:b26ab2467b1a 103 private:
benecsj 1:b26ab2467b1a 104 IpAddr m_ip;
benecsj 1:b26ab2467b1a 105 int m_port;
benecsj 1:b26ab2467b1a 106 char* m_name;
benecsj 1:b26ab2467b1a 107 };
benecsj 1:b26ab2467b1a 108
benecsj 1:b26ab2467b1a 109 #endif