/* * (c) Copyright, Real-Time Innovations, 2022. * All rights reserved. * No duplications, whole or partial, manual or electronic, may be made * without express written permission. Any such copies, or * revisions thereof, must display this notice unaltered. * This code contains trade secrets of Real-Time Innovations, Inc. */ #ifndef RTI_COLLECTOR_SERVICE_HPP_ #define RTI_COLLECTOR_SERVICE_HPP_ #include #include #include #include #include namespace rti { namespace monitoring { namespace collector { /*e \defgroup RTI_CollectorServiceLibModule RTI Monitoring Collector API * * @brief @product can be deployed as a native library linked into your * application in select architectures. * * This API allows you to create, configure and start @product instances from * your application. * * The following code shows the typical use of the API: * * \code * * int main () * { * rti::monitoring::collector::Service service( * rti::monitoring::collector::ServiceProperty() * .cfg_file("MyCollectorService.xml") * .service_name("MyCollectorService")); * ... * * service.start(); * * while(keep_running) { * sleep(); * ... * } * * return 0; * } * * \endcode * * Instead of a file, you can use XML strings to configure @product. * See ServiceProperty for more information. *

* To build your application you need to link with the @product native library * in <@ndds home>/bin/<architecture>/ . * * ### Development Requirements * * | | Linux Systems | Windows Systems | * | --------------: | :----------------: | :-------------: | * | Shared Libraries| libnddscpp2.so | nddscpp2.dll | * | Shared Libraries| librtiroutingservice.so | rtiroutingservice.dll | * | ^ | librtirsinfrastructure.so | rtirsinfrastructure.dll | * | ^ | librticollectorservice.so | rticollectorservice.dll | * | ^ | librtidlc.so | rtidlc.dll | * | ^ | libnddsmetp.so | nddsmetp.dll | * | ^ | libnddsc.so | nddsc.dll | * | ^ | librtixml2.so | rtixml2.dll | * | ^ | libnddscore.so | nddscore.dll | * | Headers | rti/monitoring/collector/RecordingService.hpp || * */ /** \ingroup RTI_CollectorServiceLibModule * * @brief The @product. * */ class Service : public dds::core::Reference { public: typedef dds::core::Reference Base; OMG_DDS_REF_TYPE_NOTYPENAME( Service, dds::core::Reference, ServiceImpl); /** * @brief Creates a @product instance * * @param[in] property * The property to configure @product instance. * * @mtsafety On non-Linux, non-Windows systems (i.e. VxWorks): * UNSAFE for multiple threads to simultaneously make the FIRST * call to any of the Service constructors. Subsequent calls are * thread safe. * On Windows and Linux systems, these calls are thread-safe. */ explicit Service(const ServiceProperty& property) : Base(new ServiceImpl(property)) { this->delegate()->remember_reference(this->delegate()); } /** * @brief Creates a @product instance * * A callable shutdown hook can optionally be provided to handle the * shutdown command received through remote administration. Upon reception * of this command, @product will notify the installed hook. * * The following example shows simple implementation of a shutdown hook * that sets a boolean flag to true when invoked: * * \code * * // Hook implmentation * struct FlagShutdownHook { * public: * FlagShutdownHook(bool& the_flag) : flag(the_flag) * { * flag = false; * } * void operator()() { * the_flag = true; * } * * bool& flag; * }; * * // Instantiate service with hook * bool my_flag; * rti::monitoring::collector::Service collector_service_instance( * property, * FlagShutdownHook(my_flag)); * ... * * * \endcode * * @param[in] property * The property to configure @product instance. * * @param[in] shutdown_hook * Callable object to handle the shutdown command. The expected * type is a void operator()() (C++11 equivalent is * std::function) * * @mtsafety On non-Linux, non-Windows systems (i.e. VxWorks): * UNSAFE for multiple threads to simultaneously make the FIRST * call to any of the Service constructors. Subsequent calls are * thread safe. * On Windows and Linux systems, these calls are thread-safe. */ template explicit Service( const ServiceProperty& property, const HookFunc& shutdown_hook) : Base(new ServiceImpl( property, new rti::routing::detail::ShutdownHookForwarder( shutdown_hook))) { this->delegate()->remember_reference(this->delegate()); } explicit Service(Base::DELEGATE_REF_T reference) : Base(reference) { if (this->delegate()) { this->delegate()->remember_reference(this->delegate()); } } virtual ~Service() = default; /** * @brief Starts @product. * * This is a non-blocking operation. @product will create its own set of * threads to perform its tasks. */ void start() { this->delegate()->start(); } /** * @brief Stops @product. * * This operation will bloc the instance is fully stopped. */ void stop() { this->delegate()->stop(); } }; typedef Service CollectorService; } } } #endif // RTI_COLLECTOR_SERVICE_HPP_