Skip to content

Commit

Permalink
feat: New Output/Input event approach
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrno committed Nov 19, 2024
1 parent 897fb1f commit 30dd550
Show file tree
Hide file tree
Showing 41 changed files with 308 additions and 253 deletions.
Empty file modified assets/images/vortex_banner.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/.gitignore
100644 → 100755
Empty file.
29 changes: 25 additions & 4 deletions main/include/modules/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class HappeningState
ERROR,
FATAL,
};

struct ModuleInputEventHappening
{
std::string m_trigger_name;
Expand All @@ -26,6 +27,15 @@ struct ModuleInputEventHappening
std::string m_timestamp;
};

struct ModuleOutputEventHappening
{
std::string m_trigger_name;
HappeningState m_state;
std::string m_log;
std::string m_timestamp;
};


// TODO : Replace all args by json values (input and output)

/**
Expand All @@ -34,10 +44,12 @@ struct ModuleInputEventHappening
class ModuleInputEvent
{
public:
ModuleInputEvent(void(*foo)(const std::shared_ptr<hArgs>& args), const std::string& name);

virtual void execute(){};
ModuleInputEvent(std::function<void(ArgumentValues&, ReturnValues&)> foo, const std::string& name);
ModuleInputEvent(std::function<void(ArgumentValues&)> foo, const std::string& name);
ModuleInputEvent(std::function<void(ReturnValues &)> foo, const std::string &name);
ModuleInputEvent(std::function<void()> foo, const std::string& name);

std::function<void(ArgumentValues&, ReturnValues&)> m_function;
void trigger_happening(const std::string& trigger_name, HappeningState state, const std::string& log);

void(*m_foo)(const std::shared_ptr<hArgs>& args);
Expand All @@ -55,11 +67,20 @@ class ModuleInputEvent
class ModuleOutputEvent
{
public:
ModuleOutputEvent(void(*foo)(const std::shared_ptr<hArgs>& args), const std::string& name);
ModuleOutputEvent(std::function<void(ArgumentValues&, ReturnValues&)> foo, const std::string& name);
ModuleOutputEvent(std::function<void(ArgumentValues&)> foo, const std::string& name);
ModuleOutputEvent(std::function<void(ReturnValues &)> foo, const std::string &name);
ModuleOutputEvent(std::function<void()> foo, const std::string& name);

std::function<void(ArgumentValues&, ReturnValues&)> m_function;

void trigger_happening(const std::string &trigger_name, HappeningState state, const std::string &log);

virtual void execute() {};

void(*m_foo)(const std::shared_ptr<hArgs>& args);
std::string m_name;
std::vector<std::shared_ptr<ModuleOutputEventHappening>> m_happenings;
};

#endif
39 changes: 33 additions & 6 deletions main/include/modules/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,46 @@ class ModuleInterface
void AddFunction(std::function<void(ReturnValues&)> foo, const std::string& name);
void AddFunction(std::function<void(ArgumentValues&, ReturnValues&)> foo, const std::string& name);

// IMPORTANT : These AddOutputEvent declaration are in reality "Handlers" of output events triggered by other compenents.
// Remember:
// - A output event is triggered via VortexMaker::ExecuteOutputEvent() by the current component to all concerned extern components with the output event added.
// - A input event is triggered via VortexMaker::ExecuteInputEvent() by a extern component to the current component with the input component added.
void AddOutputEvent(std::function<void()> foo, const std::string& name);
void AddOutputEvent(std::function<void(ArgumentValues&)> foo, const std::string& name);
void AddOutputEvent(std::function<void(ReturnValues&)> foo, const std::string& name);
void AddOutputEvent(std::function<void(ArgumentValues&, ReturnValues&)> foo, const std::string& name);
void AddInputEvent(std::function<void()> foo, const std::string& name);
void AddInputEvent(std::function<void(ArgumentValues&)> foo, const std::string& name);
void AddInputEvent(std::function<void(ReturnValues&)> foo, const std::string& name);
void AddInputEvent(std::function<void(ArgumentValues&, ReturnValues&)> foo, const std::string& name);

// TODO : AddParameterToFunction
// TODO : AddParameterToInputEvent
// TODO : AddParameterToOutputEvent
// TODO : AddReturnToFunction
// TODO : AddReturnToInputEvent
// TODO : AddReturnToOutputEvent

// TODO : AddSpawnableWindow
// TODO : AddContentBrowserItemHandler
// TODO : AddContentBrowserItemIdentifier
// TODO : AddCommonUtility
// TODO : AddMainWindow

//void AddFunction(void (*item)(), const std::string& name, Parameters params);
void AddInputEvent(void (*item)(const std::shared_ptr<hArgs>& args), const std::string& name);
void AddInputEvent(void (*item)(const std::shared_ptr<hArgs>& args), const std::string& name, DevFlag devflag, const std::string& description, const std::vector<std::tuple<std::string, std::string, std::string>>& args_def, const bool& can_callback);
void AddOutputEvent(void (*item)(const std::shared_ptr<hArgs>& args), const std::string& name);
std::shared_ptr<ModuleInterface> GetInterface();

void ExecFunction(const std::string& name);
void ExecFunction(const std::string& name, ArgumentValues& args);
void ExecFunction(const std::string& name, ReturnValues& ret);
void ExecFunction(const std::string& name, ArgumentValues& args, ReturnValues& ret);
// TODO Exec function with call back + Link to the VortexMaker API
void ExecuteFunction(const std::string& name);
void ExecuteFunction(const std::string& name, ArgumentValues& args);
void ExecuteFunction(const std::string& name, ReturnValues& ret);
void ExecuteFunction(const std::string& name, ArgumentValues& args, ReturnValues& ret);

void ExecuteOutputEvent(const std::string& name, ArgumentValues& args, ReturnValues& ret);
void ExecuteInputEvent(const std::string& name, ArgumentValues& args, ReturnValues& ret);

void ExecInputEvent(const std::string& name, std::shared_ptr<hArgs> args);

// Trigger all output events for every modules/plugins
void DeployOutputEvent(const std::string& name, std::shared_ptr<hArgs> args);
Expand Down
19 changes: 5 additions & 14 deletions main/include/vortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,12 @@ struct hMap;

struct hString;
struct hArgs;
struct VxHost;
struct VxGPOSystem;
struct EnvProject;

struct CommandOutput;
struct VxToolchain;
struct VxScript;
struct VxDistHost;
// struct VxPackage;
struct VxDistToolchain;
struct TaskProcessor;
struct ArgumentValues;
struct ReturnValues;

struct Task;
struct CommandOutput;

// Internals (from vortex_internals.h)
struct VxContext;
Expand Down Expand Up @@ -189,10 +182,8 @@ namespace VortexMaker
VORTEX_API void DeployEvent(const std::shared_ptr<hArgs> &args, const std::string &event_name);
VORTEX_API void DeployEvent(const std::shared_ptr<hArgs> &args, const std::string &event_name, void (*callback)(std::shared_ptr<hArgs> _args));

VORTEX_API void CallModuleEvent(const std::shared_ptr<hArgs> &args, const std::string &event_name, const std::string &module_name, const std::string &origin);
VORTEX_API void CallModuleEvent(const std::shared_ptr<hArgs> &args, const std::string &event_name, const std::string &module_name, void (*callback)(std::shared_ptr<hArgs> _args), const std::string &origin);
VORTEX_API void CallModuleEvent(const std::shared_ptr<hArgs> &args, const std::string &event_name, const std::string &module_name);
VORTEX_API void CallModuleEvent(const std::shared_ptr<hArgs> &args, const std::string &event_name, const std::string &module_name, void (*callback)(std::shared_ptr<hArgs> _args));
VORTEX_API void CallOutputEvent(const std::string &event_name, ArgumentValues& args, ReturnValues& ret, const std::string& origin = "unknow");
VORTEX_API void CallInputEvent(const std::string &module_name, const std::string &event_name, ArgumentValues& args, ReturnValues& ret, const std::string& origin = "unknow");

VORTEX_API void InstallModuleToSystem(const std::string &path);

Expand Down
90 changes: 78 additions & 12 deletions main/src/modules/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@
* @param foo Pointer to the function taking a shared_ptr to hArgs as parameter.
* @param name The name of the event.
*/
ModuleInputEvent::ModuleInputEvent(void (*foo)(const std::shared_ptr<hArgs>& args), const std::string& name)
: m_foo(foo), m_name(name) {}
ModuleOutputEvent::ModuleOutputEvent(std::function<void(ArgumentValues &, ReturnValues &)> foo, const std::string &name)
: m_function(foo), m_name(name) {}

