source: finroc_plugins_network_transport/tNetworkConnection.cpp @ 16:ff71e9eb88fd

Last change on this file since 16:ff71e9eb88fd was 16:ff71e9eb88fd, checked in by Max Reichardt <mreichardt@…>, 6 years ago

Replaced erroneous use of FINROC_LOG_PRINT with FINROC_LOG_PRINT_STATIC

File size: 4.6 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/tNetworkConnection.cpp
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2013-11-28
27 *
28 */
29//----------------------------------------------------------------------
30#include "plugins/network_transport/tNetworkConnection.h"
31
32//----------------------------------------------------------------------
33// External includes (system with <>, local with "")
34//----------------------------------------------------------------------
35
36//----------------------------------------------------------------------
37// Internal includes with ""
38//----------------------------------------------------------------------
39
40//----------------------------------------------------------------------
41// Debugging
42//----------------------------------------------------------------------
43#include <cassert>
44
45//----------------------------------------------------------------------
46// Namespace usage
47//----------------------------------------------------------------------
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace finroc
53{
54namespace network_transport
55{
56
57//----------------------------------------------------------------------
58// Forward declarations / typedefs / enums
59//----------------------------------------------------------------------
60
61//----------------------------------------------------------------------
62// Const values
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Implementation
67//----------------------------------------------------------------------
68
69tNetworkConnection::tNetworkConnection() :
70  encoding(tDestinationEncoding::NONE),
71  destination_is_source(false),
72  uuid(),
73  port_handle(0)
74{}
75
76tNetworkConnection::tNetworkConnection(const std::string& uuid, core::tFrameworkElement::tHandle handle, bool destination_is_source) :
77  encoding(tDestinationEncoding::UUID_AND_HANDLE),
78  destination_is_source(destination_is_source),
79  uuid(uuid),
80  port_handle(handle)
81{}
82
83bool tNetworkConnection::operator==(const tNetworkConnection& other) const
84{
85  if (encoding != other.encoding)
86  {
87    return false;
88  }
89  switch (encoding)
90  {
91  case tDestinationEncoding::NONE:
92    return true;
93  case tDestinationEncoding::UUID_AND_HANDLE:
94    return uuid == other.uuid && port_handle == other.port_handle && destination_is_source == other.destination_is_source;
95  default:
96    FINROC_LOG_PRINT(ERROR, "Unsupported encoding");
97    return false;
98  }
99}
100
101rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tNetworkConnection& connection)
102{
103  stream << connection.encoding;
104  switch (connection.encoding)
105  {
106  case tDestinationEncoding::NONE:
107    break;
108  case tDestinationEncoding::UUID_AND_HANDLE:
109    stream << connection.uuid << connection.port_handle << connection.destination_is_source;
110    break;
111  default:
112    FINROC_LOG_PRINT_STATIC(ERROR, "Unsupported encoding");
113  }
114  return stream;
115}
116
117rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tNetworkConnection& connection)
118{
119  stream >> connection.encoding;
120  switch (connection.encoding)
121  {
122  case tDestinationEncoding::NONE:
123    break;
124  case tDestinationEncoding::UUID_AND_HANDLE:
125    stream >> connection.uuid >> connection.port_handle >> connection.destination_is_source;
126    break;
127  default:
128    FINROC_LOG_PRINT_STATIC(ERROR, "Unsupported encoding");
129  }
130  return stream;
131}
132
133
134//----------------------------------------------------------------------
135// End of namespace declaration
136//----------------------------------------------------------------------
137}
138}
Note: See TracBrowser for help on using the repository browser.