2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FScl_CalendarbookRecordRetrivalThread.cpp
19 * @brief This is the implementation file for the _CalendarbookRecordRetrivalThread class.
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"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Locales;
37 namespace Tizen { namespace Social
40 _CalendarbookRecordRetrivalThread::_CalendarbookRecordRetrivalThread(void)
45 , __category(EVENT_CATEGORY_ALL)
50 _CalendarbookRecordRetrivalThread::~_CalendarbookRecordRetrivalThread(void)
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)
59 __requestId = requestId;
62 __timeZone = timeZone;
64 __countPerPage = countPerPage;
65 __category = category;
67 __pEvent.reset(&event);
69 result r = Thread::Construct();
70 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
76 _CalendarbookRecordRetrivalThread::Run(void)
79 _CalendarbookImpl calendarbookImpl;
80 std::unique_ptr<IList, AllElementsDeleter> pList;
81 std::unique_ptr<_CalendarbookRecordRetrivalEventArg> pEventArg;
83 r = calendarbookImpl.Construct();
84 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
86 r = _CalendarbookDbConnector::Connect();
87 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
89 pList.reset(calendarbookImpl.GetEventInstancesCommonN(__start, __end, __timeZone, __pageNo, __countPerPage, __category));
91 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
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.");
97 r = _CalendarbookDbConnector::Disconnect();
98 SysTryCatch(NID_SCL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
100 r = __pEvent->Fire(*pEventArg.get());
101 SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
105 __pEvent.reset(null);
111 if (__pEvent != null)
113 pEventArg.reset(new (std::nothrow) _CalendarbookRecordRetrivalEventArg(__requestId, null, r));
114 if (pEventArg != null)
116 r = __pEvent->Fire(*pEventArg);
118 __pEvent.reset(null);
121 r = _CalendarbookDbConnector::Disconnect();