Changeset 10:475d7a686fd6 in finroc_plugins_composite_ports for tInterfaceBase.cpp


Ignore:
Timestamp:
21.03.2020 16:11:47 (2 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.