Skip to content

Commit

Permalink
Merge pull request #641 from nseam/dev-task
Browse files Browse the repository at this point in the history
Added TaskManager::Add(string _entry) method
  • Loading branch information
kenorb authored Jan 27, 2022
2 parents 2d6c6cf + 6941c25 commit 263f521
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions SerializerConverter.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class SerializerConverter {
template <typename C>
static SerializerConverter FromString(string arg) {
SerializerConverter _converter(((C*)NULL).Parse(arg), 0);
#ifdef __debug__
Print("FromString(): result: ",
_converter.Node() != NULL ? _converter.Node().ToString(SERIALIZER_JSON_NO_WHITESPACES) : "NULL");
#endif
return _converter;
}

Expand Down
9 changes: 9 additions & 0 deletions Task/Task.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ struct TaskEntry {
int GetConditionId() { return cond.GetId(); }
TaskActionEntry GetAction() { return action; }
TaskConditionEntry GetCondition() { return cond; }

public:
SerializerNodeType Serialize(Serializer &s) {
s.PassStruct(THIS_REF, "aentry", action);
s.PassStruct(THIS_REF, "centry", cond);
return SerializerNodeObject;
}

SERIALIZER_EMPTY_STUB;
};
15 changes: 15 additions & 0 deletions Task/TaskCondition.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,19 @@ struct TaskConditionEntry {
}
::ArrayResize(args, _index - 1);
}

public:
// Serializers
SerializerNodeType Serialize(Serializer &s) {
s.Pass(THIS_REF, "flags", flags);
s.Pass(THIS_REF, "id", id);
s.Pass(THIS_REF, "last_check", last_check);
s.Pass(THIS_REF, "last_success", last_success);
s.Pass(THIS_REF, "tries", tries);
s.PassEnum(THIS_REF, "freq", freq);
s.PassArray(this, "args", args);
return SerializerNodeObject;
}

SERIALIZER_EMPTY_STUB;
};
13 changes: 13 additions & 0 deletions Task/TaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

// Includes.
#include "../DictObject.mqh"
#include "../SerializerConverter.mqh"
#include "../SerializerJson.mqh"
#include "Task.struct.h"
#include "TaskObject.h"

class TaskManager {
Expand Down Expand Up @@ -74,6 +77,16 @@ class TaskManager {
return tasks.Push(_ref);
}

/**
* Adds new task.
*/
bool Add(string _entry_str) {
TaskEntry _entry;
SerializerConverter::FromString<SerializerJson>(_entry_str).ToObject(_entry);
Ref<Task> _task = new Task(_entry);
return Add(_task.Ptr());
}

/**
* Adds new object task.
*/
Expand Down
4 changes: 4 additions & 0 deletions Task/tests/TaskManager.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ bool TestTaskManager01() {
_tsm.Add(_taskobj02.Ptr());
_tsm.Add(_taskobj03.Ptr());
_tsm.Add(_taskobj04.Ptr());

// @todo: Need a way to test if object was added properly.
_tsm.Add("{\"aentry\": {\"id\": 1}, \"centry\": {\"id\": 2}}");

_tsm.Process();
// @todo: Print via ToString().
return _result;
Expand Down

0 comments on commit 263f521

Please sign in to comment.