Changeset 427:0a7e413412e9 in finroc_core


Ignore:
Timestamp:
14.05.2017 13:20:19 (2 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Unifies and optimizes serialization of tConnectOptions and tUriConnectOptions (for uniform handling on Java side). Makes sure that auto-set flags erroneously set by user are ignored.

Location:
port
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • port/tConnectOptions.h

    r425 r427  
    6060//---------------------------------------------------------------------- 
    6161/*! 
    62  * Flags that can be set for connections/connectors 
     62 * Flags that can be set for connections/connectors. 
     63 * First 16 Bits are sent to Finstruct 
    6364 */ 
    6465enum class tConnectionFlag 
     
    7980  NON_PRIMARY_CONNECTOR, //!< Connector was created and is represented by higher-level connector (that still exists) (-> e.g. not necessary to transfer this connector to finstruct) 
    8081 
     82  // unused flags for future use 
     83  UNUSED_8, UNUSED_9, UNUSED_10, UNUSED_11, UNUSED_12, UNUSED_13, UNUSED_14, 
     84 
    8185  // these flags are automatically set 
     86  CONVERSION,            //!< Connector has type conversion operations attached that must be applied on publishing values 
     87  NAMED_PARAMETERS,      //!< Indicates whether connector options include named parameters (relevant mainly for uniform serialization of ConnectOptions and UriConnectorOptions (only the latter supports named parameters)) 
    8288  PUBLISHED,             //!< Only relevant for URI connectors: Has been published 
    8389  DISCONNECTED,          //!< Connector has been removed 
    84   CONVERSION             //!< Connector has type conversion operations attached that must be applied on publishing values 
    8590}; 
    8691 
     
    127132  {} 
    128133 
     134  /** 
     135   * Serialize URI connect options 
     136   * 
     137   * \param stream Stream to write to 
     138   * \param auto_set_flags Whether to auto-adjust flags 
     139   */ 
     140  void Serialize(rrlib::serialization::tOutputStream& stream, bool auto_set_flags) const; 
     141 
     142  /** 
     143   * \param conversion_operations New conversion operations 
     144   */ 
    129145  void Set(const rrlib::rtti::conversion::tConversionOperationSequence& conversion_operations) 
    130146  { 
    131147    this->conversion_operations = conversion_operations; 
    132148  } 
     149  /** 
     150   * \param conversion_operations New flags 
     151   */ 
    133152  void Set(const tConnectionFlags& flags) 
    134153  { 
    135154    this->flags = flags; 
    136155  } 
     156 
     157  /*! 
     158   * Unsets all flags that are automatically set by Finroc core. 
     159   * (Used for protection against misuse/undefined behavior) 
     160   * 
     161   * \param flags Flags to clear from auto-flags 
     162   * \return Flags with all auto-flags unset 
     163   */ 
     164  static tConnectionFlags UnsetAutoFlags(const tConnectionFlags& flags); 
    137165}; 
    138166 
     
    158186} 
    159187 
     188 
    160189inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tConnectOptions& options) 
    161190{ 
    162   stream << options.conversion_operations << options.flags.Raw(); 
     191  options.Serialize(stream, true); 
    163192  return stream; 
    164193} 
    165  
    166 inline rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tConnectOptions& options) 
    167 { 
    168   stream >> options.conversion_operations; 
    169   options.flags = tConnectionFlags(stream.ReadInt()); 
    170   return stream; 
    171 } 
    172  
     194rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tConnectOptions& options); 
    173195 
    174196//---------------------------------------------------------------------- 
  • port/tConnector.cpp

    r425 r427  
    117117  source_port(source_port), 
    118118  destination_port(destination_port), 
    119   flags(connect_options.flags | (&conversion_sequence_storage != &rrlib::rtti::conversion::tConversionOperationSequence::cNONE ? tFlags(tFlag::CONVERSION) : tFlags())) 
     119  flags(tConnectOptions::UnsetAutoFlags(connect_options.flags) | (&conversion_sequence_storage != &rrlib::rtti::conversion::tConversionOperationSequence::cNONE ? tFlags(tFlag::CONVERSION) : tFlags())) 
    120120{ 
    121121  if (flags.Get(tFlag::CONVERSION)) 
  • port/tUriConnectOptions.h

    r425 r427  
    7575  /*! Additional parameters as key/value pairs */ 
    7676  std::map<std::string, std::string> parameters; 
     77 
    7778}; 
    7879 
    79 inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tUriConnectOptions& options) 
    80 { 
    81   stream << static_cast<const tConnectOptions&>(options); 
    82   stream << options.parameters; 
    83   return stream; 
    84 } 
    85  
    86 inline rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tUriConnectOptions& options) 
    87 { 
    88   stream >> static_cast<tConnectOptions&>(options); 
    89   stream >> options.parameters; 
    90   return stream; 
    91 } 
     80// implemented in tConnectOptions.cpp (for locality of change - serialization of both classes is compatible) 
     81rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tUriConnectOptions& options); 
     82rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tUriConnectOptions& options); 
    9283 
    9384//---------------------------------------------------------------------- 
  • port/tUriConnector.cpp

    r425 r427  
    8484 
    8585tUriConnector::tUriConnector(tOwner& owner, const tURI& uri, const tConnectOptions& connect_options, const tSchemeHandler& scheme_handler) : 
    86   flags(connect_options.flags), 
     86  flags(tConnectOptions::UnsetAutoFlags(connect_options.flags) | (connect_options.conversion_operations.Size() ? tFlags(tFlag::CONVERSION) : tFlags())), 
    8787  owner(owner), 
    8888  conversion_operations(connect_options.conversion_operations), 
Note: See TracChangeset for help on using the changeset viewer.