ModuleOutputEvent::ModuleOutputEvent(std::function<void(ArgumentValues &)> foo, const std::string &name)
: m_function([foo](ArgumentValues &args, ReturnValues &ret)
{
ret = ReturnValues();
foo(args); }),
m_name(name) {}

ModuleOutputEvent::ModuleOutputEvent(std::function<void(ReturnValues &)> foo, const std::string &name)
: m_function([foo](ArgumentValues &, ReturnValues &ret)
{
foo(ret);
}),
m_name(name) {}

ModuleOutputEvent::ModuleOutputEvent(std::function<void()> foo, const std::string &name)
: m_function([foo](ArgumentValues &, ReturnValues &)
{ foo(); }),
m_name(name) {}

/**
* @brief Add a new trigger happening for a current input event
Expand All @@ -16,41 +35,88 @@ ModuleInputEvent::ModuleInputEvent(void (*foo)(const std::shared_ptr<hArgs>& arg
* @param state The name of the event.
* @param log The name of the event.
*/
void ModuleInputEvent::trigger_happening(const std::string& trigger_name, HappeningState state, const std::string& log)
void ModuleInputEvent::trigger_happening(const std::string &trigger_name, HappeningState state, const std::string &log)
{
std::shared_ptr<ModuleInputEventHappening> new_trigger = std::make_shared<ModuleInputEventHappening>();
new_trigger->m_trigger_name = trigger_name;
new_trigger->m_state = state;
new_trigger->m_log = log;
new_trigger->m_timestamp = VortexMaker::getCurrentTimeStamp();

if(state == HappeningState::INFO)
if (state == HappeningState::INFO)
{
VortexMaker::LogInfo("Modules Events", log);
}
else if(state == HappeningState::WARNING)
else if (state == HappeningState::WARNING)
{
VortexMaker::LogWarn("Modules Events", log);
}
else if(state == HappeningState::ERROR)
else if (state == HappeningState::ERROR)
{
VortexMaker::LogError("Modules Events", log);
}
else if(state == HappeningState::FATAL)
else if (state == HappeningState::FATAL)
{
VortexMaker::LogFatal("Modules Events", log);
}

this->m_happenings.push_back(new_trigger);
}


