Changeset 93:c18a28cf462d in finroc_plugins_data_ports


Ignore:
Timestamp:
05.02.2015 21:27:29 (4 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added functionality to 'hijack' ports - including tests.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • common/tAbstractDataPort.cpp

    r80 r93  
    234234    max = static_cast<int16_t>(std::max(max, port.GetStrategy())); 
    235235  } 
     236  if (GetFlag(tFlag::HIJACKED_PORT)) 
     237  { 
     238    max = -1; 
     239  } 
    236240 
    237241  // has max length (strategy) for this port changed? => propagate to sources 
     
    297301} 
    298302 
     303void tAbstractDataPort::SetHijacked(bool hijacked) 
     304{ 
     305  tLock lock(GetStructureMutex()); 
     306  if (hijacked == GetFlag(tFlag::HIJACKED_PORT)) 
     307  { 
     308    return; 
     309  } 
     310  SetFlag(tFlag::HIJACKED_PORT, hijacked); 
     311  PropagateStrategy(NULL, NULL); 
     312} 
     313 
    299314void tAbstractDataPort::SetMinNetUpdateInterval(rrlib::time::tDuration& new_interval) 
    300315{ 
  • common/tAbstractDataPort.h

    r80 r93  
    217217    port_listener = listener; 
    218218  } 
     219 
     220  /*! 
     221   * Set whether port is in hijacked mode. 
     222   * In this mode, application will no longer publish data to/via this port. 
     223   * Only 'browser' publishes will. E.g. data_playback plugin uses these. 
     224   * 
     225   * \param Whether port should be in hijacked state 
     226   */ 
     227  void SetHijacked(bool hijacked); 
    219228 
    220229  /*! 
  • common/tPublishOperation.h

    r92 r93  
    5959// Forward declarations / typedefs / enums 
    6060//---------------------------------------------------------------------- 
     61 
     62// Some raw flag combinations (defined as constants to get maximum performance - also in debug mode) 
     63enum { cRAW_FLAGS_READY_AND_HIJACKED = (core::tFrameworkElementFlag::READY | core::tFrameworkElementFlag::HIJACKED_PORT).Raw() }; 
     64enum { cRAW_FLAG_READY = core::tFrameworkElementFlags(core::tFrameworkElementFlag::READY).Raw() }; 
    6165 
    6266//---------------------------------------------------------------------- 
     
    9498  inline void Execute(TPort& port) 
    9599  { 
    96     if (!(port.IsReady() || BROWSER_PUBLISH)) 
    97     { 
    98       PrintWarning(port, "is not ready. Ignoring publishing request."); 
     100    uint flag_query = port.GetAllFlags().Raw() & cRAW_FLAGS_READY_AND_HIJACKED; 
     101    if (flag_query != cRAW_FLAG_READY && (!BROWSER_PUBLISH)) 
     102    { 
     103      if (!port.IsReady()) 
     104      { 
     105        PrintWarning(port, "is not ready. Ignoring publishing request."); 
     106      } 
    99107      this->CheckRecycle(); 
    100108      return; 
     
    199207   */ 
    200208  __attribute__((noinline)) 
    201   void PrintWarning(TPort& port, const char* warning) 
     209  static void PrintWarning(TPort& port, const char* warning) 
    202210  { 
    203211    FINROC_LOG_PRINT_STATIC(WARNING, "Port '", port.GetQualifiedName(), "' ", warning); 
  • common/tPullOperation.h

    r46 r93  
    108108  void ExecuteImplementation(TPort& port, bool first) 
    109109  { 
     110    if (port.GetFlag(core::tFrameworkElementFlag::HIJACKED_PORT)) 
     111    { 
     112      port.LockCurrentValueForPublishing(*this); 
     113      return; 
     114    } 
     115 
    110116    if ((!first) && port.pull_request_handler) 
    111117    { 
  • tests/test_collection.cpp

    r80 r93  
    275275} 
    276276 
     277void TestOutOfBoundsPublish() 
     278{ 
     279  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestOutOfBoundsPublish"); 
     280 
     281  tOutputPort<int> output_port("Output Port", parent, tBounds<int>(0, 2, tOutOfBoundsAction::DISCARD)); 
     282  tInputPort<int> input_port("Input Port", parent, tBounds<int>(0, 1)); 
     283  output_port.ConnectTo(input_port); 
     284  parent->Init(); 
     285 
     286  output_port.Publish(3); 
     287  RRLIB_UNIT_TESTS_EQUALITY(0, input_port.Get()); 
     288  output_port.Publish(2); 
     289  RRLIB_UNIT_TESTS_EQUALITY(1, input_port.Get()); 
     290 
     291  parent->ManagedDelete(); 
     292} 
     293 
     294template <typename T> 
     295void TestHijackedPublishing(const T& value_to_publish) 
     296{ 
     297  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestHijackedPublishing"); 
     298  T default_value = T(); 
     299 
     300  tOutputPort<T> output_port("Output Port", parent); 
     301  tProxyPort<T, true> proxy_port("Proxy Port", parent); 
     302  tInputPort<T> input_port("Input Port", parent); 
     303  output_port.ConnectTo(proxy_port); 
     304  proxy_port.ConnectTo(input_port); 
     305  parent->Init(); 
     306 
     307  output_port.Publish(value_to_publish); 
     308  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *proxy_port.GetPointer()); 
     309  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     310  input_port.GetWrapped()->SetHijacked(true); 
     311  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *proxy_port.GetPointer()); 
     312  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     313  output_port.Publish(default_value); 
     314  RRLIB_UNIT_TESTS_EQUALITY(default_value, *proxy_port.GetPointer()); 
     315  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     316  proxy_port.GetWrapped()->SetHijacked(true); 
     317  input_port.GetWrapped()->SetHijacked(false); 
     318  output_port.Publish(value_to_publish); 
     319  RRLIB_UNIT_TESTS_EQUALITY(default_value, *proxy_port.GetPointer()); 
     320  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     321  output_port.GetWrapped()->SetHijacked(true); 
     322  output_port.Publish(value_to_publish); 
     323 
     324  parent->ManagedDelete(); 
     325} 
     326 
    277327class DataPortsTestCollection : public rrlib::util::tUnitTestSuite 
    278328{ 
     
    290340    TestNetworkConnectionLoss<int>(4, 7); 
    291341    TestNetworkConnectionLoss<std::string>("default_value", "published_value"); 
     342    TestOutOfBoundsPublish(); 
     343    TestHijackedPublishing<int>(42); 
     344    TestHijackedPublishing<std::string>("test"); 
    292345 
    293346    tThreadLocalBufferManagement local_buffers; 
     
    296349    TestPortListeners<int>(1); 
    297350    TestNetworkConnectionLoss<int>(4, 7); 
     351    TestOutOfBoundsPublish(); 
     352    TestHijackedPublishing<int>(42); 
    298353  } 
    299354}; 
Note: See TracChangeset for help on using the changeset viewer.