Skip to content

Commit

Permalink
feat: Add better function to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrno committed Nov 18, 2024
1 parent 6e5b7e6 commit 86cb956
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 218 deletions.
2 changes: 2 additions & 0 deletions main/include/modules/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct ModuleInputEventHappening
std::string m_timestamp;
};

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

/**
* @brief Executed by other with custom parameters
*/
Expand Down
33 changes: 29 additions & 4 deletions main/include/modules/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,42 @@
#ifndef MODULE_FUNCTION_H
#define MODULE_FUNCTION_H

// TODO : Replace all args by json values (params like return)

/*
Functions models :
Foo Params Return
Function [JSONPARAMETERS] [JSONRETURN]
Function [void] [JSONRETURN]
Function [JSONPARAMETERS] [void]
Function [void] [void]
*/

/**
* @brief Scopes of a ModuleFunction. If PUBLIC, the function can be called by every other members of the project (plugins,
* modules, etc...). If PRIVATE, the function can only be called by itself. If RESTRICTED, the function can be called by linked
* members (child plugins/modules, optionnal extentions of the module/plugin)
*/
enum class ModuleFunctionScope
{
PRIVATE,
PUBLIC,
RESTRICTED
};

class ModuleFunction
{
public:
ModuleFunction(void(*foo)(), const std::string& name);
ModuleFunction(void(*m_args_foo)(const std::shared_ptr<hArgs>& args), const std::string& name);
ModuleFunction(std::function<void(const VortexMaker::Values&)> foo, const std::string& name);
ModuleFunction(std::function<void()> foo, const std::string& name);

virtual void execute() {};

void(*m_foo)();
void(*m_args_foo)(const std::shared_ptr<hArgs>& args);
std::function<void(const VortexMaker::Values&)> m_function;
VortexMaker::Values m_return_values;
ModuleFunctionScope m_scope;

std::string m_name;
std::string m_description;
bool m_can_callback;
Expand Down
9 changes: 5 additions & 4 deletions main/include/modules/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class ModuleInterface

void AddLogo(const uint8_t* hexa, size_t size);
void AddLogo(const std::string& relative_path);
void AddFunction(void (*item)(), const std::string& name);
void AddFunction(void (*item)(), const std::string& name, const std::string& description);
void AddFunction(void (*item)(const std::shared_ptr<hArgs>& args), const std::string& name, const std::string& description, const std::vector<std::tuple<std::string, std::string, std::string>>& args_def, const bool& can_callback);
void AddFunction(std::function<void()> foo, const std::string& name);
void AddFunction(std::function<void(const VortexMaker::Values&)> foo, const std::string& name);

//void AddFunction(void (*item)(), const std::string& name, Parameters params);
void AddInputEvent(void (*item)(const std::shared_ptr<hArgs>& args), const std::string& name);
Expand All @@ -60,7 +59,9 @@ class ModuleInterface
std::shared_ptr<ModuleInterface> GetInterface();

void ExecFunction(const std::string& name);
void ExecFunction(const std::string& name, std::shared_ptr<hArgs> args);
void ExecFunction(const std::string& name, const VortexMaker::Values& args);
// TODO Exec function with call back + Link to the VortexMaker API

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

// Trigger all output events for every modules/plugins
Expand Down
205 changes: 36 additions & 169 deletions main/include/vortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <dirent.h>
#include <deque>


namespace fs = std::filesystem;

#ifndef VORTEX_API
Expand Down Expand Up @@ -197,35 +196,35 @@ namespace VortexMaker

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

VORTEX_API void InstallModule(const std::string &module_name, const std::string &version, bool& restart_modules);
VORTEX_API void InstallModule(const std::string &module_name, const std::string &version, bool &restart_modules);
VORTEX_API void AddModuleToProject(const std::string &module_name);

VORTEX_API void CreateProject(const std::string &name, const std::string &path);
VORTEX_API void CreateProject(const std::string &name, const std::string &author, const std::string &version, const std::string &description, const std::string &path, const std::string& logo_path, const std::string &template_name);
VORTEX_API void CreateProject(const std::string &name, const std::string &author, const std::string &version, const std::string &description, const std::string &path, const std::string &logo_path, const std::string &template_name);
VORTEX_API void RefreshEnvironmentVortexVersionsPools();

VORTEX_API void DeleteProject(const std::string &path, const std::string& project_name);
VORTEX_API void RemoveSystemProjectEntry(const std::string& project_name);
VORTEX_API void DeleteProject(const std::string &path, const std::string &project_name);
VORTEX_API void RemoveSystemProjectEntry(const std::string &project_name);

VORTEX_API void ImportProject(const std::string &path);
VORTEX_API std::vector<std::shared_ptr<EnvProject>> FindProjectInFolder(const std::string &path);

VORTEX_API void InstallContentOnSystem(const std::string &directory);

VORTEX_API void UpdateProjectData(const std::string& old_name, const std::string& path);
VORTEX_API void UpdateProjectData(const std::string &old_name, const std::string &path);
VORTEX_API void InitEnvironment();

VORTEX_API void CreateSessionTopic(const std::string& post_topic);
VORTEX_API void CreateSessionTopic(const std::string &post_topic);
VORTEX_API void DeleteSessionTopic(const std::string &post_topic);
VORTEX_API void PostSessionState(const std::string& post_topic);
VORTEX_API void PostSessionCoreDump(const std::string& post_topic);
VORTEX_API nlohmann::json GetLastModuleOfLastSession(const std::string& post_topic);
VORTEX_API nlohmann::json GetLastSession(const std::string& post_topic);
VORTEX_API void PostSessionState(const std::string &post_topic);
VORTEX_API void PostSessionCoreDump(const std::string &post_topic);
VORTEX_API nlohmann::json GetLastModuleOfLastSession(const std::string &post_topic);
VORTEX_API nlohmann::json GetLastSession(const std::string &post_topic);

VORTEX_API void RefreshEnvironmentProjects();
VORTEX_API void UpdateEnvironmentProject();
VORTEX_API void UpdateEnvironmentProject(const std::string &name, const std::string &author, const std::string &version, const std::string& compatibleWith, const std::string &description, const std::string &path, const std::string &logo_path, const std::string &template_name);
VORTEX_API void UpdateEnvironmentProject(const std::string& oldname);
VORTEX_API void UpdateEnvironmentProject(const std::string &name, const std::string &author, const std::string &version, const std::string &compatibleWith, const std::string &description, const std::string &path, const std::string &logo_path, const std::string &template_name);
VORTEX_API void UpdateEnvironmentProject(const std::string &oldname);

VORTEX_API std::string getCurrentTimeStamp();

Expand All @@ -245,18 +244,17 @@ namespace VortexMaker
VORTEX_API void CopyAllContent();
VORTEX_API void ExecuteCommand();

VORTEX_API nlohmann::json DumpJSON(const std::string &file);
VORTEX_API void PopulateJSON(const nlohmann::json& json_data, const std::string &file);
VORTEX_API nlohmann::json DumpJSON(const std::string &file);
VORTEX_API void PopulateJSON(const nlohmann::json &json_data, const std::string &file);

VORTEX_API std::string ExtractPackageWithTar(const std::string &path, const std::string &tarballName);
VORTEX_API std::string replacePlaceholders(const std::string &command, const std::unordered_map<std::string, std::string> &replacements);

VORTEX_API std::string gen_random(const int len);
VORTEX_API std::string getHomeDirectory();
VORTEX_API void createFolderIfNotExists(const std::string& path);
VORTEX_API void createFolderIfNotExists(const std::string &path);
VORTEX_API void createJsonFileIfNotExists(const std::string &filename, const nlohmann::json &defaultData);


// Memory Allocators
// - Those functions are not reliant on the current context.
// - DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
Expand Down Expand Up @@ -936,8 +934,8 @@ class hArgs
T storedValue;
};

