simplify the ManaPlugin class, decouple it from the C plugin interface

This commit is contained in:
Florian Lüke 2024-12-27 12:40:49 +01:00
parent bfce5e76ab
commit 9c76aa93bf
3 changed files with 35 additions and 47 deletions

View file

@ -218,12 +218,12 @@ inline ModuleDataStage make_module_data_stage(const std::string &runName, mana::
inline void module_data_stage_begin_run(ModuleDataStage &ctx)
{
ctx.sink->begin_run(ctx.sinkContext, ctx.runDescriptor.dump().c_str());
ctx.sink->begin_run(ctx.runDescriptor.dump().c_str());
}
inline void module_data_stage_end_run(ModuleDataStage &ctx)
{
ctx.sink->end_run(ctx.sinkContext, ctx.runDescriptor.dump().c_str());
ctx.sink->end_run(ctx.runDescriptor.dump().c_str());
}
inline void
@ -262,13 +262,13 @@ module_data_stage_process_module_data(ModuleDataStage &ctx, int eventIndex,
extract_module_data(inputData, extractors.at(oi), spans.at(oi));
}
ctx.sink->process_event(ctx.sinkContext, eventIndex, eventInfo.outputArrays.front(),
ctx.sink->process_event(eventIndex, eventInfo.outputArrays.front(),
eventInfo.outputArrays.size(), eventInfo.sizeBytes);
}
inline void module_data_stage_process_system_event(ModuleDataStage &ctx, const u32 *data, u32 size)
{
ctx.sink->process_system_event(ctx.sinkContext, data, size);
ctx.sink->process_system_event(data, size);
}
struct ManaCountingSink: public ManaPlugin
@ -278,6 +278,7 @@ struct ManaCountingSink: public ManaPlugin
size_t totalBytes = 0;
size_t systemEventCount = 0;
size_t systemEventBytes = 0;
void reset()
{
eventCounts.clear();
@ -285,13 +286,10 @@ struct ManaCountingSink: public ManaPlugin
totalBytes = 0;
}
MANA_DEFINE_PLUGIN_INIT(init) override { return nullptr; }
MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown) override { (void)context; }
MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run) override
void init() override {}
void shutdown() override {}
void begin_run(const char *descriptor_json) override
{
(void)context;
auto jRun = nlohmann::json::parse(descriptor_json);
reset();
eventCounts.resize(jRun["events"].size());
@ -299,9 +297,8 @@ struct ManaCountingSink: public ManaPlugin
eventArrayIndexHits.resize(eventCounts.size());
}
MANA_DEFINE_PLUGIN_END_RUN(end_run) override
void end_run(const char *descriptor_json) override
{
(void)context;
auto jRun = nlohmann::json::parse(descriptor_json);
spdlog::info("ManaCountingSink: eventCounts=[{}], totalBytes={}, systemEvents={}, "
@ -323,9 +320,10 @@ struct ManaCountingSink: public ManaPlugin
}
}
MANA_DEFINE_PLUGIN_EVENT_DATA(process_event) override
void process_event(uint16_t eventIndex, mana_offset_array_t *arrays, size_t arrayCount,
size_t totalBytes) override
{
(void)context;
eventCounts.resize(std::max(eventCounts.size(), static_cast<size_t>(eventIndex + 1)));
eventArrayIndexHits.resize(eventCounts.size());
eventArrayIndexHits[eventIndex].resize(
@ -350,9 +348,8 @@ struct ManaCountingSink: public ManaPlugin
this->totalBytes += totalBytes;
}
MANA_DEFINE_PLUGIN_SYSTEM_EVENT(process_system_event) override
void process_system_event(const uint32_t *data, size_t size) override
{
(void)context;
(void)data;
++systemEventCount;
systemEventBytes += size * sizeof(u32);

View file

@ -1,13 +1,13 @@
#ifndef AAB5E4D2_A05B_4F2F_B76A_406A5A569D55
#define AAB5E4D2_A05B_4F2F_B76A_406A5A569D55
#include "mana_api.h"
#include "mana_arena.h"
#include <cassert>
#include <mesytec-mnode/mnode_cpp_types.h>
#include <mesytec-mvlc/cpp_compat.h>
#include <mesytec-mvlc/util/data_filter.h>
#include <nlohmann/json.hpp>
#include "mana_api.h"
#include "mana_arena.h"
namespace mesytec::mnode::mana
{
@ -129,12 +129,15 @@ inline nlohmann::json make_array_descriptor(const std::string &name, const std::
struct ManaPlugin
{
virtual ~ManaPlugin() = default;
virtual MANA_DEFINE_PLUGIN_INIT(init) = 0;
virtual MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown) = 0;
virtual MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run) = 0;
virtual MANA_DEFINE_PLUGIN_END_RUN(end_run) = 0;
virtual MANA_DEFINE_PLUGIN_EVENT_DATA(process_event) = 0;
virtual MANA_DEFINE_PLUGIN_SYSTEM_EVENT(process_system_event) = 0;
virtual void init() = 0;
virtual void shutdown() = 0;
virtual void begin_run(const char *descriptor_json) = 0;
virtual void end_run(const char *descriptor_json) = 0;
virtual void process_event(uint16_t eventIndex, mana_offset_array_t *arrays, size_t arrayCount,
size_t totalBytes) = 0;
virtual void process_system_event(const uint32_t *data, size_t size) = 0;
};
struct ManaCPlugin: public ManaPlugin
@ -147,35 +150,23 @@ struct ManaCPlugin: public ManaPlugin
{
}
MANA_DEFINE_PLUGIN_INIT(init) override { return context_ = plugin_.init(); }
MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown) override
void init() override { context_ = plugin_.init(); }
void shutdown() override { plugin_.shutdown(context_); }
void begin_run(const char *descriptor_json) override
{
(void)context;
plugin_.shutdown(context_);
}
MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run) override
{
(void)context;
plugin_.begin_run(context_, descriptor_json);
}
MANA_DEFINE_PLUGIN_END_RUN(end_run) override
void end_run(const char *descriptor_json) override
{
(void)context;
plugin_.end_run(context_, descriptor_json);
}
MANA_DEFINE_PLUGIN_EVENT_DATA(process_event) override
void process_event(uint16_t eventIndex, mana_offset_array_t *arrays, size_t arrayCount,
size_t totalBytes) override
{
(void)context;
plugin_.process_event(context_, eventIndex, arrays, arrayCount, totalBytes);
}
MANA_DEFINE_PLUGIN_SYSTEM_EVENT(process_system_event) override
void process_system_event(const uint32_t *data, size_t size) override
{
(void)context;
plugin_.process_system_event(context_, data, size);
}
};

View file

@ -481,13 +481,13 @@ int main(int argc, char *argv[])
// make the analysis instance available to the parser callbacks
parserContext->parser.userContext = &mana;
mana.sinkContext = mana.sink->init();
mana.sink->begin_run(mana.sinkContext, mana.runDescriptor.dump().c_str());
mana.sink->init();
mana.sink->begin_run(mana.runDescriptor.dump().c_str());
strategy->run(*listfileContext, *parserContext);
mana.sink->end_run(mana.sinkContext, mana.runDescriptor.dump().c_str());
mana.sink->shutdown(mana.sinkContext);
mana.sink->end_run(mana.runDescriptor.dump().c_str());
mana.sink->shutdown();
return 0;
}