rogue
Loading...
Searching...
No Matches
TcpCore.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_INTERFACES_STREAM_TCP_CORE_H__
18#define __ROGUE_INTERFACES_STREAM_TCP_CORE_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <atomic>
24#include <memory>
25#include <string>
26#include <thread>
27
28#include "rogue/Logging.h"
33
34namespace rogue {
35namespace interfaces {
36namespace stream {
37
54 protected:
55 // Inbound Address
56 std::string pullAddr_;
57
58 // Outbound Address
59 std::string pushAddr_;
60
61 void* zmqCtx_ = nullptr;
62 void* zmqPull_ = nullptr;
63 void* zmqPush_ = nullptr;
64
65 bool server_ = false;
66
67 // Thread background
68 void runThread();
69
70 // Rebuild zmqPush_ after a failed multipart send. Caller must hold bridgeMtx_.
71 bool rebuildPushSocket();
72
73 // Log
74 std::shared_ptr<rogue::Logging> bridgeLog_;
75
76 // Allocates received frames. Owned before the receive thread starts, so a
77 // frame arriving before a shared_ptr owns this bridge does not need
78 // shared_from_this().
79 std::shared_ptr<rogue::interfaces::stream::Pool> rxPool_;
80
81 std::unique_ptr<std::thread> thread_;
82 std::atomic<bool> threadEn_{false};
83
84 // Lock
85 std::mutex bridgeMtx_;
86
87 public:
104 static std::shared_ptr<rogue::interfaces::stream::TcpCore> create(const std::string& addr, uint16_t port, bool server);
105
107 static void setup_python();
108
127 TcpCore(const std::string& addr, uint16_t port, bool server);
128
130 ~TcpCore();
131
133 [[deprecated("Use stop() instead")]] void close();
134
136 void stop();
137
143 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
144};
145
147typedef std::shared_ptr<rogue::interfaces::stream::TcpCore> TcpCorePtr;
148
149} // namespace stream
150} // namespace interfaces
151}; // namespace rogue
152
153#endif
Stream master endpoint.
Definition Master.h:65
static std::shared_ptr< rogue::interfaces::stream::Master > create()
Creates a stream master.
Definition Master.cpp:40
Stream slave endpoint and default frame pool.
Definition Slave.h:72
Stream TCP bridge core implementation.
Definition TcpCore.h:53
void close()
Closes active bridge connections. Deprecated; use stop().
Definition TcpCore.cpp:190
std::shared_ptr< rogue::Logging > bridgeLog_
Definition TcpCore.h:74
static void setup_python()
Registers this type with Python bindings.
Definition TcpCore.cpp:458
void acceptFrame(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Receives a frame from upstream and forwards over the TCP bridge.
Definition TcpCore.cpp:276
~TcpCore()
Destroys the bridge core and releases resources.
Definition TcpCore.cpp:185
void stop()
Stops the interface and worker thread.
Definition TcpCore.cpp:194
std::shared_ptr< rogue::interfaces::stream::Pool > rxPool_
Definition TcpCore.h:79
std::atomic< bool > threadEn_
Definition TcpCore.h:82
std::unique_ptr< std::thread > thread_
Definition TcpCore.h:81
std::shared_ptr< rogue::interfaces::stream::TcpCore > TcpCorePtr
Shared pointer alias for TcpCore.
Definition TcpCore.h:147