Go to the documentation of this file.
12 #ifndef RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
15 #include <mal/Cii.hpp>
30 #include <rtctk/componentFramework/events.rad.hpp>
66 template <
class BL,
class BLF>
71 LOG4CPLUS_INFO(
GetLogger(),
"RtcComponent '" << component_name <<
"' started.");
78 make_unique<ServiceDiscovery>(svc_disc_endpoint, component_name));
106 static_assert(is_base_of_v<typename BL::ComponentType::BizLogicIf, BL>,
107 "BusinessLogic must implement BusinessLogicInterface");
109 static_assert(is_invocable_v<BLF, string const&, ServiceContainer&>,
110 "Factory must be invocable with 'std::string const&' and 'ServiceContainer&'");
112 static_assert(is_same_v<invoke_result_t<BLF, string const&, ServiceContainer&>, unique_ptr<BL>>,
113 "Factory must return type 'std::unique_ptr<BusinessLogic>'");
116 unique_ptr<BL> biz_logic;
118 biz_logic = invoke(factory, component_name, services);
120 throw std::runtime_error(
"BusinessLogic factory did not return a valid object");
123 std::throw_with_nested(
RtctkException(
"BusinessLogic factory failed"));
127 typename BL::ComponentType::InputStage input_stage(replier, engine);
129 typename BL::ComponentType::OutputStage output_stage(engine, *biz_logic);
131 typename BL::ComponentType::ModelBuilder model_builder(engine);
134 model_builder.ExportModel(emf->path().to_string());
137 model_builder.RegisterModel();
141 LOG4CPLUS_INFO(
GetLogger(),
"RtcComponent '" << component_name <<
"' terminated.");
160 is_constructible_v<BL, string const&, ServiceContainer&>,
161 "BusinessLogic must be constructible with 'std::string const&' and 'ServiceContainer&'");
163 RunAsRtcComponent<BL>(args, make_unique<BL, string const&, ServiceContainer&>);
177 int Main(
int argc,
char* argv[]) {
181 Args args{argc, argv};
184 auto log_props_file = args.GetLogPropsFile();
186 if (log_props_file.has_value()) {
187 auto props_file = log_props_file.value().path().to_string();
190 LOG4CPLUS_INFO(
GetLogger(),
"Custom log properties file loaded: " << props_file);
193 MakeLogger(component_name, log4cplus::INFO_LOG_LEVEL);
203 std::cout << e.what() << std::endl;
206 std::cout << e.what() << std::endl;
207 }
catch (std::exception
const& e) {
221 int main(
int argc,
char* argv[]) {
227 constexpr std::string_view msg =
228 "Caught exception leaked from rtctk::componentFramework::Main\n";
229 std::cerr.write(msg.data(), msg.size());
232 #endif // RTCTK_NOMAIN
234 #endif // RTCTK_COMPONENTFRAMEWORK_RTCCOMPONENTMAIN_HPP
A container that can hold any type of service.
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:489
Definition: rtcComponent.hpp:24
void Work()
Runs the event loop of the state machine.
Definition: stateMachineEngine.cpp:130
Wrapper around the SCXML State Machine Engine.
void MakeLogger(const std::string &name, log4cplus::LogLevel ll, bool log_to_file=true, bool additive=false)
Retrieve new logger programmatically.
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.
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:33
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
static const DataPointPath RUNTIME_REPO_ENDPOINT
Definition: serviceDiscovery.hpp:36
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
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
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)
static const DataPointPath REQ_REP_ENDPOINT
There is a fixed set of supported service types.
Definition: serviceDiscovery.hpp:34
void PublishState(const std::string &state)
Definition: statePublisher.cpp:36
Container class that holds services of any type.
Definition: serviceContainer.hpp:35
int Main(int argc, char *argv[])
Main function implementation.
Definition: rtcComponentMain.hpp:177
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:221
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
void RunAsRtcComponent(Args const &args, BLF factory)
RTC Component runner function, needed to run custom BusinessLogic as RTC Component.
Definition: rtcComponentMain.hpp:67
elt::mal::Uri Get(const std::string &service_name)
Get endpoint of specific service.
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:108
void SetDefaultLogger(const std::string &name)
Set the default logger.
Definition: logger.cpp:62
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 wraper for DataPoint paths which ensures that they only contain valid character...
Definition: dataPointPath.hpp:34
Header file for RuntimeRepoIf, which defines the API for RuntimeRepoAdapters.
static const DataPointPath PUB_SUB_ENDPOINT
Definition: serviceDiscovery.hpp:35
static const DataPointPath OLDB_ENDPOINT
Definition: serviceDiscovery.hpp:38
Header file for OldbIf, which defines the API for OldbAdapters.