source: finroc_plugins_network_transport/runtime_info/tConnectorInfo.h @ 22:5936c5426df0

17.03
Last change on this file since 22:5936c5426df0 was 22:5936c5426df0, checked in by Max Reichardt <mreichardt@…>, 2 years ago

Unifies serialization of tConnectorInfo and tUriConnectorInfo with tConnectOptions and tUriConnectOptions (removes redundant code)

File size: 4.9 KB
Line 
1//
2// You received this file as part of Finroc
3// A framework for intelligent robot control
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    plugins/network_transport/runtime_info/tConnectorInfo.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2017-03-11
27 *
28 * \brief   Contains tConnectorInfo
29 *
30 * \b tConnectorInfo
31 *
32 * Information on connectors relevant in tools and other runtime environments
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __plugins__network_transport__runtime_info__tConnectorInfo_h__
37#define __plugins__network_transport__runtime_info__tConnectorInfo_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include "core/port/tAbstractPort.h"
43
44//----------------------------------------------------------------------
45// Internal includes with ""
46//----------------------------------------------------------------------
47
48//----------------------------------------------------------------------
49// Namespace declaration
50//----------------------------------------------------------------------
51namespace finroc
52{
53namespace network_transport
54{
55namespace runtime_info
56{
57
58//----------------------------------------------------------------------
59// Forward declarations / typedefs / enums
60//----------------------------------------------------------------------
61
62//----------------------------------------------------------------------
63// Class declaration
64//----------------------------------------------------------------------
65//! Connector Info
66/*!
67 * Information on connectors relevant in tools and other runtime environments
68 */
69struct tConnectorInfo
70{
71
72  struct tID
73  {
74    /*! Handles of source and destination port */
75    core::tFrameworkElement::tHandle source_handle = 0, destination_handle = 0;
76
77    tID(const core::tConnector& connector) :
78      source_handle(connector.Source().GetHandle()),
79      destination_handle(connector.Destination().GetHandle())
80    {}
81
82  } id;
83
84  friend inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tConnectorInfo::tID& info);
85
86
87  struct tStaticInfo
88  {
89    /*! Flags and conversion operations for this connector */
90    core::tConnectOptions flags_and_conversion_operations;
91
92    tStaticInfo(const core::tConnector& connector) :
93      flags_and_conversion_operations({ connector.ConversionOperations(), connector.Flags() })
94    {}
95
96  } static_info;
97
98
99  tConnectorInfo(const core::tConnector& connector) :
100    id(connector),
101    static_info(connector)
102  {}
103
104  friend inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tID& info);
105  friend inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tStaticInfo& info);
106
107  /*!
108   * Serializes info on single connector to stream so that it can later
109   * be deserialized in typically another runtime environment.
110   *
111   * \param stream Binary stream to serialize to
112   * \param connector Connector whose info to write to stream
113   */
114  static void Serialize(rrlib::serialization::tOutputStream& stream, const core::tConnector& connector)
115  {
116    stream << tID(connector);
117    stream << tStaticInfo(connector);
118  }
119};
120
121inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tConnectorInfo::tID& info)
122{
123  stream << info.source_handle << info.destination_handle;
124  return stream;
125}
126
127inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tConnectorInfo::tStaticInfo& info)
128{
129  stream << info.flags_and_conversion_operations;
130  return stream;
131}
132
133inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tConnectorInfo& info)
134{
135  stream << info.id << info.static_info;
136  return stream;
137}
138
139//----------------------------------------------------------------------
140// End of namespace declaration
141//----------------------------------------------------------------------
142}
143}
144}
145
146
147#endif
Note: See TracBrowser for help on using the repository browser.