Changeset 10:475d7a686fd6 in finroc_plugins_composite_ports


Ignore:
Timestamp:
21.03.2020 16:11:47 (12 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Adds support for inheritance among port composite interfaces (sub and superclass interfaces can be connected). Change also includes that connecting secondary backends (of port composite interfaces with multiple port types) will not connect the primary. This adds more flexibility/convenience w.r.t. connecting only parts of port composite interfaces.

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • examples/example.finroc

    r9 r10  
    2323  <edge src="Aggregator Coded/Sensor Output/Simple 2" dest="Group With User/Sensor Input/Simple 1"/> 
    2424  <edge src="Aggregator Coded/Sensor Output/Simple 3" dest="Group With User/Sensor Input/Simple 2"/> 
     25  <edge src="Aggregator/Sensor Output/Fancy 1" dest="Group With User/Sensor Input/I%2FO Interconnected"/> 
    2526  <edge src="Aggregator/Sensor Output/Fancy 2" dest="Group With User/Sensor Input/Fancy 2"/> 
    2627  <edge src="Aggregator/Sensor Output/Input Output Interface 4" dest="Group With User/Sensor Input/I%2FO Interface 3"/> 
  • examples/gUser.xml

    r9 r10  
    1212    <port name="Simple 3" type="finroc.composite_ports.examples.interfaces.Simple"/> 
    1313    <port name="Simple 4" type="finroc.composite_ports.examples.interfaces.Simple"/> 
     14    <port name="I/O Interconnected" type="finroc.composite_ports.examples.interfaces.InputOutput"/> 
    1415  </interface> 
    1516  <element name="Interface User" group="finroc_plugins_composite_ports_example" type="InterfaceUser"> 
  • tInterface.h

    r8 r10  
    104104 
    105105  typedef typename std::conditional<cCONVENIENCE_PORT, structure::tComponent*, core::tPortGroup*>::type tParent; 
     106  typedef tInterfaceBase tBase; 
    106107 
    107108//---------------------------------------------------------------------- 
  • tInterfaceBase.cpp

    r8 r10  
    389389void tInterfaceBase::tBackend::OnConnect(tAbstractPort& partner, bool partner_is_destination) 
    390390{ 
    391   if (&primary_backend != this) 
    392   { 
    393     primary_backend.OnConnect(partner, this->IsOutputPort() == primary_backend.IsOutputPort() ? partner_is_destination : (!partner_is_destination)); 
     391  if (primary_backend.operation_on_all_elements_pending) 
     392  { 
    394393    return; 
    395394  } 
    396   if (this->operation_on_all_elements_pending) 
    397   { 
    398     return; 
    399   } 
    400  
    401   this->operation_on_all_elements_pending = true; 
     395 
     396  tBackend& other = static_cast<tBackend&>(partner); 
     397  bool connect_all_backends = this->IsPrimaryBackend() && other.IsPrimaryBackend(); 
     398 
     399  primary_backend.operation_on_all_elements_pending = true; 
    402400  try 
    403401  { 
    404     tBackend& other = static_cast<tBackend&>(partner).primary_backend; 
    405     if (this->custom_connect_function) 
     402    if (primary_backend.custom_connect_function) 
    406403    { 
    407404      if (partner_is_destination) 
    408405      { 
    409         custom_connect_function(*this, other); 
     406        primary_backend.custom_connect_function(*this, other); 
    410407      } 
    411408      else 
    412409      { 
    413         custom_connect_function(other, *this); 
    414       } 
    415       this->operation_on_all_elements_pending = false; 
     410        primary_backend.custom_connect_function(other, *this); 
     411      } 
     412      primary_backend.operation_on_all_elements_pending = false; 
    416413      return; 
    417414    } 
    418415 
    419416    // Connect all matching backends and ports 
    420     for (auto this_backend : this->relation_backend_mapping) 
    421     { 
    422       for (auto other_backend : other.primary_backend.relation_backend_mapping) 
    423       { 
    424         if (this_backend.first - this->primary_relation_id == other_backend.first - other.primary_relation_id) 
     417    for (auto this_backend : primary_backend.relation_backend_mapping) 
     418    { 
     419      for (auto other_backend : other.primary_backend.primary_backend.relation_backend_mapping) 
     420      { 
     421        if (this_backend.first - primary_backend.primary_relation_id == other_backend.first - other.primary_backend.primary_relation_id && (connect_all_backends || this_backend.second == this || other_backend.second == &other)) 
    425422        { 
    426423          core::tConnectionFlag direction = (this->IsOutputPort() == this_backend.second->IsOutputPort() ? partner_is_destination : (!partner_is_destination)) ? core::tConnectionFlag::DIRECTION_TO_DESTINATION : core::tConnectionFlag::DIRECTION_TO_SOURCE; 
     
    435432    FINROC_LOG_PRINT(WARNING, "Connecting failed: ", e); 
    436433  } 
    437   this->operation_on_all_elements_pending = false; 
     434  primary_backend.operation_on_all_elements_pending = false; 
    438435} 
    439436 
  • tInterfaceType.h

    r0 r10  
    4848// Internal includes with "" 
    4949//---------------------------------------------------------------------- 
    50 #include "plugins/composite_ports/internal/tInterfaceTypeInfo.h" 
    51 #include "plugins/composite_ports/internal/tGenericPortType.h" 
     50#include "plugins/composite_ports/internal/tTypeInfo.h" 
    5251 
    5352//---------------------------------------------------------------------- 
     
    6261// Forward declarations / typedefs / enums 
    6362//---------------------------------------------------------------------- 
    64  
    65 /*! 
    66  * Port class that is suitable for generic instantiation of any interface 
    67  */ 
    68 template <typename T> 
    69 class tAnyPortType : public internal::tGenericPortType<0, data_ports::tPort, T, false> 
    70 { 
    71   using internal::tGenericPortType<0, data_ports::tPort, T, false>::tGenericPortType; 
    72 }; 
    7363 
    7464//---------------------------------------------------------------------- 
     
    9181 
    9282  typedef TInterface<tAnyPortType> tGeneric; 
     83  typedef internal::tTypeInfo<tGeneric> tHolder; 
    9384 
    9485  tInterfaceType() : 
    95     rrlib::rtti::tType(&cTYPE_INFO) 
     86    rrlib::rtti::tType(&tHolder::cTYPE_INFO) 
    9687  { 
    9788  } 
     
    9990  template <size_t Tchars> 
    10091  tInterfaceType(const char(&name)[Tchars]) : 
    101     rrlib::rtti::tType(&cTYPE_INFO) 
     92    rrlib::rtti::tType(&tHolder::cTYPE_INFO) 
    10293  { 
    103     GetSharedInfo().SetName(rrlib::util::tManagedConstCharPointer(name, false), &cTYPE_INFO); 
     94    GetSharedInfo().SetName(rrlib::util::tManagedConstCharPointer(name, false), &tHolder::cTYPE_INFO); 
    10495  } 
    10596 
    10697  template <typename ... TFunctions> 
    10798  tInterfaceType(const std::string& name) : 
    108     rrlib::rtti::tType(&cTYPE_INFO) 
     99    rrlib::rtti::tType(&tHolder::cTYPE_INFO) 
    109100  { 
    110     GetSharedInfo().SetName(rrlib::util::tManagedConstCharPointer(name.c_str(), true), &cTYPE_INFO); 
     101    GetSharedInfo().SetName(rrlib::util::tManagedConstCharPointer(name.c_str(), true), &tHolder::cTYPE_INFO); 
    111102  } 
    112103 
     
    116107private: 
    117108 
    118   /*! Shared Type Info for this type */ 
    119   static internal::tInterfaceTypeInfo shared_info; 
    120  
    121   /*! Type info for this type */ 
    122   static constexpr rrlib::rtti::detail::tTypeInfo cTYPE_INFO = { typeid(tGeneric), static_cast<uint>(rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE), &rrlib::rtti::detail::tTypeInfo::cNULL_TYPE_INFO, &rrlib::rtti::detail::tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(tGeneric) }; 
    123  
    124   /*! Generic create function */ 
    125   static tInterfaceBase Create(const std::string& name, core::tPortGroup* parent) 
    126   { 
    127     return tGeneric(name, parent); 
    128   } 
    129  
    130109}; 
    131  
    132  
    133 template <template <template <typename> class TPrimaryPort, template <typename> class ... TSecondaryPorts> class TInterface> 
    134 constexpr rrlib::rtti::detail::tTypeInfo tInterfaceType<TInterface>::cTYPE_INFO; 
    135  
    136 template <template <template <typename> class TPrimaryPort, template <typename> class ... TSecondaryPorts> class TInterface> 
    137 internal::tInterfaceTypeInfo tInterfaceType<TInterface>::shared_info(&tInterfaceType<TInterface>::cTYPE_INFO, &tInterfaceType<TInterface>::Create, 0); 
    138110 
    139111//---------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.