Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
tcp_client.h
Go to the documentation of this file.
1// Copyright 2022:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Goby Underwater Autonomy Project Libraries
9// ("The Goby Libraries").
10//
11// The Goby Libraries are free software: you can redistribute them and/or modify
12// them under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// The Goby Libraries are distributed in the hope that they will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with Goby. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef GOBY_MIDDLEWARE_IO_COBS_TCP_CLIENT_H
25#define GOBY_MIDDLEWARE_IO_COBS_TCP_CLIENT_H
26
27#include <istream> // for istream
28#include <memory> // for make_shared
29#include <string> // for basic_st...
30
31#include <boost/asio/read_until.hpp> // for async_re...
32#include <boost/asio/streambuf.hpp> // for streambuf
33#include <boost/system/error_code.hpp> // for error_code
34
36#include "goby/middleware/io/detail/io_interface.h" // for PubSubLayer
37#include "goby/middleware/io/detail/tcp_client_interface.h" // for TCPClien...
38#include "goby/middleware/protobuf/io.pb.h" // for IOData
39
40namespace goby
41{
42namespace middleware
43{
44class Group;
45}
46} // namespace goby
47namespace goby
48{
49namespace middleware
50{
51namespace protobuf
52{
53class TCPClientConfig;
54}
55} // namespace middleware
56} // namespace goby
57
58namespace goby
59{
60namespace middleware
61{
62namespace io
63{
67template <const goby::middleware::Group& packet_in_group,
68 const goby::middleware::Group& packet_out_group,
70 PubSubLayer subscribe_layer = PubSubLayer::INTERTHREAD,
72 template <class> class ThreadType = goby::middleware::SimpleThread,
73 bool use_indexed_groups = false>
75 : public detail::TCPClientThread<packet_in_group, packet_out_group, publish_layer,
76 subscribe_layer, Config, ThreadType, use_indexed_groups>
77{
78 using Base = detail::TCPClientThread<packet_in_group, packet_out_group, publish_layer,
79 subscribe_layer, Config, ThreadType, use_indexed_groups>;
80
81 public:
86 : Base(config, index)
87 {
88 }
89
91
92 template <class Thread>
93 friend void cobs_async_write(Thread* this_thread,
94 std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg);
95
96 template <class Thread, class ThreadBase>
97 friend void cobs_async_read(Thread* this_thread, std::shared_ptr<ThreadBase> self);
98
99 private:
100 void async_read() override { cobs_async_read(this); }
101
102 void async_write(std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg) override
103 {
104 cobs_async_write(this, io_msg);
105 }
106
107 private:
108 boost::asio::streambuf buffer_;
109};
110} // namespace io
111} // namespace middleware
112} // namespace goby
113
114#endif
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition group.h:60
Implements Thread for a three layer middleware setup ([ intervehicle [ interprocess [ interthread ] ]...
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition thread.h:61
Reads/Writes strings from/to a TCP connection using a Consistent Overhead Byte Stuffing (COBS) binary...
Definition tcp_client.h:77
TCPClientThreadCOBS(const goby::middleware::protobuf::TCPClientConfig &config, int index=-1)
Constructs the thread.
Definition tcp_client.h:85
friend void cobs_async_write(Thread *this_thread, std::shared_ptr< const goby::middleware::protobuf::IOData > io_msg)
Definition common.h:44
friend void cobs_async_read(Thread *this_thread, std::shared_ptr< ThreadBase > self)
Definition common.h:90
The global namespace for the Goby project.