diff options
author | Disch, Simon <simon_disch@mentor.com> | 2016-08-26 16:14:07 +0200 |
---|---|---|
committer | Disch, Simon <simon_disch@mentor.com> | 2016-08-26 16:14:07 +0200 |
commit | 8c373435098b67772167b4c80e2c99c67dd16dce (patch) | |
tree | e0b07c3572fd5a74a35f8503b841d028f9a9e41d | |
parent | 534894b27a5e6b86cf8d2bd7b53d55d04f2a1bcc (diff) | |
download | genivi-common-api-runtime-8c373435098b67772167b4c80e2c99c67dd16dce.tar.gz |
CommonAPI 3.1.93.1.9
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | include/CommonAPI/Event.hpp | 7 | ||||
-rw-r--r-- | include/CommonAPI/Logger.hpp | 105 | ||||
-rw-r--r-- | include/CommonAPI/Types.hpp | 5 | ||||
-rw-r--r-- | src/CommonAPI/Address.cpp | 81 |
6 files changed, 118 insertions, 86 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b62a926..767f54b 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 8 ) +SET( LIBCOMMONAPI_PATCH_VERSION 9 ) message(STATUS "Project name: ${PROJECT_NAME}") @@ -121,6 +121,7 @@ link_directories( ) file(GLOB CAPI_SRCS "src/CommonAPI/*.cpp") +list(SORT CAPI_SRCS) add_library(CommonAPI SHARED ${CAPI_SRCS}) target_link_libraries(CommonAPI PRIVATE ${DL_LIBRARY} ${DLT_LIBRARIES}) set_target_properties(CommonAPI PROPERTIES VERSION ${LIBCOMMONAPI_MAJOR_VERSION}.${LIBCOMMONAPI_MINOR_VERSION}.${LIBCOMMONAPI_PATCH_VERSION} SOVERSION ${LIBCOMMONAPI_MAJOR_VERSION}.${LIBCOMMONAPI_MINOR_VERSION}.${LIBCOMMONAPI_PATCH_VERSION} LINKER_LANGUAGE C) @@ -136,6 +137,7 @@ CONFIGURE_FILE(commonapi.spec.in commonapi.spec) # for installation of CommonAPI header files file (GLOB_RECURSE CommonAPI_INCLUDE_INSTALL_FILES "include/CommonAPI/*.hpp") +list (SORT CommonAPI_INCLUDE_INSTALL_FILES) set_target_properties (CommonAPI PROPERTIES PUBLIC_HEADER "${CommonAPI_INCLUDE_INSTALL_FILES}") # install CommonAPI library including headers @@ -1,3 +1,3 @@ -This is CommonAPI 3.1.8 +This is CommonAPI 3.1.9 Please refer to INSTALL for further information.
\ No newline at end of file diff --git a/include/CommonAPI/Event.hpp b/include/CommonAPI/Event.hpp index 91da3d6..470146f 100644 --- a/include/CommonAPI/Event.hpp +++ b/include/CommonAPI/Event.hpp @@ -81,8 +81,9 @@ protected: (void)_subscription; } - virtual void onListenerRemoved(const Listener &_listener) { + virtual void onListenerRemoved(const Listener &_listener, const Subscription _subscription) { (void)_listener; + (void) _subscription; } virtual void onLastListenerRemoved(const Listener &_listener) { (void)_listener; @@ -121,7 +122,7 @@ typename Event<Arguments_...>::Subscription Event<Arguments_...>::subscribe(List } template<typename ... Arguments_> -void Event<Arguments_...>::unsubscribe(Subscription subscription) { +void Event<Arguments_...>::unsubscribe(const Subscription subscription) { bool isLastListener(false); bool hasUnsubscribed(false); Listener listener; @@ -152,7 +153,7 @@ void Event<Arguments_...>::unsubscribe(Subscription subscription) { subscriptionMutex_.unlock(); if (hasUnsubscribed) { - onListenerRemoved(listener); + onListenerRemoved(listener, subscription); if (isLastListener) { onLastListenerRemoved(listener); } diff --git a/include/CommonAPI/Logger.hpp b/include/CommonAPI/Logger.hpp index b4047ac..d1b86fa 100644 --- a/include/CommonAPI/Logger.hpp +++ b/include/CommonAPI/Logger.hpp @@ -20,96 +20,67 @@ #define COMMONAPI_LOGLEVEL COMMONAPI_LOGLEVEL_NONE #endif -#ifdef WIN32 +#define COMMONAPI_FATAL CommonAPI::Logger::fatal +#define COMMONAPI_ERROR CommonAPI::Logger::error +#define COMMONAPI_WARNING CommonAPI::Logger::warning +#define COMMONAPI_INFO CommonAPI::Logger::info +#define COMMONAPI_DEBUG CommonAPI::Logger::debug +#define COMMONAPI_VERBOSE CommonAPI::Logger::verbose -#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_FATAL -#define COMMONAPI_FATAL(...) \ - do { Logger::log(LoggerImpl::Level::LL_FATAL, __VA_ARGS__); } while (false); -#else -#define COMMONAPI_FATAL(...) -#endif - -#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_ERROR -#define COMMONAPI_ERROR(...) \ - do { Logger::log(LoggerImpl::Level::LL_ERROR, __VA_ARGS__); } while (false); -#else -#define COMMONAPI_ERROR(...) -#endif - -#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_WARNING -#define COMMONAPI_WARNING(...) \ - do { Logger::log(LoggerImpl::Level::LL_WARNING, __VA_ARGS__); } while (false); -#else -#define COMMONAPI_WARNING(...) -#endif - -#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_INFO -#define COMMONAPI_INFO(...) \ - do { Logger::log(LoggerImpl::Level::LL_INFO, __VA_ARGS__); } while (false); -#else -#define COMMONAPI_INFO(...) -#endif - -#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_DEBUG -#define COMMONAPI_DEBUG(...) \ - do { Logger::log(LoggerImpl::Level::LL_DEBUG, __VA_ARGS__); } while (false); -#else -#define COMMONAPI_DEBUG(...) -#endif - -#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_VERBOSE -#define COMMONAPI_VERBOSE(...) \ - do { Logger::log(LoggerImpl::Level::LL_VERBOSE, __VA_ARGS__); } while (false); -#else -#define COMMONAPI_VERBOSE(...) -#endif +namespace CommonAPI { -#else // !WIN32 +class Logger { +public: -#define COMMONAPI_FATAL(params...) \ - do { Logger::log(LoggerImpl::Level::LL_FATAL, params); } while (false); + template<typename... LogEntries_> + COMMONAPI_EXPORT static void fatal(LogEntries_... _entries) { + log(LoggerImpl::Level::LL_FATAL, _entries...); + } + template<typename... LogEntries_> + COMMONAPI_EXPORT static void error(LogEntries_... _entries) { #if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_ERROR - #define COMMONAPI_ERROR(params...) \ - do { Logger::log(LoggerImpl::Level::LL_ERROR, params); } while (false); + log(LoggerImpl::Level::LL_ERROR, _entries...); #else - #define COMMONAPI_ERROR(params...) + std::tuple<LogEntries_...> args(_entries...); #endif + } + template<typename... LogEntries_> + COMMONAPI_EXPORT static void warning(LogEntries_... _entries) { #if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_WARNING - #define COMMONAPI_WARNING(params...) \ - do { Logger::log(LoggerImpl::Level::LL_WARNING, params); } while (false); + log(LoggerImpl::Level::LL_WARNING, _entries...); #else - #define COMMONAPI_WARNING(params...) + std::tuple<LogEntries_...> args(_entries...); #endif + } + template<typename... LogEntries_> + COMMONAPI_EXPORT static void info(LogEntries_... _entries) { #if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_INFO - #define COMMONAPI_INFO(params...) \ - do { Logger::log(LoggerImpl::Level::LL_INFO, params); } while (false); + log(LoggerImpl::Level::LL_INFO, _entries...); #else - #define COMMONAPI_INFO(params...) + std::tuple<LogEntries_...> args(_entries...); #endif + } + template<typename... LogEntries_> + COMMONAPI_EXPORT static void debug(LogEntries_... _entries) { #if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_DEBUG - #define COMMONAPI_DEBUG(params...) \ - do { Logger::log(LoggerImpl::Level::LL_DEBUG, params); } while (false); + log(LoggerImpl::Level::LL_DEBUG, _entries...); #else - #define COMMONAPI_DEBUG(params...) + std::tuple<LogEntries_...> args(_entries...); #endif + } + template<typename... LogEntries_> + COMMONAPI_EXPORT static void verbose(LogEntries_... _entries) { #if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_VERBOSE - #define COMMONAPI_VERBOSE(params...) \ - do { Logger::log(LoggerImpl::Level::LL_VERBOSE, params); } while (false); + log(LoggerImpl::Level::LL_VERBOSE, _entries...); #else - #define COMMONAPI_VERBOSE(params...) + std::tuple<LogEntries_...> args(_entries...); #endif - -#endif // WIN32 - -namespace CommonAPI { - -class Logger { -public: + } template<typename... LogEntries_> COMMONAPI_EXPORT static void log(LoggerImpl::Level _level, LogEntries_... _entries) { diff --git a/include/CommonAPI/Types.hpp b/include/CommonAPI/Types.hpp index 9cf62c3..6f6801d 100644 --- a/include/CommonAPI/Types.hpp +++ b/include/CommonAPI/Types.hpp @@ -60,11 +60,6 @@ namespace CommonAPI { 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/Address.cpp b/src/CommonAPI/Address.cpp index ca49cf4..2bc100d 100644 --- a/src/CommonAPI/Address.cpp +++ b/src/CommonAPI/Address.cpp @@ -3,9 +3,11 @@ // 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 <cctype> #include <sstream> #include <CommonAPI/Address.hpp> +#include <CommonAPI/Logger.hpp> namespace CommonAPI { @@ -20,10 +22,8 @@ Address::Address(const std::string &_address) { Address::Address(const std::string &_domain, const std::string &_interface, - const std::string &_instance) - : domain_(_domain), - interface_(_interface), - instance_(_instance) { + const std::string &_instance) { + setAddress(_domain + ":" + _interface + ":" + _instance); } Address::Address(const Address &_source) @@ -74,15 +74,78 @@ Address::getAddress() const { void Address::setAddress(const std::string &_address) { - std::istringstream addressStream(_address); - if (std::getline(addressStream, domain_, ':')) { - if (std::getline(addressStream, interface_, ':')) { - if(!std::getline(addressStream, instance_, ':')) { - if(std::getline(addressStream, instance_)) { + std::string itsDomain, itsInterface, itsVersion, itsInstance; + std::size_t itsDomainPos, itsInterfacePos, itsVersionPos, itsInstancePos; + bool isValid(true); + + itsDomainPos = _address.find(':'); + if (itsDomainPos == std::string::npos) { + isValid = false; + } + + if (isValid) { + itsDomain = _address.substr(0, itsDomainPos); + itsDomainPos++; + + itsInterfacePos = _address.find(':', itsDomainPos); + if (itsInterfacePos == std::string::npos) { + isValid = false; + } + } + + if (isValid) { + itsInterface = _address.substr(itsDomainPos, itsInterfacePos-itsDomainPos); + itsInterfacePos++; + + itsVersionPos = _address.find(':', itsInterfacePos); + if (itsVersionPos == std::string::npos) { + itsInstance = _address.substr(itsInterfacePos); + } else { + itsVersion = _address.substr(itsInterfacePos, itsVersionPos-itsInterfacePos); + if (itsVersion != "") { + // check version + std::size_t itsSeparatorPos = itsVersion.find('_'); + if (itsSeparatorPos == std::string::npos) { + isValid = false; + } + + if (isValid) { + if( *(itsVersion.begin()) != 'v') + isValid = false; + if(isValid) { + for (auto it = itsVersion.begin()+1; it != itsVersion.end(); ++it) { + if (!isdigit(*it) && *it != '_') { + isValid = false; + break; + } + } + } } } + itsVersionPos++; + + if (isValid) { + itsInstancePos = _address.find(':', itsVersionPos); + if (itsInstancePos != std::string::npos) { + isValid = false; + } + + itsInstance = _address.substr(itsVersionPos); + } } } + + if (isValid) { + domain_ = itsDomain; + if (itsVersion != "") + itsInterface += ":" + itsVersion; + else + itsInterface += ":v1_0"; + interface_ = itsInterface; + instance_ = itsInstance; + } else { + COMMONAPI_ERROR("Attempted to set invalid CommonAPI address: ", _address); + } } const std::string & |