/**
* @brief Constructor for ModuleOutputEvent.
* @brief Add a new trigger happening for a current input event
*
* @param foo Pointer to the function taking a shared_ptr to hArgs as parameter.
* @param name The name of the event.
* @param trigger_name Pointer to the function taking a shared_ptr to hArgs as parameter.
* @param state The name of the event.
* @param log The name of the event.
*/
ModuleOutputEvent::ModuleOutputEvent(void (*foo)(const std::shared_ptr<hArgs>& args), const std::string& name)
: m_foo(foo), m_name(name) {}
void ModuleOutputEvent::trigger_happening(const std::string &trigger_name, HappeningState state, const std::string &log)
{
std::shared_ptr<ModuleOutputEventHappening> new_trigger = std::make_shared<ModuleOutputEventHappening>();
new_trigger->m_trigger_name = trigger_name;
new_trigger->m_state = state;
new_trigger->m_log = log;
new_trigger->m_timestamp = VortexMaker::getCurrentTimeStamp();

if (state == HappeningState::INFO)
{
VortexMaker::LogInfo("Modules Events", log);
}
else if (state == HappeningState::WARNING)
{
VortexMaker::LogWarn("Modules Events", log);
}
else if (state == HappeningState::ERROR)
{
VortexMaker::LogError("Modules Events", log);
}
else if (state == HappeningState::FATAL)
{
VortexMaker::LogFatal("Modules Events", log);
}

this->m_happenings.push_back(new_trigger);
}

ModuleInputEvent::ModuleInputEvent(std::function<void(ArgumentValues &, ReturnValues &)> foo, const std::string &name)
: m_function(foo), m_name(name) {}

ModuleInputEvent::ModuleInputEvent(std::function<void(ArgumentValues &)> foo, const std::string &name)
: m_function([foo](ArgumentValues &args, ReturnValues &ret)
{
ret = ReturnValues();
foo(args); }),
m_name(name) {}

ModuleInputEvent::ModuleInputEvent(std::function<void(ReturnValues &)> foo, const std::string &name)
: m_function([foo](ArgumentValues &, ReturnValues &ret)
{
foo(ret);
}),
m_name(name) {}

ModuleInputEvent::ModuleInputEvent(std::function<void()> foo, const std::string &name)
: m_function([foo](ArgumentValues &, ReturnValues &)
{ foo(); }),
m_name(name) {}
2 changes: 1 addition & 1 deletion main/src/modules/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ModuleFunction::ModuleFunction(std::function<void(ArgumentValues &)> foo, const
ModuleFunction::ModuleFunction(std::function<void(ReturnValues &)> foo, const std::string &name)
: m_function([foo](ArgumentValues &, ReturnValues &ret)
{
foo(ret); // Appeler la fonction avec uniquement `ReturnValues`
foo(ret);
}),
m_name(name)
{
Expand Down
Loading

0 comments on commit 30dd550

Please sign in to comment.