17 #ifndef LIB_WINSS_PIPE_CLIENT_HPP_ 18 #define LIB_WINSS_PIPE_CLIENT_HPP_ 23 #include "easylogging/easylogging++.hpp" 48 template<
typename TInstance,
typename TListener>
51 bool stopping =
false;
58 std::vector<winss::NotOwningPtr<TListener>>
listeners;
76 const std::function<
bool(TListener&)>& func) {
77 auto it = listeners.begin();
78 while (it != listeners.end()) {
82 it = listeners.erase(it);
93 if (handle == instance.GetHandle()) {
96 if (instance.Close()) {
97 TellAll([](TListener& listener) {
98 return listener.Disconnected();
109 if (result !=
SKIP) {
122 pipe_name(config.pipe_name), multiplexer(config.multiplexer) {
134 listeners.push_back(listener);
150 if (!stopping && !instance.IsConnected()) {
155 if (instance.CreateFile(pipe_name)) {
159 this->Triggered(handle);
161 if (instance.SetConnected()) {
165 TellAll([](TListener& listener) {
166 return listener.Disconnected();
189 if (instance.Close()) {
190 TellAll([](TListener& listener) {
191 return listener.Disconnected();
207 virtual bool Connected() = 0;
214 virtual bool Disconnected() = 0;
230 virtual bool WriteComplete() = 0;
247 virtual bool Received(
const std::vector<char>& message) = 0;
258 template<
typename TInstance>
260 PipeClientSendListener> {
277 if (instance.FinishWrite()) {
280 bool was_writting = instance.IsWriting();
315 virtual bool Send(
const std::vector<char>& data) {
316 if (instance.Queue(data)) {
317 return instance.Write();
343 template<
typename TInstance>
345 PipeClientReceiveListener> {
347 bool handshake =
false;
360 if (instance.FinishRead()) {
371 std::vector<char> buff = instance.SwapBuffer();
374 auto pos = std::find(buff.begin(), buff.end(), 0);
375 if (pos != buff.end()) {
376 VLOG(6) <<
"Inbound pipe handshake complete";
383 buff.erase(buff.begin(), pos);
389 <<
"Inbound pipe handshake failed (expected null byte)";
426 #endif // LIB_WINSS_PIPE_CLIENT_HPP_ virtual ~PipeClientConnectionListener()
Default destructor.
Definition: pipe_client.hpp:217
virtual void Connected()
Called when the client is connected.
Definition: pipe_client.hpp:68
A wrapper for a Windows HANDLE.
Definition: handle_wrapper.hpp:39
winss::PipeName pipe_name
The pipe instance.
Definition: pipe_client.hpp:54
OverlappedResult
The result of the overlapped operation.
Definition: pipe_instance.hpp:30
InboundPipeClientTmpl(const PipeClientConfig &config)
Creates an inbound pipe client with the given config.
Definition: pipe_client.hpp:405
virtual bool IsStopping() const
Gets if the pipe client is stopping.
Definition: pipe_client.hpp:142
virtual void Stop()
Stop the pipe client.
Definition: pipe_client.hpp:175
InboundPipeClientTmpl< winss::InboundPipeInstance > InboundPipeClient
A concrete inbound pipe client.
Definition: pipe_client.hpp:423
OutboundPipeClientTmpl(const PipeClientConfig &config)
Creates an outbound pipe client with the given config.
Definition: pipe_client.hpp:298
virtual ~PipeClientSendListener()
Default destructor.
Definition: pipe_client.hpp:233
A listener for pipe client received data events.
Definition: pipe_client.hpp:239
void TellAll(const std::function< bool(TListener &)> &func)
Call a function against all listeners.
Definition: pipe_client.hpp:75
An outbound pipe client.
Definition: pipe_client.hpp:259
winss::NotOwningPtr< winss::WaitMultiplexer > multiplexer
The event multiplexer for the named pipe client.
Definition: pipe_client.hpp:37
Pipe names are based on file system paths.
Definition: pipe_name.hpp:32
virtual void AddStopCallback(Callback callback)
Add a stop callback.
Definition: wait_multiplexer.cpp:60
virtual void Connect()
Start the connection process to the pipe server.
Definition: pipe_client.hpp:149
Definition: case_ignore.hpp:23
virtual bool Connected()=0
Called when the pipe client is connected.
virtual bool WriteComplete()=0
Called when the pipe client has finished sending data.
virtual void AddTriggeredCallback(const winss::HandleWrapper &handle, TriggeredCallback callback)
Add a triggered callback for when an event happens on the given handle.
Definition: wait_multiplexer.cpp:43
PipeClient(const PipeClientConfig &config)
Creates a pipe client with the given config.
Definition: pipe_client.hpp:121
An inbound pipe client.
Definition: pipe_client.hpp:344
Config for a named pipe client.
Definition: pipe_client.hpp:34
Wait till next result.
Definition: pipe_instance.hpp:33
virtual void AddListener(winss::NotOwningPtr< TListener > listener)
Add a listener to the client.
Definition: pipe_client.hpp:133
winss::NotOwningPtr< winss::WaitMultiplexer > multiplexer
The event multiplexer for the pipe client.
Definition: pipe_client.hpp:56
OutboundPipeClientTmpl< winss::OutboundPipeInstance > OutboundPipeClient
A concrete outbound pipe client.
Definition: pipe_client.hpp:332
TInstance instance
Marked if stopping the client.
Definition: pipe_client.hpp:53
A HANDLE wait multiplexer.
Definition: wait_multiplexer.hpp:70
void Triggered(const winss::HandleWrapper &handle)
Event handler for the pipe client.
Definition: pipe_client.hpp:92
A listener for pipe client connection events.
Definition: pipe_client.hpp:200
std::vector< winss::NotOwningPtr< TListener > > listeners
Listeners for the pipe client.
Definition: pipe_client.hpp:58
winss::PipeName pipe_name
The name of the named pipe.
Definition: pipe_client.hpp:35
virtual bool Received(const std::vector< char > &message)=0
Called when the pipe client has received data.
Close client.
Definition: pipe_instance.hpp:31
A listener for pipe client send complete events.
Definition: pipe_client.hpp:223
Base named pipe client.
Definition: pipe_client.hpp:49
virtual ~PipeClient()
Close the pipe client and notify listeners.
Definition: pipe_client.hpp:188
virtual void Triggered()
Called when an event is triggered.
Definition: pipe_client.hpp:63
virtual bool Send(const std::vector< char > &data)
Sends the given list of bytes to the pipe server.
Definition: pipe_client.hpp:315
virtual ~PipeClientReceiveListener()
Default destructor.
Definition: pipe_client.hpp:250