Changeset 165:5acc3b62811d in finroc_plugins_data_ports


Ignore:
Timestamp:
15.09.2020 16:03:56 (2 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Phase:
public
Message:

Adds function to register optional callback on port buffer allocation

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • common/tAbstractDataPort.cpp

    r151 r165  
    7373// Implementation 
    7474//---------------------------------------------------------------------- 
     75 
     76tBufferAllocationCallbackFunction tAbstractDataPort::buffer_allocation_callback_function = nullptr; 
    7577 
    7678tAbstractDataPort::tAbstractDataPort(const tAbstractDataPortCreationInfo& create_info) : 
  • common/tAbstractDataPort.h

    r151 r165  
    6969class tPullOperation; 
    7070 
     71typedef void(*tBufferAllocationCallbackFunction)(const rrlib::rtti::tType& type, size_t size); 
     72 
    7173//---------------------------------------------------------------------- 
    7274// Class declaration 
     
    170172 
    171173  /*! 
     174   * Notifies any registered callback on buffer allocation 
     175   * 
     176   * \param type Type of buffer that was allocated (optional) 
     177   * \param size Size of buffer that was allocated 
     178   * \param origin Address of object that allocated buffer 
     179   */ 
     180  static inline void NotifyBufferAllocation(const rrlib::rtti::tType& type, size_t size) 
     181  { 
     182    if (buffer_allocation_callback_function) 
     183    { 
     184      (*buffer_allocation_callback_function)(type, size); 
     185    } 
     186  } 
     187 
     188  /*! 
    172189   * \return Is data to this port pushed or pulled? 
    173190   */ 
     
    185202  { 
    186203    changed = static_cast<int8_t>(tChangeStatus::NO_CHANGE); 
     204  } 
     205 
     206  /*! 
     207   * Sets callback function for buffer allocation 
     208   * 
     209   * \param function Function 
     210   */ 
     211  static void SetBufferAllocationCallbackFunction(tBufferAllocationCallbackFunction function) 
     212  { 
     213    buffer_allocation_callback_function = function; 
    187214  } 
    188215 
     
    333360  common::tPortListenerRaw* port_listener; 
    334361 
     362  /*! Called when buffers are allocated in ports */ 
     363  static tBufferAllocationCallbackFunction buffer_allocation_callback_function; 
    335364 
    336365  /*! 
  • optimized/tCheaplyCopiedBufferManager.cpp

    r123 r165  
    3737// Internal includes with "" 
    3838//---------------------------------------------------------------------- 
     39#include "plugins/data_ports/common/tAbstractDataPort.h" 
    3940 
    4041//---------------------------------------------------------------------- 
     
    8687  memset(placement + sizeof(tCheaplyCopiedBufferManager), 0, buffer_size); 
    8788  rrlib::rtti::tDataType<int>().EmplaceGenericObject(placement + sizeof(tCheaplyCopiedBufferManager)).release();  // Type is adjusted later 
     89  common::tAbstractDataPort::NotifyBufferAllocation(rrlib::rtti::tType(), buffer_size); 
    8890  return new(placement) tCheaplyCopiedBufferManager(); 
    8991} 
  • optimized/tThreadLocalBufferManager.cpp

    r123 r165  
    3838//---------------------------------------------------------------------- 
    3939#include "plugins/data_ports/optimized/tThreadLocalBufferPools.h" 
     40#include "plugins/data_ports/common/tAbstractDataPort.h" 
    4041 
    4142//---------------------------------------------------------------------- 
     
    8687  memset(placement + sizeof(tThreadLocalBufferManager), 0, buffer_size); 
    8788  rrlib::rtti::tDataType<int>().EmplaceGenericObject(placement + sizeof(tCheaplyCopiedBufferManager)).release();  // Type is adjusted later 
     89  common::tAbstractDataPort::NotifyBufferAllocation(rrlib::rtti::tType(), buffer_size); 
    8890  return new(placement) tThreadLocalBufferManager(); 
    8991} 
  • standard/tPortBufferManager.cpp

    r106 r165  
    3737// Internal includes with "" 
    3838//---------------------------------------------------------------------- 
     39#include "plugins/data_ports/common/tAbstractDataPort.h" 
    3940 
    4041//---------------------------------------------------------------------- 
     
    7172tPortBufferManager::tPortBufferManager() : 
    7273  unused(true), 
    73   derived_from(NULL), 
    7474  compression_status(0), 
    7575  compressed_data() 
     
    8686  char* placement = (char*)operator new(sizeof(tPortBufferManager) + type.GetSize(true)); 
    8787  type.EmplaceGenericObject(placement + sizeof(tPortBufferManager)).release(); 
     88  common::tAbstractDataPort::NotifyBufferAllocation(type, type.GetSize()); 
    8889  return new(placement) tPortBufferManager(); 
    8990} 
  • standard/tPortBufferManager.h

    r88 r165  
    100100   * Later, compression might be required for network connections or recording. 
    101101   * Instead of recompressing the data, the original can be used. 
    102    * Must be called, before buffer is pusblished. 
     102   * Must be called, before buffer is published. 
    103103   * 
    104104   * Note: if Finroc data_compression plugin is not available, the data is discarded. 
     
    173173  bool unused; 
    174174 
    175   /*! PortDataManager that this manager is derived from - null if not derived */ 
    176   tPortBufferManager* derived_from; 
    177  
    178175  friend class data_compression::tPlugin; 
    179176 
Note: See TracChangeset for help on using the changeset viewer.