Windows compatible version
authorStefan Laner <laner@itestra.de>
Mon, 24 Feb 2014 08:41:53 +0000 (09:41 +0100)
committerStefan Laner <laner@itestra.de>
Wed, 26 Feb 2014 09:52:17 +0000 (10:52 +0100)
Change-Id: I775e584175ec3dcde258e7bed261c61e763d20ce

18 files changed:
CommonAPI.sln [new file with mode: 0644]
CommonAPI.vcxproj [new file with mode: 0644]
README
Tests.vcxproj [new file with mode: 0644]
src/CommonAPI/Attribute.h
src/CommonAPI/AttributeExtension.h
src/CommonAPI/Configuration.cpp
src/CommonAPI/Factory.h
src/CommonAPI/Factory.hpp
src/CommonAPI/MainLoopContext.h
src/CommonAPI/ProxyManager.h
src/CommonAPI/Runtime.cpp
src/CommonAPI/SerializableVariant.hpp
src/CommonAPI/ServicePublisher.hpp
src/CommonAPI/Stub.h
src/CommonAPI/types.h
src/CommonAPI/utils.h
src/test/VariantTest.cpp

diff --git a/CommonAPI.sln b/CommonAPI.sln
new file mode 100644 (file)
index 0000000..b10dbd0
--- /dev/null
@@ -0,0 +1,28 @@
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Visual Studio Express 2013 for Windows Desktop\r
+VisualStudioVersion = 12.0.20827.3\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Tests.vcxproj", "{872A0F1D-2EB9-443D-9869-B7F699CC0DE2}"\r
+EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CommonAPI", "CommonAPI.vcxproj", "{C18FDEDE-810E-405D-9100-57A1CC5C78A9}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|Win32 = Debug|Win32\r
+               Release|Win32 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Debug|Win32.Build.0 = Debug|Win32\r
+               {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Release|Win32.ActiveCfg = Release|Win32\r
+               {872A0F1D-2EB9-443D-9869-B7F699CC0DE2}.Release|Win32.Build.0 = Release|Win32\r
+               {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Debug|Win32.Build.0 = Debug|Win32\r
+               {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Release|Win32.ActiveCfg = Release|Win32\r
+               {C18FDEDE-810E-405D-9100-57A1CC5C78A9}.Release|Win32.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/CommonAPI.vcxproj b/CommonAPI.vcxproj
new file mode 100644 (file)
index 0000000..0ddca69
--- /dev/null
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{C18FDEDE-810E-405D-9100-57A1CC5C78A9}</ProjectGuid>\r
+    <RootNamespace>CommonAPI</RootNamespace>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v120</PlatformToolset>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v120</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>MultiByte</CharacterSet>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <IncludePath>$(IncludePath)</IncludePath>\r
+    <LibraryPath>$(LibraryPath)</LibraryPath>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <SDLCheck>true</SDLCheck>\r
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r
+      <PreprocessorDefinitions>WIN32;COMMONAPI_INTERNAL_COMPILATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <DebugInformationFormat>OldStyle</DebugInformationFormat>\r
+      <DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
+    </Link>\r
+    <Lib>\r
+      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
+    </Lib>\r
+    <Lib>\r
+      <AdditionalLibraryDirectories>C:\work\bmw\2.0\gtest-1.7.0\msvc\gtest\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\r
+      <Verbose>true</Verbose>\r
+    </Lib>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <SDLCheck>true</SDLCheck>\r
+    </ClCompile>\r
+    <Link>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClInclude Include="src\CommonAPI\Attribute.h" />\r
+    <ClInclude Include="src\CommonAPI\AttributeExtension.h" />\r
+    <ClInclude Include="src\CommonAPI\ByteBuffer.h" />\r
+    <ClInclude Include="src\CommonAPI\CommonAPI.h" />\r
+    <ClInclude Include="src\CommonAPI\Configuration.h" />\r
+    <ClInclude Include="src\CommonAPI\ContainerUtils.h" />\r
+    <ClInclude Include="src\CommonAPI\Event.h" />\r
+    <ClInclude Include="src\CommonAPI\Factory.h" />\r
+    <ClInclude Include="src\CommonAPI\Factory.hpp" />\r
+    <ClInclude Include="src\CommonAPI\InputStream.h" />\r
+    <ClInclude Include="src\CommonAPI\MainLoopContext.h" />\r
+    <ClInclude Include="src\CommonAPI\MiddlewareInfo.h" />\r
+    <ClInclude Include="src\CommonAPI\OutputStream.h" />\r
+    <ClInclude Include="src\CommonAPI\Proxy.h" />\r
+    <ClInclude Include="src\CommonAPI\ProxyManager.h" />\r
+    <ClInclude Include="src\CommonAPI\Runtime.h" />\r
+    <ClInclude Include="src\CommonAPI\SelectiveEvent.h" />\r
+    <ClInclude Include="src\CommonAPI\SerializableStruct.h" />\r
+    <ClInclude Include="src\CommonAPI\SerializableVariant.h" />\r
+    <ClInclude Include="src\CommonAPI\SerializableVariant.hpp" />\r
+    <ClInclude Include="src\CommonAPI\ServicePublisher.h" />\r
+    <ClInclude Include="src\CommonAPI\ServicePublisher.hpp" />\r
+    <ClInclude Include="src\CommonAPI\Stub.h" />\r
+    <ClInclude Include="src\CommonAPI\types.h" />\r
+    <ClInclude Include="src\CommonAPI\utils.h" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="src\CommonAPI\Configuration.cpp" />\r
+    <ClCompile Include="src\CommonAPI\ContainerUtils.cpp" />\r
+    <ClCompile Include="src\CommonAPI\Runtime.cpp" />\r
+    <ClCompile Include="src\CommonAPI\ServicePublisher.cpp" />\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
+</Project>
\ No newline at end of file
diff --git a/README b/README
index 716a182..66ba180 100644 (file)
--- a/README
+++ b/README
@@ -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 (file)
index 0000000..5cc6625
--- /dev/null
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <ItemGroup Label="ProjectConfigurations">\r
+    <ProjectConfiguration Include="Debug|Win32">\r
+      <Configuration>Debug</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+    <ProjectConfiguration Include="Release|Win32">\r
+      <Configuration>Release</Configuration>\r
+      <Platform>Win32</Platform>\r
+    </ProjectConfiguration>\r
+  </ItemGroup>\r
+  <PropertyGroup Label="Globals">\r
+    <ProjectGuid>{872A0F1D-2EB9-443D-9869-B7F699CC0DE2}</ProjectGuid>\r
+    <Keyword>Win32Proj</Keyword>\r
+    <RootNamespace>Tests</RootNamespace>\r
+    <ProjectName>Test</ProjectName>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+    <ConfigurationType>Application</ConfigurationType>\r
+    <UseDebugLibraries>true</UseDebugLibraries>\r
+    <PlatformToolset>v120</PlatformToolset>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <UseOfMfc>false</UseOfMfc>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <UseDebugLibraries>false</UseDebugLibraries>\r
+    <PlatformToolset>v120</PlatformToolset>\r
+    <WholeProgramOptimization>true</WholeProgramOptimization>\r
+    <CharacterSet>Unicode</CharacterSet>\r
+    <UseOfMfc>false</UseOfMfc>\r
+  </PropertyGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+  <ImportGroup Label="ExtensionSettings">\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+  </ImportGroup>\r
+  <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <LinkIncremental>true</LinkIncremental>\r
+    <IncludePath>C:\work\bmw\2.0\gtest-1.7.0\include;$(SolutionDir)\src\test;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>\r
+    <LibraryPath>C:\work\bmw\2.0\gtest-1.7.0\msvc\gtest\Debug;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86)</LibraryPath>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <LinkIncremental>true</LinkIncremental>\r
+  </PropertyGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+    <ClCompile>\r
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <Optimization>Disabled</Optimization>\r
+      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;COMMONAPI_INTERNAL_COMPILATION;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <UseFullPaths>true</UseFullPaths>\r
+      <DebugInformationFormat>OldStyle</DebugInformationFormat>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Console</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\r
+      <AdditionalDependencies>gtestd.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+    <ClCompile>\r
+      <WarningLevel>Level3</WarningLevel>\r
+      <PrecompiledHeader>Use</PrecompiledHeader>\r
+      <Optimization>MaxSpeed</Optimization>\r
+      <FunctionLevelLinking>true</FunctionLevelLinking>\r
+      <IntrinsicFunctions>true</IntrinsicFunctions>\r
+      <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+      <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <UseFullPaths>true</UseFullPaths>\r
+    </ClCompile>\r
+    <Link>\r
+      <SubSystem>Windows</SubSystem>\r
+      <GenerateDebugInformation>true</GenerateDebugInformation>\r
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+      <OptimizeReferences>true</OptimizeReferences>\r
+      <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\r
+    </Link>\r
+  </ItemDefinitionGroup>\r
+  <ItemGroup>\r
+    <ClCompile Include="src\test\VariantTest.cpp" />\r
+  </ItemGroup>\r
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+  <ImportGroup Label="ExtensionTargets">\r
+  </ImportGroup>\r
+</Project>
\ No newline at end of file
index aa5a213..51990c3 100644 (file)
@@ -126,6 +126,12 @@ template <typename _ValueType>
 struct ObservableAttribute: _ObservableAttributeImpl< Attribute<_ValueType> > {
 };
 
+#ifdef WIN32
+struct WINDummyAttribute {
+    WINDummyAttribute() {}
+};
+#endif
+
 } // namespace CommonAPI
 
 #endif // COMMONAPI_ATTRIBUTE_H_
index d73c2a3..d4c8075 100644 (file)
@@ -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_
index 470015d..021dd1d 100644 (file)
@@ -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());
     }
index ccf9004..4a7c729 100644 (file)
@@ -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
index 865144c..8884632 100644 (file)
 
 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,
index c988f9c..6949c0b 100644 (file)
 
 
 #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;
 
 
 /**
index e967852..ecb8799 100644 (file)
@@ -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>
index a38556a..812b410 100644 (file)
@@ -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
 }
 
 
index febff2d..fe9a53d 100644 (file)
@@ -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
index 604bf07..bab75ed 100644 (file)
@@ -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>
index f09790b..a22ae3c 100644 (file)
@@ -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 {
index b81cf5d..d6c4f95 100644 (file)
 #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 {
index 2dccfcc..1224de1 100644 (file)
@@ -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>
 #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
 
index ed793f5..e83ebe6 100755 (executable)
@@ -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);