Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_DhcpClientInfoImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                FNet_DhcpClientInfoImpl.cpp
19  * @brief               This is the implementation file for the _DhcpClientInfoImpl Class.
20  *
21  * This header file contains implementation of the _DhcpClientInfoImpl Class.
22  */
23
24
25 #include <FNetIp4Address.h>
26 #include <FNetDhcpClientInfo.h>
27 #include <FBaseSysLog.h>
28 #include "FNet_NetTypes.h"
29 #include "FNet_DhcpClientInfoImpl.h"
30
31 using namespace std;
32 using namespace Tizen::Base;
33
34 namespace Tizen { namespace Net
35 {
36
37 _DhcpClientInfoImpl::_DhcpClientInfoImpl(void)
38         : __dhcpClientName(null)
39         , __macAddress(null)
40         , __pLocalAddress(null)
41 {
42 }
43
44 _DhcpClientInfoImpl::_DhcpClientInfoImpl(const DhcpClientInfo& value)
45 {
46         const _DhcpClientInfoImpl* pDhcpClientInfoImpl = value.__pDhcpClientInfoImpl;
47
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));
51
52         __dhcpClientName = pDhcpClientInfoImpl->__dhcpClientName;
53         __macAddress = pDhcpClientInfoImpl->__macAddress;
54         __pLocalAddress = move(pLocalAddress);
55 }
56
57 _DhcpClientInfoImpl::~_DhcpClientInfoImpl(void)
58 {       
59 }
60
61 bool
62 _DhcpClientInfoImpl::Equals(const Object& obj) const
63 {
64         const _DhcpClientInfoImpl* pRhs = dynamic_cast <const _DhcpClientInfoImpl*>(&obj);
65
66         if (pRhs == null)
67         {
68                 return false;
69         }
70
71         if (__dhcpClientName != pRhs->__dhcpClientName)
72         {
73                 return false;
74         }
75
76         if (__macAddress != pRhs->__macAddress)
77         {
78                 return false;
79         }
80
81         if (__pLocalAddress != null && pRhs->__pLocalAddress != null)
82         {
83                 if (!__pLocalAddress->Equals(*pRhs->__pLocalAddress))
84                 {
85                         return false;
86                 }
87         }
88         else if (__pLocalAddress != null || pRhs->__pLocalAddress != null)
89         {
90                 return false;
91         }
92
93         return true;
94 }
95
96 int
97 _DhcpClientInfoImpl::GetHashCode(void) const
98 {
99         int hashCode = _HASH_CODE_INITIAL_VALUE;
100
101         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dhcpClientName.GetHashCode();
102         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __macAddress.GetHashCode();
103
104         if (__pLocalAddress != null)
105         {
106                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pLocalAddress->GetHashCode();
107         }
108         else
109         {
110                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
111         }
112
113         return hashCode;
114 }
115
116 String
117 _DhcpClientInfoImpl::GetName(void) const
118 {
119         return __dhcpClientName;
120 }
121
122 String
123 _DhcpClientInfoImpl::GetMacAddress(void) const
124 {
125         return __macAddress;
126 }
127
128 IpAddress*
129 _DhcpClientInfoImpl::GetLocalAddress(void) const
130 {
131         return __pLocalAddress.get();
132 }
133
134 DhcpClientInfo*
135 _DhcpClientInfoImpl::CreateDhcpClientInfoN(void)
136 {
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));
140
141         return pDhcpClientInfo;
142 }
143
144 DhcpClientInfo*
145 _DhcpClientInfoImpl::CloneDhcpClientInfoN(const DhcpClientInfo& info)
146 {
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));
150
151         return pDhcpClientInfo;
152 }
153
154 _DhcpClientInfoImpl*
155 _DhcpClientInfoImpl::GetInstance(DhcpClientInfo& dhcpClientInfo)
156 {
157         return dhcpClientInfo.__pDhcpClientInfoImpl;
158 }
159
160 const _DhcpClientInfoImpl*
161 _DhcpClientInfoImpl::GetInstance(const DhcpClientInfo& dhcpClientInfo)
162 {
163         return dhcpClientInfo.__pDhcpClientInfoImpl;
164 }
165
166 }} // Tizen::Net