diff options
author | Disch, Simon <simon_disch@mentor.com> | 2016-03-07 09:44:48 +0100 |
---|---|---|
committer | Disch, Simon <simon_disch@mentor.com> | 2016-03-07 09:45:53 +0100 |
commit | 9345fac016a33c61175e4a06675c20d8590dc201 (patch) | |
tree | 0934ba12e33faf11cd807ec24ba55a4ec78cbe54 | |
parent | 274ad1873235b333e1872ac98e7b382553fc7c8f (diff) | |
download | genivi-common-api-runtime-9345fac016a33c61175e4a06675c20d8590dc201.tar.gz |
CommonAPI 3.1.7
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | include/CommonAPI/Factory.hpp | 2 | ||||
-rw-r--r-- | include/CommonAPI/Logger.hpp | 19 | ||||
-rw-r--r-- | include/CommonAPI/ProxyManager.hpp | 15 | ||||
-rw-r--r-- | include/CommonAPI/Runtime.hpp | 4 | ||||
-rw-r--r-- | src/CommonAPI/ProxyManager.cpp | 7 | ||||
-rw-r--r-- | src/CommonAPI/Runtime.cpp | 77 |
8 files changed, 105 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 07daabd..733aa11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ PROJECT(libcommonapi) # version of CommonAPI SET( LIBCOMMONAPI_MAJOR_VERSION 3 ) SET( LIBCOMMONAPI_MINOR_VERSION 1 ) -SET( LIBCOMMONAPI_PATCH_VERSION 6 ) +SET( LIBCOMMONAPI_PATCH_VERSION 7 ) message(STATUS "Project name: ${PROJECT_NAME}") @@ -1,3 +1,3 @@ -This is CommonAPI 3.1.6 +This is CommonAPI 3.1.7 Please refer to INSTALL for further information.
\ No newline at end of file diff --git a/include/CommonAPI/Factory.hpp b/include/CommonAPI/Factory.hpp index 94bb7ec..b0ecdb3 100644 --- a/include/CommonAPI/Factory.hpp +++ b/include/CommonAPI/Factory.hpp @@ -26,6 +26,8 @@ public: virtual ~Factory() {}; + virtual void init() = 0; + virtual std::shared_ptr<Proxy> createProxy(const std::string &_domain, const std::string &_interface, const std::string &_instance, diff --git a/include/CommonAPI/Logger.hpp b/include/CommonAPI/Logger.hpp index 3a5f0b0..71c4d23 100644 --- a/include/CommonAPI/Logger.hpp +++ b/include/CommonAPI/Logger.hpp @@ -18,21 +18,26 @@ #include <CommonAPI/Export.hpp> -#define COMMONAPI_LOGLEVEL_FATAL 0 -#define COMMONAPI_LOGLEVEL_ERROR 1 -#define COMMONAPI_LOGLEVEL_WARNING 2 -#define COMMONAPI_LOGLEVEL_INFO 3 -#define COMMONAPI_LOGLEVEL_DEBUG 4 -#define COMMONAPI_LOGLEVEL_VERBOSE 5 +#define COMMONAPI_LOGLEVEL_NONE 0 +#define COMMONAPI_LOGLEVEL_FATAL 1 +#define COMMONAPI_LOGLEVEL_ERROR 2 +#define COMMONAPI_LOGLEVEL_WARNING 3 +#define COMMONAPI_LOGLEVEL_INFO 4 +#define COMMONAPI_LOGLEVEL_DEBUG 5 +#define COMMONAPI_LOGLEVEL_VERBOSE 6 #ifndef COMMONAPI_LOGLEVEL -#define COMMONAPI_LOGLEVEL COMMONAPI_LOGLEVEL_INFO +#define COMMONAPI_LOGLEVEL COMMONAPI_LOGLEVEL_NONE #endif #ifdef WIN32 +#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_FATAL #define COMMONAPI_FATAL(...) \ do { Logger::log(Logger::Level::LL_FATAL, __VA_ARGS__); } while (false); +#else +#define COMMONAPI_FATAL(...) +#endif #if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_ERROR #define COMMONAPI_ERROR(...) \ diff --git a/include/CommonAPI/ProxyManager.hpp b/include/CommonAPI/ProxyManager.hpp index 52d666c..c68e844 100644 --- a/include/CommonAPI/ProxyManager.hpp +++ b/include/CommonAPI/ProxyManager.hpp @@ -61,11 +61,26 @@ public: return NULL; } + template<template<typename ...> class ProxyClass_, typename ... AttributeExtensions_> + std::shared_ptr<ProxyClass_<AttributeExtensions_...> > + buildProxy(const std::string &_instance, std::shared_ptr<MainLoopContext> _context) { + std::shared_ptr<Proxy> proxy = createProxy(getDomain(), getInterface(), _instance, _context); + if (proxy) { + return std::make_shared<ProxyClass_<AttributeExtensions_...>>(proxy); + } + return NULL; + } + protected: COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &, const std::string &, const std::string &, const ConnectionId_t &_connection) const; + + COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &, + const std::string &, + const std::string &, + std::shared_ptr<MainLoopContext> _context) const; }; } // namespace CommonAPI diff --git a/include/CommonAPI/Runtime.hpp b/include/CommonAPI/Runtime.hpp index 09c0d3c..5b9254c 100644 --- a/include/CommonAPI/Runtime.hpp +++ b/include/CommonAPI/Runtime.hpp @@ -138,6 +138,7 @@ public: inline const std::string &getDefaultBinding() const { return defaultBinding_; }; private: + COMMONAPI_EXPORT void initFactories(); COMMONAPI_EXPORT bool readConfiguration(); COMMONAPI_EXPORT bool splitAddress(const std::string &, std::string &, std::string &, std::string &); @@ -180,6 +181,9 @@ private: std::mutex factoriesMutex_; std::mutex loadMutex_; + bool isConfigured_; + bool isInitialized_; + static std::map<std::string, std::string> properties_; static std::shared_ptr<Runtime> theRuntime__; diff --git a/src/CommonAPI/ProxyManager.cpp b/src/CommonAPI/ProxyManager.cpp index 3d55ff9..d369fbb 100644 --- a/src/CommonAPI/ProxyManager.cpp +++ b/src/CommonAPI/ProxyManager.cpp @@ -15,4 +15,11 @@ ProxyManager::createProxy( return Runtime::get()->createProxy(_domain, _interface, _instance, _connection); } +std::shared_ptr<Proxy> +ProxyManager::createProxy( + const std::string &_domain, const std::string &_interface, const std::string &_instance, + std::shared_ptr<MainLoopContext> _context) const { + return Runtime::get()->createProxy(_domain, _interface, _instance, _context); +} + } // namespace CommonAPI diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp index 7d075a2..1d0b0c5 100644 --- a/src/CommonAPI/Runtime.cpp +++ b/src/CommonAPI/Runtime.cpp @@ -49,7 +49,9 @@ std::shared_ptr<Runtime> Runtime::get() { Runtime::Runtime() : defaultBinding_(COMMONAPI_DEFAULT_BINDING), - defaultFolder_(COMMONAPI_DEFAULT_FOLDER) { + defaultFolder_(COMMONAPI_DEFAULT_FOLDER), + isConfigured_(false), + isInitialized_(false) { } Runtime::~Runtime() { @@ -58,13 +60,13 @@ Runtime::~Runtime() { bool Runtime::registerFactory(const std::string &_binding, std::shared_ptr<Factory> _factory) { - COMMONAPI_DEBUG("Registering factory for binding=", _binding); bool isRegistered(false); #ifndef WIN32 std::lock_guard<std::mutex> itsLock(factoriesMutex_); #endif if (_binding == defaultBinding_) { defaultFactory_ = _factory; + isRegistered = true; } else { auto foundFactory = factories_.find(_binding); if (foundFactory == factories_.end()) { @@ -72,12 +74,15 @@ Runtime::registerFactory(const std::string &_binding, std::shared_ptr<Factory> _ isRegistered = true; } } + + if (isRegistered && isInitialized_) + _factory->init(); + return isRegistered; } bool Runtime::unregisterFactory(const std::string &_binding) { - COMMONAPI_DEBUG("Unregistering factory for binding=", _binding); #ifndef WIN32 std::lock_guard<std::mutex> itsLock(factoriesMutex_); #endif @@ -93,11 +98,10 @@ Runtime::unregisterFactory(const std::string &_binding) { * Private */ void Runtime::init() { - static bool isInitialized(false); #ifndef WIN32 std::lock_guard<std::mutex> itsLock(mutex_); #endif - if (!isInitialized) { + if (!isConfigured_) { // Determine default configuration file const char *config = getenv("COMMONAPI_CONFIG"); if (config) { @@ -120,15 +124,28 @@ void Runtime::init() { if (folder) defaultFolder_ = folder; - // Log settings - COMMONAPI_INFO("Using default binding \'", defaultBinding_, "\'"); - COMMONAPI_INFO("Using default shared library folder \'", defaultFolder_, "\'"); - COMMONAPI_INFO("Using default configuration file \'", defaultConfig_, "\'"); - - isInitialized = true; + isConfigured_ = true; } } +void +Runtime::initFactories() { + std::lock_guard<std::mutex> itsLock(factoriesMutex_); + if (!isInitialized_) { + COMMONAPI_INFO("Using default binding \'", defaultBinding_, "\'"); + COMMONAPI_INFO("Using default shared library folder \'", defaultFolder_, "\'"); + COMMONAPI_INFO("Using default configuration file \'", defaultConfig_, "\'"); + + if (defaultFactory_) + defaultFactory_->init(); + + for (auto f : factories_) + f.second->init(); + + isInitialized_ = true; + } +} + bool Runtime::readConfiguration() { #define MAX_PATH_LEN 255 @@ -206,6 +223,9 @@ std::shared_ptr<Proxy> Runtime::createProxy( const std::string &_domain, const std::string &_interface, const std::string &_instance, const ConnectionId_t &_connectionId) { + if (!isInitialized_) { + initFactories(); + } // Check whether we already know how to create such proxies... std::shared_ptr<Proxy> proxy = createProxyHelper(_domain, _interface, _instance, _connectionId, false); @@ -224,6 +244,9 @@ std::shared_ptr<Proxy> Runtime::createProxy( const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr<MainLoopContext> _context) { + if (!isInitialized_) { + initFactories(); + } // Check whether we already know how to create such proxies... std::shared_ptr<Proxy> proxy = createProxyHelper(_domain, _interface, _instance, _context, false); @@ -242,6 +265,9 @@ Runtime::createProxy( bool Runtime::registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr<StubBase> _stub, const ConnectionId_t &_connectionId) { + if (!isInitialized_) { + initFactories(); + } bool isRegistered = registerStubHelper(_domain, _interface, _instance, _stub, _connectionId, false); if (!isRegistered) { @@ -257,6 +283,9 @@ Runtime::registerStub(const std::string &_domain, const std::string &_interface, bool Runtime::registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr<StubBase> _stub, std::shared_ptr<MainLoopContext> _context) { + if (!isInitialized_) { + initFactories(); + } bool isRegistered = registerStubHelper(_domain, _interface, _instance, _stub, _context, false); if (!isRegistered) { @@ -326,9 +355,29 @@ Runtime::loadLibrary(const std::string &_library) { itsLibrary += ".dll"; } #else - if (itsLibrary.rfind(".so") != itsLibrary.length() - 3) { - itsLibrary += ".so"; - } + std::size_t soStart = itsLibrary.rfind(".so"); + if (soStart == std::string::npos) { + // Library name does not contain ".so" --> add it + itsLibrary += ".so"; + } else if (soStart < itsLibrary.length() - 3) { + // We found ".so" but even the last one is not the end + // of the filename + soStart += 3; + + // Check the version information + while (soStart < itsLibrary.length()) { + if (itsLibrary[soStart] != '.' + && !std::isdigit(itsLibrary[soStart])) { + break; + } + soStart++; + } + + // What should be a version is something else + // --> add another ".so" + if (soStart < itsLibrary.length()) + itsLibrary += ".so"; + } #endif bool isLoaded(true); |