Merge "Export internal APIs needed by samsung-socil" into tizen_2.1
[framework/osp/social.git] / src / FSclImAddress.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17 * @file         FSclImAddress.cpp
18 * @brief        This is the implementation for ImAddress class.
19 *
20 * This file contains definitions of @e ImAddress class.
21 */
22
23 #include <FSclImAddress.h>
24 #include <FApp_AppInfo.h>
25 #include <FBaseSysLog.h>
26 #include "FScl_ImAddressImpl.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30
31 namespace Tizen { namespace Social
32 {
33
34 ImAddress::ImAddress(void)
35 {
36         __pImAddressImpl = new (std::nothrow) _ImAddressImpl();
37         SysTryReturnVoidResult(NID_SCL, __pImAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
38 }
39
40 ImAddress::ImAddress(const String& serviceProviderName, const String& imAddress)
41 {
42         __pImAddressImpl = new (std::nothrow) _ImAddressImpl(serviceProviderName, imAddress);
43         SysTryReturnVoidResult(NID_SCL, __pImAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
44 }
45
46 ImAddress::ImAddress(const ImAddress& rhs)
47 {
48         __pImAddressImpl = new (std::nothrow) _ImAddressImpl(*rhs.__pImAddressImpl);
49         SysTryReturnVoidResult(NID_SCL, __pImAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
50 }
51
52 ImAddress::~ImAddress(void)
53 {
54         delete __pImAddressImpl;
55 }
56
57 ImAddress&
58 ImAddress::operator =(const ImAddress& rhs)
59 {
60         if (this == &rhs)
61         {
62                 return *this;
63         }
64
65         *__pImAddressImpl = *rhs.__pImAddressImpl;
66
67         return *this;
68 }
69
70 bool
71 ImAddress::operator ==(const ImAddress& rhs) const
72 {
73         return *__pImAddressImpl == *rhs.__pImAddressImpl;
74 }
75
76 bool
77 ImAddress::operator !=(const ImAddress& rhs) const
78 {
79         return !(*this  == rhs);
80 }
81
82 bool
83 ImAddress::Equals(const Object& rhs) const
84 {
85         const ImAddress* pImAddress = dynamic_cast<const ImAddress*>(&rhs);
86         if (pImAddress == null)
87         {
88                 return false;
89         }
90
91         return __pImAddressImpl->Equals(*pImAddress->__pImAddressImpl);
92 }
93
94 int
95 ImAddress::GetHashCode(void) const
96 {
97         return __pImAddressImpl->GetHashCode();
98 }
99
100 String
101 ImAddress::GetServiceProviderName(void) const
102 {
103         return __pImAddressImpl->GetServiceProviderName();
104 }
105
106 String
107 ImAddress::GetImAddress(void) const
108 {
109         String imAddress = __pImAddressImpl->GetImAddress();
110
111         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
112         {
113                 if (imAddress.GetLength() > MAX_IM_ADDRESS_LENGTH)
114                 {
115                         imAddress.SetLength(MAX_IM_ADDRESS_LENGTH);
116                 }
117         }
118
119         return imAddress;
120 }
121
122 void
123 ImAddress::SetServiceProviderName(const String& serviceProviderName)
124 {
125         __pImAddressImpl->SetServiceProviderName(serviceProviderName);
126 }
127
128 result
129 ImAddress::SetImAddress(const String& imAddress)
130 {
131         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
132         {
133                 SysTryReturn(NID_SCL, imAddress.GetLength() <= MAX_IM_ADDRESS_LENGTH,
134                                 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));
135         }
136
137         return __pImAddressImpl->SetImAddress(imAddress);
138 }
139
140 }} // Tizen::Social