RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
businessLogic.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_REUSABLECOMPONENT_MUDPIPUB_BUSINESSLOGIC_HPP
13#define RTCTK_REUSABLECOMPONENT_MUDPIPUB_BUSINESSLOGIC_HPP
14
15#include <optional>
16#include <string>
17
24#include <taiclock/taiClock.hpp>
25
27
28namespace rtctk::mudpiPub {
29
30using rtctk::componentFramework::RtcComponent;
31using rtctk::componentFramework::Runnable;
32
34
36public:
38
42
43 // for each topic we have a vector of samples, where a sample is a vector of bytes
44 using UserData = std::map<std::string, std::vector<std::vector<uint8_t>>>;
45 using UserFunc = std::function<UserData(const std::string&)>;
46
47 BusinessLogic(const std::string& name,
48 ServiceContainer& services,
49 UserFunc user_func = nullptr);
50 virtual ~BusinessLogic() = default;
51 void ActivityStarting(StopToken st) override;
52 void ActivityInitialising(StopToken st) override;
53 void ActivityRunning(StopToken st) override;
54 void ActivityUpdating(StopToken st, const JsonPayload& args) override;
55
56private:
57 using DataPointPath = rtctk::componentFramework::DataPointPath;
58 using RuntimeRepoIf = rtctk::componentFramework::RuntimeRepoIf;
59 using ComponentMetricsIf = rtctk::componentFramework::ComponentMetricsIf;
60
61 log4cplus::Logger& m_logger;
62
63 AppCfg MakeAppCfg();
64
65 void UpdateAppDynamicCfg(AppCfg& cfg);
66
67 void UpdateCachedPublicationStartTime();
68 taiclock::TaiClock::time_point ResolvePublicationStartTime() const;
69
70 void WaitUntilPublicationDeadline(taiclock::TaiClock::time_point deadline,
71 const StopToken& st) const;
72
73 std::tuple<std::string, PubCfg> MakePubCfg(const std::string& prefix, const AppCfg& app_cfg);
74
75 void
76 UpdatePubDynamicCfg(const std::string& prefix, PubDynamicCfg& pub_cfg, const AppCfg& app_cfg);
77
78 std::string m_name;
79 RuntimeRepoIf& m_rtr;
80 ComponentMetricsIf& m_metrics;
81
82 perfc::CounterI64 m_pc_samples_published;
83 perfc::ScopedRegistration m_pc_samples_published_reg;
84 std::unique_ptr<rtctk::componentFramework::FrequencyEstimator<>> m_freq_estimator;
85 std::unique_ptr<rtctk::componentFramework::DurationMonitor<>> m_dur_monitor;
86
87 AppCfg m_cfg; // configuration
88 UserFunc m_user_func;
89 std::vector<std::unique_ptr<Publisher>> m_publishers;
90
91 std::atomic<bool> m_running = false;
92
93 std::optional<taiclock::TaiClock::time_point> m_publication_start_time;
94 std::string m_publication_start_timestamp;
95};
96
97} // namespace rtctk::mudpiPub
98
99#endif // RTCTK_REUSABLECOMPONENT_MUDPIPUB_BUSINESSLOGIC_HPP
Component metrics interface.
Definition componentMetricsIf.hpp:163
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:76
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:26
Container class that holds services of any type.
Definition serviceContainer.hpp:38
void ActivityUpdating(StopToken st, const JsonPayload &args) override
Definition businessLogic.cpp:160
std::map< std::string, std::vector< std::vector< uint8_t > > > UserData
Definition businessLogic.hpp:44
void ActivityInitialising(StopToken st) override
Definition businessLogic.cpp:42
void ActivityRunning(StopToken st) override
Definition businessLogic.cpp:121
BusinessLogic(const std::string &name, ServiceContainer &services, UserFunc user_func=nullptr)
Definition businessLogic.cpp:25
LifeCycle ComponentType
Definition businessLogic.hpp:37
rtctk::componentFramework::ServiceContainer ServiceContainer
Definition businessLogic.hpp:40
rtctk::componentFramework::JsonPayload JsonPayload
Definition businessLogic.hpp:39
rtctk::componentFramework::StopToken StopToken
Definition businessLogic.hpp:41
std::function< UserData(const std::string &)> UserFunc
Definition businessLogic.hpp:45
void ActivityStarting(StopToken st) override
Definition businessLogic.cpp:35
virtual ~BusinessLogic()=default
Header file for ComponentMetricsIf.
Header file for Duration Monitor.
Header file for Frequency Estimator.
rad::StopToken StopToken
Definition stopToken.hpp:19
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:24
Definition businessLogic.cpp:23
Runnable< RtcComponent > LifeCycle
Definition businessLogic.hpp:33
RTC toolkit MUDPI publisher class declaration.
Lifecycle of a basic 'RtcComponent'.
Lifecycle Extension that makes an RTC Component 'Runnable'.
Header file for RuntimeRepoIf, which defines the API for RuntimeRepoAdapters.
Life cycle extension to make RtcComponent Runnable.
Definition runnable.hpp:30
Configuration of entire MUDPI Publisher application.
Definition config.hpp:83
Dynamic Configuration of a single MUDPI Publisher object.
Definition config.hpp:28