Changeset 429:e4f565f3b102 in finroc_core


Ignore:
Timestamp:
07.06.2017 22:05:58 (22 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Makes tAbstractPort::MayConnectTo check process connect options (w.r.t. data type compatbility check) and allow tool ports to connect to pure output and input ports in both directions (for simplified subscribing in network protocols)

Location:
port
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • port/tAbstractPort.cpp

    r425 r429  
    148148  if (connect_direction_flags.Raw() == 0) // auto mode? 
    149149  { 
    150     bool to_target_possible = MayConnectTo(to); 
    151     bool to_source_possible = to.MayConnectTo(*this); 
     150    bool to_target_possible = MayConnectTo(to, connect_options); 
     151    bool to_source_possible = to.MayConnectTo(*this, connect_options); 
    152152    if (to_target_possible && to_source_possible) 
    153153    { 
     
    162162      std::stringstream reason_stream; 
    163163      reason_stream << "Could not connect ports '" << (*this) << "' and '" << to << "' for the following reason: "; 
    164       MayConnectTo(to, &reason_stream); 
     164      MayConnectTo(to, connect_options, &reason_stream); 
    165165      reason_stream << "\nConnecting in the reverse direction did not work either: "; 
    166       to.MayConnectTo(*this, &reason_stream); 
     166      to.MayConnectTo(*this, connect_options, &reason_stream); 
    167167      FINROC_LOG_PRINT(WARNING, reason_stream.str()); 
    168168      return nullptr; 
    169169    } 
     170  } 
     171  else 
     172  { 
     173    connect_direction = connect_options.flags.Get(tConnectionFlag::DIRECTION_TO_DESTINATION) ? tConnectDirection::TO_DESTINATION : tConnectDirection::TO_SOURCE; 
    170174  } 
    171175 
     
    174178  tAbstractPort& destination = (connect_direction == tConnectDirection::TO_DESTINATION) ? to : *this; 
    175179  std::stringstream reason_stream; 
    176   if (source.MayConnectTo(destination, &reason_stream)) 
     180  if (source.MayConnectTo(destination, connect_options, &reason_stream)) 
    177181  { 
    178182    FINROC_LOG_PRINT(DEBUG_VERBOSE_1, "Creating Edge from ", source, " to ", destination); 
     
    568572} 
    569573 
    570 bool tAbstractPort::MayConnectTo(tAbstractPort& destination, std::stringstream* reason_stream) const 
    571 { 
    572   if (!rrlib::rtti::conversion::tStaticCastOperation::IsImplicitlyConvertibleTo(data_type, destination.data_type)) 
     574bool tAbstractPort::MayConnectTo(tAbstractPort& destination, const tConnectOptions& connect_options, std::stringstream* reason_stream) const 
     575{ 
     576  if (connect_options.conversion_operations.Size() == 0 && (!rrlib::rtti::conversion::tStaticCastOperation::IsImplicitlyConvertibleTo(data_type, destination.data_type))) 
    573577  { 
    574578    if (reason_stream) 
     
    578582    return false; 
    579583  } 
     584  // TODO: should conversion operation be checked here already? (con: simpler if not and it will be checked anyway when creating the connector) 
     585 
     586  if (GetFlag(tFlag::TOOL_PORT) || destination.GetFlag(tFlag::TOOL_PORT)) 
     587  { 
     588    return true; // ignore flags and constraints for ports from tools 
     589  } 
    580590 
    581591  if (!GetFlag(tFlag::EMITS_DATA)) 
     
    595605    } 
    596606    return false; 
    597   } 
    598  
    599   if (GetFlag(tFlag::TOOL_PORT) || destination.GetFlag(tFlag::TOOL_PORT)) 
    600   { 
    601     return true; // ignore constraints for ports from tools 
    602607  } 
    603608 
  • port/tAbstractPort.h

    r425 r429  
    323323   * 
    324324   * \param destination Destination port to check connectability to. 
     325   * \param connect_options Any connect options to apply 
    325326   * \param reason_string If connecting is not possible, appends reason to this stream (unless it is nullptr) 
    326327   * \return Answer 
    327328   */ 
    328   bool MayConnectTo(tAbstractPort& destination, std::stringstream* reason_stream = nullptr) const; 
     329  bool MayConnectTo(tAbstractPort& destination, const tConnectOptions& connect_options = tConnectOptions(), std::stringstream* reason_stream = nullptr) const; 
    329330 
    330331  /*! 
Note: See TracChangeset for help on using the changeset viewer.