Skip to content
Snippets Groups Projects
Commit bc308732 authored by Tim Übelhör's avatar Tim Übelhör
Browse files

Added ModeliRpc projects

parent 105501ee
Branches Rpc
No related tags found
No related merge requests found
Showing
with 6601 additions and 0 deletions
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<ItemsProjectGuid>{085c4931-4962-4fbf-b2cc-e436ffedc310}</ItemsProjectGuid>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ModeliRpcCLR", "ModeliRpcCLR\ModeliRpcCLR.vcxproj", "{A8187A41-1D24-438F-9B5D-0F7BF270130E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ModeliRpcNative", "ModeliRpcNative\ModeliRpcNative.vcxproj", "{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Debug|x64.ActiveCfg = Debug|x64
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Debug|x64.Build.0 = Debug|x64
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Debug|x86.ActiveCfg = Debug|Win32
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Debug|x86.Build.0 = Debug|Win32
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Release|x64.ActiveCfg = Release|x64
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Release|x64.Build.0 = Release|x64
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Release|x86.ActiveCfg = Release|Win32
{A8187A41-1D24-438F-9B5D-0F7BF270130E}.Release|x86.Build.0 = Release|Win32
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Debug|x64.ActiveCfg = Debug|x64
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Debug|x64.Build.0 = Debug|x64
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Debug|x86.ActiveCfg = Debug|Win32
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Debug|x86.Build.0 = Debug|Win32
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Release|x64.ActiveCfg = Release|x64
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Release|x64.Build.0 = Release|x64
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Release|x86.ActiveCfg = Release|Win32
{171ED599-C0C6-4342-8328-E7ABE7F7FEAA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1F47424-6A4D-43F9-982C-D5C9154CA77F}
EndGlobalSection
EndGlobal
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
//
// 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:AssemblyTitleAttribute(L"ModeliRpcCLR")];
[assembly:AssemblyDescriptionAttribute(L"")];
[assembly:AssemblyConfigurationAttribute(L"")];
[assembly:AssemblyCompanyAttribute(L"")];
[assembly:AssemblyProductAttribute(L"ModeliRpcCLR")];
[assembly:AssemblyCopyrightAttribute(L"Copyright (c) 2017")];
[assembly:AssemblyTrademarkAttribute(L"")];
[assembly:AssemblyCultureAttribute(L"")];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
\ No newline at end of file
#include "stdafx.h"
#include "ModeliRpc.h"
#include "msclr/marshal_cppstd.h"
using namespace msclr::interop;
using namespace System::Runtime::InteropServices;
namespace ModeliRpcImpl
{
ModeliRpcImpl::ModeliRpcImpl(String^ address, int port)
{
// Managed callbacks
_newValues = gcnew NewValuesDelegate(this, &ModeliRpcImpl::onNewValues);
_log = gcnew LogDelegate(this, &ModeliRpcImpl::onLog);
// Load the unmanged instance
HINSTANCE _rpcDll = LoadLibrary("ModeliRpcNative.dll");
if (!_rpcDll)
{
throw gcnew Exception("Unable to load ModeliRpcNative.dll!");
}
createRpcFrontendType createRpcFrontend = reinterpret_cast<createRpcFrontendType>(GetProcAddress(_rpcDll, "create_klass"));
if (!createRpcFrontend)
{
FreeLibrary(_rpcDll);
throw gcnew Exception("Unable to load createRpcFrontend from DLL!");
}
_rpcFrontend = createRpcFrontend();
// Register callbacks
_rpcFrontend->registerCallbacks(
static_cast<NewValuesCallback>(Marshal::GetFunctionPointerForDelegate(_newValues).ToPointer()),
static_cast<LogCallback>(Marshal::GetFunctionPointerForDelegate(_log).ToPointer()));
// Connect
_rpcFrontend->connect(marshal_as<std::string>(address), port);
}
ModeliRpcImpl::~ModeliRpcImpl()
{
// Call the finalizer
this->!ModeliRpcImpl();
}
ModeliRpcImpl::!ModeliRpcImpl()
{
// Clear all unmanaged resources
if (_rpcFrontend)
{
_rpcFrontend->destroy();
}
if (_rpcDll)
{
FreeLibrary(_rpcDll);
}
}
void ModeliRpcImpl::onNewValues(double timestamp, ValuesStruct values)
{
throw gcnew System::NotImplementedException();
}
void ModeliRpcImpl::onLog(std::string instanceName, fmi2Status status, std::string message)
{
throw gcnew System::NotImplementedException();
}
}
\ No newline at end of file
#pragma once
#include"../ModeliRpcNative/IRpcFrontend.h"
#include <string>
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN
#endif
#include <windows.h>
using namespace System;
typedef IRpcFrontend* (*createRpcFrontendType)();
namespace capnp
{
class EzRpcClient;
}
namespace ModeliRpcImpl
{
ref class ModeliRpcImpl
{
private:
// Unmanaged rpc interface
IRpcFrontend* _rpcFrontend;
// The native project exports a dll to hide the rpc framework
HMODULE _rpcDll;
// Delegates for callbacks
delegate void NewValuesDelegate(double timestamp, ValuesStruct values);
delegate void LogDelegate(std::string instanceName, fmi2Status status, std::string message);
NewValuesDelegate^ _newValues;
LogDelegate^ _log;
// Functions for the delegates
void onNewValues(double timestamp, ValuesStruct values);
void onLog(std::string instanceName, fmi2Status status, std::string message);
public:
ModeliRpcImpl(String^ address, int port);
~ModeliRpcImpl(); // Destructor (IDisposable)
!ModeliRpcImpl(); // Finalizer
};
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<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>15.0</VCProjectVersion>
<ProjectGuid>{A8187A41-1D24-438F-9B5D-0F7BF270130E}</ProjectGuid>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>ModeliRpcCLR</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<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|Win32'">
<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)'=='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|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ModeliRpc.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Stdafx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" />
<ClCompile Include="ModeliRpc.cpp" />
<ClCompile Include="Stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="app.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="app.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ModeliRpcNative\ModeliRpcNative.vcxproj">
<Project>{171ed599-c0c6-4342-8328-e7abe7f7feaa}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ModeliRpc.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ModeliRpc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="app.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="app.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
\ No newline at end of file
========================================================================
DYNAMIC LINK LIBRARY : ModeliRpcCLR Project Overview
========================================================================
AppWizard has created this ModeliRpcCLR DLL for you.
This file contains a summary of what you will find in each of the files that
make up your ModeliRpcCLR application.
ModeliRpcCLR.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
ModeliRpcCLR.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
ModeliRpcCLR.cpp
This is the main DLL source file.
ModeliRpcCLR.h
This file contains a class declaration.
AssemblyInfo.cpp
Contains custom attributes for modifying assembly metadata.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////
// stdafx.cpp : source file that includes just the standard includes
// ModeliRpcCLR.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
ModeliRpc/ModeliRpcCLR/app.ico

40.4 KiB

File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc
#include "stdafx.h"
#include "CapnConverter.h"
#include "capnp/message.h"
CapnConverter::CapnConverter()
{
}
CapnConverter::~CapnConverter()
{
}
ValuesStruct CapnConverter::convertValues(Values::Reader reader)
{
// Read the data into std types
std::string instanceName = reader.getInstanceName();
// int
std::vector<uint32_t> intVrs;
for (auto element : reader.getIntegerValueRefs())
{
intVrs.push_back(element);
}
std::vector<int32_t> intValues;
for (auto element : reader.getIntegerValues())
{
intValues.push_back(element);
}
// real
std::vector<uint32_t> realVrs;
for (auto element : reader.getRealValueRefs())
{
realVrs.push_back(element);
}
std::vector<double> realValues;
for (auto element : reader.getRealValues())
{
realValues.push_back(element);
}
// bool
std::vector<uint32_t> boolVrs;
for (auto element : reader.getBoolValueRefs())
{
boolVrs.push_back(element);
}
std::vector<bool> boolValues;
for (auto element : reader.getBoolValues())
{
boolValues.push_back(element);
}
// string
std::vector<uint32_t> stringVrs;
for (auto element : reader.getStringValueRefs())
{
stringVrs.push_back(element);
}
std::vector<std::string> stringValues;
for (auto textReader : reader.getStringValues())
{
// std copy does not work because we have to convert the textreader implicity
stringValues.push_back(textReader);
}
// assemble
return ValuesStruct{
instanceName,
intVrs,
intValues,
realVrs,
realValues,
boolVrs,
boolValues,
stringVrs,
stringValues
};
}
Values::Builder CapnConverter::convertValues(ValuesStruct values)
{
capnp::MallocMessageBuilder builder;
auto retVal = builder.initRoot<Values>();
retVal.setInstanceName(values.instanceName);
// int
auto intVrs = retVal.initIntegerValueRefs(values.integerValueRefs.size());
for (int i = 0; i < intVrs.size(); i++)
{
intVrs.set(i, values.integerValueRefs[i]);
}
auto intValues = retVal.initIntegerValues(values.integerValues.size());
for (int i = 0; i < intValues.size(); i++)
{
intValues.set(i, values.integerValues[i]);
}
// real
auto realVrs = retVal.initRealValueRefs(values.realValueRefs.size());
for (int i = 0; i < realVrs.size(); i++)
{
realVrs.set(i, values.realValueRefs[i]);
}
auto realValues = retVal.initRealValues(values.realValues.size());
for (int i = 0; i < realValues.size(); i++)
{
realValues.set(i, values.realValues[i]);
}
// bool
auto boolVrs = retVal.initBoolValueRefs(values.boolValueRefs.size());
for (int i = 0; i < boolVrs.size(); i++)
{
boolVrs.set(i, values.boolValueRefs[i]);
}
auto boolValues = retVal.initBoolValues(values.boolValues.size());
for (int i = 0; i < boolValues.size(); i++)
{
boolValues.set(i, values.boolValues[i]);
}
// string
auto stringVrs = retVal.initStringValueRefs(values.stringValueRefs.size());
for (int i = 0; i < stringVrs.size(); i++)
{
stringVrs.set(i, values.stringValueRefs[i]);
}
auto stringValues = retVal.initStringValues(values.stringValues.size());
for (int i = 0; i < stringValues.size(); i++)
{
stringValues.set(i, values.stringValues[i]);
}
return retVal;
}
ModeliBackend::ChannelLink::Builder CapnConverter::convertChannelLink(ChannelLink channelLink)
{
capnp::MallocMessageBuilder builder;
auto retVal = builder.initRoot<ModeliBackend::ChannelLink>();
retVal.setMasterInstanceName(channelLink.masterInstanceName);
retVal.setSlaveInstanceName(channelLink.slaveInstanceName);
retVal.setMasterValueRef(channelLink.masterValueRef);
retVal.setSlaveValueRef(channelLink.slaveValueRef);
retVal.setFactor(channelLink.factor);
retVal.setOffset(channelLink.offset);
return retVal;
}
#pragma once
#include <string>
#include <vector>
#include "ModeliRpc.capnp.h"
#include "IRpcFrontend.h"
/// Several helper methods to convert our capn protocol
class CapnConverter
{
public:
CapnConverter();
~CapnConverter();
static ValuesStruct convertValues(Values::Reader reader);
static Values::Builder convertValues(ValuesStruct values);
static ModeliBackend::ChannelLink::Builder convertChannelLink(ChannelLink channelLink);
};
#pragma once
#include <string>
#include <vector>
enum fmi2Status
{
fmi2OK,
fmi2Warning,
fmi2Discard,
fmi2Error,
fmi2Fatal,
fmi2Pending
};
// Struct that will be used for the NewValues callback
struct ValuesStruct
{
std::string instanceName;
std::vector<uint32_t> integerValueRefs;
std::vector<int32_t> integerValues;
std::vector<uint32_t> realValueRefs;
std::vector<double> realValues;
std::vector<uint32_t> boolValueRefs;
std::vector<bool> boolValues;
std::vector<uint32_t> stringValueRefs;
std::vector<std::string> stringValues;
};
// Definition of a channel link
struct ChannelLink
{
std::string masterInstanceName;
std::string slaveInstanceName;
uint32_t masterValueRef;
uint32_t slaveValueRef;
double factor;
double offset;
};
// Callback definitions shall be easy to marshall
typedef void(__stdcall *NewValuesCallback)(double timestamp, ValuesStruct values);
typedef void(__stdcall *LogCallback)(std::string instanceName, int status, std::string message);
/// This interface hides the rpc (framework) implementation.
/// We can compile a pure native library and do not have to worry about CLI compiler errors.
class IRpcFrontend
{
public:
virtual void destroy() = 0;
virtual void connect(std::string address, int port) = 0;
virtual void registerCallbacks(NewValuesCallback newValuesCallback, LogCallback logCallback) = 0;
virtual fmi2Status play() = 0;
virtual void pause() = 0;
virtual fmi2Status stop() = 0;
virtual bool addFmu(std::string instanceName, std::vector<unsigned char> fmuFile) = 0;
virtual bool removeFmu(std::string instanceName) = 0;
virtual bool addChannelLink(ChannelLink channelLink) = 0;
virtual bool removeChannelink(ChannelLink channelLink) = 0;
virtual fmi2Status setValues(ValuesStruct values) = 0;
};
// Factory signature
extern "C" __declspec(dllexport) IRpcFrontend* createRpcFrontend();
\ No newline at end of file
#include "stdafx.h"
#include "ModeliFrontendImpl.h"
#include "CapnConverter.h"
ModeliFrontendImpl::ModeliFrontendImpl(NewValuesCallback newValuesCallback, LogCallback logCallback) :
_newValuesCallback(newValuesCallback), _logCallback(logCallback)
{
}
ModeliFrontendImpl::~ModeliFrontendImpl()
{
}
kj::Promise<void> ModeliFrontendImpl::newValues(NewValuesContext context)
{
_newValuesCallback(context.getParams().getTimestamp(), CapnConverter::convertValues(context.getParams().getValues()));
// Return to client
return kj::READY_NOW;
}
kj::Promise<void> ModeliFrontendImpl::log(LogContext context)
{
_logCallback(context.getParams().getInstanceName(), context.getParams().getStatus(), context.getParams().getMessage());
// Return to client
return kj::READY_NOW;
}
#pragma
#include "ModeliRpc.capnp.h"
#include "IRpcFrontend.h"
#include <string>
#include <vector>
/// This class serves as a forwarder of the callbacks.
class ModeliFrontendImpl final : public ModeliFrontend::Server
{
private:
NewValuesCallback _newValuesCallback;
LogCallback _logCallback;
public:
ModeliFrontendImpl(NewValuesCallback newValuesCallback, LogCallback logCallback);
~ModeliFrontendImpl();
// Overrides of the ModeliFrontend::Server interface
kj::Promise<void> newValues(NewValuesContext context) override;
kj::Promise<void> log(LogContext context) override;
};
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment