[native, managed] Add Calc example (#18)

This commit is contained in:
Ara Ayvazyan 2020-03-02 17:16:21 -08:00 коммит произвёл GitHub
Родитель befcbf7fa0
Коммит 557012a764
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
17 изменённых файлов: 730 добавлений и 3 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -43,3 +43,4 @@
# Generated files
UnitTestsManaged/generated
/Examples/**/generated

22
Examples/Calc/Calc.bond Normal file
Просмотреть файл

@ -0,0 +1,22 @@
namespace Calc
enum Operation
{
Add,
Subtract,
Multiply,
Divide
}
struct Request
{
0: float X;
1: float Y;
2: Operation Op = Add;
};
struct Response
{
0: float Z;
1: string Text;
}

Просмотреть файл

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E84069C7-B1E2-4BF1-9E2F-57827A42D162}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Calc.Managed</RootNamespace>
<AssemblyName>CalcManaged</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>$(SolutionDir)\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>$(SolutionDir)\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bond, Version=8.2.0.100, Culture=neutral, PublicKeyToken=87e9ead25a117286, processorArchitecture=MSIL">
<HintPath>..\..\..\IPC\Packages\Bond.Core.CSharp.8.2.0\lib\net46\Bond.dll</HintPath>
</Reference>
<Reference Include="Bond.Attributes, Version=8.2.0.100, Culture=neutral, PublicKeyToken=87e9ead25a117286, processorArchitecture=MSIL">
<HintPath>..\..\..\IPC\Packages\Bond.Core.CSharp.8.2.0\lib\net46\Bond.Attributes.dll</HintPath>
</Reference>
<Reference Include="IPC.Managed">
<HintPath>..\..\..\IPC\$(Platform)\$(Configuration)\IPC.Managed.dll</HintPath>
</Reference>
<Reference Include="IPC.Managed.Transport">
<HintPath>..\..\..\IPC\$(Platform)\$(Configuration)\IPC.Managed.Transport.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.cs" />
<Compile Include="Service.cs" />
<Compile Include="generated\Calc_types.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Managed\Build\Managed.vcxproj">
<Project>{705098F7-AAAA-4954-8165-FDDCD66231F0}</Project>
<Name>Managed</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Transport\Transport.csproj">
<Project>{BDAAAAAD-21a8-446e-840b-68718c49e7d4}</Project>
<Name>Transport</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>$(SolutionDir)\IPC\packages\Bond.Compiler.8.2.0\tools\gbc.exe c# -o=$(MSBuildProjectDirectory)\generated $(MSBuildProjectDirectory)\..\Calc.bond</PreBuildEvent>
</PropertyGroup>
</Project>

Просмотреть файл

@ -0,0 +1,86 @@
using System;
using System.Diagnostics;
using System.Threading;
using IPC.Bond.Managed;
namespace Calc.Managed
{
internal static class Client
{
private static double NextDouble(this Random random, double min, double max)
{
return random.NextDouble() * (max - min) + min;
}
public static void Run(string address)
{
Console.WriteLine("Press Ctrl+C to exit.");
Console.WriteLine($"Connecting to {address}");
using (var exit = new ManualResetEvent(false))
using (var transport = new Transport<Request, Response>())
using (var clientAccessor = transport.ConnectClient(address, true))
{
Console.CancelKeyPress += (sender, args) => { args.Cancel = true; exit.Set(); };
clientAccessor.Error += (sender, args) => Console.WriteLine($"IPC: {args.Exception.Message}");
var random = new Random();
Transport<Request, Response>.Client client = null;
while (!exit.WaitOne(TimeSpan.FromSeconds(1)))
{
if (client == null)
{
try
{
client = clientAccessor.Client;
}
catch (System.Exception e)
{
Console.WriteLine($"Failed to access the client: {e.Message}");
continue;
}
var info = $"{client.InputMemory.Name} -> {client.OutputMemory.Name}";
Console.WriteLine($"Connected: {info}");
client.Closed += (sender, args) => Console.WriteLine($"Disconnected: {info}");
}
var request = new Request
{
X = (float)random.NextDouble(1.0, 99.0),
Y = (float)random.NextDouble(1.0, 99.0),
Op = (Operation)random.Next(0, 4)
};
Response response;
var stopwatch = new Stopwatch();
stopwatch.Start();
try
{
response = client.InvokeAsync(request).Result;
}
catch (System.Exception e)
{
Console.WriteLine($"Failed to send request: {e.Message}");
client = null;
continue;
}
stopwatch.Stop();
Console.WriteLine($"{response.Text}{response.Z} [{(stopwatch.ElapsedTicks * 1000000.0) / Stopwatch.Frequency}us]");
}
Console.WriteLine("Exiting...");
client?.Dispose();
}
}
}
}

