Skip to content

Commit

Permalink
Renames Action to TaskAction
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Apr 25, 2024
1 parent 4154ad7 commit 629ed8f
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 99 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
matrix:
test:
- AccountTest
- ActionTest
- BufferStructTest
- BufferTest
- ChartTest
Expand Down
2 changes: 1 addition & 1 deletion EA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define EA_MQH

// Includes.
#include "Action.enum.h"
#include "Chart.mqh"
#include "Data.struct.h"
#include "Dict.mqh"
Expand All @@ -46,6 +45,7 @@
#include "Strategy.mqh"
#include "SummaryReport.mqh"
#include "Task/Task.h"
#include "Task/TaskAction.enum.h"
#include "Task/TaskCondition.enum.h"
#include "Terminal.mqh"
#include "Trade.mqh"
Expand Down
2 changes: 1 addition & 1 deletion EA.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ struct EAState {
public: // @todo: Move to protected.
DateTime last_updated; // Last updated.
protected:
unsigned int flags; // Action flags.
unsigned int flags; // TaskAction flags.
unsigned int new_periods; // Started periods.
public:
/* Struct's enumerations */
Expand Down
6 changes: 3 additions & 3 deletions Indicators/Indi_Drawer.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
struct IndicatorParams;

// Includes.
#include "../Action.mqh"
#include "../DictStruct.mqh"
#include "../Indicator/IndicatorTickOrCandleSource.h"
#include "../Redis.mqh"
#include "../Task/TaskAction.h"
#include "Indi_Drawer.struct.h"
#include "Price/Indi_Price.mqh"

Expand Down Expand Up @@ -106,7 +106,7 @@ class Indi_Drawer : public IndicatorTickOrCandleSource<IndiDrawerParams> {
virtual void OnTick() {
Indicator<IndiDrawerParams>::OnTick();

ActionEntry action(INDI_ACTION_SET_VALUE);
TaskActionEntry action(INDI_ACTION_SET_VALUE);
ArrayResize(action.args, 3);
action.args[0].type = TYPE_LONG;
action.args[0].integer_value = GetBarTime();
Expand All @@ -133,7 +133,7 @@ class Indi_Drawer : public IndicatorTickOrCandleSource<IndiDrawerParams> {
Print("Got: ", message.Message);
#endif
if (message.Command == "message" && message.Channel == "INDICATOR_DRAW") {
ActionEntry action_entry;
TaskActionEntry action_entry;
SerializerConverter::FromString<SerializerJson>(message.Message).ToObject(action_entry);
ExecuteAction((ENUM_INDICATOR_ACTION)action_entry.action_id, action_entry.args);
#ifdef __debug__
Expand Down
2 changes: 1 addition & 1 deletion Order.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define ORDER_MQH

// Includes.
#include "Action.enum.h"
#include "Convert.mqh"
#include "Data.define.h"
#include "Data.struct.h"
Expand All @@ -44,6 +43,7 @@
#include "Std.h"
#include "String.mqh"
#include "SymbolInfo.mqh"
#include "Task/TaskAction.enum.h"
#include "Terminal.define.h"

/* Defines for backward compatibility. */
Expand Down
4 changes: 2 additions & 2 deletions Task/Task.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#pragma once
#endif

/* Structure for task actions for Action class. */
/* Structure for task actions for TaskAction class. */
enum ENUM_TASK_ACTION {
TASK_ACTION_NONE = 0, // Does nothing.
TASK_ACTION_PROCESS, // Process tasks.
FINAL_TASK_ACTION_ENTRY
};

/* Structure for task conditions for Action class. */
/* Structure for task conditions for TaskAction class. */
enum ENUM_TASK_CONDITION {
TASK_COND_NONE = 0, // Empty condition.
TASK_COND_IS_ACTIVE, // Is active.
Expand Down
8 changes: 4 additions & 4 deletions Task/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#define TASK_MQH

// Includes.
#include "../Action.mqh"
#include "../DictStruct.mqh"
#include "../Refs.mqh"
#include "../Task/TaskCondition.h"
#include "Task.enum.h"
#include "Task.struct.h"
#include "TaskAction.h"
#include "TaskCondition.h"

class Task {
protected:
Expand Down Expand Up @@ -99,8 +99,8 @@ class Task {
bool _result = false;
if (_entry.IsActive()) {
if (TaskCondition::Test(_entry.GetCondition())) {
ActionEntry _action = _entry.GetAction();
Action::Execute(_action);
TaskActionEntry _action = _entry.GetAction();
TaskAction::Execute(_action);
if (_action.IsDone()) {
_entry.SetFlag(TASK_ENTRY_FLAG_IS_DONE, _action.IsDone());
_entry.SetFlag(TASK_ENTRY_FLAG_IS_FAILED, _action.IsFailed());
Expand Down
10 changes: 5 additions & 5 deletions Task/Task.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
#endif

// Includes.
#include "../Action.struct.h"
#include "Task.enum.h"
#include "TaskAction.struct.h"
#include "TaskCondition.struct.h"

struct TaskEntry {
ActionEntry action; // Action of the task.
TaskActionEntry action; // TaskAction of the task.
TaskConditionEntry cond; // TaskCondition of the task.
datetime expires; // Time of expiration.
datetime last_process; // Time of the last process.
datetime last_success; // Time of the last success.
unsigned char flags; // Action flags.
unsigned char flags; // TaskAction flags.
// Constructors.
void TaskEntry() { Init(); }
void TaskEntry(ActionEntry &_action, TaskConditionEntry &_cond) : action(_action), cond(_cond) { Init(); }
void TaskEntry(TaskActionEntry &_action, TaskConditionEntry &_cond) : action(_action), cond(_cond) { Init(); }
void TaskEntry(long _aid, ENUM_ACTION_TYPE _atype, long _cid, ENUM_TASK_CONDITION_TYPE _ctype)
: action(_aid, _atype), cond(_cid, _ctype) {
Init();
Expand Down Expand Up @@ -79,7 +79,7 @@ struct TaskEntry {
// Getters.
long GetActionId() { return action.GetId(); }
long GetConditionId() { return cond.GetId(); }
ActionEntry GetAction() { return action; }
TaskActionEntry GetAction() { return action; }
TaskConditionEntry GetCondition() { return cond; }
ENUM_ACTION_TYPE GetActionType() { return action.GetType(); }
ENUM_TASK_CONDITION_TYPE GetConditionType() { return cond.GetType(); }
Expand Down
6 changes: 3 additions & 3 deletions Action.enum.h → Task/TaskAction.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/**
* @file
* Includes Action's enums.
* Includes TaskAction's enums.
*/

#ifndef __MQL__
Expand All @@ -45,7 +45,7 @@ enum ENUM_ACTION_ENTRY_FLAGS {
/* Defines action types. */
enum ENUM_ACTION_TYPE {
ACTION_TYPE_NONE = 0, // None.
ACTION_TYPE_ACTION, // Action of action.
ACTION_TYPE_ACTION, // TaskAction of action.
ACTION_TYPE_EA, // EA action.
ACTION_TYPE_INDICATOR, // Order action.
ACTION_TYPE_ORDER, // Order action.
Expand All @@ -56,7 +56,7 @@ enum ENUM_ACTION_TYPE {
FINAL_ACTION_TYPE_ENTRY
};

/* Defines action types for Action class. */
/* Defines action types for TaskAction class. */
enum ENUM_ACTION_ACTION {
ACTION_ACTION_NONE = 0, // Does nothing.
ACTION_ACTION_DISABLE, // Disables action.
Expand Down
64 changes: 32 additions & 32 deletions Action.mqh → Task/TaskAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,49 @@
#define ACTION_MQH

// Forward class declaration.
class Action;
class TaskAction;

// Includes.
#include "Action.enum.h"
#include "Action.struct.h"
#include "EA.mqh"
#include "Task/TaskCondition.enum.h"
#include "../EA.mqh"
#include "TaskAction.enum.h"
#include "TaskAction.struct.h"
#include "TaskCondition.enum.h"

/**
* Action class.
* TaskAction class.
*/
class Action {
class TaskAction {
public:
protected:
// Class variables.
Ref<Log> logger;

public:
// Class variables.
DictStruct<short, ActionEntry> actions;
DictStruct<short, TaskActionEntry> actions;

/* Special methods */

/**
* Class constructor.
*/
Action() {}
Action(ActionEntry &_entry) { actions.Push(_entry); }
Action(long _action_id, ENUM_ACTION_TYPE _type) {
ActionEntry _entry(_action_id, _type);
TaskAction() {}
TaskAction(TaskActionEntry &_entry) { actions.Push(_entry); }
TaskAction(long _action_id, ENUM_ACTION_TYPE _type) {
TaskActionEntry _entry(_action_id, _type);
actions.Push(_entry);
}
template <typename T>
Action(T _action_id, void *_obj = NULL) {
ActionEntry _entry(_action_id);
TaskAction(T _action_id, void *_obj = NULL) {
TaskActionEntry _entry(_action_id);
if (_obj != NULL) {
_entry.SetObject(_obj);
}
actions.Push(_entry);
}
template <typename T>
Action(T _action_id, MqlParam &_args[], void *_obj = NULL) {
ActionEntry _entry(_action_id);
TaskAction(T _action_id, MqlParam &_args[], void *_obj = NULL) {
TaskActionEntry _entry(_action_id);
_entry.SetArgs(_args);
if (_obj != NULL) {
_entry.SetObject(_obj);
Expand All @@ -83,7 +83,7 @@ class Action {
/**
* Class copy constructor.
*/
Action(Action &_cond) { actions = _cond.GetActions(); }
TaskAction(TaskAction &_cond) { actions = _cond.GetActions(); }

/* Main methods */

Expand All @@ -92,9 +92,9 @@ class Action {
*/
bool Execute() {
bool _result = true, _executed = false;
for (DictStructIterator<short, ActionEntry> iter = actions.Begin(); iter.IsValid(); ++iter) {
for (DictStructIterator<short, TaskActionEntry> iter = actions.Begin(); iter.IsValid(); ++iter) {
bool _curr_result = false;
ActionEntry _entry = iter.Value();
TaskActionEntry _entry = iter.Value();
if (!_entry.IsValid()) {
// Ignore invalid entries.
continue;
Expand All @@ -109,12 +109,12 @@ class Action {
/**
* Execute specific action.
*/
static bool Execute(ActionEntry &_entry) {
static bool Execute(TaskActionEntry &_entry) {
bool _result = false;
switch (_entry.type) {
case ACTION_TYPE_ACTION:
if (Object::IsValid(_entry.obj)) {
_result = ((Action *)_entry.obj).ExecuteAction((ENUM_ACTION_ACTION)_entry.action_id, _entry.args);
_result = ((TaskAction *)_entry.obj).ExecuteAction((ENUM_ACTION_ACTION)_entry.action_id, _entry.args);
} else {
_result = false;
_entry.AddFlags(ACTION_ENTRY_FLAG_IS_INVALID);
Expand Down Expand Up @@ -249,15 +249,15 @@ class Action {
/**
* Returns actions.
*/
DictStruct<short, ActionEntry> *GetActions() { return &actions; }
DictStruct<short, TaskActionEntry> *GetActions() { return &actions; }

/**
* Count entry flags.
*/
unsigned int GetFlagCount(ENUM_ACTION_ENTRY_FLAGS _flag) {
unsigned int _counter = 0;
for (DictStructIterator<short, ActionEntry> iter = actions.Begin(); iter.IsValid(); ++iter) {
ActionEntry _entry = iter.Value();
for (DictStructIterator<short, TaskActionEntry> iter = actions.Begin(); iter.IsValid(); ++iter) {
TaskActionEntry _entry = iter.Value();
if (_entry.HasFlag(_flag)) {
_counter++;
}
Expand All @@ -272,8 +272,8 @@ class Action {
*/
bool SetFlags(ENUM_ACTION_ENTRY_FLAGS _flag, bool _value = true) {
unsigned int _counter = 0;
for (DictStructIterator<short, ActionEntry> iter = actions.Begin(); iter.IsValid(); ++iter) {
ActionEntry _entry = iter.Value();
for (DictStructIterator<short, TaskActionEntry> iter = actions.Begin(); iter.IsValid(); ++iter) {
TaskActionEntry _entry = iter.Value();
switch (_value) {
case false:
if (_entry.HasFlag(_flag)) {
Expand All @@ -298,7 +298,7 @@ class Action {
* Checks for Task condition.
*
* @param ENUM_ACTION_CONDITION _cond
* Action condition.
* TaskAction condition.
* @return
* Returns true when the condition is met.
*/
Expand All @@ -321,21 +321,21 @@ class Action {
// Is invalid.
return IsInvalid();
default:
logger.Ptr().Error(StringFormat("Invalid Action condition: %s!", EnumToString(_cond), __FUNCTION_LINE__));
break;
logger.Ptr().Error(StringFormat("Invalid TaskAction condition: %s!", EnumToString(_cond), __FUNCTION_LINE__));
return false;
}
return _result;
}
bool CheckCondition(ENUM_ACTION_CONDITION _cond) {
ARRAY(DataParamEntry, _args);
return Action::CheckCondition(_cond, _args);
return TaskAction::CheckCondition(_cond, _args);
}

/**
* Execute action of action.
*
* @param ENUM_ACTION_ACTION _action
* Action of action to execute.
* TaskAction of action to execute.
* @return
* Returns true when the action has been executed successfully.
*/
Expand Down Expand Up @@ -368,7 +368,7 @@ class Action {
}
bool ExecuteAction(ENUM_ACTION_ACTION _action) {
ARRAY(DataParamEntry, _args);
return Action::ExecuteAction(_action, _args);
return TaskAction::ExecuteAction(_action, _args);
}

/* Other methods */
Expand Down
Loading

0 comments on commit 629ed8f

Please sign in to comment.