2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetIp4Address.h
20 * @brief This is the header file for the %Ip4Address class.
24 * This header file contains the declarations of the %Ip4Address class.
26 #ifndef _FNET_IP4_ADDRESS_H_
27 #define _FNET_IP4_ADDRESS_H_
29 #include <FBaseResult.h>
30 #include <FBaseObject.h>
31 #include <FNetIpAddress.h>
32 #include <FNetSockSocketTypes.h>
34 namespace Tizen { namespace Net
36 class _Ip4AddressImpl;
39 * @brief This class represents an Internet Protocol version 4 (IPv4) address.
43 * The %Ip4Address class specifies the IPv4 address.
45 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/net/net_namespace.htm">Net Guide</a>. @n
47 * The following example demonstrates how to use the %Ip4Address class.
50 * using namespace Tizen::Base;
51 * using namespace Tizen::Net;
54 * MyClass::SomeMethod(void)
56 * result r = E_SUCCESS;
58 * Tizen::Base::String ip4String(L"192.168.0.1");
59 * Ip4Address* pIp4Address = new Ip4Address(ip4String);
61 * // Gets the raw IP address.
62 * int sizeOfIp4Address = 4;
64 * r = bb.Construct(sizeOfIp4Address);
65 * r = pIp4Address->GetAddress(bb);
72 class _OSP_EXPORT_ Ip4Address
77 * Initializes this instance of %Ip4Address with the address specified as a string.
81 * @param[in] ipAddr The IP Address as a string @n
82 * This string represents the IP address in dot-decimal notation (for example, 165.213.173.7) .
83 * @exception E_SUCCESS The instance is created successfully.
84 * @exception E_INVALID_ARG The specified @c ipAddr is invalid.
85 * @remarks The GetLastResult() method is used to check whether the %Ip4Address instance is created successfully.
87 Ip4Address(const Tizen::Base::String& ipAddr);
90 * Initializes this instance of %Ip4Address with the address specified as an integer.
94 * @param[in] ipAddr A unsigned @c long number containing the raw IP address @n
95 * This is a 32-bit unsigned number. It should be in host byte order.
96 * @exception E_SUCCESS The instance is created successfully.
97 * @exception E_INVALID_ARG The specified @c ipAddr is invalid.
98 * @remarks The GetLastResult() method is used to check whether the %Ip4Address instance is created successfully.
99 * @see IpAddress::NetworkToHostOrder()
100 * @see IpAddress::HostToNetworkOrder()
102 Ip4Address(unsigned long ipAddr);
105 * Copying of objects using this copy constructor is allowed.
109 * @param[in] rhs An instance of %Ip4Address
110 * @remarks The GetLastResult() method is used to check whether the %Ip4Address instance is created successfully.
112 Ip4Address(const Ip4Address& rhs);
115 * This destructor overrides Tizen::Base::Object::~Object().
119 virtual ~Ip4Address(void);
123 * Gets the address family to which the %Ip4Address belongs.
127 * @return NET_AF_IPV4
129 NetAddressFamily GetNetAddressFamily(void) const;
132 * Gets the raw IP address.
136 * @return An error code
137 * @param[out] ipAddr A Tizen::Base::ByteBuffer object containing the raw IP address
138 * @exception E_SUCCESS The method is successful.
139 * @exception E_OVERFLOW The length of the remaining bytes of @c ipAddr is less than @c 4.
140 * @remarks This method returns the raw IP address of the %Ip4Address object. The result is in host byte order. This method writes the raw address
141 * in the buffer parameter, starting from the current position. After the operation, the position of the buffer is incremented by the number
142 * of bytes successfully written even if the operation fails. The new position cannot be larger than the original limit.
144 result GetAddress(Tizen::Base::ByteBuffer& ipAddr) const;
147 * Gets the raw IP address as an integer. @n
148 * The result is in host byte order.
152 * @return An error code
153 * @param[out] ipAddr An unsigned @c long integer containing the raw IP address
154 * @exception E_SUCCESS The method is successful.
155 * @exception E_INVALID_STATE This instance is in an invalid state.
156 * @see IpAddress::NetworkToHostOrder()
157 * @see IpAddress::HostToNetworkOrder()
159 result GetAddress(unsigned long& ipAddr) const;
162 * Gets the IP address of the endpoint in textual presentation. @n
163 * An endpoint consists of an IP address and a port.
167 * @return The %Ip4Address, @n
168 * else a null string if the address is not set
169 * @remarks %Ip4Address is in the standard dot-decimal notation.
171 Tizen::Base::String ToString(void) const;
174 * Creates and returns a copy of this instance.
178 * @return The copy of this instance
179 * @remarks The GetLastResult() method is used to check whether the %IpAddress instance is copied successfully.
181 virtual IpAddress* CloneN(void) const;
184 * Copying of objects using this copy assignment operator is allowed.
188 * @return The reference of this instance
189 * @param[in] rhs An instance of %Ip4Address
191 Ip4Address& operator =(const Ip4Address& rhs);
194 * Compares the specified instance of %Ip4Address with the calling instance.
198 * @return @c true if the values match, @n
200 * @param[in] rhs The other Tizen::Base::Object to compare
201 * @see Tizen::Base::Object::Equals()
203 virtual bool Equals(const Tizen::Base::Object& rhs) const;
206 * Gets the hash value of the current instance.
210 * @return The hash value of the current instance
212 virtual int GetHashCode(void) const;
216 * This default constructor is intentionally declared as private so that only the platform can create an instance.
221 _Ip4AddressImpl* __pIp4AddressImpl;
223 friend class _Ip4AddressImpl;
228 #endif // _FNET_IP4_ADDRESS_H_