MutableTaskList type for wrt-installer JobWidgetInstall
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 27 Aug 2013 11:22:50 +0000 (13:22 +0200)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Wed, 28 Aug 2013 07:39:45 +0000 (16:39 +0900)
[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
modules/core/include/dpl/mutable_task_list.h [new file with mode: 0644]
modules/core/src/mutable_task_list.cpp [new file with mode: 0644]

index 35bbbf3..33f25ea 100644 (file)
@@ -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 (file)
index 0000000..9facbd3
--- /dev/null
@@ -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 <dpl/task.h>
+#include <list>
+
+namespace DPL {
+class MutableTaskList :
+    public Task
+{
+    private:
+        typedef std::list<Task *> 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 (file)
index 0000000..67576b8
--- /dev/null
@@ -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 <stddef.h>
+#include <dpl/mutable_task_list.h>
+#include <dpl/assert.h>
+
+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