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