Class TopicHandler

Inheritance Relationships

Derived Types

Class Documentation

class TopicHandler

Abstract interface for topic handlers.

Implement this interface to create custom handlers for specific topics. Each handler is responsible for:

  • Subscribing to its input topic

  • Processing messages (downsampling, transformation, etc.)

  • Publishing to Foxglove via the logger

Example implementation:

class MyCustomHandler : public TopicHandler {
 public:
  MyCustomHandler(rclcpp::Node* node, const HandlerConfig& config,
                  FoxgloveLogger* logger)
      : TopicHandler(node, config, logger) {
    // Setup subscription
  }

  std::string getName() const override { return "MyCustomHandler"; }

 protected:
  void processMessage(...) {
    stats_.messages_received++;
    // Custom processing logic
    if (shouldForward()) {
      // Forward to Foxglove
      stats_.messages_forwarded++;
    } else {
      stats_.messages_dropped++;
    }
  }
};

Subclassed by live_telemetry::CameraDataHandler, live_telemetry::PointCloudHandler

Public Functions

inline TopicHandler(rclcpp::Node *node, const HandlerConfig &config, FoxgloveLogger *logger)
virtual ~TopicHandler() = default
TopicHandler(const TopicHandler&) = delete
TopicHandler &operator=(const TopicHandler&) = delete
TopicHandler(TopicHandler&&) = delete
TopicHandler &operator=(TopicHandler&&) = delete
virtual std::string getName() const = 0

Get the handler name for logging and identification.

inline std::string getInputTopic() const

Get the input topic this handler is processing.

inline HandlerStats getStats() const

Get current handler statistics.

inline virtual bool isActive() const

Check if handler is active and processing messages.

Protected Functions

inline bool shouldForward() const

Helper to check if message should be forwarded based on downsample ratio.

inline void logVerbose(const std::string &message) const

Log a message if verbose mode is enabled.

Protected Attributes

rclcpp::Node *node_
HandlerConfig config_
FoxgloveLogger *logger_
HandlerStats stats_