mbed Phone Platform

Dependencies:   ulaw mbed ConfigFile

Committer:
okini3939
Date:
Sun Dec 26 15:49:07 2010 +0000
Revision:
1:0f82c574096f

        

Who changed what in which revision?

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