summaryrefslogtreecommitdiff
path: root/src
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 /src
parent1c158272e2ee4b93021a97ac3b5c207a137b0d2c (diff)
downloadgenivi-common-api-runtime-534894b27a5e6b86cf8d2bd7b53d55d04f2a1bcc.tar.gz
CommonAPI 3.1.83.1.8
Diffstat (limited to 'src')
-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
4 files changed, 214 insertions, 171 deletions
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");