list of commands to execute
This commit is contained in:
parent
3358e1a0d4
commit
aa88a040ba
32
UpdatePTUDevCtrl/work_process_list.cpp
Normal file
32
UpdatePTUDevCtrl/work_process_list.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "work_process_list.h"
|
||||||
|
#include "process/update_command.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
unsigned WorkList::nextExecIndex() const {
|
||||||
|
if (m_workList.size() > 0 && m_workListIndex < (m_workList.size() - 1)) {
|
||||||
|
return m_workListIndex + 1;
|
||||||
|
}
|
||||||
|
return std::numeric_limits<unsigned>::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<unsigned>::max();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
36
UpdatePTUDevCtrl/work_process_list.h
Normal file
36
UpdatePTUDevCtrl/work_process_list.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef WORK_LIST_H_INCLUDED
|
||||||
|
#define WORK_LIST_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class UpdateCommand;
|
||||||
|
class WorkList {
|
||||||
|
public:
|
||||||
|
std::vector<std::unique_ptr<UpdateCommand>> m_workList;
|
||||||
|
unsigned m_workListIndex{0};
|
||||||
|
|
||||||
|
WorkList() = default;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void push_back(T&& arg) {
|
||||||
|
m_workList.push_back(std::forward<T>(arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const { return m_workList.empty(); }
|
||||||
|
|
||||||
|
// move constructor: pass in classes derived from UpdateCommand
|
||||||
|
// template<typename... Ts>
|
||||||
|
//typename = typename std::enable_if<std::is_same<typename std::decay<Ts...>::type,
|
||||||
|
// UpdateCommand>::value>::type>
|
||||||
|
// WorkList(Ts&&... args)
|
||||||
|
// : m_workList(std::forward<Ts...>(args...))
|
||||||
|
// , m_workListIndex(0) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
unsigned nextExecIndex() const;
|
||||||
|
bool nextExec() const;
|
||||||
|
bool exec(bool last=false);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WORK_LIST_H_INCLUDED
|
Loading…
x
Reference in New Issue
Block a user