public:
hArgs(){};
public:
hArgs() {};

template <typename T>
void add(const hString &tag, T value)
Expand Down Expand Up @@ -977,162 +975,31 @@ class hArgs

hVector<hString> registered_arguments;


hMap<hString, ArgumentBase *> arguments;
};
//=============================================================================

//_____________________________________________________________________________
// [SECTION] Structures [OBSOLETE]
//_____________________________________________________________________________

struct VxDiag
{
std::string properName;
std::string statut;
std::string description;
std::string output;
int code;
};

struct VxScriptSave
{
char name[128] = "unknow";
char author[128] = "unknow";
};

struct VxScript
{
std::string name = "unknow"; // Proper name of the script
std::string author = "unknow"; // Proper name of the script
std::string description = "unknow"; // Short description of the script
std::string configFilePath = "unknow"; // Short description of the script
std::string path = "unknow"; // Path to script
void Refresh();
void PushSave(std::shared_ptr<VxScriptSave> save);
};

struct ToolchainSave
{
char name[128] = "unknow";
char author[128] = "unknow";
char version[128] = "unknow";
char description[128] = "unknow";
char type[128] = "unknow";
char state[128] = "unknow";
char host_arch[128] = "unknow";
char host_vendor[128] = "unknow";
char host_platform[128] = "unknow";
char host_cpu[128] = "unknow";
char host_fpu[128] = "unknow";
char builder_arch[128] = "unknow";
char builder_vendor[128] = "unknow";
char builder_platform[128] = "unknow";
char builder_cpu[128] = "unknow";
char builder_fpu[128] = "unknow";
char target_arch[128] = "unknow";
char target_vendor[128] = "unknow";
char target_platform[128] = "unknow";
char target_cpu[128] = "unknow";
char target_fpu[128] = "unknow";
char toolchain_type[128] = "unknow";
char compression[128] = "unknow";
char toolchains_compilation[128] = "unknow";
char localPackagePath[128] = "unknow";
char localScriptsPath[128] = "unknow";
char localPatchsPath[128] = "unknow";
std::vector<std::pair<char[128], char[128]>> registeredPackages;
std::vector<std::pair<char[128], char[128]>> registeredTasklists;
};

