summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/include/CAmDltWrapper.h
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerUtilities/include/CAmDltWrapper.h')
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h358
1 files changed, 31 insertions, 327 deletions
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h
index a86b4dc..1b65ec1 100644
--- a/AudioManagerUtilities/include/CAmDltWrapper.h
+++ b/AudioManagerUtilities/include/CAmDltWrapper.h
@@ -5,6 +5,7 @@
*
* \author Christian Linke, christian.linke@bmw.de BMW 2011,2012
* \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2014
+ * \author Martin Koch, mkoch@de.adit-jv.com ADIT 2020
*
* \copyright
* This Source Code Form is subject to the terms of the
@@ -12,6 +13,11 @@
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* \file CAmDltWrapper.h
+ * This file is reduced to a legacy wrapper around the new logging architecture
+ * to establish compatibility with plugins and applications developed for audio-manager
+ * versions before 7.7.0.\n
+ * For new development use CAmLogWrapper instead.
+ *
* For further information see http://www.genivi.org/.
*/
@@ -19,14 +25,12 @@
#define DLTWRAPPER_H_
#include <string>
-#include <pthread.h>
#include <sstream>
#include <iostream>
#include <fstream>
#include <map>
-#include <vector>
-#include <audiomanagerconfig.h>
-#include "audiomanagertypes.h"
+
+#include "CAmLogWrapper.h"
#ifdef WITH_DLT
# include <dlt.h>
@@ -34,6 +38,7 @@
# include <stdint.h>
# include <sstream>
+# define DLT_ID_SIZE 4
# define DLT_USER_BUF_MAX_SIZE 2048
/**
@@ -57,20 +62,6 @@ typedef enum
} DltTraceStatusType;
/**
- * This structure is used for context data used in an application.
- */
-typedef struct
-{
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char *context_description; /**< description of context */
-} DltContextData;
-
-/**
* Definitions of DLT log level
*/
typedef enum
@@ -106,21 +97,6 @@ namespace am
class CAmDltWrapper
{
public:
-
- /**
- * This structure is used for context data used in an application.
- */
- typedef struct
- {
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char *context_description; /**< description of context */
- } NoDltContextData;
-
/*
* The eunum gives the logtype
*/
@@ -151,7 +127,7 @@ public:
* register a context
*/
void registerContext(DltContext &handle, const char *contextid, const char *description);
- void registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status);
+ void registerContext(DltContext &handle, const char *contextid, const char *description, DltLogLevelType level, DltTraceStatusType status);
void unregisterContext(DltContext &handle);
bool getEnabled();
@@ -161,335 +137,63 @@ public:
bool checkLogLevel(DltLogLevelType logLevel)
{
-#ifdef WITH_DLT
-# ifdef DLT_IS_LOG_LEVEL_ENABLED
- return (dlt_user_is_logLevel_enabled(&mDltContext, logLevel) == DLT_RETURN_TRUE);
-# else
- (void)logLevel;
- return true;
-# endif
-#else // ifdef WITH_DLT
- return (logLevel <= mDltContext.log_level_user);
-#endif // ifdef WITH_DLT
- }
-
- void deinit();
- void send();
- void append(const int8_t value);
- void append(const uint8_t value);
- void append(const int16_t value);
- void append(const uint16_t value);
- void append(const int32_t value);
- void append(const uint32_t value);
- void append(const uint64_t value);
- void append(const int64_t value);
- void append(const std::string &value);
- void append(const bool value);
- void append(const std::vector<uint8_t> &data);
-
- template<class T>
- void appendNoDLT(T value)
- {
- mNoDltContextData.buffer << value << " ";
- }
-
- // specialization for const char*
- template<typename T = const char *>
- void append(const char *value)
- {
-#ifdef WITH_DLT
- if (mlogDestination == logDestination::DAEMON)
+ if (mpCurrentContext)
{
- dlt_user_log_write_string(&mDltContextData, value);
+ return mpCurrentContext->checkLogLevel(static_cast<am_LogLevel_e>(logLevel));
}
else
{
- mNoDltContextData.buffer << std::string(value);
- }
-#else // ifdef WITH_DLT
- mNoDltContextData.buffer << std::string(value);
-#endif // WITH_DLT
-
- }
-
-private:
- static const std::vector<const char *> mStr_error;
- static const std::vector<const char *> mStr_sourceState;
- static const std::vector<const char *> mStr_MuteState;
- static const std::vector<const char *> mStr_DomainState;
- static const std::vector<const char *> mStr_ConnectionState;
- static const std::vector<const char *> mStr_Availability;
- static const std::vector<const char *> mStr_Interrupt;
- static const std::vector<const char *> mStr_Handle;
- static const std::vector<const char *> mStr_NotificationStatus;
-
-public:
-
- // specialization for const am_Error_e
- template<typename T = const am_Error_e>
- void append(const am_Error_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_error.size())
- {
- std::ostringstream ss;
- ss << "value for am_Error_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_error[value]);
- }
-
- // specialization for const am_Error_e
- template<typename T = const am_SourceState_e>
- void append(const am_SourceState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_sourceState.size())
- {
- std::ostringstream ss;
- ss << "value for am_SourceState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_sourceState[value]);
- }
-
- template<typename T = const am_MuteState_e>
- void append(const am_MuteState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_MuteState.size())
- {
- std::ostringstream ss;
- ss << "value for am_MuteState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_MuteState[value]);
- }
-
- template<typename T = const am_DomainState_e>
- void append(const am_DomainState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_DomainState.size())
- {
- std::ostringstream ss;
- ss << "value for am_DomainState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
-
- return;
- }
-
- append(mStr_DomainState[value]);
- }
-
- template<typename T = const am_ConnectionState_e>
- void append(const am_ConnectionState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_ConnectionState.size())
- {
- std::ostringstream ss;
- ss << "value for am_ConnectionState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_ConnectionState[value]);
- }
-
- template<typename T = const am_Availability_e>
- void append(const am_Availability_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_Availability.size())
- {
- std::ostringstream ss;
- ss << "value for am_Availability_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_Availability[value]);
- }
-
- template<typename T = const am_InterruptState_e>
- void append(const am_InterruptState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_Interrupt.size())
- {
- std::ostringstream ss;
- ss << "value for am_InterruptState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_Interrupt[value]);
- }
-
- template<typename T = const am_Handle_e>
- void append(const am_Handle_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_Handle.size())
- {
- std::ostringstream ss;
- ss << "value for am_Handle_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
+ return getLogger()->importContext().checkLogLevel(static_cast<am_LogLevel_e>(logLevel));
}
-
- append(mStr_Handle[value]);
}
- template<typename T = const am_Handle_s>
- void append(const am_Handle_s value)
- {
- append(value.handleType);
- append(value.handle);
- }
+ void deinit();
+ void send();
- template<typename T = const am_NotificationStatus_e>
- void append(const am_NotificationStatus_e value)
+ template<typename... TArgs>
+ void append(TArgs... args)
{
- if (static_cast<std::size_t>(value) >= mStr_NotificationStatus.size())
+ if (mpCurrentContext)
{
- std::ostringstream ss;
- ss << "value for am_NotificationStatus_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
+ mpCurrentContext->append(args...);
}
-
- append(mStr_NotificationStatus[value]);
}
- // Template to print unknown pointer types with their address
- template<typename T>
- void append(T *value)
- {
- std::ostringstream ss;
- ss << "0x" << std::hex << (uint64_t)value;
- append(ss.str().c_str());
- }
-
- // Template to print unknown types
- template<typename T>
- void append(T value)
- {
- std::ostringstream ss;
- ss << std::dec << static_cast<int>(value);
- append(ss.str().c_str());
- }
-
- // Template parameter pack to generate recursive code
- void append(void) {}
- template<typename T, typename... TArgs>
- void append(T value, TArgs... args)
- {
- this->append(value);
- this->append(args...);
- }
private:
/**
* private contructor
*/
- CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename = "", bool onlyError = false); // is private because of singleton pattern
- bool initNoDlt(DltLogLevelType loglevel, DltContext *context);
- std::string now();
+ CAmDltWrapper(IAmLogger *pLogger, bool debugEnabled, bool onlyError = false); // is private because of singleton pattern
- DltContext mDltContext; //!< the default context
- DltContextData mDltContextData; //!< contextdata
- NoDltContextData mNoDltContextData; //!< contextdata for std out logging
+ IAmLogger *mpLogger; //!< pointer to underlying logger instance
+ IAmLogContext *mpCurrentContext; //!< context for direct init(), append(...) and send() operations
std::map<DltContext *, std::string> mMapContext; //!< a Map for all registered context
bool mDebugEnabled; //!< debug Enabled or not
- logDestination mlogDestination; //!< The log destination
- std::ofstream mFilename; //!< Filename for logging
bool mOnlyError; //!< Only if Log Level is above Error
- bool mLogOn; //!< Used to keep track if currently logging is on
static CAmDltWrapper *mpDLTWrapper; //!< pointer to the wrapper instance
- static pthread_mutex_t mMutex;
-
};
/**
* logs given values with a given context (register first!) and given loglevel
* @param context
* @param loglevel
- * @param value
- * @param ...
+ * @param ... args
*/
-template<typename T, typename... TArgs>
-void log(DltContext *const context, DltLogLevelType loglevel, T value, TArgs... args)
+template<typename... TArgs>
+void log(DltContext *const context, DltLogLevelType loglevel, TArgs... args)
{
- CAmDltWrapper *inst(CAmDltWrapper::instance());
- if (!inst->getEnabled())
- {
- return;
- }
-
- if (!inst->init(loglevel, context))
+ std::string contextID;
+ if (context)
{
- return;
+ contextID = std::string(context->contextID, DLT_ID_SIZE);
}
- inst->append(value);
- inst->append(args...);
- inst->send();
-}
-
-/**
- * logs given values with debuglevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logDebug(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_DEBUG, value, args...);
-}
-
-/**
- * logs given values with infolevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logInfo(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_INFO, value, args...);
+ // delegate to dedicated logging context
+ getLogger()->importContext(contextID.c_str())
+ .log(static_cast<am_LogLevel_e>(loglevel), args...);
}
-/**
- * logs given values with errorlevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logError(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_ERROR, value, args...);
-}
-
-/**
- * logs given values with warninglevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logWarning(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_WARN, value, args...);
-}
-
-/**
- * logs given values with verbose with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logVerbose(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_VERBOSE, value, args...);
-}
}