Fix TCT error.
[platform/framework/native/net.git] / src / FNetNetEndPoint.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                FNetNetEndPoint.cpp
20  * @brief               This is the implementation for the %NetEndPoint class.
21  */
22
23 #include <FBaseUtilUri.h>
24 #include <FBaseShort.h>
25 #include <FNetNetEndPoint.h>
26 #include <FNetIp4Address.h>
27 #include <FBaseSysLog.h>
28 #include "FNet_NetEndPointImpl.h"
29
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Net
33 {
34
35 NetEndPoint::NetEndPoint(void)
36         : __pNetEndPointImpl(null)
37 {
38 }
39
40 NetEndPoint::NetEndPoint(const IpAddress& ipAddress, unsigned short port)
41 {
42         __pNetEndPointImpl = new (std::nothrow) _NetEndPointImpl(ipAddress, port);
43         SysTryReturnVoidResult(NID_NET, __pNetEndPointImpl != null, E_OUT_OF_MEMORY,
44                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45         SysTryReturnVoidResult(NID_NET, GetLastResult() == E_SUCCESS, GetLastResult(),
46                         "[%s] IP address is invalid.", GetErrorMessage(GetLastResult()));
47 }
48
49 NetEndPoint::NetEndPoint(const NetEndPoint& rhs)
50 {
51         __pNetEndPointImpl = new (std::nothrow) _NetEndPointImpl(*rhs.__pNetEndPointImpl);
52         SysTryReturnVoidResult(NID_NET, __pNetEndPointImpl != null, E_OUT_OF_MEMORY,
53                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
54         SysTryReturnVoidResult(NID_NET, GetLastResult() == E_SUCCESS, GetLastResult(),
55                         "[%s] The instance is invalid.", GetErrorMessage(GetLastResult()));
56 }
57
58 NetEndPoint::~NetEndPoint()
59 {
60         delete __pNetEndPointImpl;
61         __pNetEndPointImpl = null;
62 }
63
64 NetAddressFamily
65 NetEndPoint::GetNetAddressFamily(void) const
66 {
67         return __pNetEndPointImpl->GetNetAddressFamily();
68 }
69
70 unsigned short
71 NetEndPoint::GetPort(void) const
72 {
73         return __pNetEndPointImpl->GetPort();
74 }
75
76 IpAddress*
77 NetEndPoint::GetAddress(void) const
78 {
79
80         return __pNetEndPointImpl->GetAddress();
81 }
82
83 String
84 NetEndPoint::GetNetEndPoint(void) const
85 {
86         return __pNetEndPointImpl->GetNetEndPoint();
87 }
88
89 NetEndPoint&
90 NetEndPoint::operator =(const NetEndPoint& rhs)
91 {
92         if (this == &rhs)
93         {
94                 return *this;
95         }
96
97         if (rhs.__pNetEndPointImpl != null)
98         {
99                 if (__pNetEndPointImpl != null)
100                 {
101                         *__pNetEndPointImpl = *rhs.__pNetEndPointImpl;
102                 }
103                 else
104                 {
105                         __pNetEndPointImpl = new (std::nothrow) _NetEndPointImpl(*rhs.__pNetEndPointImpl);
106                 }
107         }
108         else
109         {
110                 delete __pNetEndPointImpl;
111                 __pNetEndPointImpl = null;
112         }
113
114         return *this;
115 }
116
117 bool
118 NetEndPoint::Equals(const Object& rhs) const
119 {
120         const NetEndPoint* pRhs = dynamic_cast<const NetEndPoint*>(&rhs);
121         if (pRhs == null)
122         {
123                 return false;
124         }
125
126         const _NetEndPointImpl* pRhsImpl = _NetEndPointImpl::GetInstance(*pRhs);
127         if (pRhsImpl == null)
128         {
129                 return false;
130         }
131
132         return __pNetEndPointImpl->Equals(*pRhsImpl);
133 }
134
135 int
136 NetEndPoint::GetHashCode(void) const
137 {
138         return __pNetEndPointImpl->GetHashCode();
139 }
140
141 } } // Tizen::Net