struct HostSave
{
char name[128] = "unknow";
char author[128] = "unknow";
char version[128] = "unknow";
char description[128] = "unknow";
char type[128] = "unknow";
char state[128] = "unknow";
char vendor[128] = "unknow";
char platform[128] = "unknow";
char host_arch[128] = "unknow";
char target_arch[128] = "unknow";
char toolchainToUse[128] = "unknow";
char localPackagePath[128] = "unknow";
char localScriptsPath[128] = "unknow";
char localPatchsPath[128] = "unknow";
std::vector<std::pair<char[128], char[128]>> registeredPackages;
};

struct VxActionReport
{
std::string actionType;
std::string label;
std::string result;
std::string state;
std::string report;
};

struct VxHostSnapshot
{
std::string date;
std::string name;
// VxHostCurrentSystem snapshotSystem; // to import from
};
struct VxDistHost
namespace VortexMaker
{
// Vortex project informations
std::string name;
std::string author;
std::string target;
std::string description;
std::string type;
std::string path;
std::string state;
std::string vendor;
std::string platform;

std::string CC;
std::string CXX;
std::string AR;
std::string AS;
std::string RANLIB;
std::string LD;
std::string STRIP;

void TestingChroot();
};
/**
* @brief Data structure for modules & plugins functions, events and other stuff, oriented around
* JSON architecture to easely communicate complex types or large amount of data. Formatted in std::string
* to increase the simplicity of data transferts
*/
struct Values
{
public:
Values(){};
Values(const std::string& val): value(val) {};
std::string GetValue() { return value; };
nlohmann::json GetJsonValue() { return nlohmann::json::parse(value); };

struct VxDistToolchainSave
{
char CC_value[128];
char CXX_value[128];
char AR_value[128];
char AS_value[128];
char RANLIB_value[128];
char LD_value[128];
char STRIP_value[128];
};
void SetValue(const std::string &val) { value = val; };
void SetJsonValue(const nlohmann::json &val) { value = val; };

struct VxDistToolchain
{
// Vortex project informations
std::string name;
std::string author;
std::string target;
std::string description;
std::string type;
std::string state;
std::string path;
std::string vendor;
std::string platform;
std::string CC;
std::string CXX;
std::string AR;
std::string AS;
std::string RANLIB;
std::string LD;
std::string STRIP;
};
private:
std::string value = "null";
};
}

#endif // #ifndef VORTEX_DISABLE
9 changes: 4 additions & 5 deletions main/src/modules/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* @param foo Pointer to the function.
* @param name The name of the function.
*/
ModuleFunction::ModuleFunction(void (*foo)(), const std::string& name)
: m_foo(foo), m_name(name) {}
ModuleFunction::ModuleFunction(std::function<void(const VortexMaker::Values&)> foo, const std::string& name)
: m_function(foo), m_name(name) {}


ModuleFunction::ModuleFunction(void(*foo)(const std::shared_ptr<hArgs>& args), const std::string& name)
: m_args_foo(foo), m_name(name) {}
ModuleFunction::ModuleFunction(std::function<void()> foo, const std::string& name)
: m_function([foo](const VortexMaker::Values&) { foo(); }), m_name(name) {}
Loading

0 comments on commit 86cb956

Please sign in to comment.