/ src / common / interop / TwoWayPipeMessageIPCManaged.cpp
TwoWayPipeMessageIPCManaged.cpp
 1  #include "pch.h"
 2  #include "TwoWayPipeMessageIPCManaged.h"
 3  #include "TwoWayPipeMessageIPCManaged.g.cpp"
 4  #include "two_way_pipe_message_ipc_impl.h"
 5  #include <functional>
 6  
 7  namespace winrt::PowerToys::Interop::implementation
 8  {
 9      TwoWayPipeMessageIPCManaged::TwoWayPipeMessageIPCManaged(hstring const& inputPipeName, hstring const& outputPipeName, winrt::PowerToys::Interop::TwoWayPipeIPCReadCallback const& _callback)
10      {
11          this->_callback = _callback;
12          if (_callback != nullptr)
13          {
14              _internalReadCallback = [this](const std::wstring& msg) {
15                  this->_callback(msg);
16              };
17          }
18          _pipe = new TwoWayPipeMessageIPC(std::wstring{ inputPipeName }, std::wstring{ outputPipeName }, _internalReadCallback);
19      }
20  
21      void TwoWayPipeMessageIPCManaged::Send(hstring const& msg)
22      {
23          _pipe->send(std::wstring{ msg });
24      }
25      void TwoWayPipeMessageIPCManaged::Start()
26      {
27          _pipe->start(nullptr);
28      }
29      void TwoWayPipeMessageIPCManaged::End()
30      {
31          _pipe->end();
32      }
33      void TwoWayPipeMessageIPCManaged::Close()
34      {
35          delete _pipe;
36      }
37  }