mlink/syntaloslinkmodule.cpp
mlink/syntaloslinkmodule.cpp
Namespaces
| Name |
|---|
| Syntalos |
Source code
/*
* Copyright (C) 2020-2026 Matthias Klumpp <matthias@tenstral.net>
*
* Licensed under the GNU Lesser General Public License Version 3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the license, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "syntaloslinkmodule.h"
#include <datactl/loginternal.h>
using namespace Syntalos;
namespace Syntalos
{
SY_DEFINE_LOG_CATEGORY(logLinkMod, "sylm");
class SyntalosLinkModule::Private
{
public:
Private() = default;
~Private() = default;
std::shared_ptr<EDLDataset> defaultDataset;
};
SyntalosLinkModule::SyntalosLinkModule(SyntalosLink *slink)
: m_running(false),
d(new SyntalosLinkModule::Private),
m_slink(slink)
{
// set callbacks
m_slink->setShutdownCallback([this]() {
m_running = false;
shutdown();
});
m_slink->setPrepareRunCallback([this]() {
if (!prepare()) {
if (m_slink->state() != ModuleState::ERROR)
raiseError("Module preparation failed.");
return false;
}
return true;
});
m_slink->setStartCallback([this]() {
m_running = true;
start();
});
m_slink->setStopCallback([this]() {
m_running = false;
stop();
});
m_slink->setLoadSettingsCallback([this](const ByteVector &settings, const fs::path &baseDir) {
if (!loadSettings(settings, baseDir)) {
if (m_slink->state() != ModuleState::ERROR)
raiseError("Loading settings failed.");
return false;
}
return true;
});
m_slink->setSaveSettingsCallback([this](ByteVector &settings, const fs::path &baseDir) {
saveSettings(settings, baseDir);
return true;
});
// signal that we are ready and done with initialization
m_slink->setState(ModuleState::IDLE);
}
SyntalosLinkModule::~SyntalosLinkModule() = default;
void SyntalosLinkModule::raiseError(const std::string &title, const std::string &message)
{
m_slink->raiseError(title, message);
}
void SyntalosLinkModule::raiseError(const std::string &message)
{
m_slink->raiseError(message);
}
std::shared_ptr<SyncTimer> SyntalosLinkModule::timer() const
{
return m_slink->timer();
}
void SyntalosLinkModule::awaitData(int timeoutUsec)
{
m_slink->awaitData(timeoutUsec);
}
ModuleState SyntalosLinkModule::state() const
{
return m_slink->state();
}
void SyntalosLinkModule::setState(ModuleState state)
{
m_slink->setState(state);
}
void SyntalosLinkModule::setStatusMessage(const std::string &message)
{
m_slink->setStatusMessage(message);
}
bool SyntalosLinkModule::prepare()
{
setState(ModuleState::PREPARING);
return true;
}
void SyntalosLinkModule::start()
{
// Implemented by derived classes
setState(ModuleState::RUNNING);
}
void SyntalosLinkModule::stop()
{
// Implemented by derived classes
if (state() != ModuleState::ERROR)
setState(ModuleState::IDLE);
}
void SyntalosLinkModule::shutdown()
{
SY_LOG_INFO(logLinkMod, "Shutting down.");
awaitData(1000);
}
const TestSubjectInfo &SyntalosLinkModule::testSubject() const
{
return m_slink->testSubject();
}
void SyntalosLinkModule::saveSettings(ByteVector &settings, const fs::path &baseDir)
{
// to be implemented by child classes
}
bool SyntalosLinkModule::loadSettings(const ByteVector &settings, const fs::path &baseDir)
{
return true;
}
const RunInfo &SyntalosLinkModule::runInfo() const
{
return m_slink->runInfo();
}
auto SyntalosLinkModule::createDefaultDataset(const std::string &preferredName)
-> std::expected<std::shared_ptr<EDLDataset>, std::string>
{
if (d->defaultDataset)
return d->defaultDataset;
auto result = m_slink->createDefaultDataset(preferredName);
if (result)
d->defaultDataset = *result;
return result;
}
auto SyntalosLinkModule::createDatasetInGroup(const std::shared_ptr<EDLGroup> &parent, const std::string &name)
-> std::expected<std::shared_ptr<EDLDataset>, std::string>
{
return m_slink->reserveEdlDataset(parent, name);
}
auto SyntalosLinkModule::createStorageGroup(const std::string &name)
-> std::expected<std::shared_ptr<EDLGroup>, std::string>
{
return m_slink->createStorageGroup(name);
}
auto SyntalosLinkModule::createStorageGroup(const std::shared_ptr<EDLGroup> &parent, const std::string &name)
-> std::expected<std::shared_ptr<EDLGroup>, std::string>
{
return m_slink->reserveEdlGroup(parent, name);
}
std::unique_ptr<FreqCounterSynchronizer> SyntalosLinkModule::initCounterSynchronizer(
double frequencyHz,
const std::string &id)
{
return m_slink->initCounterSynchronizer(frequencyHz, id);
}
std::unique_ptr<SecondaryClockSynchronizer> SyntalosLinkModule::initClockSynchronizer(
double expectedFrequencyHz,
const std::string &id)
{
return m_slink->initClockSynchronizer(expectedFrequencyHz, id);
}
} // namespace Syntalos
Updated on 2026-05-22 at 16:32:47 +0000