diff options
author | Juergen Gehring <juergen.gehring@bmw.de> | 2017-06-19 07:47:01 -0700 |
---|---|---|
committer | Juergen Gehring <juergen.gehring@bmw.de> | 2017-06-19 07:47:01 -0700 |
commit | 008f6c11f5371e93c06b3ed337326008d2031084 (patch) | |
tree | f25b96bab93d4b71496793d5944e054fc8d303af | |
parent | 66de998220d90116aa603d7458e245fe6094b4eb (diff) | |
download | genivi-common-api-runtime-008f6c11f5371e93c06b3ed337326008d2031084.tar.gz |
CommonAPI 3.1.123.1.12
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | include/CommonAPI/Deployable.hpp | 3 | ||||
-rw-r--r-- | include/CommonAPI/Event.hpp | 32 | ||||
-rw-r--r-- | include/CommonAPI/Proxy.hpp | 18 | ||||
-rw-r--r-- | src/CommonAPI/Address.cpp | 7 | ||||
-rw-r--r-- | src/CommonAPI/IniFileReader.cpp | 103 | ||||
-rw-r--r-- | src/CommonAPI/Logger.cpp | 2 | ||||
-rw-r--r-- | src/CommonAPI/LoggerImpl.cpp | 2 | ||||
-rw-r--r-- | src/CommonAPI/Proxy.cpp | 8 | ||||
-rw-r--r-- | src/CommonAPI/Runtime.cpp | 8 |
11 files changed, 125 insertions, 66 deletions
@@ -1,6 +1,12 @@ Changes ======= +v3.1.12 +- Add possibility to be notified on proxy destruction via + Proxy::getCompletionFuture method +- set CommonAPI CallStatus to INVALID_VALUE for wrong CRC values +- fixed code sonar warnings + v3.1.11 - console logging - log to standard error stream instead of standard output stream - Runtime::initFactories() made public diff --git a/CMakeLists.txt b/CMakeLists.txt index 5749fef..9aeb97a 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 11 ) +SET( LIBCOMMONAPI_PATCH_VERSION 12 ) message(STATUS "Project name: ${PROJECT_NAME}") diff --git a/include/CommonAPI/Deployable.hpp b/include/CommonAPI/Deployable.hpp index c260586..cf269e8 100644 --- a/include/CommonAPI/Deployable.hpp +++ b/include/CommonAPI/Deployable.hpp @@ -19,7 +19,8 @@ template<typename Type_, typename TypeDepl_> struct Deployable : DeployableBase { Deployable(const TypeDepl_ *_depl = nullptr) - : depl_(const_cast<TypeDepl_ *>(_depl)) { + : value_(), + depl_(const_cast<TypeDepl_ *>(_depl)) { } Deployable(const Type_ &_value, const TypeDepl_ *_depl) diff --git a/include/CommonAPI/Event.hpp b/include/CommonAPI/Event.hpp index 5fbec00..67cc6dc 100644 --- a/include/CommonAPI/Event.hpp +++ b/include/CommonAPI/Event.hpp @@ -72,6 +72,7 @@ protected: void notifyListeners(const Arguments_&... _eventArguments); void notifySpecificListener(const Subscription _subscription, const Arguments_&... _eventArguments); void notifySpecificError(const Subscription _subscription, const CallStatus status); + void notifyErrorListeners(const CallStatus status); virtual void onFirstListenerAdded(const Listener &_listener) { (void)_listener; @@ -267,6 +268,37 @@ void Event<Arguments_...>::notifySpecificError(const Subscription subscription, } } +template<typename ... Arguments_> +void Event<Arguments_...>::notifyErrorListeners(const CallStatus status) { + subscriptionMutex_.lock(); + notificationMutex_.lock(); + for (auto iterator = pendingUnsubscriptions_.begin(); + iterator != pendingUnsubscriptions_.end(); + iterator++) { + subscriptions_.erase(*iterator); + } + pendingUnsubscriptions_.clear(); + + for (auto iterator = pendingSubscriptions_.begin(); + iterator != pendingSubscriptions_.end(); + iterator++) { + subscriptions_.insert(*iterator); + } + pendingSubscriptions_.clear(); + + subscriptionMutex_.unlock(); + + for (auto iterator = subscriptions_.begin(); iterator != subscriptions_.end(); iterator++) { + ErrorListener listener = std::get<1>(iterator->second); + if (listener) { + listener(status); + } + } + + notificationMutex_.unlock(); +} + + } // namespace CommonAPI #endif // COMMONAPI_EVENT_HPP_ diff --git a/include/CommonAPI/Proxy.hpp b/include/CommonAPI/Proxy.hpp index 015658f..a96141c 100644 --- a/include/CommonAPI/Proxy.hpp +++ b/include/CommonAPI/Proxy.hpp @@ -13,6 +13,7 @@ #include <cstdint> #include <memory> #include <type_traits> +#include <future> #include <CommonAPI/Address.hpp> #include <CommonAPI/Attribute.hpp> @@ -24,22 +25,25 @@ namespace CommonAPI { typedef Event<AvailabilityStatus> ProxyStatusEvent; typedef ReadonlyAttribute<Version> InterfaceVersionAttribute; -class Proxy { +class COMMONAPI_EXPORT Proxy { public: - COMMONAPI_EXPORT virtual ~Proxy() {} + virtual ~Proxy(); - COMMONAPI_EXPORT const Address &getAddress() const; + const Address &getAddress() const; - COMMONAPI_EXPORT virtual bool isAvailable() const = 0; + std::future<void> getCompletionFuture(); - COMMONAPI_EXPORT virtual bool isAvailableBlocking() const = 0; + virtual bool isAvailable() const = 0; - COMMONAPI_EXPORT virtual ProxyStatusEvent& getProxyStatusEvent() = 0; + virtual bool isAvailableBlocking() const = 0; - COMMONAPI_EXPORT virtual InterfaceVersionAttribute& getInterfaceVersionAttribute() = 0; + virtual ProxyStatusEvent& getProxyStatusEvent() = 0; + + virtual InterfaceVersionAttribute& getInterfaceVersionAttribute() = 0; protected: Address address_; + std::promise<void> completed_; }; } // namespace CommonAPI diff --git a/src/CommonAPI/Address.cpp b/src/CommonAPI/Address.cpp index 280c0be..a80b2cf 100644 --- a/src/CommonAPI/Address.cpp +++ b/src/CommonAPI/Address.cpp @@ -75,7 +75,10 @@ Address::getAddress() const { void Address::setAddress(const std::string &_address) { std::string itsDomain, itsInterface, itsVersion, itsInstance; - std::size_t itsDomainPos, itsInterfacePos, itsVersionPos, itsInstancePos; + std::size_t itsDomainPos(0); + std::size_t itsInterfacePos(0); + std::size_t itsVersionPos(0); + std::size_t itsInstancePos(0); bool isValid(true); itsDomainPos = _address.find(':'); @@ -114,7 +117,7 @@ Address::setAddress(const std::string &_address) { isValid = false; if(isValid) { for (auto it = itsVersion.begin()+1; it != itsVersion.end(); ++it) { - if (!isdigit(*it) && *it != '_') { + if (!isdigit(static_cast<unsigned char>(*it)) && *it != '_') { isValid = false; break; } diff --git a/src/CommonAPI/IniFileReader.cpp b/src/CommonAPI/IniFileReader.cpp index c91e91f..94057e0 100644 --- a/src/CommonAPI/IniFileReader.cpp +++ b/src/CommonAPI/IniFileReader.cpp @@ -29,65 +29,66 @@ IniFileReader::Section::getValue(const std::string &_key) const { bool IniFileReader::load(const std::string &_path) { std::ifstream configStream(_path); - if (configStream.is_open()) { - //COMMONAPI_INFO("Loading ini file from ", _path); + if (!configStream.is_open()) { + COMMONAPI_ERROR("Failed to load ini file: ", _path); + return false; + } - int lineCounter(0); - std::string currentSectionName; - std::shared_ptr<Section> currentSection; + int lineCounter(0); + std::string currentSectionName; + std::shared_ptr<Section> currentSection; - while (!configStream.eof()) { - std::string line; - std::getline(configStream, line); - lineCounter++; + while (!configStream.eof()) { + std::string line; + std::getline(configStream, line); + lineCounter++; - trim(line); + trim(line); - std::size_t start = line.find('['); - if (start == 0) { - std::size_t end = line.find(']'); - if (end != line.npos) { - currentSectionName = line.substr(++start, --end); - if (sections_.end() == sections_.find(currentSectionName)) { - currentSection = std::make_shared<Section>(); - if (currentSection) { - sections_[currentSectionName] = currentSection; - } - } else { - COMMONAPI_ERROR("Double definition of section \'", - currentSectionName, - "\' ignoring definition (line ", - lineCounter, - ")"); - currentSection = nullptr; + std::size_t start = line.find('['); + if (start == 0) { + std::size_t end = line.find(']'); + if (end != line.npos) { + currentSectionName = line.substr(++start, --end); + if (sections_.end() == sections_.find(currentSectionName)) { + currentSection = std::make_shared<Section>(); + if (currentSection) { + sections_[currentSectionName] = currentSection; } } else { - COMMONAPI_ERROR("Missing \']\' in section definition (line ", - lineCounter, ")"); + COMMONAPI_ERROR("Double definition of section \'", + currentSectionName, + "\' ignoring definition (line ", + lineCounter, + ")"); + currentSection = nullptr; } - } else if (currentSection) { - std::size_t pos = line.find('='); - if (pos != line.npos) { - std::string key = line.substr(0, pos); - trim(key); - if (currentSection->mappings_.end() - != currentSection->mappings_.find(key)) { - COMMONAPI_ERROR("Double definition for key \'", - key, - "'\' in section \'", - currentSectionName, - "\' (line ", - lineCounter, - ")"); - } else { - std::string value = line.substr(pos+1); - trim(value); - currentSection->mappings_[key] = value; - } - } else if (line.size() > 0) { - COMMONAPI_ERROR("Missing \'=\' in key=value definition (line ", - lineCounter, ")"); + } else { + COMMONAPI_ERROR("Missing \']\' in section definition (line ", + lineCounter, ")"); + } + } else if (currentSection) { + std::size_t pos = line.find('='); + if (pos != line.npos) { + std::string key = line.substr(0, pos); + trim(key); + if (currentSection->mappings_.end() + != currentSection->mappings_.find(key)) { + COMMONAPI_ERROR("Double definition for key \'", + key, + "'\' in section \'", + currentSectionName, + "\' (line ", + lineCounter, + ")"); + } else { + std::string value = line.substr(pos+1); + trim(value); + currentSection->mappings_[key] = value; } + } else if (line.size() > 0) { + COMMONAPI_ERROR("Missing \'=\' in key=value definition (line ", + lineCounter, ")"); } } } diff --git a/src/CommonAPI/Logger.cpp b/src/CommonAPI/Logger.cpp index 8d5c18f..268be6f 100644 --- a/src/CommonAPI/Logger.cpp +++ b/src/CommonAPI/Logger.cpp @@ -6,7 +6,7 @@ #include <CommonAPI/Logger.hpp> #include <CommonAPI/Runtime.hpp> -namespace CommonAPI {; +namespace CommonAPI { void Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt, const std::string &_level) { LoggerImpl::init(_useConsole, _fileName, _useDlt, _level); diff --git a/src/CommonAPI/LoggerImpl.cpp b/src/CommonAPI/LoggerImpl.cpp index 28143bf..fabb109 100644 --- a/src/CommonAPI/LoggerImpl.cpp +++ b/src/CommonAPI/LoggerImpl.cpp @@ -10,7 +10,7 @@ #include <CommonAPI/Runtime.hpp> #endif -namespace CommonAPI {; +namespace CommonAPI { #if defined(USE_CONSOLE) || defined(USE_FILE) std::mutex LoggerImpl::mutex_; diff --git a/src/CommonAPI/Proxy.cpp b/src/CommonAPI/Proxy.cpp index f611059..6e22f5e 100644 --- a/src/CommonAPI/Proxy.cpp +++ b/src/CommonAPI/Proxy.cpp @@ -7,9 +7,17 @@ namespace CommonAPI { +Proxy::~Proxy() { + completed_.set_value(); +} + const Address & Proxy::getAddress() const { return address_; } +std::future<void> Proxy::getCompletionFuture() { + return completed_.get_future(); +} + } // namespace CommonAPI diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp index 221264c..b9124cd 100644 --- a/src/CommonAPI/Runtime.cpp +++ b/src/CommonAPI/Runtime.cpp @@ -150,6 +150,7 @@ bool Runtime::readConfiguration() { #define MAX_PATH_LEN 255 std::string config; + bool tryLoadConfig(true); char currentDirectory[MAX_PATH_LEN]; #ifdef _WIN32 if (GetCurrentDirectory(MAX_PATH_LEN, currentDirectory)) { @@ -163,11 +164,14 @@ Runtime::readConfiguration() { struct stat s; if (stat(usedConfig_.c_str(), &s) != 0) { usedConfig_ = defaultConfig_; + if (stat(usedConfig_.c_str(), &s) != 0) { + tryLoadConfig = false; + } } } IniFileReader reader; - if (!reader.load(usedConfig_)) + if (tryLoadConfig && !reader.load(usedConfig_)) return false; std::string itsConsole("true"); @@ -367,7 +371,7 @@ Runtime::loadLibrary(const std::string &_library) { // Check the version information while (soStart < itsLibrary.length()) { if (itsLibrary[soStart] != '.' - && !std::isdigit(itsLibrary[soStart])) { + && !std::isdigit(static_cast<unsigned char>(itsLibrary[soStart]))) { break; } soStart++; |