16#ifndef YASMIN_VIEWER__YASMIN_VIEWER_NODE_HPP_
17#define YASMIN_VIEWER__YASMIN_VIEWER_NODE_HPP_
25#include <unordered_map>
28#include <rclcpp/rclcpp.hpp>
30#include "yasmin_msgs/msg/state.hpp"
31#include "yasmin_msgs/msg/state_machine.hpp"
32#include "yasmin_msgs/msg/transition.hpp"
116 static std::string
escape_json(
const std::string &value);
143 mutable std::unordered_map<std::string, CachedFsm>
fsms_;
146 rclcpp::Subscription<StateMachineMsg>::SharedPtr
fsm_sub_;
static std::string escape_json(const std::string &value)
Escapes a string for safe JSON serialization.
Definition yasmin_viewer_node.cpp:328
void stop_server()
Stops the embedded web server thread.
Definition yasmin_viewer_node.cpp:265
std::string host_
Host address used by the embedded web server.
Definition yasmin_viewer_node.hpp:149
std::mutex fsms_mutex_
Mutex protecting access to the finite state machine cache.
Definition yasmin_viewer_node.hpp:141
~YasminViewerNode() override
Destroys the YasminViewerNode and stops the web server.
Definition yasmin_viewer_node.cpp:221
void run_server()
Runs the embedded web server loop.
Definition yasmin_viewer_node.cpp:286
void start_server()
Starts the embedded web server thread.
Definition yasmin_viewer_node.cpp:260
std::string get_web_root() const
Returns the configured web root directory.
Definition yasmin_viewer_node.cpp:244
yasmin_msgs::msg::State StateMsg
Definition yasmin_viewer_node.hpp:80
std::unordered_map< std::string, CachedFsm > fsms_
Cache of serialized finite state machines indexed by name.
Definition yasmin_viewer_node.hpp:143
rclcpp::Subscription< StateMachineMsg >::SharedPtr fsm_sub_
Subscription for incoming state machine descriptions.
Definition yasmin_viewer_node.hpp:146
double max_age_seconds_
Maximum cache age in seconds before a finite state machine is removed.
Definition yasmin_viewer_node.hpp:155
std::string get_fsms_json() const
Returns the cached finite state machines as a JSON string.
Definition yasmin_viewer_node.cpp:223
void fsm_viewer_cb(const StateMachineMsg::SharedPtr msg)
Callback for incoming state machine messages.
Definition yasmin_viewer_node.cpp:246
YasminViewerNode()
Constructs the YasminViewerNode and initializes subscriptions, parameters, and the web server.
Definition yasmin_viewer_node.cpp:184
std::thread server_thread_
Background thread executing the embedded web server.
Definition yasmin_viewer_node.hpp:160
YasminViewerNode(const YasminViewerNode &)=delete
std::string web_root_
Root directory containing the web viewer files.
Definition yasmin_viewer_node.hpp:151
static std::string state_machine_to_json(const StateMachineMsg &msg)
Serializes a full state machine message into JSON.
Definition yasmin_viewer_node.cpp:410
yasmin_msgs::msg::Transition TransitionMsg
Definition yasmin_viewer_node.hpp:81
static std::string state_to_json(const StateMsg &state)
Serializes a state into JSON.
Definition yasmin_viewer_node.cpp:386
void prune_expired_locked(const std::chrono::steady_clock::time_point &now) const
Removes expired finite state machines from the cache.
Definition yasmin_viewer_node.cpp:315
yasmin_msgs::msg::StateMachine StateMachineMsg
Definition yasmin_viewer_node.hpp:79
static std::string transitions_to_json(const std::vector< TransitionMsg > &transitions)
Serializes a list of transitions into JSON.
Definition yasmin_viewer_node.cpp:368
int64_t port_
Port used by the embedded web server.
Definition yasmin_viewer_node.hpp:153
std::atomic_bool server_running_
Indicates whether the embedded web server is running.
Definition yasmin_viewer_node.hpp:158
YasminViewerNode & operator=(const YasminViewerNode &)=delete
Definition yasmin_viewer_node.hpp:34
Stores a serialized finite state machine and its last update time.
Definition yasmin_viewer_node.hpp:74
std::string json
Definition yasmin_viewer_node.hpp:75
std::chrono::steady_clock::time_point timestamp
Definition yasmin_viewer_node.hpp:76