ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
VersionInfoProvider.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "ApplicationModule.h"
6#include "ConfigReader.h"
7#include "ScalarAccessor.h"
8
9// The VersionInfo header is auto-generated by the project template in the target project.
10// References to the respective `namespace ChimeraTK::VersionInfo` must be header-only
11// to avoid inclusion in the ApplicationCore.so file.
12#include "VersionInfo.h"
13
14#include <boost/format.hpp>
15
16namespace ChimeraTK {
24 public:
25 explicit VersionInfoProvider(Application* owner);
26
27 ~VersionInfoProvider() override { dynamic_cast<Application*>(getOwner())->setVersionInfoProvider(nullptr); };
28
29 private:
30 int configPatch{appConfig().get<int>("Application/configPatchVersion")};
31
32 ScalarOutput<int> majorVersion{this, "majorVersion", "", "Major version of the application"};
33 ScalarOutput<int> minorVersion{this, "minorVersion", "", "Minor version of the application"};
34 ScalarOutput<int> patchVersion{this, "patchVersion", "", "Patch version of the application"};
35 ScalarOutput<std::string> fullVersion{
36 this, "fullVersion", "", "Full version of the application with configuration patch"};
37
38 void mainLoop() override {}
39
40 void prepare() override;
41
42 VersionInfoProvider(const VersionInfoProvider&) = delete;
43 void operator=(const VersionInfoProvider&) = delete;
44 VersionInfoProvider(VersionInfoProvider&&) = delete;
45 void operator=(VersionInfoProvider&&) = delete;
46 };
47
48 /********************************************************************************************************************/
49
50 inline void VersionInfoProvider::prepare() {
51 majorVersion = VersionInfo::major;
52 minorVersion = VersionInfo::minor;
53 patchVersion = VersionInfo::applicationPatch;
54 boost::format fmt = boost::format("%02d.%02d.%02d-%02d") % static_cast<int>(majorVersion) %
55 static_cast<int>(minorVersion) % static_cast<int>(patchVersion) % configPatch;
56 fullVersion = fmt.str();
57 writeAll();
58 }
59
61 : ApplicationModule(owner, "Application", "Module to publish version information") {
62 if(owner->getVersionInfoProvider()) {
63 throw logic_error("An application can only have one VersionInfoprovider.");
64 }
65 owner->setVersionInfoProvider(this);
66 }
67
68} // namespace ChimeraTK
ApplicationModule * getVersionInfoProvider()
void setVersionInfoProvider(ApplicationModule *provider)
const T & get(std::string variableName) const
Get value for given configuration variable.
static ConfigReader & appConfig()
Obtain the ConfigReader instance of the application.
Definition Module.cc:251
EntityOwner * getOwner() const
Definition Module.h:102
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
Definition Module.cc:157
This module can be added to applications to provide version information from the CMakeLists....
VersionInfoProvider(Application *owner)
InvalidityTracer application module.