mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
feat(examples): Add new example with custom controller plugin (statically compiled in)
This commit is contained in:
committed by
Alexey Rybalchenko
parent
4587af2eb4
commit
faa309556f
46
examples/custom-controller/main.cxx
Normal file
46
examples/custom-controller/main.cxx
Normal file
@@ -0,0 +1,46 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "MyController.h"
|
||||
#include "MyDevice.h"
|
||||
|
||||
#include <chrono> // for std::chrono_literals
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <fairmq/DeviceRunner.h>
|
||||
#include <memory> // for std::make_unique
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
DeviceRunner runner(argc, argv);
|
||||
|
||||
runner.AddHook<hooks::LoadPlugins>([](DeviceRunner& r) {
|
||||
r.fPluginManager.LoadPlugin("s:mycontroller");
|
||||
// 's:' stands for static because the plugin is compiled into the executable
|
||||
// 'mycontroller' is the plugin name passed as second arg to REGISTER_FAIRMQ_PLUGIN
|
||||
});
|
||||
|
||||
fair::Logger::SetConsoleSeverity(fair::Severity::debug);
|
||||
|
||||
runner.AddHook<hooks::InstantiateDevice>([](DeviceRunner& r) {
|
||||
r.fConfig.SetProperty<int>("catch-signals", 0);
|
||||
r.fConfig.SetProperty<bool>("please-shut-me-down", false);
|
||||
r.fDevice = std::make_unique<example::MyDevice>(r.fConfig);
|
||||
|
||||
r.fDevice->SubscribeToStateChange("example", [&r](auto state) {
|
||||
if (state == State::Running) {
|
||||
r.fDevice->WaitFor(3s);
|
||||
r.fConfig.SetProperty<bool>("please-shut-me-down", true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return runner.RunWithExceptionHandlers();
|
||||
}
|
Reference in New Issue
Block a user