From a73e52f0d2ad91e7c12dc0ba61f686b4d7c9bd8f Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Tue, 27 Aug 2013 13:22:50 +0200 Subject: [PATCH] MutableTaskList type for wrt-installer JobWidgetInstall [Issue#] LINUXWRT-820 [Feature] Muable task list class [Cause] There is need to modify list of tasks during running [Solution] New task list type [Verification] Build repo. Test together with commit from wrt-installer. Change-Id: I543144b5c1a6921e9928a9bcd59171965693459c --- modules/core/config.cmake | 2 + modules/core/include/dpl/mutable_task_list.h | 53 ++++++++++++++ modules/core/src/mutable_task_list.cpp | 104 +++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 modules/core/include/dpl/mutable_task_list.h create mode 100644 modules/core/src/mutable_task_list.cpp diff --git a/modules/core/config.cmake b/modules/core/config.cmake index 35bbbf3..33f25ea 100644 --- a/modules/core/config.cmake +++ b/modules/core/config.cmake @@ -38,6 +38,7 @@ SET(DPL_CORE_SOURCES ${PROJECT_SOURCE_DIR}/modules/core/src/file_input.cpp ${PROJECT_SOURCE_DIR}/modules/core/src/file_output.cpp ${PROJECT_SOURCE_DIR}/modules/core/src/lexical_cast.cpp + ${PROJECT_SOURCE_DIR}/modules/core/src/mutable_task_list.cpp ${PROJECT_SOURCE_DIR}/modules/core/src/mutex.cpp ${PROJECT_SOURCE_DIR}/modules/core/src/named_base_pipe.cpp ${PROJECT_SOURCE_DIR}/modules/core/src/named_output_pipe.cpp @@ -98,6 +99,7 @@ SET(DPL_CORE_HEADERS ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/foreach.h ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/generic_event.h ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/lexical_cast.h + ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/mutable_task_list.h ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/mutex.h ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/named_base_pipe.h ${PROJECT_SOURCE_DIR}/modules/core/include/dpl/named_input_pipe.h diff --git a/modules/core/include/dpl/mutable_task_list.h b/modules/core/include/dpl/mutable_task_list.h new file mode 100644 index 0000000..9facbd3 --- /dev/null +++ b/modules/core/include/dpl/mutable_task_list.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file mutable_task_list.h + * @author Tomasz Iwanek (t.iwanek@samsung.com) + * @version 1.0 + * @brief Header file for task list + */ +#ifndef DPL_MUTABLE_TASK_LIST_H +#define DPL_MUTABLE_TASK_LIST_H + +#include +#include + +namespace DPL { +class MutableTaskList : + public Task +{ + private: + typedef std::list Tasks; + + Tasks m_tasks; + Tasks::iterator m_currentTask; + + bool m_running; + + protected: + void AddTask(Task *task); + + public: + MutableTaskList(); + virtual ~MutableTaskList(); + + bool NextStep(); + bool Abort(); + size_t GetStepCount() const; +}; +} // namespace DPL + +#endif // DPL_MUTABLE_TASK_LIST_H diff --git a/modules/core/src/mutable_task_list.cpp b/modules/core/src/mutable_task_list.cpp new file mode 100644 index 0000000..67576b8 --- /dev/null +++ b/modules/core/src/mutable_task_list.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file task_list.cpp + * @author Tomasz Iwanek (t.iwanek@samsung.com) + * @version 1.0 + * @brief Implementation file for task list + */ +#include +#include +#include + +namespace DPL { +MutableTaskList::MutableTaskList() : + m_running(false) +{ + m_currentTask = m_tasks.end(); +} + +MutableTaskList::~MutableTaskList() +{ + for (Tasks::iterator i = m_tasks.begin(); i != m_tasks.end(); ++i) { + delete *i; + } +} + +void MutableTaskList::AddTask(Task *task) +{ + if(m_tasks.empty()) + { + m_tasks.push_back(task); + m_currentTask = m_tasks.begin(); + } + else + { + m_tasks.push_back(task); + } +} + +bool MutableTaskList::NextStep() +{ + m_running = true; + + Assert( + m_currentTask != m_tasks.end() && + "Task list is empty or all tasks done"); + + bool result = (*m_currentTask)->NextStep(); + + if (result) { + return true; + } + + return ++m_currentTask != m_tasks.end(); +} + +bool MutableTaskList::Abort() +{ + m_tasks.erase(m_currentTask, m_tasks.end()); + m_tasks.reverse(); + for (Tasks::iterator i = m_tasks.begin(); i != m_tasks.end();) { + //If given task does not have any "abortSteps", remove it from the list + if (!(*i)->Abort()) { + delete *i; + i = m_tasks.erase(i); + continue; + } + ++i; + } + + if (m_tasks.empty()) { + return false; + } + + m_currentTask = m_tasks.begin(); + + return true; +} + +size_t MutableTaskList::GetStepCount() const +{ + size_t count = 0; + + for (Tasks::const_iterator i = m_tasks.begin(); i != m_tasks.end(); ++i) { + count += (*i)->GetStepCount(); + } + + return count; +} + +} // namespace DPL -- 2.7.4