refactor ManaPlugin -> IManaSink, ManaCPlugin -> ManaCSink

This commit is contained in:
Florian Lüke 2024-12-27 13:57:03 +01:00
parent 8c1e122e06
commit d8eb73671d
4 changed files with 13 additions and 14 deletions

View file

@ -47,7 +47,7 @@ struct ModuleDataStage
std::vector<std::vector<nlohmann::json>> moduleInfo; std::vector<std::vector<nlohmann::json>> moduleInfo;
RunInfo runInfo; RunInfo runInfo;
nlohmann::json runDescriptor; nlohmann::json runDescriptor;
ManaPlugin *sink = nullptr; IManaSink *sink = nullptr;
void *sinkContext = nullptr; void *sinkContext = nullptr;
}; };
@ -196,7 +196,7 @@ inline nlohmann::json make_run_descriptor(const RunInfo &runInfo)
inline ModuleDataStage make_module_data_stage(const std::string &runName, mana::Arena &&arena, inline ModuleDataStage make_module_data_stage(const std::string &runName, mana::Arena &&arena,
const mvlc::CrateConfig &crateConfig, const mvlc::CrateConfig &crateConfig,
nlohmann::json moduleDb, ManaPlugin *sink, nlohmann::json moduleDb, IManaSink *sink,
void *sinkContext) void *sinkContext)
{ {
ModuleDataStage result; ModuleDataStage result;
@ -271,7 +271,7 @@ inline void module_data_stage_process_system_event(ModuleDataStage &ctx, const u
ctx.sink->process_system_event(data, size); ctx.sink->process_system_event(data, size);
} }
struct ManaCountingSink: public ManaPlugin struct ManaCountingSink: public IManaSink
{ {
std::vector<size_t> eventCounts; std::vector<size_t> eventCounts;
std::vector<std::vector<std::vector<size_t>>> eventArrayIndexHits; std::vector<std::vector<std::vector<size_t>>> eventArrayIndexHits;
@ -320,7 +320,6 @@ struct ManaCountingSink: public ManaPlugin
} }
} }
void process_event(uint16_t eventIndex, mana_offset_array_t *arrays, size_t arrayCount, void process_event(uint16_t eventIndex, mana_offset_array_t *arrays, size_t arrayCount,
size_t totalBytes) override size_t totalBytes) override
{ {

View file

@ -1,8 +1,8 @@
#ifndef A51A04C1_ABD6_4DE9_B16A_49A9DA46C67E #ifndef A51A04C1_ABD6_4DE9_B16A_49A9DA46C67E
#define A51A04C1_ABD6_4DE9_B16A_49A9DA46C67E #define A51A04C1_ABD6_4DE9_B16A_49A9DA46C67E
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View file

@ -126,10 +126,10 @@ inline nlohmann::json make_array_descriptor(const std::string &name, const std::
return make_array_descriptor(name, mana_float, size, bits); return make_array_descriptor(name, mana_float, size, bits);
} }
class ManaPlugin class IManaSink
{ {
public: public:
virtual ~ManaPlugin() = default; virtual ~IManaSink() = default;
virtual void init() = 0; virtual void init() = 0;
virtual void shutdown() = 0; virtual void shutdown() = 0;
@ -141,19 +141,19 @@ class ManaPlugin
virtual void process_system_event(const uint32_t *data, size_t size) = 0; virtual void process_system_event(const uint32_t *data, size_t size) = 0;
protected: protected:
ManaPlugin() = default; IManaSink() = default;
private: private:
ManaPlugin(const ManaPlugin &) = delete; IManaSink(const IManaSink &) = delete;
ManaPlugin &operator=(const ManaPlugin &) = delete; IManaSink &operator=(const IManaSink &) = delete;
}; };
struct ManaCPlugin: public ManaPlugin struct ManaCSink: public IManaSink
{ {
mana_plugin_t plugin_; mana_plugin_t plugin_;
void *context_ = nullptr; void *context_ = nullptr;
explicit ManaCPlugin(mana_plugin_t plugin) explicit ManaCSink(mana_plugin_t plugin)
: plugin_(plugin) : plugin_(plugin)
{ {
} }

View file

@ -413,7 +413,7 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
std::unique_ptr<mana::ManaPlugin> manaPlugin; std::unique_ptr<mana::IManaSink> manaPlugin;
boost::dll::shared_library pluginHandle; boost::dll::shared_library pluginHandle;
if (parser("--plugin")) if (parser("--plugin"))
@ -422,7 +422,7 @@ int main(int argc, char *argv[])
try try
{ {
pluginHandle = boost::dll::shared_library(pluginFile); pluginHandle = boost::dll::shared_library(pluginFile);
manaPlugin = std::make_unique<mana::ManaCPlugin>( manaPlugin = std::make_unique<mana::ManaCSink>(
pluginHandle.get<mana_plugin_t()>("mana_get_plugin")()); pluginHandle.get<mana_plugin_t()>("mana_get_plugin")());
} }
catch (const std::exception &e) catch (const std::exception &e)