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_NetConnectionInfoImpl.cpp
19 * @brief This is the implementation for the _NetConnectionInfoImpl class.
22 #include <net_connection.h>
23 #include <FBaseUtilStringUtil.h>
24 #include <FNetNetConnectionInfo.h>
25 #include <FNetIp4Address.h>
26 #include <FBaseSysLog.h>
27 #include "FNet_NetTypes.h"
28 #include "FNet_NetConnectionInfoImpl.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Utility;
34 namespace Tizen { namespace Net {
36 _NetConnectionInfoImpl::_NetConnectionInfoImpl(void)
37 : __bearerType(NET_BEARER_NONE)
38 , __protocolType(NET_PROTO_TYPE_NONE)
39 , __localAddressScheme(NET_ADDRESS_SCHEME_NONE)
40 , __dnsAddressScheme(NET_ADDRESS_SCHEME_NONE)
41 , __pLocalAddress(null)
42 , __pSubnetMaskAddress(null)
43 , __pDefaultGatewayAddress(null)
44 , __pPrimaryDnsAddress(null)
45 , __pSecondaryDnsAddress(null)
49 _NetConnectionInfoImpl::~_NetConnectionInfoImpl(void)
54 _NetConnectionInfoImpl::GetBearerType(void) const
60 _NetConnectionInfoImpl::GetProtocolType(void) const
62 return __protocolType;
66 _NetConnectionInfoImpl::GetAccessPointName(void) const
72 _NetConnectionInfoImpl::GetLocalAddressScheme(void) const
74 return __localAddressScheme;
78 _NetConnectionInfoImpl::GetLocalAddress(void) const
80 return __pLocalAddress.get();
84 _NetConnectionInfoImpl::GetDnsAddressScheme(void) const
86 return __dnsAddressScheme;
90 _NetConnectionInfoImpl::GetPrimaryDnsAddress(void) const
92 return __pPrimaryDnsAddress.get();
96 _NetConnectionInfoImpl::GetSecondaryDnsAddress(void) const
98 return __pSecondaryDnsAddress.get();
102 _NetConnectionInfoImpl::GetSubnetMaskAddress(void) const
104 return __pSubnetMaskAddress.get();
108 _NetConnectionInfoImpl::GetDefaultGatewayAddress(void) const
110 return __pDefaultGatewayAddress.get();
114 _NetConnectionInfoImpl::GetDeviceName(void) const
120 _NetConnectionInfoImpl::GetProxyAddress(void) const
122 return __proxyAddress;
126 _NetConnectionInfoImpl::CopyFrom(const _NetConnectionInfoImpl* pSource)
128 const Ip4Address* pAddress = null;
129 unique_ptr<IpAddress> pLocalAddress;
130 unique_ptr<IpAddress> pSubnetMaskAddress;
131 unique_ptr<IpAddress> pDefaultGatewayAddress;
132 unique_ptr<IpAddress> pPrimaryDnsAddress;
133 unique_ptr<IpAddress> pSecondaryDnsAddress;
135 SysTryReturnVoidResult(NID_NET, pSource != null, E_INVALID_ARG,
136 "[%s] Invalud argument is used. Source is null.", GetErrorMessage(E_INVALID_ARG));
138 pAddress = dynamic_cast<const Ip4Address*>(pSource->GetLocalAddress());
139 if (pAddress != null)
141 pLocalAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
142 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
143 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
146 pAddress = dynamic_cast<const Ip4Address*>(pSource->GetSubnetMaskAddress());
147 if (pAddress != null)
149 pSubnetMaskAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
150 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
151 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
154 pAddress = dynamic_cast<const Ip4Address*>(pSource->GetDefaultGatewayAddress());
155 if (pAddress != null)
157 pDefaultGatewayAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
158 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
159 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
162 pAddress = dynamic_cast<const Ip4Address*>(pSource->GetPrimaryDnsAddress());
163 if (pAddress != null)
165 pPrimaryDnsAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
166 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
167 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
170 pAddress = dynamic_cast<const Ip4Address*>(pSource->GetSecondaryDnsAddress());
171 if (pAddress != null)
173 pSecondaryDnsAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
174 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
175 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
178 __bearerType = pSource->GetBearerType();
179 __protocolType = pSource->GetProtocolType();
180 __apn = pSource->GetAccessPointName();
181 __localAddressScheme = pSource->GetLocalAddressScheme();
182 __dnsAddressScheme = pSource->GetDnsAddressScheme();
183 __proxyAddress = pSource->GetProxyAddress();
184 __deviceName = pSource->GetDeviceName();
186 __pLocalAddress.reset(pLocalAddress.release());
187 __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
188 __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
189 __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
190 __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
194 _NetConnectionInfoImpl::Clear()
196 __bearerType = NET_BEARER_NONE;
197 __protocolType = NET_PROTO_TYPE_NONE;
199 __deviceName.Clear();
200 __proxyAddress.Clear();
201 __localAddressScheme = NET_ADDRESS_SCHEME_NONE;
202 __dnsAddressScheme = NET_ADDRESS_SCHEME_NONE;
204 __pLocalAddress.reset(null);
205 __pSubnetMaskAddress.reset(null);
206 __pDefaultGatewayAddress.reset(null);
207 __pPrimaryDnsAddress.reset(null);
208 __pSecondaryDnsAddress.reset(null);
212 _NetConnectionInfoImpl::SetBearerType(NetBearerType bearerType)
214 __bearerType = bearerType;
218 _NetConnectionInfoImpl::SetProtocolType(NetProtocolType protocolType)
220 __protocolType = protocolType;
224 _NetConnectionInfoImpl::SetAccessPointName(const String& apn)
230 _NetConnectionInfoImpl::SetLocalAddressScheme(NetAddressScheme localAddressScheme)
232 __localAddressScheme = localAddressScheme;
236 _NetConnectionInfoImpl::SetDnsAddressScheme(NetAddressScheme dnsAddressScheme)
238 __dnsAddressScheme = dnsAddressScheme;
242 _NetConnectionInfoImpl::SetLocalAddress(const String& localAddress)
244 unique_ptr<IpAddress> pLocalAddress(new (std::nothrow) Ip4Address(localAddress));
245 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
246 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
248 __pLocalAddress.reset(pLocalAddress.release());
252 _NetConnectionInfoImpl::SetSubnetMaskAddress(const String& subnetMaskAddress)
254 unique_ptr<IpAddress> pSubnetMaskAddress(new (std::nothrow) Ip4Address(subnetMaskAddress));
255 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
256 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
258 __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
262 _NetConnectionInfoImpl::SetDefaultGatewayAddress(const String& defaultGatewayAddress)
264 unique_ptr<IpAddress> pDefaultGatewayAddress(new (std::nothrow) Ip4Address(defaultGatewayAddress));
265 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
266 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
268 __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
272 _NetConnectionInfoImpl::SetPrimaryDnsAddress(const String& primaryDnsAddress)
274 unique_ptr<IpAddress> pPrimaryDnsAddress(new (std::nothrow) Ip4Address(primaryDnsAddress));
275 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
276 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
278 __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
282 _NetConnectionInfoImpl::SetSecondaryDnsAddress(const String& secondaryDnsAddress)
284 unique_ptr<IpAddress> pSecondaryDnsAddress(new (std::nothrow) Ip4Address(secondaryDnsAddress));
285 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
286 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
288 __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
292 _NetConnectionInfoImpl::SetProxyAddress(const String& proxyAddress)
294 __proxyAddress = proxyAddress;
298 _NetConnectionInfoImpl::SetDeviceName(const String& deviceName)
300 __deviceName = deviceName;
304 _NetConnectionInfoImpl::Update(void* pProfileHandle, bool isDefault)
306 static const wchar_t _IP4_ADDRESS_EMPTY_ADDRESS[] = L":";
307 static const wchar_t _IP4_ADDRESS_DUMMY_ADDRESS[] = L"0.0.0.0";
309 NetBearerType bearerType = NET_BEARER_NONE;
310 NetProtocolType protocolType = NET_PROTO_TYPE_NONE;
314 NetAddressScheme localAddressScheme = NET_ADDRESS_SCHEME_NONE;
315 NetAddressScheme dnsAddressScheme = NET_ADDRESS_SCHEME_NONE;
316 unique_ptr<IpAddress> pLocalAddress;
317 unique_ptr<IpAddress> pSubnetMaskAddress;
318 unique_ptr<IpAddress> pDefaultGatewayAddress;
319 unique_ptr<IpAddress> pPrimaryDnsAddress;
320 unique_ptr<IpAddress> pSecondaryDnsAddress;
322 int ret = CONNECTION_ERROR_NONE;
323 connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileHandle);
324 connection_profile_type_e type = CONNECTION_PROFILE_TYPE_WIFI;
326 SysLog(NID_NET, "Update() has been called with isDefault:%d", isDefault);
330 if (pProfileHandle == null)
335 ret = connection_profile_get_type(profileHandle, &type);
336 SysLog(NID_NET, "The return value from connection_profile_get_type() is %d. Network type is %d", ret, type);
338 if (type == CONNECTION_PROFILE_TYPE_WIFI)
340 SysLog(NID_NET, "Profile type is Wi-Fi.");
341 bearerType = NET_BEARER_WIFI;
343 else if (type == CONNECTION_PROFILE_TYPE_CELLULAR)
345 SysLog(NID_NET, "Profile type is Cellular.");
348 ret = connection_profile_get_cellular_apn(profileHandle, &pApn);
349 if ((ret == CONNECTION_ERROR_NONE) && (pApn != null))
355 bearerType = NET_BEARER_PS;
359 // CONNECTION_PROFILE_TYPE_ETHERNET (For emulator: Treat ethernet as cellular.)
360 SysLog(NID_NET, "Profile type is Ethernet.");
361 bearerType = NET_BEARER_PS;
364 protocolType = NET_PROTO_TYPE_IPV4;
366 connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
367 ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
368 SysTryReturnVoidResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
369 "[%s] A system error has been occurred. The return value from connection_profile_get_ip_config_type() is %d",
370 GetErrorMessage(E_SYSTEM), ret);
372 if ((ipConfigType == CONNECTION_IP_CONFIG_TYPE_STATIC) || (ipConfigType == CONNECTION_IP_CONFIG_TYPE_FIXED))
374 localAddressScheme = NET_ADDRESS_SCHEME_STATIC;
375 dnsAddressScheme = NET_ADDRESS_SCHEME_STATIC;
379 localAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
380 dnsAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
383 char* pIpAddr = null;
386 ret = connection_profile_get_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
387 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
389 ipAddr = String(pIpAddr);
392 pLocalAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
393 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
394 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
397 ret = connection_profile_get_subnet_mask(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
398 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
400 ipAddr = String(pIpAddr);
403 pSubnetMaskAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
404 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
405 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
408 ret = connection_profile_get_gateway_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
410 ipAddr = String(pIpAddr);
413 pDefaultGatewayAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
414 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
415 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
418 ret = connection_profile_get_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
419 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
421 ipAddr = String(pIpAddr);
424 pPrimaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
425 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
426 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
429 ret = connection_profile_get_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
430 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
432 ipAddr = String(pIpAddr);
435 pSecondaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
436 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
437 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
440 char* pProxyAddr = null;
442 ret = connection_profile_get_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxyAddr);
443 SysSecureLog(NID_NET, "The return value from connection_profile_get_proxy_address() is [%d], Proxy address is [%s]", ret, pProxyAddr);
444 if ((ret == CONNECTION_ERROR_NONE) && (pProxyAddr != null))
446 proxyAddress = String(pProxyAddr);
450 if (!proxyAddress.IsEmpty())
452 if ((proxyAddress.StartsWith(_IP4_ADDRESS_DUMMY_ADDRESS, 0)) || (proxyAddress.StartsWith(_IP4_ADDRESS_EMPTY_ADDRESS, 0)))
454 proxyAddress.Clear();
455 SysLog(NID_NET, "Proxy address is invalid, so clear it.");
466 char* pDeviceName = null;
468 ret = connection_profile_get_network_interface_name(profileHandle, &pDeviceName);
469 if ((ret == CONNECTION_ERROR_NONE) && (pDeviceName != null))
471 deviceName = String(pDeviceName);
476 __bearerType = bearerType;
477 __protocolType = protocolType;
479 __localAddressScheme = localAddressScheme;
480 __dnsAddressScheme = dnsAddressScheme;
481 __proxyAddress = proxyAddress;
482 __deviceName = deviceName;
484 __pLocalAddress.reset(pLocalAddress.release());
485 __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
486 __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
487 __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
488 __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
492 _NetConnectionInfoImpl::CreateNetConnectionInfoN(void* pProfileHandle)
494 result r = E_SUCCESS;
496 unique_ptr<NetConnectionInfo> pNetConnectionInfo;
497 _NetConnectionInfoImpl* pNetConnectionInfoImpl = null;
499 SysTryReturn(NID_NET, pProfileHandle != null, null, E_INVALID_ARG,
500 "[%s] Invalid argument is used. The profile info is null.", GetErrorMessage(E_INVALID_ARG));
502 pNetConnectionInfo.reset(new (std::nothrow) NetConnectionInfo());
503 SysTryReturn(NID_NET, pNetConnectionInfo != null, null, E_OUT_OF_MEMORY,
504 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
506 pNetConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(*pNetConnectionInfo);
507 SysTryReturn(NID_NET, pNetConnectionInfoImpl != null, null, E_OUT_OF_MEMORY,
508 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
510 pNetConnectionInfoImpl->Update(pProfileHandle);
512 SysTryReturn(NID_NET, pNetConnectionInfoImpl != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
514 return pNetConnectionInfo.release();
517 _NetConnectionInfoImpl::_NetConnectionInfoImpl(const _NetConnectionInfoImpl& value)
519 unique_ptr<IpAddress> pLocalAddress;
520 unique_ptr<IpAddress> pSubnetMaskAddress;
521 unique_ptr<IpAddress> pDefaultGatewayAddress;
522 unique_ptr<IpAddress> pPrimaryDnsAddress;
523 unique_ptr<IpAddress> pSecondaryDnsAddress;
525 if (value.__pLocalAddress != null)
527 pLocalAddress.reset(value.__pLocalAddress->CloneN());
528 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
529 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
532 if (value.__pSubnetMaskAddress != null)
534 pSubnetMaskAddress.reset(value.__pSubnetMaskAddress->CloneN());
535 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
536 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
539 if (value.__pDefaultGatewayAddress != null)
541 pDefaultGatewayAddress.reset(value.__pDefaultGatewayAddress->CloneN());
542 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
543 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
546 if (value.__pPrimaryDnsAddress != null)
548 pPrimaryDnsAddress.reset(value.__pPrimaryDnsAddress->CloneN());
549 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
550 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
553 if (value.__pSecondaryDnsAddress != null)
555 pSecondaryDnsAddress.reset(value.__pSecondaryDnsAddress->CloneN());
556 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
557 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
560 __bearerType = value.__bearerType;
561 __protocolType = value.__protocolType;
563 __deviceName = value.__deviceName;
564 __proxyAddress = value.__proxyAddress;
565 __localAddressScheme = value.__localAddressScheme;
566 __dnsAddressScheme = value.__dnsAddressScheme;
568 __pLocalAddress.reset(pLocalAddress.release());
569 __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
570 __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
571 __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
572 __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
575 _NetConnectionInfoImpl&
576 _NetConnectionInfoImpl::operator =(const _NetConnectionInfoImpl& rhs)
583 unique_ptr<IpAddress> pLocalAddress;
584 unique_ptr<IpAddress> pSubnetMaskAddress;
585 unique_ptr<IpAddress> pDefaultGatewayAddress;
586 unique_ptr<IpAddress> pPrimaryDnsAddress;
587 unique_ptr<IpAddress> pSecondaryDnsAddress;
589 if (rhs.__pLocalAddress != null)
591 pLocalAddress.reset(rhs.__pLocalAddress->CloneN());
592 SysTryReturn(NID_NET, pLocalAddress != null, *this, E_OUT_OF_MEMORY,
593 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
596 if (rhs.__pSubnetMaskAddress != null)
598 pSubnetMaskAddress.reset(rhs.__pSubnetMaskAddress->CloneN());
599 SysTryReturn(NID_NET, pSubnetMaskAddress != null, *this, E_OUT_OF_MEMORY,
600 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
603 if (rhs.__pDefaultGatewayAddress != null)
605 pDefaultGatewayAddress.reset(rhs.__pDefaultGatewayAddress->CloneN());
606 SysTryReturn(NID_NET, pDefaultGatewayAddress != null, *this, E_OUT_OF_MEMORY,
607 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
610 if (rhs.__pPrimaryDnsAddress != null)
612 pPrimaryDnsAddress.reset(rhs.__pPrimaryDnsAddress->CloneN());
613 SysTryReturn(NID_NET, pPrimaryDnsAddress != null, *this, E_OUT_OF_MEMORY,
614 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
617 if (rhs.__pSecondaryDnsAddress != null)
619 pSecondaryDnsAddress.reset(rhs.__pSecondaryDnsAddress->CloneN());
620 SysTryReturn(NID_NET, pSecondaryDnsAddress != null, *this, E_OUT_OF_MEMORY,
621 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
624 __bearerType = rhs.__bearerType;
625 __protocolType = rhs.__protocolType;
627 __deviceName = rhs.__deviceName;
628 __proxyAddress = rhs.__proxyAddress;
629 __localAddressScheme = rhs.__localAddressScheme;
630 __dnsAddressScheme = rhs.__dnsAddressScheme;
632 __pLocalAddress.reset(pLocalAddress.release());
633 __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
634 __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
635 __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
636 __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
642 _NetConnectionInfoImpl::Equals(const Object& obj) const
644 const _NetConnectionInfoImpl* pRhs = dynamic_cast <const _NetConnectionInfoImpl*>(&obj);
651 if (__bearerType != pRhs->__bearerType ||
652 __protocolType != pRhs->__protocolType ||
653 __apn != pRhs->__apn ||
654 __deviceName != pRhs->__deviceName ||
655 __proxyAddress != pRhs->__proxyAddress ||
656 __localAddressScheme != pRhs->__localAddressScheme ||
657 __dnsAddressScheme != pRhs->__dnsAddressScheme )
662 if (__pLocalAddress != null && pRhs->__pLocalAddress != null)
664 if (!__pLocalAddress->Equals(*pRhs->__pLocalAddress))
669 else if (__pLocalAddress != null || pRhs->__pLocalAddress != null)
674 if (__pSubnetMaskAddress != null && pRhs->__pSubnetMaskAddress != null)
676 if (!__pSubnetMaskAddress->Equals(*pRhs->__pSubnetMaskAddress))
681 else if (__pSubnetMaskAddress != null || pRhs->__pSubnetMaskAddress != null)
686 if (__pDefaultGatewayAddress != null && pRhs->__pDefaultGatewayAddress != null)
688 if (!__pDefaultGatewayAddress->Equals(*pRhs->__pDefaultGatewayAddress))
693 else if (__pDefaultGatewayAddress != null || pRhs->__pDefaultGatewayAddress != null)
698 if (__pPrimaryDnsAddress != null && pRhs->__pPrimaryDnsAddress != null)
700 if (!__pPrimaryDnsAddress->Equals(*pRhs->__pPrimaryDnsAddress))
705 else if (__pPrimaryDnsAddress != null || pRhs->__pPrimaryDnsAddress != null)
710 if (__pSecondaryDnsAddress != null && pRhs->__pSecondaryDnsAddress != null)
712 if ( !__pSecondaryDnsAddress->Equals(*pRhs->__pSecondaryDnsAddress))
717 else if (__pSecondaryDnsAddress != null || pRhs->__pSecondaryDnsAddress != null)
726 _NetConnectionInfoImpl::GetHashCode(void) const
728 int hashCode = _HASH_CODE_INITIAL_VALUE;
730 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __bearerType;
731 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __protocolType;
732 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __apn.GetHashCode();
733 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __deviceName.GetHashCode();
734 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __proxyAddress.GetHashCode();
735 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __localAddressScheme;
736 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dnsAddressScheme;
738 if (__pLocalAddress != null)
740 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pLocalAddress->GetHashCode();
744 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
747 if (__pSubnetMaskAddress != null)
749 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pSubnetMaskAddress->GetHashCode();
753 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
756 if (__pDefaultGatewayAddress != null)
758 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pDefaultGatewayAddress->GetHashCode();
762 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
765 if (__pPrimaryDnsAddress != null)
767 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pPrimaryDnsAddress->GetHashCode();
771 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
774 if (__pSecondaryDnsAddress != null)
776 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pSecondaryDnsAddress->GetHashCode();
780 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
786 _NetConnectionInfoImpl*
787 _NetConnectionInfoImpl::GetInstance(NetConnectionInfo& netConnectionInfo)
789 return netConnectionInfo.__pNetConnectionInfoImpl;
792 const _NetConnectionInfoImpl*
793 _NetConnectionInfoImpl::GetInstance(const NetConnectionInfo& netConnectionInfo)
795 return netConnectionInfo.__pNetConnectionInfoImpl;