ChimeraTK-ApplicationCore  04.01.00
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 
16 namespace 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 
43  void operator=(const 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
ChimeraTK::VersionInfoProvider
This module can be added to applications to provide version information from the CMakeLists....
Definition: VersionInfoProvider.h:23
ChimeraTK::Module::appConfig
static ConfigReader & appConfig()
Obtain the ConfigReader instance of the application.
Definition: Module.cc:251
ChimeraTK::ConfigReader::get
const T & get(const std::string &variableName) const
Get value for given configuration variable.
Definition: ConfigReader.h:248
ConfigReader.h
ChimeraTK::Module::getOwner
EntityOwner * getOwner() const
Definition: Module.h:96
ChimeraTK::Application::getVersionInfoProvider
ApplicationModule * getVersionInfoProvider()
Definition: Application.h:176
ChimeraTK::VersionInfoProvider::VersionInfoProvider
VersionInfoProvider(Application *owner)
Definition: VersionInfoProvider.h:60
ChimeraTK::Application::setVersionInfoProvider
void setVersionInfoProvider(ApplicationModule *provider)
Definition: Application.h:177
ChimeraTK::ApplicationModule
Definition: ApplicationModule.h:24
ChimeraTK::VersionInfoProvider::~VersionInfoProvider
~VersionInfoProvider() override
Definition: VersionInfoProvider.h:27
ChimeraTK::Module::writeAll
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
Definition: Module.cc:157
ScalarAccessor.h
ApplicationModule.h
ChimeraTK
InvalidityTracer application module.
Definition: spec_dataValidityPropagation.dox:2
ChimeraTK::Application
Definition: Application.h:48