Go to the documentation of this file.
12 #ifndef RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
15 #include <mal/Cii.hpp>
34 #include <rtctk/componentFramework/events.rad.hpp>
70 template <
class BL,
class BLF>
75 LOG4CPLUS_INFO(
GetLogger(),
"RtcComponent '" << component_name <<
"' started.");
82 make_unique<ServiceDiscovery>(std::make_unique<FileServiceRegistryAdapter>(svc_disc_endpoint), component_name));
92 auto oldb_endpoint = svc_disc.GetOldbEndpoint();
97 auto component_metrics = std::make_shared<ComponentMetrics>(
109 auto event_service = std::make_shared<MalDdsEventService>();
113 auto alert_service = std::make_shared<AlertService>(
GetLogger());
118 auto rr_endpoint = svc_disc.GetReqRepEndpoint();
121 auto ps_endpoint = svc_disc.GetPubSubEndpoint();
136 static_assert(is_base_of_v<typename BL::ComponentType::BizLogicIf, BL>,
137 "BusinessLogic must implement BusinessLogicInterface");
139 static_assert(is_invocable_v<BLF, string const&, ServiceContainer&>,
140 "Factory must be invocable with 'std::string const&' and 'ServiceContainer&'");
142 static_assert(is_same_v<invoke_result_t<BLF, string const&, ServiceContainer&>, unique_ptr<BL>>,
143 "Factory must return type 'std::unique_ptr<BusinessLogic>'");
146 unique_ptr<BL> biz_logic;
148 biz_logic = invoke(factory, component_name, services);
150 throw std::runtime_error(
"BusinessLogic factory did not return a valid object");
153 std::throw_with_nested(
RtctkException(
"BusinessLogic factory failed"));
156 typename BL::ComponentType::InputStage input_stage(replier, engine);
158 typename BL::ComponentType::OutputStage output_stage(engine, *biz_logic);
160 typename BL::ComponentType::ModelBuilder model_builder(engine);
163 model_builder.ExportModel(emf->path().to_string());
166 model_builder.RegisterModel();
168 component_metrics->StartMonitoring();
171 LOG4CPLUS_INFO(
GetLogger(),
"RtcComponent '" << component_name <<
"' terminated.");
190 is_constructible_v<BL, string const&, ServiceContainer&>,
191 "BusinessLogic must be constructible with 'std::string const&' and 'ServiceContainer&'");
193 RunAsRtcComponent<BL>(args, make_unique<BL, string const&, ServiceContainer&>);
207 int Main(
int argc,
char* argv[]) {
211 Args args{argc, argv};
214 auto log_props_file = args.GetLogPropsFile();
216 if (log_props_file.has_value()) {
217 auto props_file = log_props_file.value().path().to_string();
220 LOG4CPLUS_INFO(
GetLogger(),
"Custom log properties file loaded: " << props_file);
223 MakeLogger(component_name, log4cplus::INFO_LOG_LEVEL);
233 std::cout << e.what() << std::endl;
236 std::cerr << e.what() << std::endl;
237 }
catch (std::exception
const& e) {
251 int main(
int argc,
char* argv[]) {
257 constexpr std::string_view msg =
258 "Caught exception leaked from rtctk::componentFramework::Main\n";
259 std::cerr.write(msg.data(), msg.size());
262 #endif // RTCTK_NOMAIN
264 #endif // RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
A container that can hold any type of service.
ServiceEndpoint GetRuntimeRepoEndpoint()
Get the Runtime Repository Endpoint from the ServiceDiscovery.
Definition: serviceDiscovery.cpp:35
std::string GetTypeName(const std::type_info &tid)
Definition: rtcComponent.hpp:114
Receive commands via MAL.
void SetDataPoint(const DataPointPath &path, const T value)
Sets a datapoint in the repository.
Definition: repositoryIf.hpp:573
Definition: rtcComponent.hpp:24
void Work()
Runs the event loop of the state machine.
Definition: stateMachineEngine.cpp:133
Wrapper around the SCXML State Machine Engine.
Service & Get(const std::string &name="")
Get a handle to a service.
Definition: serviceContainer.hpp:85
Definition: rtcComponent.hpp:30
void LogConfigure(const std::string &cfg_file_name="")
Initial logging system configuration.
Declares ComponentMetrics.
void Add(Service &&service, const std::string &name="")
Insert new service into the container.
Definition: serviceContainer.hpp:48
Publishes the stdif state topic via MAL.
detail::Args Args
Definition: rtcComponentMain.hpp:37
Definition: commandReplier.cpp:20
Class that implements a very basic service discover mechanism.
void RtcComponentMain(rtctk::componentFramework::Args const &args)
Main entry point for user code, method must be implemented by component developers.
Definition: main.cpp:22
virtual bool DataPointExists(const DataPointPath &path) const =0
Checks for the existence of a datapoint in the repository.
Class used to publish state-changed-topic using MAL.
Definition: statePublisher.hpp:33
Implementation of the event service.
Class that implements a very basic service discovery mechanism.
Definition: serviceDiscovery.hpp:29
Definition: rtcComponent.hpp:38
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
Provides details for core functionality of an RTC Component.
Definition: stateMachineEngine.hpp:31
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition: exceptions.hpp:157
Alert observer that publishes alerts to event service using the typed event AlertStatusEvent.
Definition: alertService.hpp:100
Component metrics interface.
Definition: componentMetricsIf.hpp:177
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:18
RAII class to clean-up logging without leaking memory.
Definition: logger.hpp:23
log4cplus::Logger & GetLogger(const std::string &name="")
Get handle to a specific logger (used with logging macros)
void PublishState(const std::string &state)
Definition: statePublisher.cpp:36
Simple alert observer that writes alerts to log.
Definition: alertService.hpp:84
Container class that holds services of any type.
Definition: serviceContainer.hpp:35
Configures ComponentMetrics from a runtime repository.
Definition: componentMetrics.hpp:39
Alert Service interface.
Definition: alertServiceIf.hpp:303
int Main(int argc, char *argv[])
Main function implementation.
Definition: rtcComponentMain.hpp:207
std::string GetComponentName() const
Definition: rtcComponent.hpp:44
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:251
elt::mal::Uri GetServiceDiscEndpoint() const
Definition: rtcComponent.hpp:48
Definition: oldbIf.hpp:20
Class that handles reception of commands using MAL.
Definition: commandReplier.hpp:26
Interface class for providing pub/sub facilities for JSON events.
Definition: eventServiceIf.hpp:26
void MakeLogger(const std::string &name, log4cplus::LogLevel ll, bool log_to_file=true, bool additive=false, log4cplus::LogLevel log_to_console_threshold=log4cplus::NOT_SET_LOG_LEVEL)
Retrieve new logger programmatically.
void RunAsRtcComponent(Args const &args, BLF factory)
RTC Component runner function, needed to run custom BusinessLogic as RTC Component.
Definition: rtcComponentMain.hpp:71
Definition: runtimeRepoIf.hpp:20
Definition: mudpiProcessingError.hpp:119
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
Logging Support Library based on log4cplus.
void RegisterStateChangeHandler(StateMethod on_statechange)
Register state changed handler.
Definition: stateMachineEngine.cpp:111
void SetDefaultLogger(const std::string &name)
Set the default logger.
Definition: logger.cpp:66
Class that implements a very basic service discover mechanism.
virtual void CreateDataPoint(const DataPointPath &path, const std::type_info &type)=0
Creates a new datapoint in the repository with a specified type.
std::optional< elt::mal::Uri > GetModelExportFile() const
Definition: rtcComponent.hpp:60
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:65
Header file for RuntimeRepoIf, which defines the API for RuntimeRepoAdapters.
Header file for OldbIf, which defines the API for OldbAdapters.