24 #ifndef GOBY_MIDDLEWARE_IO_DETAIL_TCP_CLIENT_INTERFACE_H
25 #define GOBY_MIDDLEWARE_IO_DETAIL_TCP_CLIENT_INTERFACE_H
33 #include <boost/asio/ip/tcp.hpp>
53 PubSubLayer subscribe_layer,
typename Config,
template <
class>
class ThreadType,
54 bool use_indexed_groups =
false>
56 :
public IOThread<line_in_group, line_out_group, publish_layer, subscribe_layer, Config,
57 boost::asio::ip::tcp::socket, ThreadType, use_indexed_groups>
59 using Base =
IOThread<line_in_group, line_out_group, publish_layer, subscribe_layer, Config,
60 boost::asio::ip::tcp::socket, ThreadType, use_indexed_groups>;
62 using ConfigType = Config;
69 std::string(
"tcp: ") +
config.remote_address() +
":" +
72 boost::asio::ip::tcp::resolver resolver(this->
mutable_io());
73 remote_endpoint_ = *resolver.resolve(
74 {this->cfg().remote_address(),
std::to_string(this->cfg().remote_port()),
75 boost::asio::ip::resolver_query_base::numeric_service});
78 this->interthread().template publish<line_in_group>(ready);
83 auto event = std::make_shared<goby::middleware::protobuf::TCPClientEvent>();
84 if (this->index() != -1)
85 event->set_index(this->index());
86 event->set_event(goby::middleware::protobuf::TCPClientEvent::EVENT_DISCONNECT);
87 *
event->mutable_local_endpoint() = endpoint_convert<protobuf::TCPEndPoint>(local_endpoint_);
88 *
event->mutable_remote_endpoint() =
89 endpoint_convert<protobuf::TCPEndPoint>(remote_endpoint_);
91 <<
"Event: " <<
event->ShortDebugString() << std::endl;
92 this->publish_in(event);
98 *io_msg->mutable_tcp_src() = endpoint_convert<protobuf::TCPEndPoint>(remote_endpoint_);
99 *io_msg->mutable_tcp_dest() = endpoint_convert<protobuf::TCPEndPoint>(local_endpoint_);
103 void async_write(std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg)
override
109 void open_socket()
override
113 auto event = std::make_shared<goby::middleware::protobuf::TCPClientEvent>();
114 if (this->index() != -1)
115 event->set_index(this->index());
116 event->set_event(goby::middleware::protobuf::TCPClientEvent::EVENT_CONNECT);
117 *
event->mutable_local_endpoint() = endpoint_convert<protobuf::TCPEndPoint>(local_endpoint_);
118 *
event->mutable_remote_endpoint() =
119 endpoint_convert<protobuf::TCPEndPoint>(remote_endpoint_);
121 <<
"Event: " <<
event->ShortDebugString() << std::endl;
122 this->publish_in(event);
128 boost::asio::ip::tcp::endpoint remote_endpoint_;
129 boost::asio::ip::tcp::endpoint local_endpoint_;
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
boost::asio::io_context & mutable_io()
const std::string & glog_group()
boost::asio::ip::tcp::socket & mutable_socket()
Access the (mutable) socket (or serial_port) object.
friend void basic_async_write(IOThreadImplementation *this_thread, std::shared_ptr< const goby::middleware::protobuf::IOData > io_msg)
TCPClientThread(const Config &config, int index=-1)
Constructs the thread.
~TCPClientThread() override
void insert_endpoints(std::shared_ptr< goby::middleware::protobuf::IOData > &io_msg)
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
goby::util::logger::GroupSetter group(std::string n)
detail namespace with internal helper functions
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::acomms::abc::protobuf::Config >, 11, false > config
std::string to_string(goby::middleware::protobuf::Layer layer)
The global namespace for the Goby project.
util::FlexOstream glog
Access the Goby logger through this object.