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