summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Huss <dirk_huss@mentor.com>2016-05-25 19:00:32 +0200
committerDirk Huss <dirk_huss@mentor.com>2016-05-25 19:00:32 +0200
commit534894b27a5e6b86cf8d2bd7b53d55d04f2a1bcc (patch)
tree3ee994cc8d94f3c5e96c1b88dd15bc9d58e81e89
parent1c158272e2ee4b93021a97ac3b5c207a137b0d2c (diff)
downloadgenivi-common-api-runtime-534894b27a5e6b86cf8d2bd7b53d55d04f2a1bcc.tar.gz
CommonAPI 3.1.83.1.8
-rw-r--r--CMakeLists.txt30
-rw-r--r--README2
-rw-r--r--include/CommonAPI/Address.hpp2
-rw-r--r--include/CommonAPI/Config.hpp6
-rw-r--r--include/CommonAPI/Event.hpp31
-rw-r--r--include/CommonAPI/Export.hpp4
-rw-r--r--include/CommonAPI/Extensions/AttributeCacheExtension.hpp1
-rw-r--r--include/CommonAPI/Logger.hpp84
-rw-r--r--include/CommonAPI/LoggerImpl.hpp77
-rw-r--r--include/CommonAPI/Runtime.hpp2
-rw-r--r--include/CommonAPI/Variant.hpp22
-rw-r--r--src/CommonAPI/Address.cpp4
-rw-r--r--src/CommonAPI/Logger.cpp167
-rw-r--r--src/CommonAPI/LoggerImpl.cpp200
-rw-r--r--src/CommonAPI/Runtime.cpp14
15 files changed, 380 insertions, 266 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 733aa11..b62a926 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 7 )
+SET( LIBCOMMONAPI_PATCH_VERSION 8 )
message(STATUS "Project name: ${PROJECT_NAME}")
@@ -52,7 +52,9 @@ string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_FOR_SPEC_IN)
# Offer the user the choice of overriding the installation directories
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
+set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for binaries")
set(INSTALL_INCLUDE_DIR include/CommonAPI-${COMMONAPI_API_HEADER_VERSION} CACHE PATH "Installation directory for header files")
+
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR cmake)
else()
@@ -60,6 +62,12 @@ else()
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
+OPTION(USE_FILE "Set to OFF to disable file logging" OFF )
+message(STATUS "USE_FILE is set to value: ${USE_FILE}")
+
+OPTION(USE_CONSOLE "Set to OFF to disable console logging" OFF )
+message(STATUS "USE_CONSOLE is set to value: ${USE_CONSOLE}")
+
# Make relative paths absolute (needed later on)
foreach(p LIB INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
@@ -76,14 +84,21 @@ SET( LICENSE "MPLv2" )
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
##############################################################################
-
# CommonAPI build section
+
+IF(USE_FILE)
+ add_definitions(-DUSE_FILE)
+ENDIF(USE_FILE)
+IF(USE_CONSOLE)
+ add_definitions(-DUSE_CONSOLE)
+ENDIF(USE_CONSOLE)
+
IF(MSVC)
message("using MSVC Compiler")
- add_definitions(-DCOMMONAPI_INTERNAL_COMPILATION)
- add_compile_options(/EHsc /wd"4996")
+ add_definitions(-DCOMMONAPI_INTERNAL_COMPILATION -DCOMMONAPI_DLL_COMPILATION)
+ add_compile_options(/EHsc /wd4996)
ELSE ()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -Werror -DCOMMONAPI_INTERNAL_COMPILATION -DUSE_CONSOLE")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -Werror -DCOMMONAPI_INTERNAL_COMPILATION")
ENDIF(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_LOGLEVEL=COMMONAPI_LOGLEVEL_${MAX_LOG_LEVEL}")
@@ -106,9 +121,9 @@ link_directories(
)
file(GLOB CAPI_SRCS "src/CommonAPI/*.cpp")
-add_library(CommonAPI ${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} LINKER_LANGUAGE C)
+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)
set_target_properties (CommonAPI PROPERTIES INTERFACE_LINK_LIBRARY "")
##############################################################################
@@ -127,6 +142,7 @@ set_target_properties (CommonAPI PROPERTIES PUBLIC_HEADER "${CommonAPI_INCLUDE_I
install(TARGETS CommonAPI
EXPORT CommonAPITargets
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
+ RUNTIME DESTINATION ${INSTALL_BIN_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/CommonAPI"
)
diff --git a/README b/README
index 1dddf9d..3120f4b 100644
--- a/README
+++ b/README
@@ -1,3 +1,3 @@
-This is CommonAPI 3.1.7
+This is CommonAPI 3.1.8
Please refer to INSTALL for further information. \ No newline at end of file
diff --git a/include/CommonAPI/Address.hpp b/include/CommonAPI/Address.hpp
index 74a13d4..39cac8b 100644
--- a/include/CommonAPI/Address.hpp
+++ b/include/CommonAPI/Address.hpp
@@ -15,7 +15,7 @@ namespace CommonAPI {
class Address {
public:
- COMMONAPI_EXPORT Address() = default;
+ COMMONAPI_EXPORT Address();
COMMONAPI_EXPORT Address(const std::string &_address);
COMMONAPI_EXPORT Address(const std::string &_domain,
const std::string &_interface,
diff --git a/include/CommonAPI/Config.hpp b/include/CommonAPI/Config.hpp
index fb99bf3..e4450d5 100644
--- a/include/CommonAPI/Config.hpp
+++ b/include/CommonAPI/Config.hpp
@@ -10,7 +10,11 @@
namespace CommonAPI {
-static const Timeout_t DEFAULT_SEND_TIMEOUT_MS = 5000;
+#ifndef DEFAULT_SEND_TIMEOUT
+#define DEFAULT_SEND_TIMEOUT 5000
+#endif
+
+static const Timeout_t DEFAULT_SEND_TIMEOUT_MS = DEFAULT_SEND_TIMEOUT;
} // namespace CommonAPI
diff --git a/include/CommonAPI/Event.hpp b/include/CommonAPI/Event.hpp
index a31c677..91da3d6 100644
--- a/include/CommonAPI/Event.hpp
+++ b/include/CommonAPI/Event.hpp
@@ -71,7 +71,7 @@ public:
protected:
void notifyListeners(const Arguments_&... _eventArguments);
void notifySpecificListener(const Subscription _subscription, const Arguments_&... _eventArguments);
- void notifyError(const CallStatus status);
+ void notifySpecificError(const Subscription _subscription, const CallStatus status);
virtual void onFirstListenerAdded(const Listener &_listener) {
(void)_listener;
@@ -216,7 +216,7 @@ void Event<Arguments_...>::notifySpecificListener(const Subscription subscriptio
}
template<typename ... Arguments_>
-void Event<Arguments_...>::notifyError(const CallStatus status) {
+void Event<Arguments_...>::notifySpecificError(const Subscription subscription, const CallStatus status) {
subscriptionMutex_.lock();
notificationMutex_.lock();
@@ -236,13 +236,34 @@ void Event<Arguments_...>::notifyError(const CallStatus status) {
subscriptionMutex_.unlock();
for (auto iterator = subscriptions_.begin(); iterator != subscriptions_.end(); iterator++) {
- ErrorListener listener = std::get<1>(iterator->second);
- if (listener) {
- listener(status);
+ if (subscription == iterator->first) {
+ ErrorListener listener = std::get<1>(iterator->second);
+ if (listener) {
+ listener(status);
+ }
}
}
notificationMutex_.unlock();
+
+ if (status != CommonAPI::CallStatus::SUCCESS) {
+ subscriptionMutex_.lock();
+ auto listenerIterator = subscriptions_.find(subscription);
+ if (subscriptions_.end() != listenerIterator) {
+ if (pendingUnsubscriptions_.end() == pendingUnsubscriptions_.find(subscription)) {
+ if (0 == pendingSubscriptions_.erase(subscription)) {
+ pendingUnsubscriptions_.insert(subscription);
+ }
+ }
+ }
+ else {
+ listenerIterator = pendingSubscriptions_.find(subscription);
+ if (pendingSubscriptions_.end() != listenerIterator) {
+ pendingSubscriptions_.erase(subscription);
+ }
+ }
+ subscriptionMutex_.unlock();
+ }
}
} // namespace CommonAPI
diff --git a/include/CommonAPI/Export.hpp b/include/CommonAPI/Export.hpp
index 1513ac9..b95693b 100644
--- a/include/CommonAPI/Export.hpp
+++ b/include/CommonAPI/Export.hpp
@@ -8,6 +8,7 @@
#ifdef WIN32
#define COMMONAPI_EXPORT __declspec(dllexport)
+ #define COMMONAPI_EXPORT_CLASS_EXPLICIT
#if COMMONAPI_DLL_COMPILATION
#define COMMONAPI_IMPORT_EXPORT __declspec(dllexport)
@@ -15,7 +16,8 @@
#define COMMONAPI_IMPORT_EXPORT __declspec(dllimport)
#endif
#else
- #define COMMONAPI_EXPORT
+ #define COMMONAPI_EXPORT __attribute__ ((visibility ("default")))
+ #define COMMONAPI_EXPORT_CLASS_EXPLICIT COMMONAPI_EXPORT
#define COMMONAPI_IMPORT_EXPORT
#endif
diff --git a/include/CommonAPI/Extensions/AttributeCacheExtension.hpp b/include/CommonAPI/Extensions/AttributeCacheExtension.hpp
index f6a0cb1..7a8e8d5 100644
--- a/include/CommonAPI/Extensions/AttributeCacheExtension.hpp
+++ b/include/CommonAPI/Extensions/AttributeCacheExtension.hpp
@@ -8,7 +8,6 @@
#include <CommonAPI/CommonAPI.hpp>
-#include <cassert>
#include <memory>
#include <type_traits>
diff --git a/include/CommonAPI/Logger.hpp b/include/CommonAPI/Logger.hpp
index 52a55bf..b4047ac 100644
--- a/include/CommonAPI/Logger.hpp
+++ b/include/CommonAPI/Logger.hpp
@@ -6,19 +6,9 @@
#ifndef COMMONAPI_LOGGER_HPP_
#define COMMONAPI_LOGGER_HPP_
-#ifdef USE_DLT
-#include <dlt/dlt.h>
-#endif
-
-#include <cstdint>
-#include <fstream>
-#include <memory>
-#include <mutex>
-#include <sstream>
-
-#include <CommonAPI/Export.hpp>
+#include <CommonAPI/LoggerImpl.hpp>
-#define COMMONAPI_LOGLEVEL_NONE 0
+#define COMMONAPI_LOGLEVEL_NONE 0
#define COMMONAPI_LOGLEVEL_FATAL 1
#define COMMONAPI_LOGLEVEL_ERROR 2
#define COMMONAPI_LOGLEVEL_WARNING 3
@@ -34,42 +24,42 @@
#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_FATAL
#define COMMONAPI_FATAL(...) \
- do { Logger::log(Logger::Level::LL_FATAL, __VA_ARGS__); } while (false);
+ 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(Logger::Level::LL_ERROR, __VA_ARGS__); } while (false);
+ 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(Logger::Level::LL_WARNING, __VA_ARGS__); } while (false);
+ 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(Logger::Level::LL_INFO, __VA_ARGS__); } while (false);
+ 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(Logger::Level::LL_DEBUG, __VA_ARGS__); } while (false);
+ 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(Logger::Level::LL_VERBOSE, __VA_ARGS__); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_VERBOSE, __VA_ARGS__); } while (false);
#else
#define COMMONAPI_VERBOSE(...)
#endif
@@ -77,39 +67,39 @@
#else // !WIN32
#define COMMONAPI_FATAL(params...) \
- do { Logger::log(Logger::Level::LL_FATAL, params); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_FATAL, params); } while (false);
#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_ERROR
#define COMMONAPI_ERROR(params...) \
- do { Logger::log(Logger::Level::LL_ERROR, params); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_ERROR, params); } while (false);
#else
#define COMMONAPI_ERROR(params...)
#endif
#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_WARNING
#define COMMONAPI_WARNING(params...) \
- do { Logger::log(Logger::Level::LL_WARNING, params); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_WARNING, params); } while (false);
#else
#define COMMONAPI_WARNING(params...)
#endif
#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_INFO
#define COMMONAPI_INFO(params...) \
- do { Logger::log(Logger::Level::LL_INFO, params); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_INFO, params); } while (false);
#else
#define COMMONAPI_INFO(params...)
#endif
#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_DEBUG
#define COMMONAPI_DEBUG(params...) \
- do { Logger::log(Logger::Level::LL_DEBUG, params); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_DEBUG, params); } while (false);
#else
#define COMMONAPI_DEBUG(params...)
#endif
#if COMMONAPI_LOGLEVEL >= COMMONAPI_LOGLEVEL_VERBOSE
#define COMMONAPI_VERBOSE(params...) \
- do { Logger::log(Logger::Level::LL_VERBOSE, params); } while (false);
+ do { Logger::log(LoggerImpl::Level::LL_VERBOSE, params); } while (false);
#else
#define COMMONAPI_VERBOSE(params...)
#endif
@@ -120,20 +110,14 @@ namespace CommonAPI {
class Logger {
public:
- COMMONAPI_EXPORT enum class Level : uint8_t {
- LL_FATAL = 0, LL_ERROR = 1, LL_WARNING = 2, LL_INFO = 3, LL_DEBUG = 4, LL_VERBOSE = 5
- };
-
- COMMONAPI_EXPORT Logger();
- COMMONAPI_EXPORT ~Logger();
template<typename... LogEntries_>
- COMMONAPI_EXPORT static void log(Level _level, LogEntries_... _entries) {
+ COMMONAPI_EXPORT static void log(LoggerImpl::Level _level, LogEntries_... _entries) {
#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
- if (_level < maximumLogLevel_) {
+ if (LoggerImpl::isLogged(_level)) {
std::stringstream buffer;
log_intern(buffer, _entries...);
- Logger::get()->doLog(_level, buffer.str());
+ LoggerImpl::get()->doLog(_level, buffer.str());
}
#else
(void)_level;
@@ -144,11 +128,6 @@ public:
COMMONAPI_EXPORT static void init(bool, const std::string &, bool, const std::string &);
private:
- COMMONAPI_EXPORT static inline Logger *get() {
- static Logger theLogger;
- return &theLogger;
- }
-
COMMONAPI_EXPORT static void log_intern(std::stringstream &_buffer) {
(void)_buffer;
}
@@ -158,35 +137,6 @@ private:
_buffer << _entry;
log_intern(_buffer, _moreEntries...);
}
-
- COMMONAPI_EXPORT void doLog(Level _level, const std::string &_message);
-
-#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
- static Level stringAsLevel(const std::string &_level);
-#endif
-#if defined(USE_CONSOLE) || defined(USE_FILE)
- static std::string levelAsString(Level _level);
-#endif
-#ifdef USE_DLT
- static DltLogLevelType levelAsDlt(Level _level);
-#endif
-#if defined(USE_CONSOLE) || defined(USE_FILE)
- static std::mutex mutex_;
-#endif
-#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
- static Level maximumLogLevel_;
-#endif
-#ifdef USE_CONSOLE
- static bool useConsole_;
-#endif
-#ifdef USE_FILE
- static std::shared_ptr<std::ofstream> file_;
-#endif
-#ifdef USE_DLT
- static bool useDlt_;
- DLT_DECLARE_CONTEXT(dlt_);
- bool ownAppID_;
-#endif
};
} // namespace CommonAPI
diff --git a/include/CommonAPI/LoggerImpl.hpp b/include/CommonAPI/LoggerImpl.hpp
new file mode 100644
index 0000000..1491e1b
--- /dev/null
+++ b/include/CommonAPI/LoggerImpl.hpp
@@ -0,0 +1,77 @@
+// Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// 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/.
+
+#ifndef COMMONAPI_LOGGER_IMPL_HPP_
+#define COMMONAPI_LOGGER_IMPL_HPP_
+
+#ifdef USE_DLT
+#include <dlt/dlt.h>
+#endif
+
+#include <cstdint>
+#include <fstream>
+#include <memory>
+#include <mutex>
+#include <sstream>
+
+#include <CommonAPI/Export.hpp>
+
+
+namespace CommonAPI {
+
+class Logger;
+
+class LoggerImpl {
+public:
+ friend class Logger;
+
+ enum class Level : uint8_t COMMONAPI_EXPORT {
+ LL_FATAL = 0, LL_ERROR = 1, LL_WARNING = 2, LL_INFO = 3, LL_DEBUG = 4, LL_VERBOSE = 5
+ };
+
+ static void init(bool, const std::string &, bool, const std::string &);
+
+private:
+
+ LoggerImpl();
+ ~LoggerImpl();
+
+ COMMONAPI_EXPORT static bool isLogged(Level _level);
+
+ COMMONAPI_EXPORT static LoggerImpl* get();
+
+ COMMONAPI_EXPORT void doLog(Level _level, const std::string &_message);
+
+#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
+ static Level stringAsLevel(const std::string &_level);
+#endif
+#if defined(USE_CONSOLE) || defined(USE_FILE)
+ static std::string levelAsString(Level _level);
+#endif
+#ifdef USE_DLT
+ static DltLogLevelType levelAsDlt(Level _level);
+#endif
+#if defined(USE_CONSOLE) || defined(USE_FILE)
+ static std::mutex mutex_;
+#endif
+#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
+ static Level maximumLogLevel_;
+#endif
+#ifdef USE_CONSOLE
+ static bool useConsole_;
+#endif
+#ifdef USE_FILE
+ static std::shared_ptr<std::ofstream> file_;
+#endif
+#ifdef USE_DLT
+ static bool useDlt_;
+ DLT_DECLARE_CONTEXT(dlt_);
+ bool ownAppID_;
+#endif
+};
+
+} // namespace CommonAPI
+
+#endif // COMMONAPI_LOGGER_IMPL_HPP_
diff --git a/include/CommonAPI/Runtime.hpp b/include/CommonAPI/Runtime.hpp
index 5b9254c..626bf4e 100644
--- a/include/CommonAPI/Runtime.hpp
+++ b/include/CommonAPI/Runtime.hpp
@@ -168,6 +168,8 @@ private:
COMMONAPI_EXPORT bool loadLibrary(const std::string &);
private:
+ std::string usedConfig_;
+
std::string defaultBinding_;
std::string defaultFolder_;
std::string defaultConfig_;
diff --git a/include/CommonAPI/Variant.hpp b/include/CommonAPI/Variant.hpp
index 96f283a..b139704 100644
--- a/include/CommonAPI/Variant.hpp
+++ b/include/CommonAPI/Variant.hpp
@@ -3,7 +3,6 @@
// 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 <cassert>
#include <cstdint>
#include <iostream>
#include <memory>
@@ -17,6 +16,8 @@
#include <CommonAPI/Deployable.hpp>
#include <CommonAPI/Deployment.hpp>
+#include <CommonAPI/Logger.hpp>
+
#ifndef COMMONAPI_VARIANT_HPP_
#define COMMONAPI_VARIANT_HPP_
@@ -223,7 +224,7 @@ private:
public:
inline bool hasValue() const {
- return (valueType_ != 0);
+ return (valueType_ != 0 && valueType_ <= TypesTupleSize::value );
}
typename std::aligned_storage<maxSize>::type valueStorage_;
@@ -239,7 +240,7 @@ struct ApplyVoidIndexVisitor<Variant_> {
static
void visit(Variant_ &, uint8_t &) {
- assert(false);
+ COMMONAPI_ERROR("ApplyVoidIndexVisitor<Variant_>::visit type not found");
}
};
@@ -269,12 +270,12 @@ struct ApplyVoidVisitor<Visitor_, Variant_> {
static
void visit(Visitor_ &, Variant_ &) {
- assert(false);
+ COMMONAPI_ERROR("ApplyVoidIndexVisitor<Visitor_, Variant_>::visit - type not found");
}
static
void visit(Visitor_ &, const Variant_ &) {
- assert(false);
+ COMMONAPI_ERROR("ApplyVoidIndexVisitor<Visitor_, Variant_>::visit(const) - type not found");
}
};
@@ -312,7 +313,7 @@ struct ApplyBoolVisitor<Visitor_, Variant_> {
static const uint8_t index = 0;
static bool visit(Visitor_ &, Variant_ &) {
- assert(false);
+ COMMONAPI_ERROR("ApplyBoolVisitor<Visitor_, Variant_>::visit - type not found");
return false;
}
};
@@ -342,12 +343,13 @@ struct ApplyStreamVisitor<Visitor_, Variant_, Deployment_> {
static
void visit(Visitor_ &, Variant_ &, const Deployment_ *) {
- //assert(false);
+ COMMONAPI_ERROR("ApplyStreamVisitor<Visitor_, Variant_, Deployment_>::visit - type not found");
+
}
static
void visit(Visitor_ &, const Variant_ &, const Deployment_ *) {
- //assert(false);
+ COMMONAPI_ERROR("ApplyStreamVisitor<Visitor_, Variant_, Deployment_>::visit(const) - type not found");
}
};
@@ -746,10 +748,8 @@ void Variant<Types_...>::set(U_ &&_value, const bool _clear) {
ApplyVoidVisitor<
DeleteVisitor<maxSize>, Variant<Types_...>, Types_...
>::visit(visitor, *this);
- } else {
- new (&valueStorage_) selected_type_t(std::move(any_container_value));
}
-
+ new (&valueStorage_) selected_type_t(std::move(any_container_value));
valueType_ = TypeIndex<Types_...>::template get<selected_type_t>();
}
diff --git a/src/CommonAPI/Address.cpp b/src/CommonAPI/Address.cpp
index 0a7344a..ca49cf4 100644
--- a/src/CommonAPI/Address.cpp
+++ b/src/CommonAPI/Address.cpp
@@ -9,6 +9,10 @@
namespace CommonAPI {
+Address::Address() {
+
+}
+
Address::Address(const std::string &_address) {
// TODO: handle error situation (_address is no valid CommonAPI address)
setAddress(_address);
diff --git a/src/CommonAPI/Logger.cpp b/src/CommonAPI/Logger.cpp
index 0de6c9a..c3f9213 100644
--- a/src/CommonAPI/Logger.cpp
+++ b/src/CommonAPI/Logger.cpp
@@ -3,174 +3,13 @@
// 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 <iostream>
-
#include <CommonAPI/Logger.hpp>
#include <CommonAPI/Runtime.hpp>
-namespace CommonAPI {
-
-#if defined(USE_CONSOLE) || defined(USE_FILE)
-std::mutex Logger::mutex_;
-#endif
-
-#ifdef USE_CONSOLE
-bool Logger::useConsole_(true);
-#endif
-
-#ifdef USE_FILE
-std::shared_ptr<std::ofstream> Logger::file_;
-#endif
-
-#ifdef USE_DLT
-bool Logger::useDlt_(false);
-#endif
-
-#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
-Logger::Level Logger::maximumLogLevel_(Logger::Level::LL_INFO);
-#endif
-
-Logger::Logger() {
-#ifdef USE_DLT
- if (useDlt_) {
- std::string context = Runtime::getProperty("LogContext");
- if (context == "") context = "CAPI";
- if (DLT_RETURN_ERROR == dlt_register_context(&dlt_, context.c_str(), "CAPI")) {
- std::string app = Runtime::getProperty("LogApplication");
- if (app == "") app = "CAPI";
- ownAppID_ = true;
- DLT_REGISTER_APP(app.c_str(), "CAPI");
- DLT_REGISTER_CONTEXT(dlt_, context.c_str(), "CAPI");
- }
- }
-#endif
-}
-
-Logger::~Logger() {
-#ifdef USE_DLT
- if (useDlt_) {
- DLT_UNREGISTER_CONTEXT(dlt_);
- if (ownAppID_) {
- DLT_UNREGISTER_APP();
- }
- }
-#endif
-}
-
-void
-Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt, const std::string &_level) {
-#ifdef USE_CONSOLE
- useConsole_ = _useConsole;
-#else
- (void)_useConsole;
-#endif
-#ifdef USE_FILE
- if (_fileName != "") {
- file_ = std::make_shared<std::ofstream>();
- if (file_)
- file_->open(_fileName.c_str(), std::ofstream::out | std::ofstream::app);
- }
-#else
- (void)_fileName;
-#endif
-#ifdef USE_DLT
- useDlt_ = _useDlt;
-#else
- (void)_useDlt;
-#endif
-#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
- maximumLogLevel_ = stringAsLevel(_level);
-#endif
-}
-
+namespace CommonAPI {;
void
-Logger::doLog(Level _level, const std::string &_message) {
-#ifdef USE_CONSOLE
- if (useConsole_) {
- std::lock_guard<std::mutex> itsLock(mutex_);
- std::cout << "[CAPI][" << levelAsString(_level) << "] " << _message << std::endl;
- }
-#endif
-#ifdef USE_FILE
- if (file_ && file_->is_open()) {
- std::lock_guard<std::mutex> itsLock(mutex_);
- (*(file_.get())) << "[CAPI][" << levelAsString(_level) << "] " << _message << std::endl;
- }
-#endif
-#ifdef USE_DLT
- if (useDlt_) {
- DLT_LOG_STRING(dlt_, levelAsDlt(_level), _message.c_str());
- }
-#endif
-}
-
-#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
-Logger::Level
-Logger::stringAsLevel(const std::string &_level) {
- if (_level == "fatal")
- return Level::LL_FATAL;
-
- if (_level == "error")
- return Level::LL_ERROR;
-
- if (_level == "warning")
- return Level::LL_WARNING;
-
- if (_level == "info")
- return Level::LL_INFO;
-
- if (_level == "debug")
- return Level::LL_DEBUG;
-
- if (_level == "verbose")
- return Level::LL_VERBOSE;
-
- return Level::LL_INFO;
-}
-#endif
-
-#if defined(USE_CONSOLE) || defined(USE_FILE)
-std::string
-Logger::levelAsString(Logger::Level _level) {
- switch (_level) {
- case Level::LL_FATAL:
- return "FATAL";
- case Level::LL_ERROR:
- return "ERROR";
- case Level::LL_WARNING:
- return "WARNING";
- case Level::LL_INFO:
- return "INFO";
- case Level::LL_DEBUG:
- return "DEBUG";
- case Level::LL_VERBOSE:
- return "VERBOSE";
- default:
- return "";
- }
-}
-#endif
-
-#ifdef USE_DLT
-DltLogLevelType
-Logger::levelAsDlt(Logger::Level _level) {
- switch (_level) {
- case Level::LL_FATAL:
- return DLT_LOG_FATAL;
- case Level::LL_ERROR:
- return DLT_LOG_ERROR;
- case Level::LL_WARNING:
- return DLT_LOG_WARN;
- case Level::LL_INFO:
- return DLT_LOG_INFO;
- case Level::LL_DEBUG:
- return DLT_LOG_DEBUG;
- case Level::LL_VERBOSE:
- return DLT_LOG_VERBOSE;
- default:
- return DLT_LOG_DEFAULT;
- }
+ Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt, const std::string &_level) {
+ LoggerImpl::init(_useConsole, _fileName, _useDlt, _level);
}
-#endif
} //namespace CommonAPI
diff --git a/src/CommonAPI/LoggerImpl.cpp b/src/CommonAPI/LoggerImpl.cpp
new file mode 100644
index 0000000..fc119d3
--- /dev/null
+++ b/src/CommonAPI/LoggerImpl.cpp
@@ -0,0 +1,200 @@
+// Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// 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 <iostream>
+
+#include <CommonAPI/LoggerImpl.hpp>
+#ifdef USE_DLT
+#include <CommonAPI/Runtime.hpp>
+#endif
+
+namespace CommonAPI {;
+
+#if defined(USE_CONSOLE) || defined(USE_FILE)
+std::mutex LoggerImpl::mutex_;
+#endif
+
+#ifdef USE_CONSOLE
+bool LoggerImpl::useConsole_(true);
+#endif
+
+#ifdef USE_FILE
+std::shared_ptr<std::ofstream> LoggerImpl::file_;
+#endif
+
+#ifdef USE_DLT
+bool LoggerImpl::useDlt_(false);
+#endif
+
+#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
+LoggerImpl::Level LoggerImpl::maximumLogLevel_(LoggerImpl::Level::LL_INFO);
+#endif
+
+LoggerImpl::LoggerImpl() {
+#ifdef USE_DLT
+ if (useDlt_) {
+ std::string app = Runtime::getProperty("LogApplication");
+ if (!app.empty()) {
+ ownAppID_ = true;
+ DLT_REGISTER_APP(app.c_str(), "CommonAPI Application");
+ }
+
+ std::string context = Runtime::getProperty("LogContext");
+ if (context == "") context = "CAPI";
+ DLT_REGISTER_CONTEXT(dlt_, context.c_str(), "CAPI");
+ }
+#endif
+}
+
+LoggerImpl::~LoggerImpl() {
+#ifdef USE_DLT
+ if (useDlt_) {
+ DLT_UNREGISTER_CONTEXT(dlt_);
+ if (ownAppID_) {
+ DLT_UNREGISTER_APP();
+ }
+ }
+#endif
+}
+
+LoggerImpl* LoggerImpl::get() {
+ static LoggerImpl theLoggerImpl;
+ return &theLoggerImpl;
+}
+
+
+void
+LoggerImpl::init(bool _useConsole, const std::string &_fileName, bool _useDlt, const std::string &_level) {
+#ifdef USE_CONSOLE
+ useConsole_ = _useConsole;
+#else
+ (void)_useConsole;
+#endif
+#ifdef USE_FILE
+ if (_fileName != "") {
+ file_ = std::make_shared<std::ofstream>();
+ if (file_)
+ file_->open(_fileName.c_str(), std::ofstream::out | std::ofstream::app);
+ }
+#else
+ (void)_fileName;
+#endif
+#ifdef USE_DLT
+ useDlt_ = _useDlt;
+#else
+ (void)_useDlt;
+#endif
+#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
+ maximumLogLevel_ = stringAsLevel(_level);
+#else
+ (void)_level;
+#endif
+}
+
+void
+LoggerImpl::doLog(Level _level, const std::string &_message) {
+#ifdef USE_CONSOLE
+ if (useConsole_) {
+ std::lock_guard<std::mutex> itsLock(mutex_);
+ std::cout << "[CAPI][" << levelAsString(_level) << "] " << _message << std::endl;
+ }
+#endif
+#ifdef USE_FILE
+ if (file_ && file_->is_open()) {
+ std::lock_guard<std::mutex> itsLock(mutex_);
+ (*(file_.get())) << "[CAPI][" << levelAsString(_level) << "] " << _message << std::endl;
+ }
+#endif
+#ifdef USE_DLT
+ if (useDlt_) {
+ DLT_LOG_STRING(dlt_, levelAsDlt(_level), _message.c_str());
+ }
+#endif
+#if !defined(USE_CONSOLE) && !defined(USE_FILE) && !defined(USE_DLT)
+ (void)_level;
+ (void)_message;
+#endif
+}
+
+#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
+LoggerImpl::Level
+LoggerImpl::stringAsLevel(const std::string &_level) {
+ if (_level == "fatal")
+ return Level::LL_FATAL;
+
+ if (_level == "error")
+ return Level::LL_ERROR;
+
+ if (_level == "warning")
+ return Level::LL_WARNING;
+
+ if (_level == "info")
+ return Level::LL_INFO;
+
+ if (_level == "debug")
+ return Level::LL_DEBUG;
+
+ if (_level == "verbose")
+ return Level::LL_VERBOSE;
+
+ return Level::LL_INFO;
+}
+#endif
+
+#if defined(USE_CONSOLE) || defined(USE_FILE)
+std::string
+LoggerImpl::levelAsString(LoggerImpl::Level _level) {
+ switch (_level) {
+ case Level::LL_FATAL:
+ return "FATAL";
+ case Level::LL_ERROR:
+ return "ERROR";
+ case Level::LL_WARNING:
+ return "WARNING";
+ case Level::LL_INFO:
+ return "INFO";
+ case Level::LL_DEBUG:
+ return "DEBUG";
+ case Level::LL_VERBOSE:
+ return "VERBOSE";
+ default:
+ return "";
+ }
+}
+#endif
+
+#ifdef USE_DLT
+DltLogLevelType
+LoggerImpl::levelAsDlt(LoggerImpl::Level _level) {
+ switch (_level) {
+ case Level::LL_FATAL:
+ return DLT_LOG_FATAL;
+ case Level::LL_ERROR:
+ return DLT_LOG_ERROR;
+ case Level::LL_WARNING:
+ return DLT_LOG_WARN;
+ case Level::LL_INFO:
+ return DLT_LOG_INFO;
+ case Level::LL_DEBUG:
+ return DLT_LOG_DEBUG;
+ case Level::LL_VERBOSE:
+ return DLT_LOG_VERBOSE;
+ default:
+ return DLT_LOG_DEFAULT;
+ }
+}
+#endif
+
+bool
+LoggerImpl::isLogged(LoggerImpl::Level _level) {
+#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
+ return (_level <= maximumLogLevel_) ? true : false;
+#else
+ (void)_level;
+ return false;
+#endif
+}
+
+} // namespace CommonAPI
diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp
index 1d0b0c5..6ba6864 100644
--- a/src/CommonAPI/Runtime.cpp
+++ b/src/CommonAPI/Runtime.cpp
@@ -132,9 +132,9 @@ void
Runtime::initFactories() {
std::lock_guard<std::mutex> itsLock(factoriesMutex_);
if (!isInitialized_) {
+ COMMONAPI_INFO("Loading configuration file \'", usedConfig_, "\'");
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();
@@ -156,18 +156,18 @@ Runtime::readConfiguration() {
#else
if (getcwd(currentDirectory, MAX_PATH_LEN)) {
#endif
- config = currentDirectory;
- config += "/";
- config += COMMONAPI_DEFAULT_CONFIG_FILE;
+ usedConfig_ = currentDirectory;
+ usedConfig_ += "/";
+ usedConfig_ += COMMONAPI_DEFAULT_CONFIG_FILE;
struct stat s;
- if (stat(config.c_str(), &s) != 0) {
- config = defaultConfig_;
+ if (stat(usedConfig_.c_str(), &s) != 0) {
+ usedConfig_ = defaultConfig_;
}
}
IniFileReader reader;
- if (!reader.load(config))
+ if (!reader.load(usedConfig_))
return false;
std::string itsConsole("true");