summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Laner <laner@itestra.de>2014-02-24 09:41:53 +0100
committerStefan Laner <laner@itestra.de>2014-02-26 10:52:17 +0100
commitb94ed2030fd13d100a757d531983b2fd2498b62e (patch)
treecc2c675f7999130edbd4ea76ebd6458d0d730c9b /src
parentfa209eed0e5c81c277601aa24069fa23f61b675d (diff)
downloadgenivi-common-api-runtime-b94ed2030fd13d100a757d531983b2fd2498b62e.tar.gz
Windows compatible version
Change-Id: I775e584175ec3dcde258e7bed261c61e763d20ce
Diffstat (limited to 'src')
-rw-r--r--src/CommonAPI/Attribute.h6
-rw-r--r--src/CommonAPI/AttributeExtension.h14
-rw-r--r--src/CommonAPI/Configuration.cpp16
-rw-r--r--src/CommonAPI/Factory.h47
-rw-r--r--src/CommonAPI/Factory.hpp27
-rw-r--r--src/CommonAPI/MainLoopContext.h18
-rw-r--r--src/CommonAPI/ProxyManager.h18
-rw-r--r--src/CommonAPI/Runtime.cpp26
-rw-r--r--src/CommonAPI/SerializableVariant.hpp10
-rw-r--r--src/CommonAPI/ServicePublisher.hpp2
-rw-r--r--src/CommonAPI/Stub.h9
-rw-r--r--src/CommonAPI/types.h19
-rw-r--r--src/CommonAPI/utils.h44
-rwxr-xr-xsrc/test/VariantTest.cpp4
14 files changed, 196 insertions, 64 deletions
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);