diff --git a/UpdatePTUDevCtrl/work_process_list.cpp b/UpdatePTUDevCtrl/work_process_list.cpp new file mode 100644 index 0000000..5955afc --- /dev/null +++ b/UpdatePTUDevCtrl/work_process_list.cpp @@ -0,0 +1,32 @@ +#include "work_process_list.h" +#include "process/update_command.h" + +#include +#include + +unsigned WorkList::nextExecIndex() const { + if (m_workList.size() > 0 && m_workListIndex < (m_workList.size() - 1)) { + return m_workListIndex + 1; + } + return std::numeric_limits::max(); +} + +bool WorkList::nextExec() const { + return m_workListIndex < m_workList.size(); +} + +bool WorkList::exec(bool last) { + if (last == false) { + if (nextExec()) { + m_workList[m_workListIndex]->start("/opt/app/tools/atbupdate"); + m_workListIndex += 1; + return true; + } + } else { + m_workList.back()->start("/opt/app/tools/atbupdate"); + m_workListIndex = std::numeric_limits::max(); + return true; + } + + return false; +} diff --git a/UpdatePTUDevCtrl/work_process_list.h b/UpdatePTUDevCtrl/work_process_list.h new file mode 100644 index 0000000..974e2c1 --- /dev/null +++ b/UpdatePTUDevCtrl/work_process_list.h @@ -0,0 +1,36 @@ +#ifndef WORK_LIST_H_INCLUDED +#define WORK_LIST_H_INCLUDED + +#include +#include + +class UpdateCommand; +class WorkList { +public: + std::vector> m_workList; + unsigned m_workListIndex{0}; + + WorkList() = default; + + template + void push_back(T&& arg) { + m_workList.push_back(std::forward(arg)); + } + + bool empty() const { return m_workList.empty(); } + + // move constructor: pass in classes derived from UpdateCommand + // template + //typename = typename std::enable_if::type, + // UpdateCommand>::value>::type> + // WorkList(Ts&&... args) + // : m_workList(std::forward(args...)) + // , m_workListIndex(0) { + //} + + unsigned nextExecIndex() const; + bool nextExec() const; + bool exec(bool last=false); +}; + +#endif // WORK_LIST_H_INCLUDED