Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNetIp4Address.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 /**
19  * @file                FNetIp4Address.cpp
20  * @brief               This is the implementation for the %Ip4Address class.
21  */
22
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"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Utility;
34
35 namespace Tizen { namespace Net
36 {
37
38 Ip4Address::Ip4Address(const String& ipAddr)
39 {
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));
43 }
44
45 Ip4Address::Ip4Address(unsigned long ipAddr)
46 {
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));
50 }
51
52 Ip4Address::Ip4Address(const Ip4Address& rhs)
53 {
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));
57 }
58
59 Ip4Address::~Ip4Address(void)
60 {
61         delete __pIp4AddressImpl;
62         __pIp4AddressImpl = null;
63 }
64
65 NetAddressFamily
66 Ip4Address::GetNetAddressFamily(void) const
67 {
68         return __pIp4AddressImpl->GetNetAddressFamily();
69 }
70
71 result
72 Ip4Address::GetAddress(ByteBuffer& ipAddr) const
73 {
74         result r = E_SUCCESS;
75
76         r = __pIp4AddressImpl->GetAddress(ipAddr);
77         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
78
79         return r;
80 }
81
82 result
83 Ip4Address::GetAddress(unsigned long& ipAddr) const
84 {
85         result r = E_SUCCESS;
86
87         r = __pIp4AddressImpl->GetAddress(ipAddr);
88         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
89
90         return r;
91 }
92
93 String
94 Ip4Address::ToString(void) const
95 {
96         return __pIp4AddressImpl->ToString();
97 }
98
99 Ip4Address&
100 Ip4Address::operator =(const Ip4Address& rhs)
101 {
102         if (this == &rhs)
103         {
104                 return *this;
105         }
106
107         _pIpAddressImpl = null; // Not used yet
108
109         *__pIp4AddressImpl = *rhs.__pIp4AddressImpl;
110
111         return *this;
112 }
113
114 IpAddress*
115 Ip4Address::CloneN(void) const
116 {
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));
120
121         return pClone;
122 }
123
124 bool
125 Ip4Address::Equals(const Object& rhs) const
126 {
127         const Ip4Address* pRhs = dynamic_cast<const Ip4Address*>(&rhs);
128
129         if (pRhs == null)
130         {
131                 return false;
132         }
133
134         const _Ip4AddressImpl* pRhsImpl = _Ip4AddressImpl::GetInstance(*pRhs);
135
136         if (pRhsImpl == null)
137         {
138                 return false;
139         }
140
141         return __pIp4AddressImpl->Equals(*pRhsImpl);
142 }
143
144 int
145 Ip4Address::GetHashCode(void) const
146 {
147         return __pIp4AddressImpl->GetHashCode();
148 }
149
150 } } // Tizen::Net