You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.8 KiB
131 lines
3.8 KiB
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QVariant>
|
|
#include <QVector>
|
|
#include <QTimer>
|
|
#include "IXLua.h"
|
|
|
|
/// @Brief 任务触发器
|
|
class XTaskConditionTrigger : public QObject {
|
|
Q_OBJECT;
|
|
public:
|
|
void doTrigger(const QString& funName) {
|
|
emit notifyTrigger(funName);
|
|
}
|
|
|
|
signals:
|
|
void notifyTrigger(const QString& funName);
|
|
};
|
|
|
|
/// @Brief 任务条件
|
|
class XTaskCondition : public IXLuaValueObject, public IXLuaParamCallback {
|
|
public:
|
|
enum
|
|
{
|
|
TRIGGER_CONDITION_TYPE_NONE, // 未知
|
|
TRIGGER_CONDITION_TYPE_TIMER, // 定时器
|
|
TRIGGER_CONDITION_TYPE_OPER, // 操作事件
|
|
};
|
|
|
|
private:
|
|
typedef struct MixedItem {
|
|
int groupIndex; // 组号
|
|
QString name;
|
|
int index;
|
|
QVariant value1;
|
|
QVariant value2;
|
|
|
|
bool isProcess;
|
|
bool isOk;
|
|
|
|
MixedItem() :groupIndex(-1), index(0), isProcess(false), isOk(false) {}
|
|
}MixedItem;
|
|
|
|
typedef struct XConditionInfo {
|
|
int groupIndex; // 组号
|
|
unsigned int type; // 条件类型
|
|
int value; // 值(定时器值或其它值)
|
|
QString funName; // 函数名
|
|
QVector<MixedItem> items; // 事件数据列表
|
|
|
|
bool isProcess; // 是否处理
|
|
|
|
QTimer* timer; // 定时器
|
|
|
|
XConditionInfo():groupIndex(0),type(0),value(0), isProcess(false),timer(nullptr) {
|
|
|
|
}
|
|
~XConditionInfo() {
|
|
if (nullptr != timer) {
|
|
delete timer; // 手动释放
|
|
timer = nullptr;
|
|
}
|
|
}
|
|
QTimer* getTimer() {
|
|
if (nullptr == timer) {
|
|
timer = new QTimer;
|
|
}
|
|
return timer;
|
|
}
|
|
|
|
}XConditionInfo;
|
|
|
|
public:
|
|
XTaskCondition();
|
|
virtual ~XTaskCondition();
|
|
|
|
virtual unsigned int pushParam(IVariantProcessor* proc)/* = 0;*/ { return 0; }
|
|
|
|
virtual void getReturnValues(unsigned int count, IVariantProcessor* proc)/* = 0*/;
|
|
|
|
void buildConditions();
|
|
void begin(XTaskConditionTrigger* trigger);
|
|
void reset();
|
|
|
|
// 任务事件检测
|
|
void onTaskEventCheck(const QString& name, const QString& value, const char* value2 = nullptr);
|
|
|
|
private:
|
|
virtual void setCount(unsigned int count)/* = 0*/;
|
|
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, bool value)/* = 0*/;
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, short value)/* = 0*/;
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, int value)/* = 0*/;
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, long long value) /*= 0*/;
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, float value)/* = 0*/;
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, double value) /*= 0*/;
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, char value) /*= 0*/ { }
|
|
virtual void setValue(unsigned int objIndex, unsigned int varIndex, const char* value) /*= 0*/;
|
|
|
|
void setMixedItemValue(unsigned int objIndex, unsigned int varIndex, const QVariant& value);
|
|
|
|
MixedItem& getMixedItem(unsigned int objIndex);
|
|
XConditionInfo* getConditionInfo(int groupIndex);
|
|
|
|
bool checkPrevMixedItemIsOk(const MixedItem& item) const;
|
|
void checkMixedItemIsOk(MixedItem& item, const QString& value, const char* value2 = nullptr);
|
|
|
|
// 检测多个条件
|
|
XConditionInfo* checkMutiConditionInfos(QVector<XConditionInfo*>& conds, const QString& name, const QString& value, const char* value2 = nullptr);
|
|
bool checkConditionInfo(XConditionInfo* pInfo, const QString& name, const QString& value, const char* value2 = nullptr);
|
|
|
|
private:
|
|
enum
|
|
{
|
|
ATTR_INDEX_GROUP,
|
|
ATTR_INDEX_NAME,
|
|
ATTR_INDEX_INDEX,
|
|
ATTR_INDEX_VALUE1,
|
|
ATTR_INDEX_VALUE2
|
|
};
|
|
|
|
QVector<XConditionInfo> condInfos; // 条件信息列表
|
|
QVector<MixedItem> tmpItems; // 临时列表
|
|
|
|
XTaskConditionTrigger* condTrigger; // 条件触发器
|
|
|
|
const QString COND_TYPE_NAME_EVENT_CHECK = QStringLiteral("__事件检测__");
|
|
const QString COND_TYPE_NAME_TIMER = QStringLiteral("__定时器__");
|
|
}; |