Changeset 186:bf8a796dc6b6 in finroc_plugins_data_ports


Ignore:
Timestamp:
08.02.2022 07:36:55 (10 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Tags:
tip
Message:

Adds extended destination buffer pointer type to tConversionConnector - providing additional settings with respect to published buffer to conversion operations (makes it possible, for example, to set output buffer timestamp if input buffer contains multiple).

Location:
common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/tConversionConnector.cpp

    r173 r186  
    7272tConversionConnector::tConversionConnector(core::tAbstractPort& source_port, core::tAbstractPort& destination_port, const core::tConnectOptions& connect_options) : 
    7373  tConnector(source_port, destination_port, connect_options, conversion_operation), 
    74   conversion_operation(connect_options.conversion_operations.Compile(false, source_port.GetDataType(), destination_port.GetDataType())) 
     74  conversion_operation(connect_options.conversion_operations.Compile(false, source_port.GetDataType(), destination_port.GetDataType(), typeid(tDestinationPointer))) 
    7575{ 
    7676  static_assert(sizeof(destination_port_generic_memory) == sizeof(tGenericPort), "Adjust array size"); 
     
    8282{} 
    8383 
    84 void tConversionConnector::Publish(const rrlib::rtti::tGenericObject& input_data, const rrlib::time::tTimestamp& timestamp, tChangeStatus change_constant) const 
     84void tConversionConnector::Publish(const rrlib::rtti::tGenericObject& input_data, const rrlib::time::tTimestamp& input_timestamp, tChangeStatus change_constant) const 
    8585{ 
    8686  try 
     
    8888    tGenericPort& generic_port = const_cast<tGenericPort&>(reinterpret_cast<const tGenericPort&>(destination_port_generic_memory[0])); 
    8989    tPortDataPointer<rrlib::rtti::tGenericObject> buffer = generic_port.GetUnusedBuffer(); 
    90     buffer.SetTimestamp(timestamp); 
    91     conversion_operation.Convert(input_data, *buffer); 
    92     generic_port.BrowserPublish(buffer, true, change_constant); 
     90    rrlib::time::tTimestamp timestamp = input_timestamp; 
     91    bool skip = false; 
     92    tDestinationPointer destination_pointer(*buffer, timestamp, skip); 
     93    conversion_operation.Convert(input_data, destination_pointer); 
     94    if (!skip) 
     95    { 
     96      buffer.SetTimestamp(timestamp); 
     97      generic_port.BrowserPublish(buffer, true, change_constant); 
     98    } 
    9399  } 
    94100  catch (const std::exception& e) 
  • common/tConversionConnector.h

    r173 r186  
    9696 
    9797 
     98  /*! Destination Pointer used in tConversionConnector 
     99   * 
     100   * Provides additional settings with respect to published buffer to conversion operations 
     101   */ 
     102  class tDestinationPointer : public rrlib::rtti::tTypedPointer 
     103  { 
     104  public: 
     105 
     106    tDestinationPointer(const tTypedPointer& pointer, rrlib::time::tTimestamp& timestamp, bool& skip) : 
     107      tTypedPointer(pointer), 
     108      timestamp(timestamp), 
     109      skip(skip) 
     110    {} 
     111 
     112    // Convenience constructor for use in conversion operation implementations' first conversion function 
     113    tDestinationPointer(const tTypedPointer& pointer, const tDestinationPointer& share_additional_settings_with) : 
     114      tDestinationPointer(pointer, share_additional_settings_with.timestamp, share_additional_settings_with.skip) 
     115    {} 
     116 
     117 
     118    /*! 
     119     * \return Destination timestamp 
     120     */ 
     121    rrlib::time::tTimestamp& Timestamp() const 
     122    { 
     123      return timestamp; 
     124    } 
     125 
     126    /*! 
     127     * \return Whether to skip converting this value 
     128     */ 
     129    bool& Skip() const 
     130    { 
     131      return skip; 
     132    } 
     133 
     134  private: 
     135 
     136    /*! Destination timestamp (set to timestamp input data buffer by default) */ 
     137    rrlib::time::tTimestamp& timestamp; 
     138 
     139    /*! Whether to skip converting this value (without printing a warning; similar but somewhat more efficient than throwing tSilentConversionException) */ 
     140    bool& skip; 
     141  }; 
     142 
    98143  class tSilentConversionException : public std::exception 
    99 {}; 
     144  { 
     145  }; 
    100146 
    101147//---------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.