Просмотреть файл

@ -0,0 +1,34 @@
using System;
namespace Calc.Managed
{
static class Program
{
static int Main(string[] args)
{
var address = "ipc://calc";
switch (args.Length)
{
case 1:
if (args[0] == "--server")
{
Server.Run(address);
break;
}
else if (args[0] == "--client")
{
Client.Run(address);
break;
}
goto default;
default:
Console.WriteLine("Pass --server or --client option.");
return 1;
}
return 0;
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CalcManaged")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CalcManaged")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e84069c7-b1e2-4bf1-9e2f-57827a42d162")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,41 @@
using System;
using System.Threading;
using IPC.Bond.Managed;
namespace Calc.Managed
{
internal static class Server
{
public static void Run(string address)
{
Console.WriteLine($"Hosting server at {address}");
using (var transport = new Transport<Request, Response>())
using (var serversAccessor = transport.AcceptServers(address, (inMemory, outMemory) => new Service().Invoke))
{
serversAccessor.Error += (sender, args) => Console.WriteLine($"IPC: {args.Exception.Message}");
serversAccessor.Connected += (sender, args) =>
Console.WriteLine($"Connected: {args.Component.InputMemory.Name} -> {args.Component.OutputMemory.Name}");
serversAccessor.Disconnected += (sender, args) =>
Console.WriteLine($"Disconnected: {args.Component.InputMemory.Name} -> {args.Component.OutputMemory.Name}");
Console.WriteLine("Press Ctrl+C to exit.");
using (var exit = new ManualResetEvent(false))
{
Console.CancelKeyPress += (sender, args) => { args.Cancel = true; exit.Set(); };
exit.WaitOne();
}
Console.WriteLine("Exiting...");
foreach (var server in serversAccessor.Servers) // Just to trigger Disconnected events
{
server.Dispose();
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,46 @@
using System.Text;
using System.Threading.Tasks;
namespace Calc.Managed
{
internal class Service
{
public Task<Response> Invoke(Request request)
{
var response = new Response();
var text = new StringBuilder();
text.Append(request.X);
text.Append(' ');
switch (request.Op)
{
case Operation.Add:
response.Z = request.X + request.Y;
text.Append('+');
break;
case Operation.Subtract:
response.Z = request.X - request.Y;
text.Append('-');
break;
case Operation.Multiply:
response.Z = request.X * request.Y;
text.Append('*');
break;
case Operation.Divide:
response.Z = request.X / request.Y;
text.Append('/');
break;
}
text.Append(' ');
text.Append(request.Y);
text.Append(" = ");
response.Text = text.ToString();
return Task.FromResult(response);
}
}
}

Просмотреть файл

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{40DD9D26-2E80-44C5-917C-85036B8D7DE6}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CalcNative</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
<Import Project="..\..\..\IPC\Packages\boost.1.71.0.0\build\boost.targets" Condition="Exists('..\..\..\IPC\Packages\boost.1.71.0.0\build\boost.targets')" />
<Import Project="..\..\..\IPC\Packages\boost_date_time-vc142.1.71.0.0\build\boost_date_time-vc142.targets" Condition="Exists('..\..\..\IPC\Packages\boost_date_time-vc142.1.71.0.0\build\boost_date_time-vc142.targets')" />
<Import Project="..\..\..\IPC\Packages\boost_locale-vc142.1.71.0.0\build\boost_locale-vc142.targets" Condition="Exists('..\..\..\IPC\Packages\boost_locale-vc142.1.71.0.0\build\boost_locale-vc142.targets')" />
<Import Project="..\..\..\IPC\Packages\boost_thread-vc142.1.71.0.0\build\boost_thread-vc142.targets" Condition="Exists('..\..\..\IPC\Packages\boost_thread-vc142.1.71.0.0\build\boost_thread-vc142.targets')" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\..\..\Inc;..\..\..\IPC\Inc;..\..\..\bond\build\target\$(Configuration)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CONSOLE;BOND_COMPACT_BINARY_PROTOCOL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>..\..\..\IPC\$(Platform)\$(Configuration)\IPC.lib;..\..\..\bond\build\target\$(Configuration)\lib\bond\bond.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<PreBuildEvent>
<Command>$(SolutionDir)\IPC\packages\Bond.Compiler.8.2.0\tools\gbc.exe c++ -o=$(MSBuildProjectDirectory)\generated $(MSBuildProjectDirectory)\..\Calc.bond</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PreBuildEvent>
<Command>$(SolutionDir)\IPC\packages\Bond.Compiler.8.2.0\tools\gbc.exe c++ -o=$(MSBuildProjectDirectory)\generated $(MSBuildProjectDirectory)\..\Calc.bond</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Client.cpp" />
<ClCompile Include="generated\Calc_types.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Server.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Native\Build\Native.vcxproj">
<Project>{2030ed0d-4667-4299-87cd-ace298bdf56d}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Service.h" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\IPC\Packages\boost.1.71.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\IPC\Packages\boost.1.71.0.0\build\boost.targets'))" />
<Error Condition="!Exists('..\..\..\IPC\Packages\boost_date_time-vc142.1.71.0.0\build\boost_date_time-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\IPC\Packages\boost_date_time-vc142.1.71.0.0\build\boost_date_time-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\IPC\Packages\boost_locale-vc142.1.71.0.0\build\boost_locale-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\IPC\Packages\boost_locale-vc142.1.71.0.0\build\boost_locale-vc142.targets'))" />
<Error Condition="!Exists('..\..\..\IPC\Packages\boost_thread-vc142.1.71.0.0\build\boost_thread-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\IPC\Packages\boost_thread-vc142.1.71.0.0\build\boost_thread-vc142.targets'))" />
</Target>
</Project>

Просмотреть файл

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="Service.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="Client.cpp" />
<ClCompile Include="Server.cpp" />
<ClCompile Include="generated\Calc_types.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,82 @@
#include "generated/Calc_reflection.h"
#include <IPC/Bond/Transport.h>
#include <chrono>
#include <random>
#include <future>
#include <memory>
#include <iostream>
#include <signal.h>
namespace Calc
{
void RunClient(const char* address)
{
static std::promise<void> s_exit;
signal(SIGINT, [](int signal) { s_exit.set_value(); });
std::cout << "Press Ctrl+C to exit." << std::endl;
auto exit = s_exit.get_future();
IPC::Bond::Transport<Request, Response> transport;
std::cout << "Connecting to " << address << std::endl;
auto clientAccessor = transport.ConnectClient(address, true);
std::mt19937 rng(std::random_device{}());
std::uniform_real_distribution<float> nums{ 1.f, 99.f };
std::uniform_int_distribution<> op{ 0, 3 };
for (std::shared_ptr<IPC::Bond::Transport<Request, Response>::Client> client;
exit.wait_for(std::chrono::seconds{ 1 }) == std::future_status::timeout; )
{
if (!client)
{
try
{
client = clientAccessor();
}
catch (const std::exception & e)
{
std::cout << "Failed to access the client: " << e.what() << std::endl;
continue;
}
auto info = client->GetConnection().GetInputChannel().GetMemory()->GetName() + " -> "
+ client->GetConnection().GetOutputChannel().GetMemory()->GetName();
std::cout << "Connected: " << info << std::endl;
client->GetConnection().RegisterCloseHandler([info] { std::cout << "Disconnected: " << info << std::endl; }, true);
}
Request request;
request.X = nums(rng);
request.Y = nums(rng);
request.Op = static_cast<Operation>(op(rng));
boost::optional<Response> response;
const auto begin = std::chrono::steady_clock::now();
try
{
response = (*client)(std::move(request)).get();
}
catch (std::exception& e)
{
std::cout << "Failed to send request: " << e.what() << std::endl;
client = {};
continue;
}
const auto end = std::chrono::steady_clock::now();
const auto latency = std::chrono::duration_cast<std::chrono::microseconds>(end - begin);
std::cout << response->Text << response->Z << " [" << latency.count() << "us]" << std::endl;
}
std::cout << "Exiting..." << std::endl;
}
}

Просмотреть файл

@ -0,0 +1,38 @@
#include "Service.h"
#include "generated/Calc_reflection.h"
#include <IPC/Bond/Transport.h>
#include <future>
#include <iostream>
#include <signal.h>
namespace Calc
{
void RunServer(const char* address)
{
IPC::Bond::Transport<Request, Response> transport;
std::cout << "Hosting server at " << address << std::endl;
auto serversAccessor = transport.AcceptServers(
address,
[](auto& connection, const auto& /*pools*/, const auto& /*serializer*/)
{
const auto info = connection.GetInputChannel().GetMemory()->GetName() + " -> "
+ connection.GetOutputChannel().GetMemory()->GetName();
std::cout << "Connected: " << info << std::endl;
connection.RegisterCloseHandler([info] { std::cout << "Disconnected: " << info << std::endl; }, true);
return Service{};
});
static std::promise<void> s_exit;
signal(SIGINT, [](int signal) { s_exit.set_value(); });
std::cout << "Press Ctrl+C to exit." << std::endl;
s_exit.get_future().wait();
std::cout << "Exiting..." << std::endl;
}
}

Просмотреть файл

@ -0,0 +1,62 @@
#include "generated/Calc_types.h"
#include <future>
#include <exception>
#include <sstream>
#include <iostream>
namespace Calc
{
class Service
{
public:
template <typename Callback>
void operator()(std::future<Request> request, Callback&& callback)
{
try
{
callback(Process(request.get()));
}
catch (const std::exception& e)
{
std::cout << "Failed to send response: " << e.what() << std::endl;
}
}
private:
Response Process(const Request& request)
{
Response response;
std::ostringstream text;
text << request.X << ' ';
switch (request.Op)
{
case Operation::Add:
response.Z = request.X + request.Y;
text << '+';
break;
case Operation::Subtract:
response.Z = request.X - request.Y;
text << '-';
break;
case Operation::Multiply:
response.Z = request.X * request.Y;
text << '*';
break;
case Operation::Divide:
response.Z = request.X / request.Y;
text << '/';
break;
}
text << ' ' << request.Y << " = ";
response.Text = text.str();
return response;
}
};
}

Просмотреть файл

@ -0,0 +1,35 @@
#include <iostream>
namespace Calc
{
void RunServer(const char* address);
void RunClient(const char* address);
}
int main(int argc, char* argv[])
{
constexpr auto c_address = "ipc://calc";
switch (argc)
{
case 2:
if (std::strcmp(argv[1], "--server") == 0)
{
Calc::RunServer(c_address);
break;
}
else if (std::strcmp(argv[1], "--client") == 0)
{
Calc::RunClient(c_address);
break;
}
default:
std::cout << "Pass --server or --client option." << std::endl;
return 1;
}
return 0;
}

Просмотреть файл

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bond.Compiler" version="8.2.0" targetFramework="native" />
<package id="boost" version="1.71.0.0" targetFramework="native" />
<package id="boost_date_time-vc142" version="1.71.0.0" targetFramework="native" />
<package id="boost_locale-vc142" version="1.71.0.0" targetFramework="native" />
<package id="boost_thread-vc142" version="1.71.0.0" targetFramework="native" />
</packages>

Просмотреть файл

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests\Build\UnitTests.vcxproj", "{2A3B9657-1D10-4A71-AA21-62AD4106CED4}"
EndProject
@ -15,6 +15,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transport", "Transport\Tran
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestsManaged", "UnitTestsManaged\UnitTestsManaged.csproj", "{BDFCB3AD-21A8-446E-840B-68718C49E7D4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{400CF9E7-45B2-4AEF-A76F-2E8289A27077}"
ProjectSection(SolutionItems) = preProject
Examples\Calc\Calc.bond = Examples\Calc\Calc.bond
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalcNative", "Examples\Calc\CalcNative\CalcNative.vcxproj", "{40DD9D26-2E80-44C5-917C-85036B8D7DE6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalcManaged", "Examples\Calc\CalcManaged\CalcManaged.csproj", "{E84069C7-B1E2-4BF1-9E2F-57827A42D162}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -45,8 +54,23 @@ Global
{BDFCB3AD-21A8-446E-840B-68718C49E7D4}.Debug|x64.Build.0 = Debug|x64
{BDFCB3AD-21A8-446E-840B-68718C49E7D4}.Release|x64.ActiveCfg = Release|x64
{BDFCB3AD-21A8-446E-840B-68718C49E7D4}.Release|x64.Build.0 = Release|x64
{40DD9D26-2E80-44C5-917C-85036B8D7DE6}.Debug|x64.ActiveCfg = Debug|x64
{40DD9D26-2E80-44C5-917C-85036B8D7DE6}.Debug|x64.Build.0 = Debug|x64
{40DD9D26-2E80-44C5-917C-85036B8D7DE6}.Release|x64.ActiveCfg = Release|x64
{40DD9D26-2E80-44C5-917C-85036B8D7DE6}.Release|x64.Build.0 = Release|x64
{E84069C7-B1E2-4BF1-9E2F-57827A42D162}.Debug|x64.ActiveCfg = Debug|x64
{E84069C7-B1E2-4BF1-9E2F-57827A42D162}.Debug|x64.Build.0 = Debug|x64
{E84069C7-B1E2-4BF1-9E2F-57827A42D162}.Release|x64.ActiveCfg = Release|x64
{E84069C7-B1E2-4BF1-9E2F-57827A42D162}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{40DD9D26-2E80-44C5-917C-85036B8D7DE6} = {400CF9E7-45B2-4AEF-A76F-2E8289A27077}
{E84069C7-B1E2-4BF1-9E2F-57827A42D162} = {400CF9E7-45B2-4AEF-A76F-2E8289A27077}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4AA99B23-F620-4801-9653-59F81A3D3D09}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -15,7 +15,7 @@ In order to build the library you will need to do the following:
# Getting Started
Start with [C++](https://github.com/Microsoft/IPC.Bond/blob/master/UnitTests/TransportTests.cpp) and [C#](https://github.com/Microsoft/IPC.Bond/blob/master/UnitTestsManaged/TransportTests.cs) tests.
Start with [examples](https://github.com/Microsoft/IPC.Bond/tree/master/Examples), [C++](https://github.com/Microsoft/IPC.Bond/blob/master/UnitTests/TransportTests.cpp) and [C#](https://github.com/Microsoft/IPC.Bond/blob/master/UnitTestsManaged/TransportTests.cs) tests.
# Contributing