13#ifndef RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
14#define RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
34#include <fmt/format.h>
36#include <boost/core/demangle.hpp>
38#include <boost/stacktrace.hpp>
72template <
class BL,
class BLF>
79 using boost::core::demangle;
153 static_assert(std::is_base_of_v<typename BL::ComponentType::BizLogicIf, BL>,
154 "BusinessLogic must implement BusinessLogicInterface");
157 std::is_invocable_v<BLF, const std::string&, ServiceContainer&>,
158 "Factory must be invocable with 'const std::string&' and 'ServiceContainer&'");
161 std::is_same_v<std::invoke_result_t<BLF, const std::string&, ServiceContainer&>,
162 std::unique_ptr<BL>>,
163 "Factory must return type 'std::unique_ptr<BusinessLogic>'");
171 "BusinessLogic factory did not return a valid object");
173 }
catch (
const std::exception&
ex) {
183 if (
auto emf =
args.GetModelExportFile();
emf) {
195 }
catch (
const std::exception&
ex) {
214 std::is_constructible_v<BL, const std::string&, ServiceContainer&>,
215 "BusinessLogic must be constructible with 'const std::string&' and 'ServiceContainer&'");
237 }
catch (
const CLI::ParseError&
e) {
238 return args.PrintHelpOrErrMsg(
e);
239 }
catch (
const std::exception&
e) {
240 fmt::print(
stderr,
"RtcComponentMain failed during argument parsing: {}\n",
e.what());
248 auto name =
args.GetComponentName();
255 auto level =
debug_mode ? log4cplus::DEBUG_LOG_LEVEL : log4cplus::INFO_LOG_LEVEL;
258 }
catch (
const std::exception&
e) {
259 fmt::print(
stderr,
"Failed to initialize log system: {}\n",
e.what());
269 }
catch (
const std::exception&
e) {
282int main(
int argc,
char* argv[]) {
283 std::set_terminate([]() {
286 std::exception_ptr eptr{std::current_exception()};
288 LOG4CPLUS_FATAL(GetLogger(
"rtctk"),
289 "Unhandled Exception caught: "
291 << boost::to_string(boost::stacktrace::stacktrace()));
293 LOG4CPLUS_FATAL(GetLogger(
"rtctk"),
294 "Exiting without exception.\nBacktrace:\n"
295 << boost::to_string(boost::stacktrace::stacktrace()));
305 constexpr std::string_view msg =
306 "Caught exception leaked from rtctk::componentFramework::Main\n";
307 std::cerr.write(msg.data(), msg.size());
Alert Service interface.
Definition alertServiceIf.hpp:128
Class used to parse default command line arguments.
Definition rtcComponentArgs.hpp:33
void Parse()
do the actual parsing of CLI
Definition rtcComponentArgs.cpp:48
Class that handles reception of commands using MAL.
Definition commandReplier.hpp:30
Component metrics interface.
Definition componentMetricsIf.hpp:85
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
Interface class for providing pub/sub facilities for JSON events.
Definition eventServiceIf.hpp:29
RAII class to clean-up logging without leaking memory.
Definition logger.hpp:28
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition exceptions.hpp:159
Base interface for all OLDB adapters.
Definition oldbIf.hpp:25
static std::unique_ptr< OldbIf > CreateAdapter(const elt::mal::Uri &uri)
Factory method used to create the appropriate OLDB adapter depending on the URI scheme.
Definition oldbIf.cpp:18
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:27
static std::unique_ptr< RuntimeRepoIf > CreateAdapter(const elt::mal::Uri &uri)
Factory method used to create the appropriate Runtime Configuration Repository adapter depending on t...
Definition runtimeRepoIf.cpp:19
Container class that holds services of any type.
Definition serviceContainer.hpp:39
void Add(Service &&service, const std::string &name="")
Insert new service into the container.
Definition serviceContainer.hpp:62
Service & Get(const std::string &name="")
Get a handle to a service.
Definition serviceContainer.hpp:100
Class that implements a very basic service discovery mechanism.
Definition serviceDiscovery.hpp:33
ServiceEndpoint GetRuntimeRepoEndpoint()
Get the Runtime Repository Endpoint from the ServiceDiscovery.
Definition serviceDiscovery.cpp:59
static const std::string COMPONENT_TYPE
the string for component type (default)
Definition serviceRegistryIf.hpp:60
Definition stateMachineEngine.hpp:35
void RegisterStateChangeHandler(StateMethod on_statechange)
Register state changed handler.
Definition stateMachineEngine.cpp:144
Class used to publish state-changed-topic using MAL.
Definition statePublisher.hpp:36
Receive commands via MAL.
Declares ComponentMetrics.
Provides macros and utilities for exception handling.
Logging Support Library based on log4cplus.
Implementation of the event service.
Definition commandReplier.cpp:22
void RunAsRtcComponent(const Args &args, BLF factory)
RTC Component runner function, needed to run custom BusinessLogic as RTC Component.
Definition rtcComponentMain.hpp:73
auto WrapWithNested(E &&exception) noexcept(std::is_nothrow_constructible_v< detail::UnspecifiedNested< typename std::decay_t< E > >, E && >)
Constructs an unspecified exception that derives from both the provided object and std::nested_except...
Definition exceptions.hpp:95
log4cplus::Logger & GetLogger(const std::string &name="app")
Get handle to a specific logger.
Definition logger.cpp:193
int Main(int argc, char *argv[])
Main function implementation.
Definition rtcComponentMain.hpp:231
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
void LogConfigure(const std::string &app_name, const std::string &props_file_name)
Performs custom logging configuration for any application.
Definition logger.cpp:71
Header file for OldbIf, which defines the API for OldbAdapters.
Provides argument parsing functionality of an RTC Component.
void RtcComponentMain(const rtctk::componentFramework::Args &args)
Main entry point for user code, this method must be implemented by component developers.
Definition main.cpp:43
int main(int argc, char *argv[])
Main function, this is private to the RTC Tk and shall NOT be used by component developers.
Definition rtcComponentMain.hpp:282
Header file for RuntimeRepoIf, which defines the API for RuntimeRepoAdapters.
A container that can hold any type of service.
Class that implements a very basic service discover mechanism.
Class that implements the service registry interface.
Wrapper around the SCXML State Machine Engine.
Publishes the stdif state topic via MAL.