Class simulation_framework::core::lifecycle::BaseActivity
Last update: 22.04.2026
Definition: core/lifecycle/activity/base_activity.h (line 77)
This is the basic implementation of IActivity interface. Inheriting classes, i.e. a concrete simulation activity, should implement their logic in ExecuteStep() and add needed pub/sub in AddPublisherAndSubscriber() method.
To join the simulation, an activity is basic component which can publish/subscribe message through communication channel and be scheduled by user config as desired. This class is the base class for any other customized activity.
Example of creating inherited 'MyActivity' using 'MyLogic' library This activity is listening to the Topic 'TopicSubscribingOn' and providing Topic 'TopicToBePublished', with corresponding underlying message type MyMessageType_Sub and MyMessageType_Pub.
#include "core/lifecycle/activity/base_activity.h"
#include "my_logic.h"
class MyActivity : public BaseActivity
{
public:
MyActivity(const std::string& name,
std::shared_ptr<CommunicationManager> communication_manager_ptr,
SchedulerClientPtr scheduler_client,
MyLogic my_logic) : core::lifecycle::BaseActivity(name, communication_manager_ptr, std::move(scheduler_client)),
my_logic_(my_logic)
~MyActivity = default;
void AddPublisherAndSubscriber() override
{
AddPublisher<core::Topic<MyMessageType_Pub>>(
"TopicToBePublished", [&]() { return msg_pub_; }
);
AddSubscriber<core::Topic<MyMessageType_Sub>>(
"TopicSubscribingOn", [&](const MyMessageType_Sub& msg) { msg_sub_ = msg; }
);
}
void ExecuteStep() override
{
my_logic_.DoSomething();
msg_pub_ = my_logic_.GetUpdatedMsg(msg_sub_);
}
private:
MyLogic my_logic_;
MyMessageType_Sub msg_sub_{};
MyMessageType_Pub msg_pub_{};
};
Inherits from:
Inherited by:
Members
- AddPublisher
- AddPublisherAndSubscriber
- AddSubscriber
- BaseActivity
- BaseActivity
- BaseActivity
- BaseActivity
- ExecuteStep
- Finalize
- GetCurrentTimestamp
- GetCustomizedParameters
- GetCycleTime
- GetName
- GetSimulationOutputDirectory
- Init
- SetSimulationSettings
- SetUpCommunication
- Shutdown
- Step
- WaitForPubSubConnection
- ~BaseActivity
- ~IActivity
Public functions
Function BaseActivity
simulation_framework::core::lifecycle::BaseActivity::BaseActivity(const std::string &activity_name, std::shared_ptr< core::CommunicationManager > communication_manager_ptr, std::unique_ptr< scheduling::ISchedulerClient > scheduler_client)
Construct an BaseActivity to join simulation.
Parameters:
- activity_name: a unique name of activity in string, which is used as identifier for connections
- communication_manager_ptr: communication manager interface to enable activity join in the com-channel
- scheduler_client: the client which receives event from scheduler server
Parameters:
- const std::string & activity_name
- std::shared_ptr< core::CommunicationManager > communication_manager_ptr
- std::unique_ptr< scheduling::ISchedulerClient > scheduler_client
Return type:
Function BaseActivity
simulation_framework::core::lifecycle::BaseActivity::BaseActivity(const std::string &activity_name, std::shared_ptr< core::CommunicationManager > communication_manager_ptr, std::unique_ptr< scheduling::ISchedulerClient > scheduler_client, std::chrono::milliseconds timeout)
Construct an BaseActivity to join simulation.
Parameters:
- activity_name: a unique name of activity in string, which is used as identifier for connections
- communication_manager_ptr: communication manager interface to enable activity join in the com-channel
- scheduler_client: the client which receives event from scheduler server
- timeout: timeout in milliseconds for event handling
Parameters:
- const std::string & activity_name
- std::shared_ptr< core::CommunicationManager > communication_manager_ptr
- std::unique_ptr< scheduling::ISchedulerClient > scheduler_client
- std::chrono::milliseconds timeout
Return type:
Function BaseActivity
simulation_framework::core::lifecycle::BaseActivity::BaseActivity(const std::string &activity_name, const Topics &topics)
Construct an BaseActivity using RTIDDS communication to join simulation.
Parameters:
- activity_name: A unique name of activity in string, which is used as identifier for connections
- topics: Topics which this activity want to interact with, i.e. subscribe on or publish to
Parameters:
Return type:
Function BaseActivity
simulation_framework::core::lifecycle::BaseActivity::BaseActivity(const std::string &activity_name, const Topics &topics, std::chrono::milliseconds timeout)
Construct an BaseActivity using RTIDDS communication to join simulation.
Parameters:
- activity_name: A unique name of activity in string, which is used as identifier for connections
- topics: Topics which this activity want to interact with, i.e. subscribe on or publish to
- timeout: Timeout in millisecond to wait until an event successfully received or sent
Parameters:
Return type:
Function ~BaseActivity
virtual simulation_framework::core::lifecycle::BaseActivity::~BaseActivity()
Destructor of an BaseActivity class.
Return type:
Function GetName
std::string simulation_framework::core::lifecycle::BaseActivity::GetName() const override
Returns:
the name of this activity
Return type: std::string
Reimplements: GetName
Function SetUpCommunication
void simulation_framework::core::lifecycle::BaseActivity::SetUpCommunication() final
Register this activity's bounding communications, managed by higher level. Modifying by inheriting classes is NOT allowed.
Return type: void
Reimplements: SetUpCommunication
Function Step
void simulation_framework::core::lifecycle::BaseActivity::Step() final
Calls the ExecuteStep() for internal logic and send/receive message from corresponding pub/sub, managed by higher level. Modifying by inheriting classes is NOT allowed.
Return type: void
Reimplements: Step
Function Shutdown
void simulation_framework::core::lifecycle::BaseActivity::Shutdown() final
Active shutdown the simulation. Simulation will finish planned events before this and shutdown gracefully
Return type: void
Reimplements: Shutdown
Function GetCurrentTimestamp
time::Timestamp simulation_framework::core::lifecycle::BaseActivity::GetCurrentTimestamp() const final
Get current simulation timestamp.
Returns:
The current simulation timestamp
Return type: time::Timestamp
Reimplements: GetCurrentTimestamp
Function GetCycleTime
std::chrono::milliseconds simulation_framework::core::lifecycle::BaseActivity::GetCycleTime() const final
Return cycle time of this activity as duration in milliseconds.
Returns:
The cycle time of this activity as duration in milliseconds
Return type: std::chrono::milliseconds
Reimplements: GetCycleTime
Function GetSimulationOutputDirectory
std::string simulation_framework::core::lifecycle::BaseActivity::GetSimulationOutputDirectory() const final
Return output directory of simulation as string.
Returns:
The output directory of simulation
Return type: std::string
Reimplements: GetSimulationOutputDirectory
Function GetCustomizedParameters
const SimulationParameters::CustomizedParameters & simulation_framework::core::lifecycle::BaseActivity::GetCustomizedParameters() const final
Retrieves the customized parameters for the activity.
Returns:
A map of customized parameters. key is the name of the customized parameter, value is the value of the customized parameter in type of std::string.
Return type: const SimulationParameters::CustomizedParameters &
Reimplements: GetCustomizedParameters
Function SetSimulationSettings
void simulation_framework::core::lifecycle::BaseActivity::SetSimulationSettings(const scheduling::SimulationSettings &sim_settings) final
Set the simulation settings for this activity.
Parameters:
- sim_settings: The simulation settings struct
Parameters:
- const scheduling::SimulationSettings & sim_settings
Return type: void
Reimplements: SetSimulationSettings
Protected functions
Function Init
void simulation_framework::core::lifecycle::BaseActivity::Init() override
Initialize this activity with customized action.
Return type: void
Reimplements: Init
Reimplemented by:
Function Finalize
void simulation_framework::core::lifecycle::BaseActivity::Finalize() override
Finalize this activity with customized action.
Return type: void
Reimplements: Finalize
Function ExecuteStep
virtual void simulation_framework::core::lifecycle::BaseActivity::ExecuteStep()=0
Core operation of customer logic in a concrete activity.
Return type: void
Reimplemented by:
Function AddPublisherAndSubscriber
virtual void simulation_framework::core::lifecycle::BaseActivity::AddPublisherAndSubscriber()=0
Addition of Pub/Sub into a concrete activity.
Return type: void
Reimplemented by:
Function AddPublisher
void simulation_framework::core::lifecycle::BaseActivity::AddPublisher(const core::TopicId &topic_id, typename Topic::PublisherCallback callback)
Template method which allows user to add one publisher pushing message to the given Topic.
Parameters:
- topic_id: the name of Topic in string
- callback: publisher callback function
Parameters:
Return type: void
Function AddSubscriber
void simulation_framework::core::lifecycle::BaseActivity::AddSubscriber(const core::TopicId &topic_id, typename Topic::SubscriberMessageCallback callback)
Template method which allows user to add one subscriber receiving message to the given Topic.
Parameters:
- topic_id: the name of Topic in string
- callback: subscriber callback function
Parameters:
Return type: void