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.
18 * @file FNet_DhcpClientInfoImpl.cpp
19 * @brief This is the implementation file for the _DhcpClientInfoImpl Class.
21 * This header file contains implementation of the _DhcpClientInfoImpl Class.
25 #include <FNetIp4Address.h>
26 #include <FNetDhcpClientInfo.h>
27 #include <FBaseSysLog.h>
28 #include "FNet_NetTypes.h"
29 #include "FNet_DhcpClientInfoImpl.h"
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Net
37 _DhcpClientInfoImpl::_DhcpClientInfoImpl(void)
38 : __dhcpClientName(null)
40 , __pLocalAddress(null)
44 _DhcpClientInfoImpl::_DhcpClientInfoImpl(const DhcpClientInfo& value)
46 const _DhcpClientInfoImpl* pDhcpClientInfoImpl = value.__pDhcpClientInfoImpl;
48 unique_ptr<Ip4Address> pLocalAddress(new (std::nothrow) Ip4Address(pDhcpClientInfoImpl->__pLocalAddress->ToString()));
49 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
50 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
52 __dhcpClientName = pDhcpClientInfoImpl->__dhcpClientName;
53 __macAddress = pDhcpClientInfoImpl->__macAddress;
54 __pLocalAddress = move(pLocalAddress);
57 _DhcpClientInfoImpl::~_DhcpClientInfoImpl(void)
62 _DhcpClientInfoImpl::Equals(const Object& obj) const
64 const _DhcpClientInfoImpl* pRhs = dynamic_cast <const _DhcpClientInfoImpl*>(&obj);
71 if (__dhcpClientName != pRhs->__dhcpClientName)
76 if (__macAddress != pRhs->__macAddress)
81 if (__pLocalAddress != null && pRhs->__pLocalAddress != null)
83 if (!__pLocalAddress->Equals(*pRhs->__pLocalAddress))
88 else if (__pLocalAddress != null || pRhs->__pLocalAddress != null)
97 _DhcpClientInfoImpl::GetHashCode(void) const
99 int hashCode = _HASH_CODE_INITIAL_VALUE;
101 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dhcpClientName.GetHashCode();
102 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __macAddress.GetHashCode();
104 if (__pLocalAddress != null)
106 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pLocalAddress->GetHashCode();
110 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
117 _DhcpClientInfoImpl::GetName(void) const
119 return __dhcpClientName;
123 _DhcpClientInfoImpl::GetMacAddress(void) const
129 _DhcpClientInfoImpl::GetLocalAddress(void) const
131 return __pLocalAddress.get();
135 _DhcpClientInfoImpl::CreateDhcpClientInfoN(void)
137 DhcpClientInfo* pDhcpClientInfo = new (std::nothrow) DhcpClientInfo();
138 SysTryReturn(NID_NET, pDhcpClientInfo, null, E_OUT_OF_MEMORY,
139 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
141 return pDhcpClientInfo;
145 _DhcpClientInfoImpl::CloneDhcpClientInfoN(const DhcpClientInfo& info)
147 DhcpClientInfo* pDhcpClientInfo = new (std::nothrow) DhcpClientInfo(info);
148 SysTryReturn(NID_NET, pDhcpClientInfo, null, E_OUT_OF_MEMORY,
149 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
151 return pDhcpClientInfo;
155 _DhcpClientInfoImpl::GetInstance(DhcpClientInfo& dhcpClientInfo)
157 return dhcpClientInfo.__pDhcpClientInfoImpl;
160 const _DhcpClientInfoImpl*
161 _DhcpClientInfoImpl::GetInstance(const DhcpClientInfo& dhcpClientInfo)
163 return dhcpClientInfo.__pDhcpClientInfoImpl;