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.cpp
20 * @brief This is the implementation for the %Ip4Address class.
23 #include <FBaseDataType.h>
24 #include <FBaseObject.h>
25 #include <FBaseString.h>
26 #include <FBaseUtilStringUtil.h>
27 #include <FNetNetTypes.h>
28 #include <FNetIp4Address.h>
29 #include <FBaseSysLog.h>
30 #include "FNet_Ip4AddressImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Utility;
35 namespace Tizen { namespace Net
38 Ip4Address::Ip4Address(const String& ipAddr)
40 __pIp4AddressImpl = new (std::nothrow) _Ip4AddressImpl(ipAddr);
41 SysTryReturnVoidResult(NID_NET, __pIp4AddressImpl != null, E_OUT_OF_MEMORY,
42 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 Ip4Address::Ip4Address(unsigned long ipAddr)
47 __pIp4AddressImpl = new (std::nothrow) _Ip4AddressImpl(ipAddr);
48 SysTryReturnVoidResult(NID_NET, __pIp4AddressImpl != null, E_OUT_OF_MEMORY,
49 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
52 Ip4Address::Ip4Address(const Ip4Address& rhs)
54 __pIp4AddressImpl = new (std::nothrow) _Ip4AddressImpl(*rhs.__pIp4AddressImpl);
55 SysTryReturnVoidResult(NID_NET, __pIp4AddressImpl != null, E_OUT_OF_MEMORY,
56 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
59 Ip4Address::~Ip4Address(void)
61 delete __pIp4AddressImpl;
62 __pIp4AddressImpl = null;
66 Ip4Address::GetNetAddressFamily(void) const
68 return __pIp4AddressImpl->GetNetAddressFamily();
72 Ip4Address::GetAddress(ByteBuffer& ipAddr) const
76 r = __pIp4AddressImpl->GetAddress(ipAddr);
77 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
83 Ip4Address::GetAddress(unsigned long& ipAddr) const
87 r = __pIp4AddressImpl->GetAddress(ipAddr);
88 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
94 Ip4Address::ToString(void) const
96 return __pIp4AddressImpl->ToString();
100 Ip4Address::operator =(const Ip4Address& rhs)
107 _pIpAddressImpl = null; // Not used yet
109 *__pIp4AddressImpl = *rhs.__pIp4AddressImpl;
115 Ip4Address::CloneN(void) const
117 Ip4Address* pClone = new (std::nothrow) Ip4Address(*this);
118 SysTryReturn(NID_NET, pClone != null, null, E_OUT_OF_MEMORY,
119 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
125 Ip4Address::Equals(const Object& rhs) const
127 const Ip4Address* pRhs = dynamic_cast<const Ip4Address*>(&rhs);
134 const _Ip4AddressImpl* pRhsImpl = _Ip4AddressImpl::GetInstance(*pRhs);
136 if (pRhsImpl == null)
141 return __pIp4AddressImpl->Equals(*pRhsImpl);
145 Ip4Address::GetHashCode(void) const
147 return __pIp4AddressImpl->GetHashCode();