27#include <condition_variable>
30#include <shared_mutex>
34#include <tf2_ros/buffer.h>
35#include <tf2_ros/transform_listener.h>
36#include <rclcpp/rclcpp.hpp>
38#include "event_detector/DifferenceBasedBuffer.hpp"
39#include "event_detector/common.hpp"
89 void update(
const std::vector<ClientConnection>& clients);
103 void insert(
const typename std::shared_ptr<const T>& sample,
const rclcpp::Time& stamp,
104 const std::string& client_id,
const std::string& topic,
105 const bool clear_if_time_is_running_backwards =
true);
121 std::vector<std::string>
getFrames(
const std::string& client_id);
137 std::vector<Stamped<T>>
get(
const std::string& client_id =
"",
const std::string& frame_id =
"",
138 const std::string& topic =
"");
157 std::vector<Stamped<T>>
get(
const int k,
const std::string& client_id =
"",
const std::string& frame_id =
"",
158 const std::string& topic =
"");
178 std::vector<Stamped<T>>
get(
const rclcpp::Time& start_time,
const rclcpp::Time& end_time,
179 const std::string& client_id =
"",
const std::string& frame_id =
"",
180 const std::string& topic =
"");
202 std::vector<Stamped<T>>
get(
const int k,
const rclcpp::Time& start_time,
const rclcpp::Time& end_time,
203 const std::string& client_id =
"",
const std::string& frame_id =
"",
204 const std::string& topic =
"");
217 string_map<std::vector<Stamped<T>>>
getWithTopic(
const int k,
const rclcpp::Time& start_time,
218 const rclcpp::Time& end_time,
const std::string& client_id =
"",
219 const std::string& frame_id =
"",
const std::string& topic =
"");
234 void clearBuffer(
const std::string& client_id,
const std::string& topic);
331#define DATATYPE(TYPE, VAR) \
333 DataBuffers<TYPE> VAR;
334#include "event_detector/datatypes.macro"
340#include "event_detector/BufferManager.tpp"
Ring-buffer-like container for keeping only values within a fixed range of a secondary index paramete...
Template class designed to hold all buffers for a specific data type.
string_map_2d< rclcpp::Time > last_stamp_by_client_topic_
container to store the last time stamp for each client and topic
std::string getInfo() const
Returns a string representation of the buffers that are currently present.
string_map< std::vector< Stamped< T > > > getWithTopic(const int k, const rclcpp::Time &start_time, const rclcpp::Time &end_time, const std::string &client_id="", const std::string &frame_id="", const std::string &topic="")
Same as corresponding get, but returns samples grouped by topic.
void setBufferManager(BufferManager *manager)
Assigns the managing BufferManager.
string_map_2d< Buffer< std::shared_ptr< const T > > > buffer_by_client_topic_
container for data buffers, stored by client ID and topic
std::shared_mutex reconfigure_mutex_
std::vector< std::string > getFrames(const std::string &client_id)
Gets the frame IDs for a specific client that has buffered data.
std::vector< Stamped< T > > get(const int k, const rclcpp::Time &start_time, const rclcpp::Time &end_time, const std::string &client_id="", const std::string &frame_id="", const std::string &topic="")
Fetches most recent k buffer samples within specified timeframe.
void insert(const typename std::shared_ptr< const T > &sample, const rclcpp::Time &stamp, const std::string &client_id, const std::string &topic, const bool clear_if_time_is_running_backwards=true)
Inserts a new ROS message into the buffer.
std::vector< Stamped< T > > get(const int k, const std::string &client_id="", const std::string &frame_id="", const std::string &topic="")
Fetches most recent k buffer samples.
void clearBuffer(const std::string &client_id, const std::string &topic)
Clears buffer for a specific client and topic.
string_map_2d< std::string > frame_by_client_topic_
container to store frame ID by client ID and topic
bool timeIsRunningBackwards(const std::string &client_id, const std::string &topic, const rclcpp::Time &stamp)
Checks whether time is running backwards for a specific client and topic.
std::vector< Stamped< T > > get(const std::string &client_id="", const std::string &frame_id="", const std::string &topic="")
Fetches all buffer samples.
std::vector< Stamped< T > > get(const rclcpp::Time &start_time, const rclcpp::Time &end_time, const std::string &client_id="", const std::string &frame_id="", const std::string &topic="")
Fetches all buffer samples within specified timeframe.
std::vector< std::string > getClients()
Gets the clients IDs that have buffered data.
string_map_2d< std::shared_ptr< std::shared_mutex > > mutex_by_client_topic_
container to store mutexes for locking buffer access
DataBuffers()
Creates a new DataBuffers instance.
BufferManager * manager_
managing BufferManager
void update(const std::vector< ClientConnection > &clients)
Creates buffers and mutexes for topics mentioned in clients. If a buffer and mutex already exists for...
Component of the Event Detector responsible for buffering live data.
std::mutex buffer_lock_mutex_
mutex for locking all buffer access
BufferManager()
Creates a new BufferManager.
void lockBuffers(const bool is_write)
Locks all buffers for either write or read mode.
std::string getInfo() const
Returns a string representation of all buffers that are currently present.
std::condition_variable buffer_lock_condition_variable_
condition variable to lock write/read buffer access
void unlockBuffers(const bool is_write)
Unlocks all buffers for either write or read mode.
int buffer_lock_n_threads_
helper variable to count threads in write/read buffer access mode