2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FScl_CalendarbookRecordRetrivalThread.cpp
18 * @brief This is the implementation file for the _CalendarbookRecordRetrivalThread class.
22 #include <FBaseColIList.h>
23 #include <FBaseSysLog.h>
24 #include <FBaseColAllElementsDeleter.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"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::Locales;
36 namespace Tizen { namespace Social
39 _CalendarbookRecordRetrivalThread::_CalendarbookRecordRetrivalThread(void)
44 , __category(EVENT_CATEGORY_ALL)
49 _CalendarbookRecordRetrivalThread::~_CalendarbookRecordRetrivalThread(void)
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)
58 __requestId = requestId;
61 __timeZone = timeZone;
63 __countPerPage = countPerPage;
64 __category = category;
66 __pEvent.reset(&event);
68 result r = Thread::Construct();
69 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
75 _CalendarbookRecordRetrivalThread::Run(void)
78 _CalendarbookImpl calendarbookImpl;
79 std::unique_ptr<IList, AllElementsDeleter> pList;
80 std::unique_ptr<_CalendarbookRecordRetrivalEventArg> pEventArg;
82 r = calendarbookImpl.Construct();
83 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
85 r = _CalendarbookDbConnector::Connect();
86 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
88 pList.reset(calendarbookImpl.GetEventInstancesCommonN(__start, __end, __timeZone, __pageNo, __countPerPage, __category));
90 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
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, "[E_OUT_OF_MEMORY] Memory allocation failed.");
96 r = _CalendarbookDbConnector::Disconnect();
97 SysTryCatch(NID_SCL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
99 r = __pEvent->Fire(*pEventArg.get());
100 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
104 __pEvent.reset(null);
110 if (__pEvent != null)
112 pEventArg.reset(new (std::nothrow) _CalendarbookRecordRetrivalEventArg(__requestId, null, r));
113 if (pEventArg != null)
115 r = __pEvent->Fire(*pEventArg);
117 __pEvent.reset(null);
120 r = _CalendarbookDbConnector::Disconnect();