[N_SE-32914, 33582] Fixed priority converting codes
[framework/osp/social.git] / src / FSclImAddress.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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         FSclImAddress.cpp
19 * @brief        This is the implementation for ImAddress class.
20 *
21 * This file contains definitions of @e ImAddress class.
22 */
23
24 #include <FSclImAddress.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseSysLog.h>
27 #include "FScl_ImAddressImpl.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Social
33 {
34
35 ImAddress::ImAddress(void)
36 {
37         __pImAddressImpl = new (std::nothrow) _ImAddressImpl();
38         SysTryReturnVoidResult(NID_SCL, __pImAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
39 }
40
41 ImAddress::ImAddress(const String& serviceProviderName, const String& imAddress)
42 {
43         __pImAddressImpl = new (std::nothrow) _ImAddressImpl(serviceProviderName, imAddress);
44         SysTryReturnVoidResult(NID_SCL, __pImAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 }
46
47 ImAddress::ImAddress(const ImAddress& rhs)
48 {
49         __pImAddressImpl = new (std::nothrow) _ImAddressImpl(*rhs.__pImAddressImpl);
50         SysTryReturnVoidResult(NID_SCL, __pImAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 }
52
53 ImAddress::~ImAddress(void)
54 {
55         delete __pImAddressImpl;
56 }
57
58 ImAddress&
59 ImAddress::operator =(const ImAddress& rhs)
60 {
61         if (this == &rhs)
62         {
63                 return *this;
64         }
65
66         *__pImAddressImpl = *rhs.__pImAddressImpl;
67
68         return *this;
69 }
70
71 bool
72 ImAddress::operator ==(const ImAddress& rhs) const
73 {
74         return *__pImAddressImpl == *rhs.__pImAddressImpl;
75 }
76
77 bool
78 ImAddress::operator !=(const ImAddress& rhs) const
79 {
80         return !(*this  == rhs);
81 }
82
83 bool
84 ImAddress::Equals(const Object& rhs) const
85 {
86         const ImAddress* pImAddress = dynamic_cast<const ImAddress*>(&rhs);
87         if (pImAddress == null)
88         {
89                 return false;
90         }
91
92         return __pImAddressImpl->Equals(*pImAddress->__pImAddressImpl);
93 }
94
95 int
96 ImAddress::GetHashCode(void) const
97 {
98         return __pImAddressImpl->GetHashCode();
99 }
100
101 String
102 ImAddress::GetServiceProviderName(void) const
103 {
104         return __pImAddressImpl->GetServiceProviderName();
105 }
106
107 String
108 ImAddress::GetImAddress(void) const
109 {
110         String imAddress = __pImAddressImpl->GetImAddress();
111
112         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
113         {
114                 if (imAddress.GetLength() > MAX_IM_ADDRESS_LENGTH)
115                 {
116                         imAddress.SetLength(MAX_IM_ADDRESS_LENGTH);
117                 }
118         }
119
120         return imAddress;
121 }
122
123 void
124 ImAddress::SetServiceProviderName(const String& serviceProviderName)
125 {
126         __pImAddressImpl->SetServiceProviderName(serviceProviderName);
127 }
128
129 result
130 ImAddress::SetImAddress(const String& imAddress)
131 {
132         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
133         {
134                 SysTryReturn(NID_SCL, imAddress.GetLength() <= MAX_IM_ADDRESS_LENGTH,
135                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the imAddress exceeds MAX_IM_ADDRESS_LENGTH.", GetErrorMessage(E_INVALID_ARG));
136         }
137
138         return __pImAddressImpl->SetImAddress(imAddress);
139 }
140
141 }} // Tizen::Social