testing of combination of LCS and LAN

Dependencies:   mbed

Committer:
damir
Date:
Wed Jan 14 13:29:55 2015 +0000
Revision:
0:a7a6a692162f
Test of LAN

Who changed what in which revision?

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