C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_viewer::YasminViewerNode Class Reference

ROS 2 node that receives state machine descriptions and exposes them for the web viewer. More...

#include <yasmin_viewer_node.hpp>

Inheritance diagram for yasmin_viewer::YasminViewerNode:
Collaboration diagram for yasmin_viewer::YasminViewerNode:

Classes

struct  CachedFsm
 Stores a serialized finite state machine and its last update time. More...

Public Member Functions

 YasminViewerNode ()
 Constructs the YasminViewerNode and initializes subscriptions, parameters, and the web server.
 ~YasminViewerNode () override
 Destroys the YasminViewerNode and stops the web server.
 YasminViewerNode (const YasminViewerNode &)=delete
YasminViewerNode & operator= (const YasminViewerNode &)=delete
std::string get_fsms_json () const
 Returns the cached finite state machines as a JSON string.
std::string get_web_root () const
 Returns the configured web root directory.

Private Types

using StateMachineMsg = yasmin_msgs::msg::StateMachine
using StateMsg = yasmin_msgs::msg::State
using TransitionMsg = yasmin_msgs::msg::Transition

Private Member Functions

void fsm_viewer_cb (const StateMachineMsg::SharedPtr msg)
 Callback for incoming state machine messages.
void start_server ()
 Starts the embedded web server thread.
void stop_server ()
 Stops the embedded web server thread.
void run_server ()
 Runs the embedded web server loop.
void prune_expired_locked (const std::chrono::steady_clock::time_point &now) const
 Removes expired finite state machines from the cache.

Static Private Member Functions

static std::string escape_json (const std::string &value)
 Escapes a string for safe JSON serialization.
static std::string transitions_to_json (const std::vector< TransitionMsg > &transitions)
 Serializes a list of transitions into JSON.
static std::string state_to_json (const StateMsg &state)
 Serializes a state into JSON.
static std::string state_machine_to_json (const StateMachineMsg &msg)
 Serializes a full state machine message into JSON.

Private Attributes

std::mutex fsms_mutex_
 Mutex protecting access to the finite state machine cache.
std::unordered_map< std::string, CachedFsm > fsms_
 Cache of serialized finite state machines indexed by name.
rclcpp::Subscription< StateMachineMsg >::SharedPtr fsm_sub_
 Subscription for incoming state machine descriptions.
std::string host_
 Host address used by the embedded web server.
std::string web_root_
 Root directory containing the web viewer files.
int64_t port_
 Port used by the embedded web server.
double max_age_seconds_
 Maximum cache age in seconds before a finite state machine is removed.
std::atomic_bool server_running_
 Indicates whether the embedded web server is running.
std::thread server_thread_
 Background thread executing the embedded web server.

Detailed Description

ROS 2 node that receives state machine descriptions and exposes them for the web viewer.

Member Typedef Documentation

◆ StateMachineMsg

using yasmin_viewer::YasminViewerNode::StateMachineMsg = yasmin_msgs::msg::StateMachine
private

◆ StateMsg

using yasmin_viewer::YasminViewerNode::StateMsg = yasmin_msgs::msg::State
private

◆ TransitionMsg

using yasmin_viewer::YasminViewerNode::TransitionMsg = yasmin_msgs::msg::Transition
private

Constructor & Destructor Documentation

◆ YasminViewerNode() [1/2]

yasmin_viewer::YasminViewerNode::YasminViewerNode ( )

Constructs the YasminViewerNode and initializes subscriptions, parameters, and the web server.

◆ ~YasminViewerNode()

yasmin_viewer::YasminViewerNode::~YasminViewerNode ( )
override

Destroys the YasminViewerNode and stops the web server.

◆ YasminViewerNode() [2/2]

yasmin_viewer::YasminViewerNode::YasminViewerNode ( const YasminViewerNode & )
delete

Member Function Documentation

◆ escape_json()

std::string yasmin_viewer::YasminViewerNode::escape_json ( const std::string & value)
staticprivate

Escapes a string for safe JSON serialization.

Parameters
valueInput string.
Returns
Escaped JSON string.

◆ fsm_viewer_cb()

void yasmin_viewer::YasminViewerNode::fsm_viewer_cb ( const StateMachineMsg::SharedPtr msg)
private

Callback for incoming state machine messages.

Parameters
msgReceived state machine message.

◆ get_fsms_json()

std::string yasmin_viewer::YasminViewerNode::get_fsms_json ( ) const

Returns the cached finite state machines as a JSON string.

Returns
JSON representation of all cached finite state machines.

◆ get_web_root()

std::string yasmin_viewer::YasminViewerNode::get_web_root ( ) const

Returns the configured web root directory.

Returns
Path to the web root directory.

◆ operator=()

YasminViewerNode & yasmin_viewer::YasminViewerNode::operator= ( const YasminViewerNode & )
delete

◆ prune_expired_locked()

void yasmin_viewer::YasminViewerNode::prune_expired_locked ( const std::chrono::steady_clock::time_point & now) const
private

Removes expired finite state machines from the cache.

Parameters
nowCurrent time used for age comparison.

◆ run_server()

void yasmin_viewer::YasminViewerNode::run_server ( )
private

Runs the embedded web server loop.

◆ start_server()

void yasmin_viewer::YasminViewerNode::start_server ( )
private

Starts the embedded web server thread.

◆ state_machine_to_json()

std::string yasmin_viewer::YasminViewerNode::state_machine_to_json ( const StateMachineMsg & msg)
staticprivate

Serializes a full state machine message into JSON.

Parameters
msgState machine message to serialize.
Returns
JSON representation of the state machine.

◆ state_to_json()

std::string yasmin_viewer::YasminViewerNode::state_to_json ( const StateMsg & state)
staticprivate

Serializes a state into JSON.

Parameters
stateState message to serialize.
Returns
JSON representation of the state.

◆ stop_server()

void yasmin_viewer::YasminViewerNode::stop_server ( )
private

Stops the embedded web server thread.

◆ transitions_to_json()

std::string yasmin_viewer::YasminViewerNode::transitions_to_json ( const std::vector< TransitionMsg > & transitions)
staticprivate

Serializes a list of transitions into JSON.

Parameters
transitionsList of transitions.
Returns
JSON representation of the transitions.

Member Data Documentation

◆ fsm_sub_

rclcpp::Subscription<StateMachineMsg>::SharedPtr yasmin_viewer::YasminViewerNode::fsm_sub_
private

Subscription for incoming state machine descriptions.

◆ fsms_

std::unordered_map<std::string, CachedFsm> yasmin_viewer::YasminViewerNode::fsms_
mutableprivate

Cache of serialized finite state machines indexed by name.

◆ fsms_mutex_

std::mutex yasmin_viewer::YasminViewerNode::fsms_mutex_
mutableprivate

Mutex protecting access to the finite state machine cache.

◆ host_

std::string yasmin_viewer::YasminViewerNode::host_
private

Host address used by the embedded web server.

◆ max_age_seconds_

double yasmin_viewer::YasminViewerNode::max_age_seconds_
private

Maximum cache age in seconds before a finite state machine is removed.

◆ port_

int64_t yasmin_viewer::YasminViewerNode::port_
private

Port used by the embedded web server.

◆ server_running_

std::atomic_bool yasmin_viewer::YasminViewerNode::server_running_
private

Indicates whether the embedded web server is running.

◆ server_thread_

std::thread yasmin_viewer::YasminViewerNode::server_thread_
private

Background thread executing the embedded web server.

◆ web_root_

std::string yasmin_viewer::YasminViewerNode::web_root_
private

Root directory containing the web viewer files.


The documentation for this class was generated from the following files: