merge with master
[framework/osp/messaging.git] / src / FMsg_EtwsPrimaryNotificationImpl.cpp
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Apache License, Version 2.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.apache.org/licenses/LICENSE-2.0\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an "AS IS" BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 /**\r
18  * @file                FMsg_EtwsPrimaryNotificationImpl.cpp\r
19  * @brief               This is the implementation file for the %_EtwsPrimaryNotificationImpl class.\r
20  *\r
21  * This file contains the implementation of the %_EtwsPrimaryNotificationImpl class.\r
22  */\r
23 \r
24 #include <msg.h>\r
25 #include <msg_transport.h>\r
26 #include <msg_storage.h>\r
27 #include <FMsgEtwsPrimaryNotification.h>\r
28 #include <FBaseSysLog.h>\r
29 #include <FSec_AccessController.h>\r
30 #include "FMsg_Types.h"\r
31 #include "FMsg_EtwsPrimaryNotificationImpl.h"\r
32 \r
33 using namespace Tizen::Base;\r
34 using namespace Tizen::Messaging;\r
35 using namespace Tizen::Security;\r
36 \r
37 namespace Tizen { namespace Messaging\r
38 {\r
39 \r
40 _EtwsPrimaryNotificationImpl::_EtwsPrimaryNotificationImpl(void)\r
41         : __etwsMsgTime()\r
42         , __pEtwsSerialNumber(null)\r
43         , __pEtwsSecurityInfo(null)\r
44         , __etwsMessageId(0)\r
45         , __pEtwsWarningType(null)\r
46 {\r
47         __pEtwsSerialNumber = new (std::nothrow) ByteBuffer();\r
48         SysTryReturnVoidResult(NID_MSG, __pEtwsSerialNumber != null, E_OUT_OF_MEMORY, "memory allocation failed");\r
49         __pEtwsSerialNumber->Construct(0);\r
50         __pEtwsSerialNumber->SetPosition(0);\r
51 \r
52         __pEtwsSecurityInfo = new (std::nothrow) ByteBuffer();\r
53         SysTryReturnVoidResult(NID_MSG, __pEtwsSecurityInfo != null, E_OUT_OF_MEMORY, "memory allocation failed");\r
54         __pEtwsSecurityInfo->Construct(0);\r
55         __pEtwsSecurityInfo->SetPosition(0);\r
56 \r
57         __pEtwsWarningType = new (std::nothrow) ByteBuffer();\r
58         SysTryReturnVoidResult(NID_MSG, __pEtwsWarningType != null, E_OUT_OF_MEMORY, "memory allocation failed");\r
59         __pEtwsWarningType->Construct(0);\r
60         __pEtwsWarningType->SetPosition(0);\r
61 }\r
62 \r
63 _EtwsPrimaryNotificationImpl::_EtwsPrimaryNotificationImpl(const _EtwsPrimaryNotificationImpl& value)\r
64 {\r
65         __etwsMsgTime = value.__etwsMsgTime;\r
66         __etwsMessageId = value.__etwsMessageId;\r
67 \r
68         __pEtwsSerialNumber->SetArray(value.__pEtwsSerialNumber->GetPointer(), 0, value.__pEtwsSerialNumber->GetLimit());\r
69         __pEtwsSerialNumber->SetPosition(0);\r
70 \r
71         __pEtwsSecurityInfo->SetArray(value.__pEtwsSecurityInfo->GetPointer(), 0, value.__pEtwsSecurityInfo->GetLimit());\r
72         __pEtwsSecurityInfo->SetPosition(0);\r
73 \r
74         __pEtwsWarningType->SetArray(value.__pEtwsWarningType->GetPointer(), 0, value.__pEtwsWarningType->GetLimit());\r
75         __pEtwsWarningType->SetPosition(0);\r
76 }\r
77 \r
78 result\r
79 _EtwsPrimaryNotificationImpl::SetEtwsMessageImpl(const Tizen::Base::DateTime& dateTime, const Tizen::Base::ByteBuffer& etwsSerialNumber, const Tizen::Base::ByteBuffer&\r
80                                         etwsSecurityInfo, int etwsMessageId, const Tizen::Base::ByteBuffer& etwsWarningType)\r
81 {\r
82         result r = E_SUCCESS;\r
83 \r
84         __etwsMsgTime = dateTime;\r
85         __etwsMessageId = etwsMessageId;\r
86 \r
87         __pEtwsSerialNumber = new (std::nothrow) ByteBuffer();\r
88         SysTryReturn(NID_MSG, __pEtwsSerialNumber != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed");\r
89         r = __pEtwsSerialNumber->Construct(etwsSerialNumber);\r
90         r = __pEtwsSerialNumber->SetPosition(0);\r
91 \r
92         __pEtwsSecurityInfo = new (std::nothrow) ByteBuffer();\r
93         SysTryCatch(NID_MSG, __pEtwsSecurityInfo != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
94         r = __pEtwsSecurityInfo->Construct(etwsSecurityInfo);\r
95         r = __pEtwsSecurityInfo->SetPosition(0);\r
96 \r
97         __pEtwsWarningType = new (std::nothrow) ByteBuffer();\r
98         SysTryCatch(NID_MSG, __pEtwsWarningType != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
99         r = __pEtwsWarningType->Construct(etwsWarningType);\r
100         r = __pEtwsWarningType->SetPosition(0);\r
101 \r
102         return r;\r
103 \r
104 CATCH:\r
105         SetLastResult(GetLastResult());\r
106         if (__pEtwsSerialNumber)\r
107         {\r
108                 delete __pEtwsSerialNumber;\r
109                 __pEtwsSerialNumber = null;\r
110         }\r
111 \r
112         if (__pEtwsSecurityInfo)\r
113         {\r
114                 delete __pEtwsSecurityInfo;\r
115                 __pEtwsSecurityInfo = null;\r
116         }\r
117         return r;\r
118 }\r
119 \r
120 _EtwsPrimaryNotificationImpl::~_EtwsPrimaryNotificationImpl(void)\r
121 {\r
122         if (__pEtwsSerialNumber)\r
123         {\r
124                 delete __pEtwsSerialNumber;\r
125                 __pEtwsSerialNumber = null;\r
126         }\r
127 \r
128         if (__pEtwsSecurityInfo)\r
129         {\r
130                 delete __pEtwsSecurityInfo;\r
131                 __pEtwsSecurityInfo = null;\r
132         }\r
133 \r
134         if (__pEtwsWarningType)\r
135         {\r
136                 delete __pEtwsWarningType;\r
137                 __pEtwsWarningType = null;\r
138         }\r
139 }\r
140 \r
141 _EtwsPrimaryNotificationImpl&\r
142 _EtwsPrimaryNotificationImpl::operator =(const _EtwsPrimaryNotificationImpl& rhs)\r
143 {\r
144         if (this != &rhs)\r
145         {\r
146                 __etwsMsgTime = rhs.__etwsMsgTime;\r
147                 __etwsMessageId = rhs.__etwsMessageId;\r
148 \r
149                 __pEtwsSerialNumber->SetArray(rhs.__pEtwsSerialNumber->GetPointer(), 0, rhs.__pEtwsSerialNumber->GetLimit());\r
150                 __pEtwsSerialNumber->SetPosition(0);\r
151 \r
152                 __pEtwsSecurityInfo->SetArray(rhs.__pEtwsSecurityInfo->GetPointer(), 0, rhs.__pEtwsSecurityInfo->GetLimit());\r
153                 __pEtwsSecurityInfo->SetPosition(0);\r
154 \r
155                 __pEtwsWarningType->SetArray(rhs.__pEtwsWarningType->GetPointer(), 0, rhs.__pEtwsWarningType->GetLimit());\r
156                 __pEtwsWarningType->SetPosition(0);\r
157         }\r
158 \r
159         return (*this);\r
160 }\r
161 \r
162 EtwsPrimaryNotification*\r
163 _EtwsPrimaryNotificationImpl::CloneN() const\r
164 {\r
165         EtwsPrimaryNotification* pEtwsMsg = null;\r
166         result r = E_SUCCESS;\r
167 \r
168         pEtwsMsg = _EtwsPrimaryNotificationImpl::GetEtwsPrimaryNotificationN();\r
169         SysTryCatch(NID_MSG, pEtwsMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
170 \r
171         r = _EtwsPrimaryNotificationImpl::GetInstance(*pEtwsMsg)->SetEtwsMessageImpl(__etwsMsgTime, *(__pEtwsSerialNumber), *(__pEtwsSecurityInfo), __etwsMessageId, *(__pEtwsWarningType));\r
172         SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "etwsimpl message construct failed");\r
173 \r
174         SetLastResult(GetLastResult());\r
175         return pEtwsMsg;\r
176 \r
177 CATCH:\r
178         SetLastResult(GetLastResult());\r
179         if (pEtwsMsg)\r
180         {\r
181                 delete pEtwsMsg;\r
182                 pEtwsMsg = null;\r
183         }\r
184         return null;\r
185 }\r
186 \r
187 bool\r
188 _EtwsPrimaryNotificationImpl::Equals(const Tizen::Base::Object& obj) const\r
189 {\r
190         const _EtwsPrimaryNotificationImpl* pEtwsPrimaryNotificationImpl = dynamic_cast<const _EtwsPrimaryNotificationImpl*>(&obj);\r
191 \r
192         if (!pEtwsPrimaryNotificationImpl)\r
193         {\r
194                 SysLog(NID_MSG, "dynamic_cast is failed");\r
195                 return false;\r
196         }\r
197 \r
198         // sender time\r
199         if (__etwsMsgTime != pEtwsPrimaryNotificationImpl->__etwsMsgTime)\r
200         {\r
201                 return false;\r
202         }\r
203 \r
204         // etws serial number\r
205         if (__pEtwsSerialNumber != pEtwsPrimaryNotificationImpl->__pEtwsSerialNumber)\r
206         {\r
207                 return false;\r
208         }\r
209 \r
210         // etws security info\r
211         if (__pEtwsSecurityInfo != pEtwsPrimaryNotificationImpl->__pEtwsSecurityInfo)\r
212         {\r
213                 return false;\r
214         }\r
215 \r
216         // cbs message id\r
217         if (__etwsMessageId != pEtwsPrimaryNotificationImpl->__etwsMessageId)\r
218         {\r
219                 return false;\r
220         }\r
221 \r
222         // Etws warning type\r
223         if (__pEtwsWarningType != pEtwsPrimaryNotificationImpl->__pEtwsWarningType)\r
224         {\r
225                 return false;\r
226         }\r
227 \r
228         return true;\r
229 }\r
230 \r
231 int\r
232 _EtwsPrimaryNotificationImpl::GetHashCode(void) const\r
233 {\r
234         int hash = 0;\r
235 \r
236         hash = __etwsMsgTime.GetHashCode() + __pEtwsSerialNumber->GetHashCode() + __pEtwsSecurityInfo->GetHashCode() + __etwsMessageId + __pEtwsWarningType->GetHashCode();\r
237 \r
238         return hash;\r
239 }\r
240 \r
241 EtwsPrimaryNotification*\r
242 _EtwsPrimaryNotificationImpl::GetEtwsPrimaryNotificationN()\r
243 {\r
244         result r = E_SUCCESS;\r
245         EtwsPrimaryNotification* pEtwsMsg = null;\r
246 \r
247         pEtwsMsg = new (std::nothrow) EtwsPrimaryNotification();\r
248         SysTryCatch(NID_MSG, pEtwsMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
249 \r
250         return pEtwsMsg;\r
251 \r
252 CATCH:\r
253         return null;\r
254 }\r
255 \r
256 _EtwsPrimaryNotificationImpl*\r
257 _EtwsPrimaryNotificationImpl::GetInstance(EtwsPrimaryNotification& etwsMessage)\r
258 {\r
259         return etwsMessage.__pEtwsPrimaryNotificationImpl;\r
260 }\r
261 \r
262 \r
263 Tizen::Base::ByteBuffer*\r
264 _EtwsPrimaryNotificationImpl::GetSerialNumberN(void) const\r
265 {\r
266         result r = E_SUCCESS;\r
267         Tizen::Base::ByteBuffer* pEtwsSerialNumber = null;\r
268 \r
269         ClearLastResult();\r
270 \r
271         pEtwsSerialNumber = new (std::nothrow) ByteBuffer();\r
272         SysTryCatch(NID_MSG, pEtwsSerialNumber != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
273 \r
274         r = pEtwsSerialNumber->Construct(*__pEtwsSerialNumber);\r
275         r = pEtwsSerialNumber->SetPosition(0);\r
276 \r
277         SetLastResult(r);\r
278 \r
279         return pEtwsSerialNumber;\r
280 \r
281 CATCH:\r
282         SetLastResult(r);\r
283 \r
284         return null;\r
285 }\r
286 \r
287 Tizen::Base::DateTime\r
288 _EtwsPrimaryNotificationImpl::GetReceivedTime(void) const\r
289 {\r
290         return __etwsMsgTime;\r
291 }\r
292 \r
293 Tizen::Base::ByteBuffer*\r
294 _EtwsPrimaryNotificationImpl::GetWarningSecurityInfoN(void) const\r
295 {\r
296         result r = E_SUCCESS;\r
297         Tizen::Base::ByteBuffer* pEtwsSecurityInfo = null;\r
298 \r
299         ClearLastResult();\r
300 \r
301         pEtwsSecurityInfo = new (std::nothrow) ByteBuffer();\r
302         SysTryCatch(NID_MSG, pEtwsSecurityInfo != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
303 \r
304         r = pEtwsSecurityInfo->Construct(*__pEtwsSecurityInfo);\r
305         r = pEtwsSecurityInfo->SetPosition(0);\r
306 \r
307         SetLastResult(r);\r
308 \r
309         return pEtwsSecurityInfo;\r
310 \r
311 CATCH:\r
312         SetLastResult(r);\r
313 \r
314         return null;\r
315 }\r
316 \r
317 int\r
318 _EtwsPrimaryNotificationImpl::GetMessageId(void) const\r
319 {\r
320         return __etwsMessageId;\r
321 }\r
322 \r
323 Tizen::Base::ByteBuffer*\r
324 _EtwsPrimaryNotificationImpl::GetWarningTypeN(void) const\r
325 {\r
326         result r = E_SUCCESS;\r
327         Tizen::Base::ByteBuffer* pEtwsWarningType = null;\r
328 \r
329         ClearLastResult();\r
330 \r
331         pEtwsWarningType = new (std::nothrow) ByteBuffer();\r
332         SysTryCatch(NID_MSG, pEtwsWarningType != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");\r
333 \r
334         r = pEtwsWarningType->Construct(*__pEtwsWarningType);\r
335         r = pEtwsWarningType->SetPosition(0);\r
336 \r
337         SetLastResult(r);\r
338 \r
339         return pEtwsWarningType;\r
340 \r
341 CATCH:\r
342         SetLastResult(r);\r
343 \r
344         return null;\r
345 }\r
346 \r
347 } } // Tizen::Messaging\r