source: finroc_plugins_network_transport/runtime_info/tUriConnectorInfo.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: 5.8 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/tUriConnectorInfo.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2017-03-11
27 *
28 * \brief   Contains tUriConnectorInfo
29 *
30 * \b tUriConnectorInfo
31 *
32 * Information on URI connectors relevant in tools and other runtime environments
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __plugins__network_transport__runtime_info__tUriConnectorInfo_h__
37#define __plugins__network_transport__runtime_info__tUriConnectorInfo_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include "core/port/tUriConnector.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//! URI connector info
66/*!
67 * Information on URI connectors relevant in tools and other runtime environments
68 */
69struct tUriConnectorInfo
70{
71  struct tID
72  {
73    /*! Handle of owner */
74    core::tFrameworkElement::tHandle owner_handle = 0;
75
76    /*! Index of URI connector in owner list */
77    uint8_t index = 0;
78
79    tID(const core::tUriConnector& connector) :
80      owner_handle(connector.Owner().GetHandle()),
81      index(GetIndex(connector))
82    {}
83
84  } id;
85
86  struct tStaticInfo
87  {
88    /*! Flags and conversion operations for this connector */
89    core::tConnectOptions flags_and_conversion_operations;
90
91    /*! URI of partner port (preferably normalized) */
92    rrlib::uri::tURI uri;
93
94    /*! Scheme handler for connector's URI scheme */
95    const core::tUriConnector::tSchemeHandler* scheme_handler = nullptr;
96
97    tStaticInfo(const core::tUriConnector& connector) :
98      flags_and_conversion_operations({ connector.ConversionOperations(), connector.Flags() }),
99                                    uri(connector.Uri()),
100                                    scheme_handler(&connector.GetSchemeHandler())
101    {}
102
103    static void Serialize(rrlib::serialization::tOutputStream& stream, const core::tConnectOptions& flags_and_conversion_operations,
104                          const rrlib::uri::tURI& uri, const core::tUriConnector::tSchemeHandler& scheme_handler);
105
106  } static_info;
107
108  struct tDynamicInfo
109  {
110    /*! Status of connector */
111    core::tUriConnector::tStatus status = core::tUriConnector::tStatus::DISCONNECTED;
112
113    tDynamicInfo(const core::tUriConnector& connector) :
114      status(connector.GetStatus())
115    {}
116
117  } dynamic_info;
118
119
120  tUriConnectorInfo(const core::tUriConnector& connector) :
121    id(connector),
122    static_info(connector),
123    dynamic_info(connector)
124  {}
125
126  /*!
127   * \param Connector Connector whose index in owner to get of
128   * \return Index in owner vector
129   */
130  static uint8_t GetIndex(const core::tUriConnector& connector);
131
132  /*!
133   * Serializes info on single URI connector to stream so that it can later
134   * be deserialized in typically another runtime environment.
135   *
136   * \param stream Binary stream to serialize to
137   * \param connector URI connector whose info to write to stream
138   */
139  static void Serialize(rrlib::serialization::tOutputStream& stream, const core::tUriConnector& connector);
140};
141
142
143inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tUriConnectorInfo::tID& info)
144{
145  stream << info.owner_handle << info.index;
146  return stream;
147}
148
149inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tUriConnectorInfo::tStaticInfo& info)
150{
151  tUriConnectorInfo::tStaticInfo::Serialize(stream, info.flags_and_conversion_operations, info.uri, *info.scheme_handler);
152  return stream;
153}
154
155inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tUriConnectorInfo::tDynamicInfo& info)
156{
157  stream << info.status;
158  return stream;
159}
160
161inline rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tUriConnectorInfo& info)
162{
163  stream << info.id << info.static_info << info.dynamic_info;
164  return stream;
165}
166
167
168//----------------------------------------------------------------------
169// End of namespace declaration
170//----------------------------------------------------------------------
171}
172}
173}
174
175
176#endif
Note: See TracBrowser for help on using the repository browser.