@@ -35,7 +35,7 @@ enum class PortKind { DATA, CONTROL };
3535// Base operator class
3636class Operator {
3737 public:
38- Operator (std::string id) : id_(std::move(id)) {}
38+ Operator (std::string id) : id_(std::move(id)), max_size_per_port_( 17280 ) {}
3939 virtual ~Operator () = default ;
4040
4141 virtual std::string type_name () const = 0;
@@ -156,9 +156,10 @@ class Operator {
156156 size_t num_data_ports () const { return data_ports_.size (); }
157157 size_t num_control_ports () const { return control_ports_.size (); }
158158 size_t num_output_ports () const { return output_ports_.size (); }
159+ size_t max_size_per_port () const { return max_size_per_port_; }
159160
160161 // Runtime port access for data with type checking
161- virtual void receive_data (std::unique_ptr<BaseMessage> msg, size_t port_index) {
162+ virtual timestamp_t receive_data (std::unique_ptr<BaseMessage> msg, size_t port_index) {
162163 if (port_index >= data_ports_.size ()) {
163164 throw std::runtime_error (" Invalid data port index at " + type_name () + " (" + id_ + " )" + " :" +
164165 std::to_string (port_index));
@@ -183,8 +184,17 @@ class Operator {
183184 RTBOT_RECORD_MESSAGE (id_, type_name (), std::move (msg->clone ()));
184185#endif
185186
187+ timestamp_t time_dequeued = -1 ;
188+
189+ if (data_ports_[port_index].queue .size () == max_size_per_port_) {
190+ time_dequeued = data_ports_[port_index].queue .front ()->time ;
191+ data_ports_[port_index].queue .pop_front ();
192+ }
193+
186194 data_ports_[port_index].queue .push_back (std::move (msg));
187195 data_ports_with_new_data_.insert (port_index);
196+
197+ return time_dequeued;
188198 }
189199
190200 virtual void reset () {
@@ -247,7 +257,7 @@ class Operator {
247257 }
248258
249259 // Runtime port access for control messages with type checking
250- virtual void receive_control (std::unique_ptr<BaseMessage> msg, size_t port_index) {
260+ virtual timestamp_t receive_control (std::unique_ptr<BaseMessage> msg, size_t port_index) {
251261 if (port_index >= control_ports_.size ()) {
252262 throw std::runtime_error (" Invalid control port index at " + type_name () + " (" + id_ + " )" + " :" +
253263 std::to_string (port_index));
@@ -269,8 +279,17 @@ class Operator {
269279 // Update last timestamp
270280 control_ports_[port_index].last_timestamp = msg->time ;
271281
282+ timestamp_t time_dequeued = -1 ;
283+
284+ if (control_ports_[port_index].queue .size () == max_size_per_port_) {
285+ time_dequeued = control_ports_[port_index].queue .front ()->time ;
286+ control_ports_[port_index].queue .pop_front ();
287+ }
288+
272289 control_ports_[port_index].queue .push_back (std::move (msg));
273290 control_ports_with_new_data_.insert (port_index);
291+
292+ return time_dequeued;
274293 }
275294
276295 std::shared_ptr<Operator> connect (std::shared_ptr<Operator> child, size_t output_port = 0 ,
@@ -417,6 +436,7 @@ class Operator {
417436 std::vector<Connection> connections_;
418437 std::set<size_t > data_ports_with_new_data_;
419438 std::set<size_t > control_ports_with_new_data_;
439+ std::size_t max_size_per_port_;
420440};
421441
422442} // namespace rtbot
0 commit comments