Changeset 23:3c9cac2a0cc1 in finroc_plugins_composite_ports
- Timestamp:
- 20.03.2021 11:51:25 (23 months ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
internal/tGenericPortType.h
r17 r23 128 128 assert(creation_info.data_type); 129 129 130 data_ports::tGenericPort port(creation_info); 131 this->SetWrapped(port.GetWrapped()); 130 this->SetWrapped(parent_backend->CreatePort(creation_info, Tprimary_interface_relations)); 132 131 } 133 132 … … 166 165 // Create port instance via factory 167 166 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); 168 this->SetWrapped(core::tPortFactory::CreatePort(name, *parent_backend, rrlib::rtti::tType::FindTypeByRtti(typeid(T).name()), parent_backend->GetDefaultPortFlags(true) | extra_flags)); 167 core::tAbstractPortCreationInfo creation_info; 168 creation_info.name = name; 169 creation_info.parent = parent_backend; 170 creation_info.data_type = rrlib::rtti::tType::FindTypeByRtti(typeid(T).name()); 171 creation_info.flags = parent_backend->GetDefaultPortFlags(true) | extra_flags; 172 this->SetWrapped(parent_backend->CreatePort(creation_info, Tprimary_interface_relations)); 169 173 } 170 174 -
internal/tInterfaceTypeInfo.cpp
r17 r23 39 39 // Internal includes with "" 40 40 //---------------------------------------------------------------------- 41 #include "plugins/composite_ports/interface_types.h" 41 42 42 43 //---------------------------------------------------------------------- -
internal/tInterfaceTypeInfo.h
r17 r23 111 111 auto name = GenerateName(typeid(TInterface).name()); 112 112 rrlib::rtti::tType type = rrlib::rtti::tType::FindType(name.Get()); 113 return type && IsInterfaceType(type)? type : rrlib::rtti::tType();113 return type.GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE ? type : rrlib::rtti::tType(); 114 114 } 115 115 … … 141 141 rrlib::rtti::detail::tTypeInfo* type_info_partial = nullptr; 142 142 143 /*! Pointer to full type info this interface type has a partial type info*/143 /*! Pointer to full type info (possibly relevant if this interface type has a partial type info) */ 144 144 const rrlib::rtti::detail::tTypeInfo* type_info_full = nullptr; 145 145 -
internal/type_traits.h
r22 r23 93 93 ePTR_COUNTER_PART_PARAMETER_IF_INPUT, 94 94 ePTR_SERVER_IF_INPUT, 95 ePTR_CLIENT_IF_INPUT 95 ePTR_CLIENT_IF_INPUT, 96 ePTR_DIMENSION 96 97 }; 97 98 -
tInterfaceBase.cpp
r22 r23 43 43 #include "plugins/composite_ports/internal/tInterfaceTypeInfo.h" 44 44 #include "plugins/composite_ports/internal/type_traits.h" 45 #include "plugins/composite_ports/tInterfaceModifier.h" 45 46 46 47 //---------------------------------------------------------------------- … … 77 78 namespace 78 79 { 80 81 const tInterfaceModifier::tImplementation cMODIFIER_DEFAULT_IMPLEMENTATION; 79 82 80 83 const core::tFrameworkElement* GetAggregator(const core::tFrameworkElement& element, core::tFrameworkElementFlags* extend_with_default_ports_flags = nullptr) … … 113 116 } 114 117 return element.GetParent() ? GetAggregator(*element.GetParent(), extend_with_default_ports_flags) : nullptr; 118 } 119 120 tInterfaceBase::tPrimaryPortType ModifierDefinesPartialInterface(const core::tFrameworkElement& parent_interface, const rrlib::rtti::tType& interface_type) 121 { 122 if ((!parent_interface.IsPort()) && parent_interface.GetFlag(tFlag::INTERFACE) && internal::IsComponent(parent_interface.GetParent())) 123 { 124 tInterfaceModifier* interface_modifier = parent_interface.GetParent()->GetAnnotation<tInterfaceModifier>(); 125 if (interface_modifier) 126 { 127 return interface_modifier->Implementation().PartialInterface(interface_type); 128 } 129 } 130 return tInterfaceBase::tPrimaryPortType::ANY; 131 } 132 133 tInterfaceBase::tPrimaryPortType ModifierDefinesPartialInterface(const core::tFrameworkElement* any_element, const rrlib::rtti::tType& interface_type) 134 { 135 if (any_element) 136 { 137 auto aggregator = GetAggregator(*any_element); 138 return ModifierDefinesPartialInterface(*aggregator, interface_type); 139 } 140 return tInterfaceBase::tPrimaryPortType::ANY; 115 141 } 116 142 … … 132 158 } 133 159 134 //void ReplaceAny(std::string& s, const std::string& seach_string, const std::string& replace_with) // TODO135 //{136 // auto index = s.find(seach_string);137 // while (index != std::string::npos)138 // {139 // s.replace(index, seach_string.length(), replace_with);140 // index = s.find(seach_string);141 // }142 //}143 144 160 void FindInterfacesBelowImplementation(std::vector<tInterfaceBase>& result, core::tFrameworkElement& parent, const rrlib::rtti::tType& type, bool skip_derived_interfaces) 145 161 { … … 277 293 278 294 tInterfaceBase::tBackend::tBackend(const rrlib::rtti::tType& interface_type, core::tFrameworkElement* parent_component, core::tFrameworkElement* parent, int primary_relation_id, const std::string& name, bool convenience_port_type, const tConnectFunction& custom_connect_function, tCreateMissingComponentInterfaceFunction create_missing_component_interface_function, tPrimaryPortType primary_port_type, bool partial_interface) : 279 tAbstractPort(MakeCreationInfo(interface_type, name, *parent, partial_interface || tScopedExtraConstructorParameters::Get()->partial_interface )),295 tAbstractPort(MakeCreationInfo(interface_type, name, *parent, partial_interface || tScopedExtraConstructorParameters::Get()->partial_interface || ModifierDefinesPartialInterface(parent, interface_type))), 280 296 parent_component(parent_component), 281 297 primary_backend(*this), … … 285 301 create_missing_component_interface_function(create_missing_component_interface_function), 286 302 primary_port_type(primary_port_type), 287 partial_interface(static_cast<const internal::tInterfaceTypeInfo&>(GetDataType().SharedTypeInfo()).GetFullType() != GetDataType()) 303 partial_interface(static_cast<const internal::tInterfaceTypeInfo&>(GetDataType().SharedTypeInfo()).GetFullType() != GetDataType()), 304 partial_interface_primary_port_type(true) 288 305 { 289 306 all_backends.emplace_back(this); … … 292 309 { 293 310 auto aggregator = GetAggregator(*this); 294 bool sensor_parent = (aggregator && aggregator->GetFlag(tFlag::SENSOR_DATA)); 295 bool controller_parent = (aggregator && aggregator->GetFlag(tFlag::CONTROLLER_DATA)); 296 if ((sensor_parent && primary_port_type == tPrimaryPortType::CONTROLLER_PORT) || (controller_parent && primary_port_type == tPrimaryPortType::SENSOR_PORT)) 311 auto partial_definition = ModifierDefinesPartialInterface(*aggregator, interface_type); 312 if (partial_definition != tPrimaryPortType::ANY) 313 { 314 this->partial_interface_primary_port_type = partial_definition == primary_port_type; 315 } 316 else 317 { 318 bool sensor_parent = (aggregator && (aggregator->GetFlag(tFlag::SENSOR_DATA) || partial_definition == tInterfaceBase::tPrimaryPortType::SENSOR_PORT)); 319 bool controller_parent = (aggregator && (aggregator->GetFlag(tFlag::CONTROLLER_DATA) || partial_definition == tInterfaceBase::tPrimaryPortType::CONTROLLER_PORT)); 320 if ((sensor_parent && primary_port_type == tPrimaryPortType::CONTROLLER_PORT) || (controller_parent && primary_port_type == tPrimaryPortType::SENSOR_PORT)) 321 { 322 this->partial_interface_primary_port_type = false; 323 } 324 } 325 if (!this->partial_interface_primary_port_type) 297 326 { 298 327 primary_relation_backend = nullptr; … … 309 338 create_missing_component_interface_function(nullptr), 310 339 primary_port_type(primary.primary_port_type), 311 partial_interface(primary.partial_interface) 340 partial_interface(primary.partial_interface), 341 partial_interface_primary_port_type(primary.partial_interface_primary_port_type) 312 342 { 313 343 } … … 369 399 } 370 400 throw std::runtime_error("Unspecified port direction"); 401 } 402 403 core::tAbstractPort* tInterfaceBase::tBackend::CreatePort(const core::tAbstractPortCreationInfo& creation_info, int primary_relation_id) const 404 { 405 return cMODIFIER_DEFAULT_IMPLEMENTATION.CreatePort(creation_info, primary_relation_id); 371 406 } 372 407 … … 408 443 parent = this->GetParent(); 409 444 } 445 else if (this->partial_interface && (!IsPartOfPartialInstantiation(primary_relation_id, this->partial_interface_primary_port_type))) 446 { 447 parent = nullptr; // Skip 448 } 410 449 else 411 450 { … … 421 460 422 461 const core::tFrameworkElementFlags relevant_flags = tFlag::SENSOR_DATA | tFlag::CONTROLLER_DATA | tFlag::INTERFACE_FOR_INPUTS | tFlag::INTERFACE_FOR_OUTPUTS | tFlag::PROXY_INTERFACE | tFlag::PARAMETER_INTERFACE; 462 tInterfaceModifier* interface_modifier = component_interface->GetParent()->GetAnnotation<tInterfaceModifier>(); 423 463 424 464 // Compute opcode sequence … … 442 482 } 443 483 484 int remaining_relations = relation_list.size(); 444 485 for (int opcode : relation_list) 445 486 { 487 remaining_relations--; 446 488 core::tFrameworkElementFlags original_flags = use_these_original_flags.Raw() ? use_these_original_flags : parent_candidate->GetAllFlags(); 447 489 use_these_original_flags = core::tFrameworkElementFlags(); … … 534 576 } 535 577 536 if ((!new_candidate) && this->IsPartialInterface() && ((partial_interface_direction_is_output && (!target_set_flags.Get(tFlag::INTERFACE_FOR_OUTPUTS))) || ((!partial_interface_direction_is_output) && target_set_flags.Get(tFlag::INTERFACE_FOR_OUTPUTS)) || target_set_flags.Get(tFlag::INTERFACE_FOR_RPC_PORTS)))578 if ((!new_candidate) && ((this->IsPartialInterface() && remaining_relations) || interface_modifier)) 537 579 { 538 580 use_these_original_flags = target_set_flags; … … 560 602 } 561 603 } 604 assert(remaining_relations == 0); 562 605 563 606 parent = parent_candidate; 564 } 565 566 if (parent && partial_interface) 567 { 568 auto aggregator = GetAggregator(*parent); 569 if ((partial_interface_direction_is_output && aggregator->GetFlag(tFlag::INTERFACE_FOR_INPUTS)) || ((!partial_interface_direction_is_output) && aggregator->GetFlag(tFlag::INTERFACE_FOR_OUTPUTS))) 570 { 571 parent = nullptr; 607 if (interface_modifier) 608 { 609 parent = interface_modifier->Implementation().GetComponentInterface(parent_candidate && parent_candidate->GetFlag(tFlag::INTERFACE) ? static_cast<core::tPortGroup*>(parent_candidate) : nullptr, primary_relation_id); 572 610 } 573 611 } … … 625 663 } 626 664 665 bool tInterfaceBase::tBackend::IsPartOfPartialInstantiation(int primary_relation_id, bool partial_instantiation_variant_primary_port_type) 666 { 667 typedef internal::tPortTypeRelation tOpCode; 668 int switch_count = 0; 669 while (primary_relation_id) 670 { 671 int opcode = primary_relation_id & 0xFF; 672 switch_count += ((opcode == tOpCode::ePTR_COUNTER_PART || opcode == tOpCode::ePTR_COUNTER_PART_PARAMETER_IF_INPUT) ? 1 : 0); 673 primary_relation_id = primary_relation_id >> 8; 674 } 675 bool primary_port_type_relation_id = (switch_count % 2) == 0; 676 return primary_port_type_relation_id == partial_instantiation_variant_primary_port_type; 677 } 678 627 679 void tInterfaceBase::tBackend::OnConnect(tAbstractPort& partner, bool partner_is_destination) 628 680 { -
tInterfaceBase.h
r22 r23 75 75 extern const std::string cINTERFACE_TAG_SINGLE_BACKEND_INSTANTIATION; 76 76 77 /*!78 * \param type Data type to check79 * \return Is specified data type a port composite interface type?80 */81 inline bool IsInterfaceType(const rrlib::rtti::tType& type)82 {83 return type.GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE;84 }85 86 77 87 78 //---------------------------------------------------------------------- … … 102 93 /*! 103 94 * Allows to specify type of primary port 104 * I sset, this allows to instantiate interfaces partially95 * If set, this allows to instantiate interfaces partially 105 96 */ 106 97 enum tPrimaryPortType … … 333 324 tPrimaryPortType primary_port_type; 334 325 335 /*! Whether this interface is a partial interface */336 bool partial_interface ;326 /*! Whether this interface is a partial interface (and if yes, whether partial instantiation should instantiate the primary port type ports (instead of the secondary)) */ 327 bool partial_interface, partial_interface_primary_port_type; 337 328 338 329 /*! … … 349 340 350 341 /*! 342 * Creates port (generic instantiation only) 343 * Called for all data and RPC ports to be created below port composite interface root. 344 * (Behavior of this function may be altered by modifier) 345 * 346 * \param creation_info Creation info to use. 347 * \param primary_relation_id Primary relation ID, as used in interface classes (zero is primary port type) 348 */ 349 core::tAbstractPort* CreatePort(const core::tAbstractPortCreationInfo& creation_info, int primary_relation_id) const; 350 351 /*! 351 352 * (called by tGenericPortType) 352 353 * \param primary_relation_id Relation id to primary port type … … 354 355 */ 355 356 tBackend* GetBackend(int primary_relation_id); 357 358 /*! 359 * Defines which ports are part of partial instantiations. 360 * Partial instantiations either contain all ports of the primary type (+ all port types in the same direction) - 361 * or the secondary. 362 * 363 * \param primary_relation_id Relation id to primary port type 364 * \param partial_interface_variant_primary_port_type Whether partial instantiation should instantiate the primary port type ports (instead of the secondary) 365 * \return Whether ports with relation id are part of the specified variant 366 */ 367 static bool IsPartOfPartialInstantiation(int primary_relation_id, bool partial_interface_variant_primary_port_type); 356 368 }; 357 369
Note: See TracChangeset
for help on using the changeset viewer.