summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/include
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerUtilities/include')
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h358
-rwxr-xr-xAudioManagerUtilities/include/CAmLogWrapper.h128
-rwxr-xr-xAudioManagerUtilities/include/CAmLoggerDlt.h90
-rwxr-xr-xAudioManagerUtilities/include/CAmLoggerFile.h105
-rwxr-xr-xAudioManagerUtilities/include/CAmLoggerStdOut.h113
-rw-r--r--AudioManagerUtilities/include/CAmSerializer.h2
-rwxr-xr-xAudioManagerUtilities/include/CAmTimeUtility.h45
-rwxr-xr-xAudioManagerUtilities/include/IAmLogger.h345
-rw-r--r--AudioManagerUtilities/include/TAmPluginTemplate.h2
9 files changed, 859 insertions, 329 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...);
-}
}
diff --git a/AudioManagerUtilities/include/CAmLogWrapper.h b/AudioManagerUtilities/include/CAmLogWrapper.h
new file mode 100755
index 0000000..224c3ac
--- /dev/null
+++ b/AudioManagerUtilities/include/CAmLogWrapper.h
@@ -0,0 +1,128 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2017, ADIT GmbH
+ *
+ * \author Mattia Guerra, mguerra@de.adit-jv.com ADIT 2017
+ * \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2017
+ *
+ * \copyright
+ * 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/.
+ *
+ * \file CAmLogWrapper.h
+ * For further information see http://www.genivi.org/.
+ */
+
+#ifndef LOGWRAPPER_H_
+#define LOGWRAPPER_H_
+
+#include <audiomanagerconfig.h>
+#include "pthread.h"
+#include "IAmLogger.h"
+#include "audiomanagertypes.h"
+
+namespace am
+{
+/**
+ * This class is instantiated as a singleton and offers logging to a default context (maincontext).
+ * Logging under the default context can simply be done with the logDebug/logInfo/logError/logWarning/logVerbose
+ * templates. For logging with a different context, you need to register a context with registerContext,
+ * method provided by backends implementing the IAmLogger interface. registerContext returns a logging context.
+ * To import this context into other classes use importContext, method provided by backends implementing the IAmLogger
+ * interface. To access the IAmLogger interface, simply ask CAmLogWrapper::instance().
+ */
+class CAmLogWrapper
+{
+public:
+ static IAmLogger *instantiateOnce(const char *appid, const char *description,
+ const am_LogStatus_e logStatus = LS_ON, const am_LogService_e logService = DEFAULT_LOG_SERVICE,
+ const std::string Filename = "", bool onlyError = false);
+ static IAmLogger *instance(const am_LogService_e logservice = DEFAULT_LOG_SERVICE);
+
+ inline static am_LogService_e getLogService()
+ {
+ return mLogService;
+ }
+
+ virtual ~CAmLogWrapper();
+
+private:
+ CAmLogWrapper(void); //!< is private because of singleton pattern
+ static IAmLogger *mpLogger; //!< pointer to the logger instance
+ static std::string mAppId;
+ static std::string mDescription;
+ static am_LogStatus_e mLogStatus;
+ static am_LogService_e mLogService;
+ static std::string mFilename;
+ static bool mOnlyError;
+};
+
+/**
+ * returns the instance of instantiated IAmLogger
+ * @return
+ */
+inline IAmLogger *getLogger()
+{
+ return (CAmLogWrapper::instance(CAmLogWrapper::getLogService()));
+}
+
+/**
+ * logs given values with debuglevel with the default context
+ * @param value
+ * @param ...
+ */
+template<typename T, typename... TArgs>
+void logDebug(const T &value, const TArgs & ... args)
+{
+ getLogger()->logToDefaultContext(LL_DEBUG, value, args...);
+}
+
+/**
+ * logs given values with infolevel with the default context
+ * @param value
+ * @param ...
+ */
+template<typename T, typename... TArgs>
+void logInfo(const T &value, const TArgs & ... args)
+{
+ getLogger()->logToDefaultContext(LL_INFO, value, args...);
+}
+
+/**
+ * logs given values with errorlevel with the default context
+ * @param value
+ * @param ...
+ */
+template<typename T, typename... TArgs>
+void logError(const T &value, const TArgs & ... args)
+{
+ getLogger()->logToDefaultContext(LL_ERROR, value, args...);
+}
+
+/**
+ * logs given values with warninglevel with the default context
+ * @param value
+ * @param ...
+ */
+template<typename T, typename... TArgs>
+void logWarning(const T &value, const TArgs & ... args)
+{
+ getLogger()->logToDefaultContext(LL_WARN, value, args...);
+}
+
+/**
+ * logs given values with verboselevel with the default context
+ * @param value
+ * @param ...
+ */
+template<typename T, typename... TArgs>
+void logVerbose(const T &value, const TArgs & ... args)
+{
+ getLogger()->logToDefaultContext(LL_VERBOSE, value, args...);
+}
+
+}
+
+#endif /* LOGWRAPPER_H_ */
diff --git a/AudioManagerUtilities/include/CAmLoggerDlt.h b/AudioManagerUtilities/include/CAmLoggerDlt.h
new file mode 100755
index 0000000..5af0aad
--- /dev/null
+++ b/AudioManagerUtilities/include/CAmLoggerDlt.h
@@ -0,0 +1,90 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2017, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * 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/.
+ *
+ * \file CAmLoggerDlt.h
+ * For further information see http://www.genivi.org/.
+ */
+
+#ifndef LOGGERDLT_H_
+#define LOGGERDLT_H_
+
+#include "IAmLogger.h"
+#include <dlt/dlt.h>
+#include <map>
+#include <string>
+#include <string.h>
+#include <vector>
+
+namespace am
+{
+
+class CAmLogContextDlt : public IAmLogContext
+{
+public:
+ CAmLogContextDlt(const char *id);
+ virtual ~CAmLogContextDlt() {}
+ DltContext *getHandle();
+
+private:
+ /* IAmLogContext */
+ bool configure(const am_LogLevel_e loglevel) override;
+ void send() override;
+ void append(const int8_t value) override;
+ void append(const uint8_t value) override;
+ void append(const int16_t value) override;
+ void append(const uint16_t value) override;
+ void append(const int32_t value) override;
+ void append(const uint32_t value) override;
+ void append(const uint64_t value) override;
+ void append(const int64_t value) override;
+ void append(const bool value) override;
+ void append(const std::vector<uint8_t> &data) override;
+ void append(const char *value) override;
+
+ template<class T>
+ void append(T value);
+
+ bool checkLogLevel(const am_LogLevel_e logLevel) override;
+
+private:
+ const char *mId;
+ DltContext mDltContext;
+ DltContextData mDltContextData;
+};
+
+class CAmLoggerDlt : public IAmLogger
+{
+public:
+ ~CAmLoggerDlt();
+
+ /* IAmLogger */
+ void registerApp(const char *appid, const char *description) override;
+ void unregisterApp() override;
+ IAmLogContext &registerContext(const char *contextid, const char *description) override;
+ IAmLogContext &registerContext(const char *contextid, const char *description,
+ const am_LogLevel_e level, const am_LogStatus_e status) override;
+ IAmLogContext &importContext(const char *contextid = NULL) override;
+ void unregisterContext(const char *contextid) override;
+
+private:
+ CAmLogContextDlt &createContext(const char *contextid);
+
+private:
+ std::map<const char *, CAmLogContextDlt *> mCtxTable;
+};
+
+}
+
+#endif /* LOGGERDLT_H_ */
diff --git a/AudioManagerUtilities/include/CAmLoggerFile.h b/AudioManagerUtilities/include/CAmLoggerFile.h
new file mode 100755
index 0000000..de09a63
--- /dev/null
+++ b/AudioManagerUtilities/include/CAmLoggerFile.h
@@ -0,0 +1,105 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2017, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * 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/.
+ *
+ * \file CAmLoggerFile.h
+ * For further information see http://www.genivi.org/.
+ */
+
+#ifndef LOGGERFILE_H_
+#define LOGGERFILE_H_
+
+#include "IAmLogger.h"
+#include <map>
+#include <string>
+#include <string.h>
+#include <fstream>
+
+namespace am
+{
+
+class CFileHeader
+{
+public:
+ CFileHeader(const char *ctx = "LOG")
+ : mCtx(ctx) {}
+ friend std ::ostream &operator <<(std::ostream &out, const CFileHeader &h);
+
+ const char *mCtx;
+};
+
+class CAmLogContextFile : public IAmLogContext
+{
+public:
+ CAmLogContextFile(const char *id, const am_LogLevel_e level, const am_LogStatus_e status, std::ofstream &filestream);
+ virtual ~CAmLogContextFile() {}
+
+ /* IAmLogContext */
+ bool checkLogLevel(const am_LogLevel_e logLevel) override;
+
+private:
+ /* IAmLogContext */
+ bool configure(const am_LogLevel_e loglevel) override;
+ void send() override;
+ void append(const int8_t value) override;
+ void append(const uint8_t value) override;
+ void append(const int16_t value) override;
+ void append(const uint16_t value) override;
+ void append(const int32_t value) override;
+ void append(const uint32_t value) override;
+ void append(const uint64_t value) override;
+ void append(const int64_t value) override;
+ void append(const bool value) override;
+ void append(const std::vector<uint8_t> &data) override;
+ void append(const char *value) override;
+
+ template<class T>
+ void appendFile(T value);
+
+private:
+ CFileHeader mHeader;
+ am_LogLevel_e mLogLevel;
+ am_LogStatus_e mLogStatus;
+ std::ofstream &mFilestream;
+};
+
+class CAmLoggerFile : public IAmLogger
+{
+public:
+ CAmLoggerFile(const am_LogStatus_e status, const bool onlyError = false, const std::string &filename = "");
+ ~CAmLoggerFile();
+
+ /* IAmLogger */
+ void registerApp(const char *appid, const char *description) override;
+ void unregisterApp() override;
+ IAmLogContext &registerContext(const char *contextid, const char *description) override;
+ IAmLogContext &registerContext(const char *contextid, const char *description,
+ const am_LogLevel_e level, const am_LogStatus_e status) override;
+ IAmLogContext &importContext(const char *contextid = NULL) override;
+ void unregisterContext(const char *contextid) override;
+
+private:
+ void print(std::string str);
+
+private:
+ CFileHeader mHeader;
+ const am_LogStatus_e mLogStatus;
+ const am_LogLevel_e mStandardLogLevel;
+ std::ofstream mFilestream;
+ std::map<const char *, CAmLogContextFile *> mCtxTable;
+};
+
+}
+
+#endif /* LOGGERFILE_H_ */
diff --git a/AudioManagerUtilities/include/CAmLoggerStdOut.h b/AudioManagerUtilities/include/CAmLoggerStdOut.h
new file mode 100755
index 0000000..3821aba
--- /dev/null
+++ b/AudioManagerUtilities/include/CAmLoggerStdOut.h
@@ -0,0 +1,113 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2015, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * 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/.
+ *
+ * \file CAmLoggerStdOut.h
+ * For further information see http://www.genivi.org/.
+ */
+
+#ifndef LOGGERSTDOUT_H_
+#define LOGGERSTDOUT_H_
+
+#include "IAmLogger.h"
+#include <map>
+#include <string>
+#include <string.h>
+
+namespace am
+{
+
+static const std::string CC_BLACK = "\x1b[0;30m";
+static const std::string CC_RED = "\x1b[0;31m";
+static const std::string CC_GREEN = "\x1b[0;32m";
+static const std::string CC_YELLOW = "\x1b[0;33m";
+static const std::string CC_BLUE = "\x1b[0;34m";
+static const std::string CC_MAGENTA = "\x1b[0;35m";
+static const std::string CC_CYAN = "\x1b[0;36m";
+static const std::string CC_WHITE = "\x1b[0;37m";
+static const std::string CC_RESET = "\x1b[0;39m";
+
+class CStdOutHeader
+{
+public:
+ CStdOutHeader(const char *ctx = "LOG", const std::string &color = CC_BLUE)
+ : mCtx(ctx)
+ , mCc(color) {}
+ friend std ::ofstream &operator <<(std::ofstream &out, const CStdOutHeader &h);
+
+ const char *mCtx;
+ const std::string &mCc;
+};
+
+class CAmLogContextStdOut : public IAmLogContext
+{
+public:
+ CAmLogContextStdOut(const char *id, const am_LogLevel_e level, const am_LogStatus_e status);
+ virtual ~CAmLogContextStdOut() {}
+
+ void changeLogLS(const am_LogLevel_e level, const am_LogStatus_e status);
+
+ /* IAmLogContext */
+ bool checkLogLevel(const am_LogLevel_e logLevel) override;
+
+private:
+ /* IAmLogContext */
+ bool configure(const am_LogLevel_e loglevel) override;
+ void send() override;
+ void append(const int8_t value) override;
+ void append(const uint8_t value) override;
+ void append(const int16_t value) override;
+ void append(const uint16_t value) override;
+ void append(const int32_t value) override;
+ void append(const uint32_t value) override;
+ void append(const uint64_t value) override;
+ void append(const int64_t value) override;
+ void append(const bool value) override;
+ void append(const std::vector<uint8_t> &data) override;
+ void append(const char *value) override;
+
+ template<class T>
+ void appendStdOut(T value);
+
+private:
+ CStdOutHeader mHeader;
+ am_LogLevel_e mLogLevel;
+ am_LogStatus_e mLogStatus;
+};
+
+class CAmLoggerStdOut : public IAmLogger
+{
+public:
+ CAmLoggerStdOut(const am_LogStatus_e status, const bool onlyError = false);
+ ~CAmLoggerStdOut();
+
+ /* IAmLogger */
+ void registerApp(const char *appid, const char *description) override;
+ void unregisterApp() override;
+ IAmLogContext &registerContext(const char *contextid, const char *description) override;
+ IAmLogContext &registerContext(const char *contextid, const char *description,
+ const am_LogLevel_e level, const am_LogStatus_e status) override;
+ IAmLogContext &importContext(const char *contextid = NULL) override;
+ void unregisterContext(const char *contextid) override;
+
+private:
+ CStdOutHeader mHeader;
+ const am_LogStatus_e mLogStatus;
+ const am_LogLevel_e mStandardLogLevel;
+ std::map<const char *, CAmLogContextStdOut *> mCtxTable;
+};
+
+}
+
+#endif /* LOGGERSTDOUT_H_ */
diff --git a/AudioManagerUtilities/include/CAmSerializer.h b/AudioManagerUtilities/include/CAmSerializer.h
index 5fd1977..1c86942 100644
--- a/AudioManagerUtilities/include/CAmSerializer.h
+++ b/AudioManagerUtilities/include/CAmSerializer.h
@@ -23,7 +23,7 @@
#include <memory>
#include <stdexcept>
#include <unistd.h>
-#include "CAmDltWrapper.h"
+#include "CAmLogWrapper.h"
#include "CAmSocketHandler.h"
/*!
diff --git a/AudioManagerUtilities/include/CAmTimeUtility.h b/AudioManagerUtilities/include/CAmTimeUtility.h
new file mode 100755
index 0000000..2f0a29d
--- /dev/null
+++ b/AudioManagerUtilities/include/CAmTimeUtility.h
@@ -0,0 +1,45 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2016, ADIT GmbH
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * 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/.
+ *
+ * \file CAmTimeUtility.h
+ * For further information see http://www.genivi.org/.
+ */
+
+#ifndef TIMEUTILITY_H_
+#define TIMEUTILITY_H_
+
+#include <string>
+
+namespace am
+{
+
+class CAmTimeUtility
+{
+public:
+ static inline std::string now()
+ {
+ time_t t(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
+ struct tm *timeinfo(localtime(&t));
+ char buffer[80];
+ strftime(buffer, 80, "%D %T ", timeinfo);
+ return (std::string(buffer));
+ }
+
+ virtual ~CAmTimeUtility();
+};
+
+}
+
+#endif /* TIMEUTILITY_H_ */
diff --git a/AudioManagerUtilities/include/IAmLogger.h b/AudioManagerUtilities/include/IAmLogger.h
new file mode 100755
index 0000000..4517657
--- /dev/null
+++ b/AudioManagerUtilities/include/IAmLogger.h
@@ -0,0 +1,345 @@
+/**
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2015, ADIT GmbH
+ *
+ * \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2015
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * 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/.
+ *
+ * \file IAmLogger.h
+ * For further information see http://www.genivi.org/.
+ */
+
+#ifndef LOGGER_H_
+#define LOGGER_H_
+
+#include <pthread.h>
+#include <stdint.h>
+#include <sstream>
+#include <vector>
+#include <cassert>
+#include "audiomanagertypes.h"
+
+
+namespace am
+{
+
+#define DEFAULT_CONTEXT "DEF"
+#define DEFAULT_DESCRIPTION "default Context registered by DLT Logger Class"
+
+#define DEFAULT_LOG_SERVICE static_cast<am_LogService_e>(0)
+
+enum am_LogService_e
+{
+ LOG_SERVICE_DLT,
+ LOG_SERVICE_STDOUT,
+ LOG_SERVICE_FILE,
+ LOG_SERVICE_OFF
+};
+
+enum am_LogLevel_e
+{
+ LL_OFF = 0x00, /**< Log level off */
+ LL_FATAL = 0x01, /**< fatal system error */
+ LL_ERROR = 0x02, /**< error with impact to correct functionality */
+ LL_WARN = 0x03, /**< warning, correct behavior could not be ensured */
+ LL_INFO = 0x04, /**< informational */
+ LL_DEBUG = 0x05, /**< debug */
+ LL_VERBOSE = 0x06 /**< highest grade of information */
+};
+
+enum am_LogStatus_e
+{
+ LS_OFF = 0x00,
+ LS_ON = 0x01
+};
+
+class IAmLogContext
+{
+ // enable cooperation with legacy class CAmDltWrapper
+ friend class CAmDltWrapper;
+
+public:
+ virtual ~IAmLogContext() {}
+
+ /**
+ * logs given loglevel and given values
+ * @param loglevel
+ * @param ...
+ */
+ template<typename... TArgs>
+ void off(const TArgs & ... args)
+ {
+ this->log(LL_OFF, args...);
+ }
+
+ template<typename... TArgs>
+ void fatal(const TArgs & ... args)
+ {
+ this->log(LL_FATAL, args...);
+ }
+
+ template<typename... TArgs>
+ void error(const TArgs & ... args)
+ {
+ this->log(LL_ERROR, args...);
+ }
+
+ template<typename... TArgs>
+ void warn(const TArgs & ... args)
+ {
+ this->log(LL_WARN, args...);
+ }
+
+ template<typename... TArgs>
+ void info(const TArgs & ... args)
+ {
+ this->log(LL_INFO, args...);
+ }
+
+ template<typename... TArgs>
+ void debug(const TArgs & ... args)
+ {
+ this->log(LL_DEBUG, args...);
+ }
+
+ template<typename... TArgs>
+ void verbose(const TArgs & ... args)
+ {
+ this->log(LL_VERBOSE, args...);
+ }
+
+ template<typename... TArgs>
+ void log(const am_LogLevel_e loglevel, const TArgs & ... args)
+ {
+ if (!this->configure(loglevel))
+ {
+ return;
+ }
+
+ this->append(args...);
+ this->send();
+ }
+
+ virtual bool checkLogLevel(const am_LogLevel_e logLevel) = 0;
+
+ virtual bool configure(const am_LogLevel_e loglevel) = 0;
+
+private:
+ virtual void send() = 0;
+
+ virtual void append(const int8_t value) = 0;
+ virtual void append(const uint8_t value) = 0;
+ virtual void append(const int16_t value) = 0;
+ virtual void append(const uint16_t value) = 0;
+ virtual void append(const int32_t value) = 0;
+ virtual void append(const uint32_t value) = 0;
+ virtual void append(const uint64_t value) = 0;
+ virtual void append(const int64_t value) = 0;
+ virtual void append(const bool value) = 0;
+ virtual void append(const std::vector<uint8_t> &data) = 0;
+ virtual void append(const char *value) = 0;
+
+ template<typename T = std::string &>
+ void append(const std::string &value)
+ {
+ this->append(value.c_str());
+ }
+
+ template<typename T>
+ void append_enum(const T &value, const T &tmax, const std::vector<const char *> &text)
+ {
+ assert(tmax == text.size());
+ try
+ {
+ this->append(text.at(value));
+ }
+ catch (const std::out_of_range &)
+ {
+ this->append(__PRETTY_FUNCTION__);
+ this->append(static_cast<int32_t>(value));
+ this->append("out of range!");
+ }
+ }
+
+ template<typename T = am_Error_e>
+ void append(const am_Error_e value)
+ {
+ this->append_enum(value, E_MAX, std::vector<const char *> {
+ "E_OK",
+ "E_UNKNOWN",
+ "E_OUT_OF_RANGE",
+ "E_NOT_USED",
+ "E_DATABASE_ERROR",
+ "E_ALREADY_EXISTS",
+ "E_NO_CHANGE",
+ "E_NOT_POSSIBLE",
+ "E_NON_EXISTENT",
+ "E_ABORTED",
+ "E_WRONG_FORMAT",
+ "E_COMMUNICATION"
+ }
+ );
+ }
+
+ template<typename T = am_SourceState_e>
+ void append(const am_SourceState_e value)
+ {
+ this->append_enum(value, SS_MAX, std::vector<const char *> {
+ "SS_UNKNNOWN",
+ "SS_ON",
+ "SS_OFF",
+ "SS_PAUSED"
+ }
+ );
+ }
+
+ template<typename T = am_MuteState_e>
+ void append(const am_MuteState_e value)
+ {
+ this->append_enum(value, MS_MAX, std::vector<const char *> {
+ "MS_UNKNOWN",
+ "MS_MUTED",
+ "MS_UNMUTED"
+ }
+ );
+ }
+
+ template<typename T = am_DomainState_e>
+ void append(const am_DomainState_e value)
+ {
+ this->append_enum(value, DS_MAX, std::vector<const char *> {
+ "DS_UNKNOWN",
+ "DS_CONTROLLED",
+ "DS_INDEPENDENT_STARTUP",
+ "DS_INDEPENDENT_RUNDOWN"
+ }
+ );
+ }
+
+ template<typename T = am_ConnectionState_e>
+ void append(const am_ConnectionState_e value)
+ {
+ this->append_enum(value, CS_MAX, std::vector<const char *> {
+ "CS_UNKNOWN",
+ "CS_CONNECTING",
+ "CS_CONNECTED",
+ "CS_DISCONNECTING",
+ "CS_DISCONNECTED",
+ "CS_SUSPENDED"
+ }
+ );
+ }
+
+ template<typename T = am_Availability_e>
+ void append(const am_Availability_e value)
+ {
+ this->append_enum(value, A_MAX, std::vector<const char *> {
+ "A_UNKNOWN",
+ "A_AVAILABLE",
+ "A_UNAVAILABLE"
+ }
+ );
+ }
+
+ template<typename T = am_InterruptState_e>
+ void append(const am_InterruptState_e value)
+ {
+ this->append_enum(value, IS_MAX, std::vector<const char *> {
+ "IS_UNKNOWN",
+ "IS_OFF",
+ "IS_INTERRUPTED"
+ }
+ );
+ }
+
+ template<typename T = am_Handle_e>
+ void append(const am_Handle_e value)
+ {
+ this->append_enum(value, H_MAX, std::vector<const char *> {
+ "H_UNKNOWN",
+ "H_CONNECT",
+ "H_DISCONNECT",
+ "H_SETSOURCESTATE",
+ "H_SETSINKVOLUME",
+ "H_SETSOURCEVOLUME",
+ "H_SETSINKSOUNDPROPERTY",
+ "H_SETSOURCESOUNDPROPERTY",
+ "H_SETSINKSOUNDPROPERTIES",
+ "H_SETSOURCESOUNDPROPERTIES",
+ "H_CROSSFADE",
+ "H_SETVOLUMES",
+ "H_SETSINKNOTIFICATION",
+ "H_SETSOURCENOTIFICATION"
+ }
+ );
+ }
+
+ template<typename T = am_Handle_s>
+ void append(const am_Handle_s value)
+ {
+ this->append(value.handle);
+ this->append(value.handleType);
+ }
+
+ // 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;
+ this->append(ss.str().c_str());
+ }
+
+ // Template to print unknown types
+ template<typename T>
+ void append(T value)
+ {
+ std::ostringstream ss;
+ ss << std::dec << value;
+ this->append(ss.str().c_str());
+ }
+
+ // Template parameter pack to generate recursive code
+ void append(void) {}
+ template<typename T, typename... TArgs>
+ void append(const T &value, const TArgs & ... args)
+ {
+ this->append(value);
+ this->append(args...);
+ }
+
+};
+
+class IAmLogger
+{
+public:
+ virtual ~IAmLogger() {}
+ virtual void registerApp(const char *appid, const char *description) = 0;
+ virtual void unregisterApp() = 0;
+ virtual IAmLogContext &registerContext(const char *contextid, const char *description) = 0;
+ virtual IAmLogContext &registerContext(const char *contextid, const char *description,
+ const am_LogLevel_e level, const am_LogStatus_e status) = 0;
+ virtual IAmLogContext &importContext(const char *contextid = NULL) = 0;
+ virtual void unregisterContext(const char *contextid) = 0;
+
+ template<typename T, typename... TArgs>
+ void logToDefaultContext(const am_LogLevel_e loglevel, const T &value, const TArgs & ... args)
+ {
+ this->importContext().log(loglevel, value, args...);
+ }
+
+};
+
+}
+
+#endif // LOGGER_H_
diff --git a/AudioManagerUtilities/include/TAmPluginTemplate.h b/AudioManagerUtilities/include/TAmPluginTemplate.h
index b030123..f386cc2 100644
--- a/AudioManagerUtilities/include/TAmPluginTemplate.h
+++ b/AudioManagerUtilities/include/TAmPluginTemplate.h
@@ -26,7 +26,7 @@
#include <dlfcn.h>
#include <libgen.h>
-#include "CAmDltWrapper.h"
+#include "CAmLogWrapper.h"
namespace am
{