diff options
author | Stefan Laner <laner@itestra.de> | 2014-02-24 09:41:53 +0100 |
---|---|---|
committer | Stefan Laner <laner@itestra.de> | 2014-02-26 10:52:17 +0100 |
commit | b94ed2030fd13d100a757d531983b2fd2498b62e (patch) | |
tree | cc2c675f7999130edbd4ea76ebd6458d0d730c9b | |
parent | fa209eed0e5c81c277601aa24069fa23f61b675d (diff) | |
download | genivi-common-api-runtime-b94ed2030fd13d100a757d531983b2fd2498b62e.tar.gz |
Windows compatible version
Change-Id: I775e584175ec3dcde258e7bed261c61e763d20ce
-rw-r--r-- | CommonAPI.sln | 28 | ||||
-rw-r--r-- | CommonAPI.vcxproj | 116 | ||||
-rw-r--r-- | README | 9 | ||||
-rw-r--r-- | Tests.vcxproj | 95 | ||||
-rw-r--r-- | src/CommonAPI/Attribute.h | 6 | ||||
-rw-r--r-- | src/CommonAPI/AttributeExtension.h | 14 | ||||
-rw-r--r-- | src/CommonAPI/Configuration.cpp | 16 | ||||
-rw-r--r-- | src/CommonAPI/Factory.h | 47 | ||||
-rw-r--r-- | src/CommonAPI/Factory.hpp | 27 | ||||
-rw-r--r-- | src/CommonAPI/MainLoopContext.h | 18 | ||||
-rw-r--r-- | src/CommonAPI/ProxyManager.h | 18 | ||||
-rw-r--r-- | src/CommonAPI/Runtime.cpp | 26 | ||||
-rw-r--r-- | src/CommonAPI/SerializableVariant.hpp | 10 | ||||
-rw-r--r-- | src/CommonAPI/ServicePublisher.hpp | 2 | ||||
-rw-r--r-- | src/CommonAPI/Stub.h | 9 | ||||
-rw-r--r-- | src/CommonAPI/types.h | 19 | ||||
-rw-r--r-- | src/CommonAPI/utils.h | 44 | ||||
-rwxr-xr-x | src/test/VariantTest.cpp | 4 |
18 files changed, 444 insertions, 64 deletions
diff --git a/CommonAPI.sln b/CommonAPI.sln new file mode 100644 index 0000000..b10dbd0 --- /dev/null +++ b/CommonAPI.sln @@ -0,0 +1,28 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Express 2013 for Windows Desktop
+VisualStudioVersion = 12.0.20827.3
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Tests.vcxproj", "{872A0F1D-2EB9-443D-9869-B7F699CC0DE2}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CommonAPI", "CommonAPI.vcxproj", "{C18FDEDE-810E-405D-9100-57A1CC5C78A9}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Debug|Win32.ActiveCfg = Debug|Win32
+ {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Debug|Win32.Build.0 = Debug|Win32
+ {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Release|Win32.ActiveCfg = Release|Win32
+ {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Release|Win32.Build.0 = Release|Win32
+ {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Debug|Win32.Build.0 = Debug|Win32
+ {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Release|Win32.ActiveCfg = Release|Win32
+ {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/CommonAPI.vcxproj b/CommonAPI.vcxproj new file mode 100644 index 0000000..0ddca69 --- /dev/null +++ b/CommonAPI.vcxproj @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="12.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>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{C18FDEDE-810E-405D-9100-57A1CC5C78A9}</ProjectGuid>
+ <RootNamespace>CommonAPI</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v120</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v120</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <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>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <IncludePath>$(IncludePath)</IncludePath>
+ <LibraryPath>$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <PreprocessorDefinitions>WIN32;COMMONAPI_INTERNAL_COMPILATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DebugInformationFormat>OldStyle</DebugInformationFormat>
+ <DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
+ </Lib>
+ <Lib>
+ <AdditionalLibraryDirectories>C:\work\bmw\2.0\gtest-1.7.0\msvc\gtest\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <Verbose>true</Verbose>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="src\CommonAPI\Attribute.h" />
+ <ClInclude Include="src\CommonAPI\AttributeExtension.h" />
+ <ClInclude Include="src\CommonAPI\ByteBuffer.h" />
+ <ClInclude Include="src\CommonAPI\CommonAPI.h" />
+ <ClInclude Include="src\CommonAPI\Configuration.h" />
+ <ClInclude Include="src\CommonAPI\ContainerUtils.h" />
+ <ClInclude Include="src\CommonAPI\Event.h" />
+ <ClInclude Include="src\CommonAPI\Factory.h" />
+ <ClInclude Include="src\CommonAPI\Factory.hpp" />
+ <ClInclude Include="src\CommonAPI\InputStream.h" />
+ <ClInclude Include="src\CommonAPI\MainLoopContext.h" />
+ <ClInclude Include="src\CommonAPI\MiddlewareInfo.h" />
+ <ClInclude Include="src\CommonAPI\OutputStream.h" />
+ <ClInclude Include="src\CommonAPI\Proxy.h" />
+ <ClInclude Include="src\CommonAPI\ProxyManager.h" />
+ <ClInclude Include="src\CommonAPI\Runtime.h" />
+ <ClInclude Include="src\CommonAPI\SelectiveEvent.h" />
+ <ClInclude Include="src\CommonAPI\SerializableStruct.h" />
+ <ClInclude Include="src\CommonAPI\SerializableVariant.h" />
+ <ClInclude Include="src\CommonAPI\SerializableVariant.hpp" />
+ <ClInclude Include="src\CommonAPI\ServicePublisher.h" />
+ <ClInclude Include="src\CommonAPI\ServicePublisher.hpp" />
+ <ClInclude Include="src\CommonAPI\Stub.h" />
+ <ClInclude Include="src\CommonAPI\types.h" />
+ <ClInclude Include="src\CommonAPI\utils.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="src\CommonAPI\Configuration.cpp" />
+ <ClCompile Include="src\CommonAPI\ContainerUtils.cpp" />
+ <ClCompile Include="src\CommonAPI\Runtime.cpp" />
+ <ClCompile Include="src\CommonAPI\ServicePublisher.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file @@ -52,6 +52,8 @@ Use autotools to build this package: # sudo make install (or alternative install process, eg. checkinstall on debian-based distributions, such as Ubuntu) ---- If the environment variable GTEST_CONFIG is set to the path of the gtest-config script in a Gtest tree test will also be built. +---- +To build the Windows version of CommonAPI with Visual Studio, you can use the solution file CommonAPI.sln. It is configured to build CommonAPI as a static library. == Linking against CommonAPI @@ -186,6 +188,13 @@ default will take precedence over those two default paths. Separator between several paths is ":". +== Remarks on Windows version + +Due to a compiler bug in Visual Studio 2013, which is not able to call constructors of variadic template packs, if they contain zero elements, the factory’s buildProxy method does not return a proxy without AttributeExtensions, but implicitly adds a WINDummyAttributeExtension. So to assign such a proxy use the auto keyword or the typedef ***ProxyDefault in the generated ***Proxy.h. +This restriction does only affect the windows port. The typedef is cross platform compatible as it points to a proxy with empty template list on Linux. + +The Windows version does not support dynamic loading. + == Working on the code & contribution .First get the code from the git: diff --git a/Tests.vcxproj b/Tests.vcxproj new file mode 100644 index 0000000..5cc6625 --- /dev/null +++ b/Tests.vcxproj @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="12.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>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{872A0F1D-2EB9-443D-9869-B7F699CC0DE2}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>Tests</RootNamespace>
+ <ProjectName>Test</ProjectName>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v120</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>false</UseOfMfc>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v120</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>false</UseOfMfc>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <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>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <IncludePath>C:\work\bmw\2.0\gtest-1.7.0\include;$(SolutionDir)\src\test;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
+ <LibraryPath>C:\work\bmw\2.0\gtest-1.7.0\msvc\gtest\Debug;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;COMMONAPI_INTERNAL_COMPILATION;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <UseFullPaths>true</UseFullPaths>
+ <DebugInformationFormat>OldStyle</DebugInformationFormat>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>gtestd.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <UseFullPaths>true</UseFullPaths>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="src\test\VariantTest.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/src/CommonAPI/Attribute.h b/src/CommonAPI/Attribute.h index aa5a213..51990c3 100644 --- a/src/CommonAPI/Attribute.h +++ b/src/CommonAPI/Attribute.h @@ -126,6 +126,12 @@ template <typename _ValueType> struct ObservableAttribute: _ObservableAttributeImpl< Attribute<_ValueType> > { }; +#ifdef WIN32 +struct WINDummyAttribute { + WINDummyAttribute() {} +}; +#endif + } // namespace CommonAPI #endif // COMMONAPI_ATTRIBUTE_H_ diff --git a/src/CommonAPI/AttributeExtension.h b/src/CommonAPI/AttributeExtension.h index d73c2a3..d4c8075 100644 --- a/src/CommonAPI/AttributeExtension.h +++ b/src/CommonAPI/AttributeExtension.h @@ -37,6 +37,20 @@ class AttributeExtension { _AttributeType& baseAttribute_; }; +#ifdef WIN32 +template<typename _AttributeType> +class WINDummyAttributeExtension : public CommonAPI::AttributeExtension<_AttributeType> { + typedef AttributeExtension<_AttributeType> __baseClass_t; + WINDummyAttribute dummyAttribute; +public: + WINDummyAttributeExtension() {}; + WINDummyAttributeExtension(Proxy& proxy) : + AttributeExtension<_AttributeType>(dummyAttribute) {} + + ~WINDummyAttributeExtension() {} +}; +#endif + } // namespace CommonAPI #endif // COMMON_API_DBUS_ATTRIBUTE_EXTENSION_H_ diff --git a/src/CommonAPI/Configuration.cpp b/src/CommonAPI/Configuration.cpp index 470015d..021dd1d 100644 --- a/src/CommonAPI/Configuration.cpp +++ b/src/CommonAPI/Configuration.cpp @@ -123,8 +123,22 @@ void Configuration::readConfigFile(std::ifstream& addressConfigFile) { void Configuration::readEnvironmentVariables() { librarySearchPaths_ = split(COMMONAPI_STD_LIB_PATH, ':'); + bool errorOccured = false; +#ifdef WIN32 + char* environmentBindingPath; + size_t len; + errno_t err = _dupenv_s(&environmentBindingPath, &len, COMMONAPI_ENVIRONMENT_BINDING_PATH); + if (err != 0 || environmentBindingPath == NULL) { + errorOccured = true; + } +#else const char* environmentBindingPath = getenv(COMMONAPI_ENVIRONMENT_BINDING_PATH); - if (environmentBindingPath) { + if (!environmentBindingPath) { + errorOccured = true; + } +#endif + + if (!errorOccured) { std::vector<std::string> environmentPaths = split(environmentBindingPath, ':'); librarySearchPaths_.insert(librarySearchPaths_.begin(), environmentPaths.begin(), environmentPaths.end()); } diff --git a/src/CommonAPI/Factory.h b/src/CommonAPI/Factory.h index ccf9004..4a7c729 100644 --- a/src/CommonAPI/Factory.h +++ b/src/CommonAPI/Factory.h @@ -24,6 +24,7 @@ #include "Stub.h" #include "types.h" #include "utils.h" +#include "AttributeExtension.h" namespace CommonAPI { @@ -91,10 +92,33 @@ class Factory { * @return a shared pointer to the constructed proxy */ template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions> - std::shared_ptr<_ProxyClass<_AttributeExtensions...> > + std::shared_ptr< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension<WINDummyAttribute>, +#endif + _AttributeExtensions...> + > buildProxy(const std::string& participantId, const std::string& serviceName, - const std::string& domain); + const std::string& domain) { + std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::getInterfaceId(), participantId, serviceName, domain); + + if(abstractMiddlewareProxy) { + auto returnProxy = std::make_shared< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension<WINDummyAttribute>, +#endif + _AttributeExtensions...> + >(abstractMiddlewareProxy); + + return returnProxy; + } + else { + return NULL; + } + } /** * \brief Build a proxy for the specified address @@ -106,8 +130,23 @@ class Factory { * @return a shared pointer to the constructed proxy */ template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions > - std::shared_ptr<_ProxyClass<_AttributeExtensions...> > - buildProxy(const std::string& serviceAddress); + std::shared_ptr< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension<WINDummyAttribute>, +#endif + _AttributeExtensions...> + > + buildProxy(const std::string& serviceAddress) { + std::string domain; + std::string serviceName; + std::string participantId; + if (!splitValidAddress(serviceAddress, domain, serviceName, participantId)) { + return false; + } + + return buildProxy<_ProxyClass, _AttributeExtensions...>(participantId, serviceName, domain); + } /** * \brief Build a proxy for the specified address with one extension for all attributes diff --git a/src/CommonAPI/Factory.hpp b/src/CommonAPI/Factory.hpp index 865144c..8884632 100644 --- a/src/CommonAPI/Factory.hpp +++ b/src/CommonAPI/Factory.hpp @@ -12,33 +12,6 @@ namespace CommonAPI { -template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions> -std::shared_ptr<_ProxyClass<_AttributeExtensions...> > -Factory::buildProxy(const std::string& participantId, - const std::string& serviceName, - const std::string& domain) { - - std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::InterfaceType::getInterfaceId(), participantId, serviceName, domain); - if (abstractMiddlewareProxy) { - return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy); - } - return NULL; -} - -template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions > -std::shared_ptr<_ProxyClass<_AttributeExtensions...> > -Factory::buildProxy(const std::string& serviceAddress) { - - std::string domain; - std::string serviceName; - std::string participantId; - if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) { - return std::shared_ptr<_ProxyClass<_AttributeExtensions...> >(); - } - - return buildProxy<_ProxyClass, _AttributeExtensions...>(participantId, serviceName, domain); -} - template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension> std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t> Factory::buildProxyWithDefaultAttributeExtension(const std::string& participantId, diff --git a/src/CommonAPI/MainLoopContext.h b/src/CommonAPI/MainLoopContext.h index c988f9c..6949c0b 100644 --- a/src/CommonAPI/MainLoopContext.h +++ b/src/CommonAPI/MainLoopContext.h @@ -14,16 +14,29 @@ #include <stdint.h> + +#ifdef WIN32 +#include <WinSock2.h> +#else #include <poll.h> +#endif + +#ifdef WIN32 +#undef max +#endif + #include <limits> #include <vector> #include <chrono> #include <list> +#include <functional> namespace CommonAPI { + + enum class DispatchPriority { VERY_HIGH, HIGH, @@ -114,9 +127,8 @@ struct Watch { virtual const std::vector<DispatchSource*>& getDependentDispatchSources() = 0; }; - -constexpr int64_t TIMEOUT_INFINITE = std::numeric_limits<int64_t>::max(); -constexpr int64_t TIMEOUT_NONE = 0; +const int64_t TIMEOUT_INFINITE = std::numeric_limits<int64_t>::max(); +const int64_t TIMEOUT_NONE = 0; /** diff --git a/src/CommonAPI/ProxyManager.h b/src/CommonAPI/ProxyManager.h index e967852..ecb8799 100644 --- a/src/CommonAPI/ProxyManager.h +++ b/src/CommonAPI/ProxyManager.h @@ -51,14 +51,26 @@ class ProxyManager { virtual InstanceAvailabilityStatusChangedEvent& getInstanceAvailabilityStatusChangedEvent() = 0; template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions> - std::shared_ptr<_ProxyClass<_AttributeExtensions...> > + std::shared_ptr< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension<WINDummyAttribute>, +#endif + _AttributeExtensions...> + > buildProxy(const std::string& instanceName) { std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(instanceName); if (abstractMiddlewareProxy) { - return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy); + auto returnProxy = std::make_shared< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension<WINDummyAttribute>, +#endif + _AttributeExtensions...> + >(abstractMiddlewareProxy); + return returnProxy; } return NULL; - } template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension> diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp index a38556a..812b410 100644 --- a/src/CommonAPI/Runtime.cpp +++ b/src/CommonAPI/Runtime.cpp @@ -6,8 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include <sys/types.h> #include <sys/stat.h> +#ifndef WIN32 #include <dirent.h> #include <dlfcn.h> +#endif #include <algorithm> #include <iostream> @@ -28,7 +30,7 @@ static bool isDynamic_ = false; static const char COMMONAPI_LIB_PREFIX[] = "libCommonAPI-"; static const char MIDDLEWARE_INFO_SYMBOL_NAME[] = "middlewareInfo"; - +#ifndef WIN32 inline bool Runtime::tryLoadLibrary(const std::string& libraryPath, void** sharedLibraryHandle, MiddlewareInfo** foundMiddlewareInfo) { @@ -66,7 +68,6 @@ inline bool Runtime::tryLoadLibrary(const std::string& libraryPath, return true; } - bool Runtime::checkAndLoadLibrary(const std::string& libraryPath, const std::string& requestedBindingIdentifier, bool keepLibrary) { @@ -102,7 +103,6 @@ bool Runtime::checkAndLoadLibrary(const std::string& libraryPath, return true; } - bool Runtime::checkAndLoadDefaultLibrary(std::string& foundBindingIdentifier, const std::string& libraryPath) { void* sharedLibraryHandle = NULL; MiddlewareInfo* foundMiddlewareInfo; @@ -122,7 +122,6 @@ bool Runtime::checkAndLoadDefaultLibrary(std::string& foundBindingIdentifier, co return true; } - const std::vector<std::string> Runtime::readDirectory(const std::string& path) { std::vector<std::string> result; struct stat filestat; @@ -167,7 +166,7 @@ const std::vector<std::string> Runtime::readDirectory(const std::string& path) { return result; } - +#endif struct LibraryVersion { int32_t major; @@ -185,7 +184,7 @@ bool operator<(LibraryVersion const& lhs, LibraryVersion const& rhs) { return lhs.major < rhs.major; } - +#ifndef WIN32 std::shared_ptr<Runtime> Runtime::checkDynamicLibraries(const std::string& requestedMiddlewareName, LoadState& loadState) { const std::string& middlewareLibraryPath = Configuration::getInstance().getMiddlewareLibraryPath(requestedMiddlewareName); @@ -294,7 +293,7 @@ std::shared_ptr<Runtime> Runtime::checkDynamicLibraries(LoadState& loadState) { return std::shared_ptr<Runtime>(); } - +#endif void Runtime::registerRuntimeLoader(const std::string& middlewareName, const MiddlewareRuntimeLoadFunction& middlewareRuntimeLoadFunction) { if (!registeredRuntimeLoadFunctions_) { @@ -325,14 +324,23 @@ std::shared_ptr<Runtime> Runtime::load(LoadState& loadState) { if (defaultRuntimeLoader != registeredRuntimeLoadFunctions_->end()) { return (defaultRuntimeLoader->second)(); } + +#ifdef WIN32 + return std::shared_ptr<Runtime>(); +#else return checkDynamicLibraries(defaultBindingIdentifier, loadState); +#endif } else { const auto defaultRuntimeLoader = registeredRuntimeLoadFunctions_->begin(); if (defaultRuntimeLoader != registeredRuntimeLoadFunctions_->end()) { return (defaultRuntimeLoader->second)(); } +#ifdef WIN32 + return std::shared_ptr<Runtime>(); +#else return checkDynamicLibraries(loadState); +#endif } } @@ -356,7 +364,11 @@ std::shared_ptr<Runtime> Runtime::load(const std::string& middlewareIdOrAlias, L return (foundRuntimeLoader->second)(); } +#ifdef WIN32 + return std::shared_ptr<Runtime>(); +#else return checkDynamicLibraries(middlewareName, loadState); +#endif } diff --git a/src/CommonAPI/SerializableVariant.hpp b/src/CommonAPI/SerializableVariant.hpp index febff2d..fe9a53d 100644 --- a/src/CommonAPI/SerializableVariant.hpp +++ b/src/CommonAPI/SerializableVariant.hpp @@ -175,7 +175,11 @@ public: void operator()(const _Type&) { _Type value; inputStream_ >> value; +#ifdef WIN32 + lhs_.set<_Type>(std::move(value), false); +#else lhs_.Variant<_Types...>::template set<_Type>(std::move(value), false); +#endif } private: @@ -233,7 +237,11 @@ public: template<typename _Type> void operator()(const _Type& value) const { +#ifdef WIN32 + lhs_.set<_Type>(value, clear_); +#else lhs_.Variant<_Types...>::template set<_Type>(value, clear_); +#endif } template<typename _Type> @@ -453,7 +461,7 @@ const _Type & Variant<_Types...>::get() const { if (cType == valueType_) { return *(reinterpret_cast<const _Type *>(&valueStorage_)); } else { -#ifdef __EXCEPTIONS +#if defined(__EXCEPTIONS) || defined(WIN32) std::bad_cast toThrow; throw toThrow; #else diff --git a/src/CommonAPI/ServicePublisher.hpp b/src/CommonAPI/ServicePublisher.hpp index 604bf07..bab75ed 100644 --- a/src/CommonAPI/ServicePublisher.hpp +++ b/src/CommonAPI/ServicePublisher.hpp @@ -20,7 +20,7 @@ bool ServicePublisher::registerService(std::shared_ptr<_Stub> stub, std::shared_ptr<Factory> factory) { std::shared_ptr<StubBase> stubBase = std::dynamic_pointer_cast<StubBase>(stub); - return registerService(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain, factory); + return registerService(stubBase, _Stub::StubInterface::getInterfaceId(), participantId, serviceName, domain, factory); } template<typename _Stub> diff --git a/src/CommonAPI/Stub.h b/src/CommonAPI/Stub.h index f09790b..a22ae3c 100644 --- a/src/CommonAPI/Stub.h +++ b/src/CommonAPI/Stub.h @@ -29,7 +29,8 @@ public: virtual const std::string& getInstanceId() const = 0; }; -struct StubBase { +class StubBase { +public: virtual ~StubBase() { } }; @@ -37,7 +38,7 @@ struct StubBase { template<typename _StubAdapter, typename _StubRemoteEventHandler> class Stub: public virtual StubBase { static_assert(std::is_base_of<StubAdapter, _StubAdapter>::value, "Invalid StubAdapter Class!"); - public: +public: typedef _StubAdapter StubAdapterType; typedef _StubRemoteEventHandler RemoteEventHandlerType; @@ -48,9 +49,9 @@ class Stub: public virtual StubBase { virtual const std::shared_ptr<_StubAdapter> getStubAdapter() { return stubAdapter_; } - protected: - std::shared_ptr<_StubAdapter> stubAdapter_; +protected: + std::shared_ptr<_StubAdapter> stubAdapter_; }; enum SelectiveBroadcastSubscriptionEvent { diff --git a/src/CommonAPI/types.h b/src/CommonAPI/types.h index b81cf5d..d6c4f95 100644 --- a/src/CommonAPI/types.h +++ b/src/CommonAPI/types.h @@ -29,6 +29,25 @@ #endif +#ifdef WIN32 +#define CCALL __cdecl +#pragma section(".CRT$XCU",read) +#define INITIALIZER(f) \ + static void __cdecl f(void); \ + __declspec(allocate(".CRT$XCU")) void(__cdecl*f##_)(void) = f; \ + static void __cdecl f(void) +#else +#define CCALL +#define INITIALIZER(f) \ + static void f(void) __attribute__((constructor)); \ + static void f(void) +#endif + +#ifdef WIN32 +#define usleep(micSec) \ + std::this_thread::sleep_for(std::chrono::microseconds(micSec)) +#endif + namespace CommonAPI { enum class AvailabilityStatus { diff --git a/src/CommonAPI/utils.h b/src/CommonAPI/utils.h index 2dccfcc..1224de1 100644 --- a/src/CommonAPI/utils.h +++ b/src/CommonAPI/utils.h @@ -7,9 +7,10 @@ #ifndef COMMONAPI_UTILS_H_ #define COMMONAPI_UTILS_H_ -#include <unistd.h> +#ifndef WIN32 #include <dirent.h> #include <dlfcn.h> +#endif #include <sys/stat.h> #include <cstring> @@ -19,6 +20,16 @@ #include <algorithm> #include <iostream> +#include <locale> +#include <functional> + +#ifdef WIN32 +#include <xfunctional> +#define WIN32_LEAN_AND_MEAN // this prevents windows.h from including winsock.h, which causes duplicate definitions with winsock2.h +#include <windows.h> +#else +#include <unistd.h> +#endif namespace CommonAPI { @@ -38,6 +49,11 @@ namespace CommonAPI { * @return The name of the currently executing binary. */ inline std::string getCurrentBinaryFileFQN() { +#ifdef WIN32 + TCHAR result[MAX_PATH]; + std::basic_string<TCHAR> resultString(result, GetModuleFileName(NULL, result, MAX_PATH)); + return std::string(resultString.begin(), resultString.end()); +#else char fqnOfBinary[FILENAME_MAX]; char pathToProcessImage[FILENAME_MAX]; @@ -47,9 +63,11 @@ inline std::string getCurrentBinaryFileFQN() { if (lengthOfFqn != -1) { fqnOfBinary[lengthOfFqn] = '\0'; return std::string(std::move(fqnOfBinary)); - } else { + } + else { return std::string(""); } +#endif } /** @@ -89,6 +107,10 @@ inline std::vector<std::string> split(const std::string& s, char delim) { return split(s, delim, elems); } +inline bool isspace(char c) { + return std::isspace(c, std::locale()); +} + /** * \brief Trims whitespaces from beginning and end of a std::string. * @@ -99,18 +121,18 @@ inline void trim(std::string& toTrim) { toTrim.begin(), std::find_if(toTrim.begin(), toTrim.end(), - std::not1(std::ptr_fun<int, int>(std::isspace))) - ); + std::not1(std::ptr_fun(isspace))) + ); toTrim.erase( std::find_if(toTrim.rbegin(), toTrim.rend(), - std::not1(std::ptr_fun<int, int>(std::isspace))).base(), - toTrim.end() - ); + std::not1(std::ptr_fun(isspace))).base(), + toTrim.end() + ); } inline bool notIsdigit(char c) { - return !std::isdigit(c); + return !std::isdigit(c, std::locale()); } /** @@ -130,7 +152,7 @@ inline bool containsOnlyDigits(const std::string& toCheck) { } inline bool notIsalnum(char c) { - return !std::isalnum(c); + return !std::isalnum(c, std::locale()); } /** @@ -210,7 +232,7 @@ inline bool isValidCommonApiAddress(const std::string& commonApiAddress) { return isValidDomainName(splittedAddress[0]) && isValidServiceName(splittedAddress[1]) && isValidInstanceId(splittedAddress[2]); } - +#ifndef WIN32 /** * \brief Loads a specific generic library at runtime. * @@ -336,7 +358,7 @@ inline void findAndLoadGenericLibraries(const std::string& requestedMiddlewareNa findAndLoadGenericLibraries(requestedMiddlewareName, singleSearchPath.c_str()); } } - +#endif } //namespace CommonAPI diff --git a/src/test/VariantTest.cpp b/src/test/VariantTest.cpp index ed793f5..e83ebe6 100755 --- a/src/test/VariantTest.cpp +++ b/src/test/VariantTest.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include <gtest/gtest.h> -#include <src/CommonAPI/SerializableVariant.h> +#include "../CommonAPI/SerializableVariant.h" using namespace CommonAPI; @@ -64,7 +64,7 @@ struct test2: CommonAPI::SerializableStruct { TEST_F(VariantTest, VariantTestPack) { int fromInt = 5; - double fromDouble = 12.344d; + double fromDouble = 12.344; std::string fromString = "123abcsadfaljkawlöfasklöerklöfjasklfjysklfjaskfjsklösdfdko4jdfasdjioögjopefgip3rtgjiprg!"; Variant<int, double, std::string> myVariant(fromInt); |