Changeset 16:7846a42aed44 in finroc_plugins_composite_ports


Ignore:
Timestamp:
08.05.2020 12:22:41 (2 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Tags:
tip
Message:

Extends port composite interfaces to fully support RPC ports

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • internal/tGenericPortType.h

    r0 r16  
    132132 
    133133template <int Tprimary_interface_relations, template <typename> class TPortType, typename T> 
     134class tGenericPortType<Tprimary_interface_relations, TPortType, T, true, false> : public TPortType<T> 
     135{ 
     136 
     137//---------------------------------------------------------------------- 
     138// Public methods and typedefs 
     139//---------------------------------------------------------------------- 
     140public: 
     141 
     142  static_assert(std::is_base_of<rpc_ports::tRPCInterface, T>::value, "Invalid"); 
     143 
     144  template <typename TParent, typename ... TRest> 
     145  tGenericPortType(const std::string& name, TParent* parent, const TRest&... rest) 
     146  { 
     147    if (!parent->Backend())  // When used for type id extraction 
     148    { 
     149      return; 
     150    } 
     151 
     152    tInterfaceBase::tBackend* parent_backend = parent->Backend()->GetBackend(Tprimary_interface_relations); 
     153    // Create port instance via factory 
     154    core::tFrameworkElementFlags extra_flags = parent_backend->CreateOutputPort(Tprimary_interface_relations) ? (core::tFrameworkElementFlag::OUTPUT_PORT | core::tFrameworkElementFlag::EMITS_DATA) : (core::tFrameworkElementFlag::ACCEPTS_DATA | core::tFrameworkElementFlag::PORT); 
     155    this->SetWrapped(core::tPortFactory::CreatePort(name, *parent_backend, rrlib::rtti::tType::FindTypeByRtti(typeid(T).name()), parent_backend->GetDefaultPortFlags(true) | extra_flags)); 
     156  } 
     157 
     158//---------------------------------------------------------------------- 
     159// Private fields and methods 
     160//---------------------------------------------------------------------- 
     161private: 
     162 
     163}; 
     164 
     165 
     166template <int Tprimary_interface_relations, template <typename> class TPortType, typename T> 
    134167class tGenericPortType<Tprimary_interface_relations, TPortType, T, true, true> : public TPortType<T> 
    135168{ 
    136169 
    137 //---------------------------------------------------------------------- 
    138 // Public methods and typedefs 
    139 //---------------------------------------------------------------------- 
    140 public: 
    141  
    142   template <typename TParent, typename ... TRest> 
    143   tGenericPortType(const std::string& name, TParent* parent, const TRest&... rest) 
    144   { 
    145     if (!parent->Backend())  // When used for type id extraction 
    146     { 
    147       return; 
    148     } 
    149  
    150     tInterfaceBase::tBackend* parent_backend = parent->Backend()->GetBackend(Tprimary_interface_relations); 
    151     // Create port instance via factory 
    152     this->SetWrapped(core::tPortFactory::CreatePort(name, *parent_backend, rrlib::rtti::tType::FindTypeByRtti(typeid(T).name()), parent_backend->GetDefaultPortFlags(false))); 
     170  static_assert(std::is_base_of<rpc_ports::tRPCInterface, T>::value, "Invalid"); 
     171 
     172//---------------------------------------------------------------------- 
     173// Public methods and typedefs 
     174//---------------------------------------------------------------------- 
     175public: 
     176 
     177  template <typename TParent, typename ... TRest> 
     178  tGenericPortType(const std::string& name, TParent* parent, TRest&&... rest) 
     179  { 
     180    if (!parent->Backend())  // When used for type id extraction 
     181    { 
     182      return; 
     183    } 
     184 
     185    tInterfaceBase::tBackend* parent_backend = parent->Backend()->GetBackend(Tprimary_interface_relations); 
     186    static_cast<TPortType<T>&>(*this) = TPortType<T>(name, parent_backend, parent_backend->GetDefaultPortFlags(false), std::forward<TRest>(rest)...); 
    153187  } 
    154188 
  • internal/type_traits.h

    r6 r16  
    9191  ePTR_PARAMETER, 
    9292  ePTR_COUNTER_PART, 
    93   ePTR_COUNTER_PART_PARAMETER_IF_INPUT 
     93  ePTR_COUNTER_PART_PARAMETER_IF_INPUT, 
     94  ePTR_SERVER_IF_INPUT, 
     95  ePTR_CLIENT_IF_INPUT 
    9496}; 
    9597 
     
    110112struct IsRPCPort 
    111113{ 
    112   enum { value = !std::is_base_of<data_ports::tPort<tTestType>, TPortType<tTestType>>::value }; 
     114  enum { value = (!std::is_base_of<data_ports::tPort<tTestType>, TPortType<tTestType>>::value) && (!std::is_base_of<parameters::tParameter<tTestType>, TPortType<tTestType>>::value) }; 
    113115}; 
    114116 
     
    137139struct IsInputPort 
    138140{ 
    139   enum { value = std::is_base_of<data_ports::tInputPort<double>, TPortType<double>>::value  || 
    140          std::is_base_of<data_ports::tProxyPort<double, false>, TPortType<double>>::value 
     141  enum { value = std::is_base_of<data_ports::tInputPort<double>, TPortType<double>>::value || 
     142         std::is_base_of<data_ports::tProxyPort<double, false>, TPortType<double>>::value || 
     143         std::is_base_of<parameters::tParameter<double>, TPortType<double>>::value 
    141144       }; 
    142145}; 
     
    226229using MakeCounterPartParameterIfInput = MakeCounterDirectionPort<TPort, true>; 
    227230 
     231template <template <typename> class TPort, bool TServer> 
     232struct MakeRPCPort 
     233{ 
     234  template <typename T> 
     235  using base_type = typename std::conditional < std::is_base_of<data_ports::tProxyPort<tTestType, false>, TPort<tTestType>>::value || std::is_base_of<data_ports::tProxyPort<tTestType, true>, TPort<tTestType>>::value, rpc_ports::tProxyPort<T, false>, rpc_ports::tClientPort<T >>::type; 
     236 
     237  template <typename T> 
     238  using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; 
     239}; 
     240template <template <typename> class TPort> 
     241struct MakeRPCPort<TPort, true> 
     242{ 
     243  template <typename T> 
     244  using base_type = typename std::conditional < std::is_base_of<data_ports::tProxyPort<tTestType, false>, TPort<tTestType>>::value || std::is_base_of<data_ports::tProxyPort<tTestType, true>, TPort<tTestType>>::value, rpc_ports::tProxyPort<T, true>, rpc_ports::tServerPort<T >>::type; 
     245 
     246  template <typename T> 
     247  using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; 
     248}; 
     249 
     250template <template <typename> class TPort> 
     251using MakeServerIfInput = MakeRPCPort<TPort, IsInputPort<TPort>::value>; 
     252template <template <typename> class TPort> 
     253using MakeClientIfInput = MakeRPCPort<TPort, IsOutputPort<TPort>::value>; 
     254 
    228255 
    229256template <typename TPort> 
  • tInterface.h

    r10 r16  
    8181template <template <typename> class TPortType> 
    8282using tCounterPartParameterInputs = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_COUNTER_PART_PARAMETER_IF_INPUT, TPortType, internal::MakeCounterPartParameterIfInput>; //::template base_port; 
     83 
     84template <template <typename T> class TPortType> 
     85using tServerIfInput = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_SERVER_IF_INPUT, TPortType, internal::MakeServerIfInput>; 
     86template <template <typename T> class TPortType> 
     87using tClientIfInput = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_CLIENT_IF_INPUT, TPortType, internal::MakeClientIfInput>; 
    8388 
    8489} 
  • tInterfaceBase.cpp

    r15 r16  
    105105        (*extend_with_default_ports_flags) |= tFlag::EMITS_DATA | tFlag::ACCEPTS_DATA; 
    106106      } 
     107      if (element.GetFlag(tFlag::INTERFACE_FOR_RPC_PORTS)) 
     108      { 
     109        (*extend_with_default_ports_flags) |= tFlag::EMITS_DATA | tFlag::ACCEPTS_DATA; 
     110      } 
    107111    } 
    108112    return &element; 
     
    210214    if (other_port && other_port->IsPort()) 
    211215    { 
    212       port->ConnectTo(static_cast<core::tAbstractPort&>(*other_port), connect_options); 
    213     } 
    214   } 
     216      if (port->GetDataType().GetTypeClassification() == rrlib::rtti::tTypeClassification::RPC_TYPE) 
     217      { 
     218        auto option_copy = connect_options; 
     219        option_copy.flags.Set(core::tConnectionFlag::DIRECTION_TO_SOURCE, false); 
     220        option_copy.flags.Set(core::tConnectionFlag::DIRECTION_TO_DESTINATION, false); 
     221        port->ConnectTo(static_cast<core::tAbstractPort&>(*other_port), option_copy); 
     222      } 
     223      else 
     224      { 
     225        port->ConnectTo(static_cast<core::tAbstractPort&>(*other_port), connect_options); 
     226      } 
     227    } 
     228  } 
     229} 
     230 
     231bool tInterfaceBase::tBackend::CreateOutputPort(int primary_relation_id) 
     232{ 
     233  auto* backend = GetBackend(primary_relation_id); 
     234  if (backend->GetFlag(tFlag::INTERFACE_FOR_OUTPUTS)) 
     235  { 
     236    return true; 
     237  } 
     238  if (backend->GetFlag(tFlag::INTERFACE_FOR_INPUTS) || backend->GetFlag(tFlag::PARAMETER_INTERFACE)) 
     239  { 
     240    return false; 
     241  } 
     242  if (backend->GetFlag(tFlag::INTERFACE_FOR_RPC_PORTS)) 
     243  { 
     244    int last_relation = primary_relation_id & 0xFF; 
     245    bool derived_from_backend_is_output = CreateOutputPort(primary_relation_id >> 8); 
     246    if (last_relation == internal::tPortTypeRelation::ePTR_CLIENT_IF_INPUT) 
     247    { 
     248      return !derived_from_backend_is_output; 
     249    } 
     250    else if (last_relation == internal::tPortTypeRelation::ePTR_SERVER_IF_INPUT) 
     251    { 
     252      return derived_from_backend_is_output; 
     253    } 
     254  } 
     255  throw std::runtime_error("Unpecified port direction"); 
    215256} 
    216257 
     
    340381        target_unset_flags = core::tFrameworkElementFlags(); 
    341382        break; 
     383      case internal::tPortTypeRelation::ePTR_SERVER_IF_INPUT: 
     384      case internal::tPortTypeRelation::ePTR_CLIENT_IF_INPUT: 
     385        target_set_flags = tFlag::INTERFACE_FOR_RPC_PORTS; 
     386        target_unset_flags = core::tFrameworkElementFlags(); 
     387        break; 
    342388      default: 
    343389        break; 
  • tInterfaceBase.h

    r13 r16  
    280280     * (called by tGenericPortType) 
    281281     * \param primary_relation_id Relation id to primary port type 
     282     * \return Whether port with this relation is an output (or client) port 
     283     */ 
     284    bool CreateOutputPort(int primary_relation_id); 
     285 
     286    /*! 
     287     * (called by tGenericPortType) 
     288     * \param primary_relation_id Relation id to primary port type 
    282289     * \return Backend with specified index 
    283290     */ 
     
    346353        return &module->GetParameters(); 
    347354      } 
     355      else if (required_flags.Get(tFlag::INTERFACE_FOR_RPC_PORTS)) 
     356      { 
     357        return &module->GetServices(); 
     358      } 
    348359      return nullptr; 
    349360    } 
     
    376387        return &module->GetParameters(); 
    377388      } 
     389      else if (required_flags.Get(tFlag::INTERFACE_FOR_RPC_PORTS)) 
     390      { 
     391        return &module->GetServices(); 
     392      } 
    378393      return nullptr; 
    379394    } 
Note: See TracChangeset for help on using the changeset viewer.