Fix code for TDIS-5396
[framework/osp/social.git] / src / FScl_CalendarbookRecordRetrivalThread.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        FScl_CalendarbookRecordRetrivalThread.cpp
19  * @brief       This is the implementation file for the _CalendarbookRecordRetrivalThread class.
20  *
21  */
22
23 #include <FBaseColIList.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseColAllElementsDeleter.h>
26 #include "FScl_CalendarbookImpl.h"
27 #include "FScl_CalendarbookRecordRetrivalEvent.h"
28 #include "FScl_CalendarbookRecordRetrivalEventArg.h"
29 #include "FScl_CalendarbookRecordRetrivalThread.h"
30 #include "FScl_CalendarbookDbConnector.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Locales;
36
37 namespace Tizen { namespace Social
38 {
39
40 _CalendarbookRecordRetrivalThread::_CalendarbookRecordRetrivalThread(void)
41         : __requestId(-1)
42         , __pEvent(null)
43         , __pageNo(0)
44         , __countPerPage(0)
45         , __category(EVENT_CATEGORY_ALL)
46 {
47         // empty body
48 }
49
50 _CalendarbookRecordRetrivalThread::~_CalendarbookRecordRetrivalThread(void)
51 {
52 }
53
54 result
55 _CalendarbookRecordRetrivalThread::Construct(RequestId requestId, _CalendarbookRecordRetrivalEvent& event
56                 , const DateTime& start, const DateTime& end, const TimeZone& timeZone
57                 , int pageNo, int countPerPage, unsigned long category)
58 {
59         __requestId = requestId;
60         __start = start;
61         __end = end;
62         __timeZone = timeZone;
63         __pageNo = pageNo;
64         __countPerPage = countPerPage;
65         __category = category;
66
67         __pEvent.reset(&event);
68
69         result r = Thread::Construct();
70         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
71
72         return E_SUCCESS;
73 }
74
75 Object*
76 _CalendarbookRecordRetrivalThread::Run(void)
77 {
78         result r = E_SUCCESS;
79         _CalendarbookImpl calendarbookImpl;
80         std::unique_ptr<IList, AllElementsDeleter> pList;
81         std::unique_ptr<_CalendarbookRecordRetrivalEventArg> pEventArg;
82
83         r = calendarbookImpl.Construct();
84         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
85
86         r = _CalendarbookDbConnector::Connect();
87         SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
88
89         pList.reset(calendarbookImpl.GetEventInstancesCommonN(__start, __end, __timeZone, __pageNo, __countPerPage, __category));
90         r = GetLastResult();
91         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
92
93         pEventArg.reset(new (std::nothrow) _CalendarbookRecordRetrivalEventArg(__requestId, pList.get(), r));
94         SysTryCatch(NID_SCL, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
95         pList.release();
96
97         r = _CalendarbookDbConnector::Disconnect();
98         SysTryCatch(NID_SCL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
99
100         r = __pEvent->Fire(*pEventArg.get());
101         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
102
103         pEventArg.release();
104
105         __pEvent.reset(null);
106
107         return null;
108
109 CATCH:
110
111         if (__pEvent != null)
112         {
113                 pEventArg.reset(new (std::nothrow) _CalendarbookRecordRetrivalEventArg(__requestId, null, r));
114                 if (pEventArg != null)
115                 {
116                         r = __pEvent->Fire(*pEventArg);
117                 }
118                 __pEvent.reset(null);
119         }
120
121         r = _CalendarbookDbConnector::Disconnect();
122
123         return null;
124 }
125
126 }} // Tizen::Social