3f8a025f927e7a2981f7ccae2e20e8b112525d60
[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         __pNetEndPointImpl = rhs.__pNetEndPointImpl;
98
99         return *this;
100 }
101
102 bool
103 NetEndPoint::Equals(const Object& rhs) const
104 {
105         const NetEndPoint* pRhs = dynamic_cast<const NetEndPoint*>(&rhs);
106         if (pRhs == null)
107         {
108                 return false;
109         }
110
111         const _NetEndPointImpl* pRhsImpl = _NetEndPointImpl::GetInstance(*pRhs);
112         if (pRhsImpl == null)
113         {
114                 return false;
115         }
116
117         return __pNetEndPointImpl->Equals(*pRhsImpl);
118 }
119
120 int
121 NetEndPoint::GetHashCode(void) const
122 {
123         return __pNetEndPointImpl->GetHashCode();
124 }
125
126 } } // Tizen::Net