2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 TaskManager.cpp
18 * @author Lukasz Marek (l.marek@samsung.com)
19 * @author Wojciech Bielawski (w.bielawski@samsung.com)
23 #include "TaskManager.h"
26 #include <dpl/log/log.h>
27 #include <calendar-svc-provider.h>
28 #include <calendar-svc-errors.h>
31 const int ID_ALL_ACCOUNTS = 0;
32 const int TASK_ID = 1;
33 const char* SERVICE_PROVIDER_NAME = "phone";
34 const char* TASK_NAME = "test";
37 namespace WrtDeviceApis {
42 int TaskManager::m_instanceCount = 0;
44 TaskManager::TaskManager()
47 /* wac platform doesn't support calendar manager.
48 * This implementation have to implement it on its own.
49 * One calendar have to be created and stored for further use.
51 DPL::Mutex::ScopedLock mx(&m_constructorMutex);
52 if (m_instanceCount == 0) {
53 LogDebug("opening calendar DB");
54 if (CAL_SUCCESS != calendar_svc_connect()) {
55 ThrowMsg(Commons::PlatformException,
56 "Calendar DB initialization failed");
62 TaskManager::~TaskManager()
65 DPL::Mutex::ScopedLock mx(&m_constructorMutex);
67 if (m_instanceCount == 0) {
68 LogDebug("closing calendar DB");
69 if (CAL_SUCCESS != calendar_svc_close()) {
70 LogError("Calendar database not clearly closed.");
75 int TaskManager::getAccountId()
77 return ID_ALL_ACCOUNTS;
80 const char *TaskManager::getServiceProviderName()
82 return SERVICE_PROVIDER_NAME;
85 std::list<ITaskPtr> TaskManager::getTasksInternal()
88 std::list<ITaskPtr> result;
89 ITaskPtr defaultTask(new Task());
90 defaultTask->setName(TASK_NAME);
91 defaultTask->setId(TASK_ID);
92 defaultTask->setAccountId(ID_ALL_ACCOUNTS);
93 defaultTask->setType(Task::DEVICE_TASK);
94 result.push_back(defaultTask);
98 void TaskManager::OnRequestReceived(const IEventGetTasksPtr &task)
102 const std::list<ITaskPtr> &result = getTasksInternal();
103 task->tryCancelled();
104 task->setResult(true);
105 std::list<ITaskPtr>::const_iterator it = result.begin(), end =
107 for (; it != end; ++it) {
111 Catch(Commons::EventCancelledException)
113 //revert changes if any
115 task->setCancelAllowed(true);