Deprecate ATL based IPC wrapper library (#2248)

* Deprecate ATL based IPC wrapper library

* C# projects now use named pipe server implementations from two_way_pipe_message
through the interop C++/Cli library.

* Added Unit testing to interop library
This commit is contained in:
Tomas Agustin Raies
2020-04-23 17:11:02 -07:00
committed by GitHub
parent 81551104ce
commit 63d989cab4
38 changed files with 820 additions and 1515 deletions

View File

@@ -1,12 +1,19 @@
#pragma once
#include <common\keyboard_layout.h>
#include <common\two_way_pipe_message_ipc.h>
#include <msclr\marshal.h>
#include <msclr\marshal_cppstd.h>
#include <functional>
using namespace System;
using namespace System::Runtime::InteropServices;
//https://docs.microsoft.com/en-us/cpp/dotnet/how-to-wrap-native-class-for-use-by-csharp?view=vs-2019
namespace interop
{
public ref class LayoutMapManaged
public
ref class LayoutMapManaged
{
public:
LayoutMapManaged() :
@@ -17,12 +24,11 @@ public ref class LayoutMapManaged
delete _map;
}
String ^ GetKeyName(DWORD key)
{
String ^ GetKeyName(DWORD key) {
return gcnew String(_map->GetKeyName(key).c_str());
}
void Updatelayout()
void Updatelayout()
{
_map->UpdateLayout();
}
@@ -36,5 +42,65 @@ public ref class LayoutMapManaged
private:
LayoutMap* _map;
};
}
public
ref class TwoWayPipeMessageIPCManaged
{
public:
delegate void ReadCallback(String ^ message);
TwoWayPipeMessageIPCManaged(String ^ inputPipeName, String ^ outputPipeName, ReadCallback ^ callback)
{
_wrapperCallback = gcnew InternalReadCallback(this, &TwoWayPipeMessageIPCManaged::ReadCallbackHelper);
_callback = callback;
TwoWayPipeMessageIPC::callback_function cb = nullptr;
if (callback != nullptr)
{
cb = (TwoWayPipeMessageIPC::callback_function)(void*)Marshal::GetFunctionPointerForDelegate(_wrapperCallback);
}
_pipe = new TwoWayPipeMessageIPC(
msclr::interop::marshal_as<std::wstring>(inputPipeName),
msclr::interop::marshal_as<std::wstring>(outputPipeName),
cb);
}
~TwoWayPipeMessageIPCManaged()
{
delete _pipe;
}
void Send(String ^ msg)
{
_pipe->send(msclr::interop::marshal_as<std::wstring>(msg));
}
void Start()
{
_pipe->start(nullptr);
}
void End()
{
_pipe->end();
}
protected:
!TwoWayPipeMessageIPCManaged()
{
delete _pipe;
}
private:
delegate void InternalReadCallback(const std::wstring& msg);
TwoWayPipeMessageIPC* _pipe;
ReadCallback ^ _callback;
InternalReadCallback ^ _wrapperCallback;
void ReadCallbackHelper(const std::wstring& msg)
{
_callback(gcnew String(msg.c_str()));
}
};
}