From b94ed2030fd13d100a757d531983b2fd2498b62e Mon Sep 17 00:00:00 2001 From: Stefan Laner Date: Mon, 24 Feb 2014 09:41:53 +0100 Subject: Windows compatible version Change-Id: I775e584175ec3dcde258e7bed261c61e763d20ce --- CommonAPI.sln | 28 ++++++++ CommonAPI.vcxproj | 116 ++++++++++++++++++++++++++++++++++ README | 9 +++ Tests.vcxproj | 95 ++++++++++++++++++++++++++++ src/CommonAPI/Attribute.h | 6 ++ src/CommonAPI/AttributeExtension.h | 14 ++++ src/CommonAPI/Configuration.cpp | 16 ++++- src/CommonAPI/Factory.h | 47 ++++++++++++-- src/CommonAPI/Factory.hpp | 27 -------- src/CommonAPI/MainLoopContext.h | 18 +++++- src/CommonAPI/ProxyManager.h | 18 +++++- src/CommonAPI/Runtime.cpp | 26 ++++++-- src/CommonAPI/SerializableVariant.hpp | 10 ++- src/CommonAPI/ServicePublisher.hpp | 2 +- src/CommonAPI/Stub.h | 9 +-- src/CommonAPI/types.h | 19 ++++++ src/CommonAPI/utils.h | 44 +++++++++---- src/test/VariantTest.cpp | 4 +- 18 files changed, 444 insertions(+), 64 deletions(-) create mode 100644 CommonAPI.sln create mode 100644 CommonAPI.vcxproj create mode 100644 Tests.vcxproj 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 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {C18FDEDE-810E-405D-9100-57A1CC5C78A9} + CommonAPI + + + + StaticLibrary + true + v120 + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + $(IncludePath) + $(LibraryPath) + + + + Level3 + Disabled + true + MultiThreadedDebugDLL + WIN32;COMMONAPI_INTERNAL_COMPILATION;%(PreprocessorDefinitions) + OldStyle + 4996;%(DisableSpecificWarnings) + + + true + %(AdditionalDependencies) + + + %(AdditionalDependencies) + + + C:\work\bmw\2.0\gtest-1.7.0\msvc\gtest\Debug;%(AdditionalLibraryDirectories) + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README b/README index 716a182..66ba180 100644 --- 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 index 0000000..5cc6625 --- /dev/null +++ b/Tests.vcxproj @@ -0,0 +1,95 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {872A0F1D-2EB9-443D-9869-B7F699CC0DE2} + Win32Proj + Tests + Test + + + + Application + true + v120 + Unicode + false + + + DynamicLibrary + false + v120 + true + Unicode + false + + + + + + + + + + + + + true + C:\work\bmw\2.0\gtest-1.7.0\include;$(SolutionDir)\src\test;$(VC_IncludePath);$(WindowsSDK_IncludePath) + C:\work\bmw\2.0\gtest-1.7.0\msvc\gtest\Debug;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86) + + + true + + + + NotUsing + Level3 + Disabled + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;COMMONAPI_INTERNAL_COMPILATION;_DEBUG;%(PreprocessorDefinitions) + true + OldStyle + + + Console + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + gtestd.lib;%(AdditionalDependencies) + + + + + Level3 + Use + MaxSpeed + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + + + + + \ 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 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 +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 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 class _ProxyClass, typename ... _AttributeExtensions> - std::shared_ptr<_ProxyClass<_AttributeExtensions...> > + std::shared_ptr< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension, +#endif + _AttributeExtensions...> + > buildProxy(const std::string& participantId, const std::string& serviceName, - const std::string& domain); + const std::string& domain) { + std::shared_ptr abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::getInterfaceId(), participantId, serviceName, domain); + + if(abstractMiddlewareProxy) { + auto returnProxy = std::make_shared< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension, +#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 class _ProxyClass, typename ... _AttributeExtensions > - std::shared_ptr<_ProxyClass<_AttributeExtensions...> > - buildProxy(const std::string& serviceAddress); + std::shared_ptr< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension, +#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 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 abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::InterfaceType::getInterfaceId(), participantId, serviceName, domain); - if (abstractMiddlewareProxy) { - return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy); - } - return NULL; -} - -template 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 class _ProxyClass, template class _AttributeExtension> std::shared_ptr::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 + +#ifdef WIN32 +#include +#else #include +#endif + +#ifdef WIN32 +#undef max +#endif + #include #include #include #include +#include namespace CommonAPI { + + enum class DispatchPriority { VERY_HIGH, HIGH, @@ -114,9 +127,8 @@ struct Watch { virtual const std::vector& getDependentDispatchSources() = 0; }; - -constexpr int64_t TIMEOUT_INFINITE = std::numeric_limits::max(); -constexpr int64_t TIMEOUT_NONE = 0; +const int64_t TIMEOUT_INFINITE = std::numeric_limits::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 class _ProxyClass, typename ... _AttributeExtensions> - std::shared_ptr<_ProxyClass<_AttributeExtensions...> > + std::shared_ptr< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension, +#endif + _AttributeExtensions...> + > buildProxy(const std::string& instanceName) { std::shared_ptr abstractMiddlewareProxy = createProxy(instanceName); if (abstractMiddlewareProxy) { - return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy); + auto returnProxy = std::make_shared< + _ProxyClass< +#ifdef WIN32 + CommonAPI::WINDummyAttributeExtension, +#endif + _AttributeExtensions...> + >(abstractMiddlewareProxy); + return returnProxy; } return NULL; - } template class _ProxyClass, template 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 #include +#ifndef WIN32 #include #include +#endif #include #include @@ -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 Runtime::readDirectory(const std::string& path) { std::vector result; struct stat filestat; @@ -167,7 +166,7 @@ const std::vector 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::checkDynamicLibraries(const std::string& requestedMiddlewareName, LoadState& loadState) { const std::string& middlewareLibraryPath = Configuration::getInstance().getMiddlewareLibraryPath(requestedMiddlewareName); @@ -294,7 +293,7 @@ std::shared_ptr Runtime::checkDynamicLibraries(LoadState& loadState) { return std::shared_ptr(); } - +#endif void Runtime::registerRuntimeLoader(const std::string& middlewareName, const MiddlewareRuntimeLoadFunction& middlewareRuntimeLoadFunction) { if (!registeredRuntimeLoadFunctions_) { @@ -325,14 +324,23 @@ std::shared_ptr Runtime::load(LoadState& loadState) { if (defaultRuntimeLoader != registeredRuntimeLoadFunctions_->end()) { return (defaultRuntimeLoader->second)(); } + +#ifdef WIN32 + return std::shared_ptr(); +#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(); +#else return checkDynamicLibraries(loadState); +#endif } } @@ -356,7 +364,11 @@ std::shared_ptr Runtime::load(const std::string& middlewareIdOrAlias, L return (foundRuntimeLoader->second)(); } +#ifdef WIN32 + return std::shared_ptr(); +#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 void operator()(const _Type& value) const { +#ifdef WIN32 + lhs_.set<_Type>(value, clear_); +#else lhs_.Variant<_Types...>::template set<_Type>(value, clear_); +#endif } template @@ -453,7 +461,7 @@ const _Type & Variant<_Types...>::get() const { if (cType == valueType_) { return *(reinterpret_cast(&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) { std::shared_ptr stubBase = std::dynamic_pointer_cast(stub); - return registerService(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain, factory); + return registerService(stubBase, _Stub::StubInterface::getInterfaceId(), participantId, serviceName, domain, factory); } template 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 class Stub: public virtual StubBase { static_assert(std::is_base_of::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 +#ifndef WIN32 #include #include +#endif #include #include @@ -19,6 +20,16 @@ #include #include +#include +#include + +#ifdef WIN32 +#include +#define WIN32_LEAN_AND_MEAN // this prevents windows.h from including winsock.h, which causes duplicate definitions with winsock2.h +#include +#else +#include +#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 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 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(std::isspace))) - ); + std::not1(std::ptr_fun(isspace))) + ); toTrim.erase( std::find_if(toTrim.rbegin(), toTrim.rend(), - std::not1(std::ptr_fun(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 -#include +#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 myVariant(fromInt); -- cgit v1.2.1