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"
32
33namespace rogue {
34namespace interfaces {
35namespace stream {
36
53 protected:
54 // Inbound Address
55 std::string pullAddr_;
56
57 // Outbound Address
58 std::string pushAddr_;
59
60 void* zmqCtx_ = nullptr;
61 void* zmqPull_ = nullptr;
62 void* zmqPush_ = nullptr;
63
64 bool server_ = false;
65
66 // Thread background
67 void runThread();
68
69 // Rebuild zmqPush_ after a failed multipart send. Caller must hold bridgeMtx_.
70 bool rebuildPushSocket();
71
72 // Log
73 std::shared_ptr<rogue::Logging> bridgeLog_;
74
75 std::unique_ptr<std::thread> thread_;
76 std::atomic<bool> threadEn_{false};
77
78 // Lock
79 std::mutex bridgeMtx_;
80
81 public:
98 static std::shared_ptr<rogue::interfaces::stream::TcpCore> create(const std::string& addr, uint16_t port, bool server);
99
101 static void setup_python();
102
121 TcpCore(const std::string& addr, uint16_t port, bool server);
122
124 ~TcpCore();
125
127 [[deprecated("Use stop() instead")]] void close();
128
130 void stop();
131
137 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
138};
139
141typedef std::shared_ptr<rogue::interfaces::stream::TcpCore> TcpCorePtr;
142
143} // namespace stream
144} // namespace interfaces
145}; // namespace rogue
146
147#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:52
void close()
Closes active bridge connections. Deprecated; use stop().
Definition TcpCore.cpp:188
std::shared_ptr< rogue::Logging > bridgeLog_
Definition TcpCore.h:73
static void setup_python()
Registers this type with Python bindings.
Definition TcpCore.cpp:454
void acceptFrame(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Receives a frame from upstream and forwards over the TCP bridge.
Definition TcpCore.cpp:274
~TcpCore()
Destroys the bridge core and releases resources.
Definition TcpCore.cpp:183
void stop()
Stops the interface and worker thread.
Definition TcpCore.cpp:192
std::atomic< bool > threadEn_
Definition TcpCore.h:76
std::unique_ptr< std::thread > thread_
Definition TcpCore.h:75
std::shared_ptr< rogue::interfaces::stream::TcpCore > TcpCorePtr
Shared pointer alias for TcpCore.
Definition TcpCore.h:141