Changeset 49:ad6afe9e37d7 in finroc_plugins_rpc_ports


Ignore:
Timestamp:
20.03.2021 11:39:32 (5 weeks ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Tags:
tip
Message:

Adds option to customize in RPC port implementation subclasses how/which server port is obtained

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • internal/tRPCPort.cpp

    r38 r49  
    9191tRpcPortFactory default_rpc_port_factory; 
    9292 
    93 static core::tAbstractPortCreationInfo ProcessPortCreationInfo(core::tAbstractPortCreationInfo& info) 
     93static core::tAbstractPortCreationInfo ProcessPortCreationInfo(core::tAbstractPortCreationInfo info) 
    9494{ 
    9595  info.flags.Set(core::tFrameworkElement::tFlag::PUSH_STRATEGY, false); // unsets push strategy flag so that port is not erroneously identified as data port 
     
    9898 
    9999 
    100 tRPCPort::tRPCPort(core::tAbstractPortCreationInfo creation_info, tRPCInterface* call_handler) : 
     100tRPCPort::tRPCPort(const core::tAbstractPortCreationInfo& creation_info, tRPCInterface* call_handler) : 
    101101  core::tAbstractPort(ProcessPortCreationInfo(creation_info)), 
    102102  call_handler(call_handler) 
     
    107107 
    108108 
    109 tRPCPort* tRPCPort::GetServer(bool include_network_ports) const 
     109void tRPCPort::GetAllRPCPortsBelow(std::vector<tRPCPort*>& result, core::tFrameworkElement& parent) 
    110110{ 
    111   tRPCPort* current = const_cast<tRPCPort*>(this); 
    112   while (true) 
     111  for (auto it = parent.SubElementsBegin(); it != parent.SubElementsEnd(); ++it) 
     112  { 
     113    if (it->IsPort() && IsRPCType(static_cast<core::tAbstractPort&>(*it).GetDataType())) 
     114    { 
     115      result.push_back(static_cast<tRPCPort*>(&*it)); 
     116    } 
     117  } 
     118} 
     119 
     120tRPCPort* tRPCPort::GetServerDefault(const tRPCPort* port, bool include_network_ports) 
     121{ 
     122  tRPCPort* current = const_cast<tRPCPort*>(port); 
     123  while (current) 
    113124  { 
    114125    if (current->IsServer() || (include_network_ports && current->GetFlag(tFlag::NETWORK_ELEMENT))) 
     
    124135    } 
    125136 
    126     if (current == nullptr || current == last) 
     137    if (current == last) 
    127138    { 
    128139      return nullptr; 
    129140    } 
     141 
     142    if (current->GetFlag(tFlag::NON_STANDARD_ASSIGN)) 
     143    { 
     144      return current->GetServerCustomized(include_network_ports); 
     145    } 
    130146  } 
     147  return nullptr; 
     148} 
     149 
     150tRPCPort* tRPCPort::GetServerCustomized(bool include_network_ports) const 
     151{ 
     152  FINROC_LOG_PRINT(ERROR, "NON_STANDARD_ASSIGN flag erroneously set"); 
     153  return GetServerDefault(this, include_network_ports); 
    131154} 
    132155 
     
    135158  // Check whether one of the two ports is connected to a server 
    136159  const tRPCPort& other_interface_port = static_cast<const tRPCPort&>(other); 
    137   const tRPCPort* server_port_of_this = (IsServer() || GetFlag(tFlag::NETWORK_ELEMENT)) ? this : GetServer(); 
    138   const tRPCPort* server_port_of_other = (other_interface_port.IsServer() || other_interface_port.GetFlag(tFlag::NETWORK_ELEMENT)) ? &other_interface_port : other_interface_port.GetServer(); 
     160  const tRPCPort* server_port_of_this = (IsServer() || GetFlag(tFlag::NETWORK_ELEMENT)) ? this : GetServerDefault(this, false); 
     161  const tRPCPort* server_port_of_other = (other_interface_port.IsServer() || other_interface_port.GetFlag(tFlag::NETWORK_ELEMENT)) ? &other_interface_port : GetServerDefault(&other_interface_port, false); 
    139162  if (server_port_of_this && server_port_of_other) 
    140163  { 
  • internal/tRPCPort.h

    r25 r49  
    104104 
    105105 
    106   tRPCPort(core::tAbstractPortCreationInfo creation_info, tRPCInterface* call_handler); 
     106  tRPCPort(const core::tAbstractPortCreationInfo& creation_info, tRPCInterface* call_handler); 
    107107 
    108108  ~tRPCPort(); 
    109109 
    110110 
    111 //  /*! 
    112 //   * Deserializes call from stream and executes it 
    113 //   * 
    114 //   * \param stream Stream to deserialize from 
    115 //   * \param call_returner Object to possibly pass future to value to that will be returned 
    116 //   */ 
    117 //  void DeserializeAndExecuteCall(rrlib::serialization::tInputStream& stream) 
    118 //  { 
    119 //    uint8_t function_index; 
    120 //    stream >> function_index; 
    121 //    (*GetTypeInfo()->methods[function_index].deserialize_function)(stream, call_returner, GetTypeInfo()->methods[function_index].function_pointer); 
    122 //  } 
     111  /*! 
     112   * Utility function to collect all RPC ports below specified framework element 
     113   * 
     114   * \param Vector with result. Notably, it is not cleared. 
     115   * \param parent Framework element below which to collect all RPC ports 
     116   */ 
     117  static void GetAllRPCPortsBelow(std::vector<tRPCPort*>& result, core::tFrameworkElement& parent); 
    123118 
    124119  /*! 
     
    133128   * (Usually called on client ports) 
    134129   * 
    135    * \param include_network_ports Also return network ports? 
    136    * \return "Server" Port that handles method call (or null if there is no such port) 
    137    */ 
    138   tRPCPort* GetServer(bool include_network_ports = false) const; 
     130   * \return "Server" Port that handles method call (or nullptr if there is no such port) 
     131   */ 
     132  inline tRPCPort* GetServer() 
     133  { 
     134    return GetFlag(tFlag::NON_STANDARD_ASSIGN) ? GetServerCustomized(true) : GetServerDefault(this, true); 
     135  } 
    139136 
    140137  /*! 
     
    164161 
    165162//---------------------------------------------------------------------- 
     163// Protected methods 
     164//---------------------------------------------------------------------- 
     165protected: 
     166 
     167  /*! 
     168   * Default implementation of GetServer method. 
     169   * 
     170   * \param current Port to get server for 
     171   * \param include_network_ports Also return network ports? 
     172   * \return "Server" Port that handles method call (or nullptr if there is no such port) 
     173   */ 
     174  static tRPCPort* GetServerDefault(const tRPCPort* current, bool include_network_ports); 
     175 
     176//---------------------------------------------------------------------- 
    166177// Private fields and methods 
    167178//---------------------------------------------------------------------- 
     
    173184  tRPCInterface* const call_handler; 
    174185 
     186 
     187  /*! 
     188   * Subclasses may implement customized variants of GetServer. 
     189   * In order to do so, they can override this method and set the NON_STANDARD_ASSIGN flag. 
     190   * 
     191   * Customizations may call GetServerDefault. 
     192   * (the default implementation prints an error message and calls GetServerDefault) 
     193   * 
     194   * \param include_network_ports Also return network ports? 
     195   * \return "Server" Port that handles method call (or nullptr if there is no such port) 
     196   */ 
     197  virtual tRPCPort* GetServerCustomized(bool include_network_ports) const; 
    175198 
    176199  virtual tAbstractPort::tConnectDirection InferConnectDirection(const tAbstractPort& other) const override; 
  • tClientPort.h

    r44 r49  
    170170  void Call(TFunction function, TArgs && ... args) 
    171171  { 
    172     internal::tRPCPort* server_port = GetWrapped()->GetServer(true); 
     172    internal::tRPCPort* server_port = GetWrapped()->GetServer(); 
    173173    if (server_port) 
    174174    { 
     
    211211    static_assert(!std::is_base_of<internal::tIsFuture, tReturn>::value, "Call NativeFutureCall() for functions returning a future"); 
    212212 
    213     internal::tRPCPort* server_port = GetWrapped()->GetServer(true); 
     213    internal::tRPCPort* server_port = GetWrapped()->GetServer(); 
    214214    if (!server_port) 
    215215    { 
     
    258258    static_assert(!std::is_base_of<internal::tIsFuture, tReturn>::value, "Call NativeFutureCall() for functions returning a future"); 
    259259 
    260     internal::tRPCPort* server_port = GetWrapped()->GetServer(true); 
     260    internal::tRPCPort* server_port = GetWrapped()->GetServer(); 
    261261    if (!server_port) 
    262262    { 
     
    296296    static_assert(!std::is_base_of<internal::tIsFuture, tReturn>::value, "Call NativeFutureCall() for functions returning a future"); 
    297297 
    298     internal::tRPCPort* server_port = GetWrapped()->GetServer(true); 
     298    internal::tRPCPort* server_port = GetWrapped()->GetServer(); 
    299299    if (!server_port) 
    300300    { 
     
    332332  typename core::tFrameworkElement::tHandle GetServerHandle() 
    333333  { 
    334     internal::tRPCPort* server_port = GetWrapped()->GetServer(true); 
     334    internal::tRPCPort* server_port = GetWrapped()->GetServer(); 
    335335    return server_port ? server_port->GetHandle() : 0; 
    336336  } 
     
    359359    static_assert(std::is_base_of<internal::tIsFuture, tReturn>::value, "Only suitable for functions returning a tFuture"); 
    360360 
    361     internal::tRPCPort* server_port = GetWrapped()->GetServer(true); 
     361    internal::tRPCPort* server_port = GetWrapped()->GetServer(); 
    362362    if (!server_port) 
    363363    { 
Note: See TracChangeset for help on using the changeset viewer.