diff options
author | GENIVI Audio Manager Maintainer <genivi-maint-audiomanager@smtp1.genivi.org> | 2018-02-07 08:01:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-07 08:01:33 +0100 |
commit | bcaeed20bbbb4375ae925d507821d2bef64e737b (patch) | |
tree | 4ee83de4b3b00c9c513c83d5c4e7c6bb8107d954 /AudioManagerUtilities | |
parent | aa59667c69254b0e2cb43cfcdba8d83db4f26e73 (diff) | |
parent | a551ce940f073a7a2afa7df104b9eabc99e9f4a2 (diff) | |
download | audiomanager-bcaeed20bbbb4375ae925d507821d2bef64e737b.tar.gz |
Merge pull request #23 from JensLorenz/cmake_and_dlt_endless_loop_fix
Cmake and dlt endless loop fix
Diffstat (limited to 'AudioManagerUtilities')
-rw-r--r-- | AudioManagerUtilities/include/CAmDltWrapper.h | 367 | ||||
-rw-r--r-- | AudioManagerUtilities/src/CAmDbusWrapper.cpp | 18 |
2 files changed, 194 insertions, 191 deletions
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h index 79df911..4d725d8 100644 --- a/AudioManagerUtilities/include/CAmDltWrapper.h +++ b/AudioManagerUtilities/include/CAmDltWrapper.h @@ -29,68 +29,68 @@ #include "audiomanagertypes.h" #ifdef WITH_DLT - #include <dlt.h> + #include <dlt.h> #else - #include <stdint.h> - #include <sstream> - - #define DLT_USER_BUF_MAX_SIZE 2048 - - /** - * This structure is used for every context used in an application. - */ - typedef struct - { - char contextID[4]; /**< context id */ - int32_t log_level_pos; /**< offset in user-application context field */ - int32_t log_level_user; /** any message above this log level is not logged */ - } DltContext; - - /** - * Definition of DLT trace status - */ - typedef enum - { - DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */ - DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */ - DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */ - } 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 - { - DLT_LOG_DEFAULT = -1, /**< Default log level */ - DLT_LOG_OFF = 0x00, /**< Log level off */ - DLT_LOG_FATAL = 0x01, /**< fatal system error */ - DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ - DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ - DLT_LOG_INFO = 0x04, /**< informational */ - DLT_LOG_DEBUG = 0x05, /**< debug */ - DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ - } DltLogLevelType; - - #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO - #define DLT_DECLARE_CONTEXT(CONTEXT) \ - DltContext CONTEXT; - - #define DLT_IMPORT_CONTEXT(CONTEXT) \ - extern DltContext CONTEXT; + #include <stdint.h> + #include <sstream> + + #define DLT_USER_BUF_MAX_SIZE 2048 + + /** + * This structure is used for every context used in an application. + */ + typedef struct + { + char contextID[4]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ + int32_t log_level_user; /** any message above this log level is not logged */ + } DltContext; + + /** + * Definition of DLT trace status + */ + typedef enum + { + DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */ + DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */ + DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */ + } 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 + { + DLT_LOG_DEFAULT = -1, /**< Default log level */ + DLT_LOG_OFF = 0x00, /**< Log level off */ + DLT_LOG_FATAL = 0x01, /**< fatal system error */ + DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ + DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ + DLT_LOG_INFO = 0x04, /**< informational */ + DLT_LOG_DEBUG = 0x05, /**< debug */ + DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ + } DltLogLevelType; + + #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO + #define DLT_DECLARE_CONTEXT(CONTEXT) \ + DltContext CONTEXT; + + #define DLT_IMPORT_CONTEXT(CONTEXT) \ + extern DltContext CONTEXT; #endif // WITH_DLT @@ -107,56 +107,55 @@ 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 - */ - enum logDestination - { - DAEMON=0, //!< logging with the DLT daemon - COMMAND_LINE=1, //!< logging with commandline - FILE_OUT =2 //!< logging into a file - }; - - /** - * Instanciate the Dlt Wrapper - * @param appid The AppID - * @param description A description of the Application - * @param debugEnabled if set to true, debug outputs will be generated, default = true - * @param logDest the destination, the log should be written - * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT - * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false - */ - static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); + /** + * 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 + */ + enum logDestination + { + DAEMON=0, //!< logging with the DLT daemon + COMMAND_LINE=1, //!< logging with commandline + FILE_OUT =2 //!< logging into a file + }; + + /** + * Instanciate the Dlt Wrapper + * @param appid The AppID + * @param description A description of the Application + * @param debugEnabled if set to true, debug outputs will be generated, default = true + * @param logDest the destination, the log should be written + * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT + * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false + */ + static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); /** * get the Wrapper Instance */ static CAmDltWrapper* instance(); - - /** - * register a context - */ + + /** + * 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 unregisterContext(DltContext& handle); bool getEnabled(); ~CAmDltWrapper(); - - + bool init(DltLogLevelType loglevel, DltContext* context = NULL); bool checkLogLevel(DltLogLevelType logLevel) { @@ -189,147 +188,147 @@ public: void append(const std::vector<uint8_t> & data); template<class T> void appendNoDLT(T value) - { - mNoDltContextData.buffer << 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) - { - dlt_user_log_write_string(&mDltContextData, value); - } - else - { - mNoDltContextData.buffer << std::string(value); - } - #else - mNoDltContextData.buffer << std::string(value); - #endif //WITH_DLT - - } - + #ifdef WITH_DLT + if (mlogDestination == logDestination::DAEMON) + { + dlt_user_log_write_string(&mDltContextData, value); + } + else + { + mNoDltContextData.buffer << std::string(value); + } + #else + 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; + 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 ((int)value >=mStr_error.size()) + if (static_cast<std::size_t>(value) >= mStr_error.size()) { - append("value for am_Error_e out of bounds!"); - append(value); - return; + append("value for am_Error_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_error[value]); + 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 ((int)value >=(mStr_sourceState.size())) + if (static_cast<std::size_t>(value) >= mStr_sourceState.size()) { - append("value for am_SourceState_e out of bounds!"); - append(value); - return; + append("value for am_SourceState_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_sourceState[value]); + append(mStr_sourceState[value]); } template<typename T = const am_MuteState_e> void append(const am_MuteState_e value) { - if ((int)value >=mStr_MuteState.size()) + if (static_cast<std::size_t>(value) >= mStr_MuteState.size()) { - append("value for am_MuteState_e out of bounds!"); - append(value); - return; + append("value for am_MuteState_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_MuteState[value]); + append(mStr_MuteState[value]); } template<typename T = const am_DomainState_e> void append(const am_DomainState_e value) { - if ((int)value >= mStr_DomainState.size()) + if (static_cast<std::size_t>(value) >= mStr_DomainState.size()) { - append("value for am_DomainState_e out of bounds!"); - append(value); - return; + append("value for am_DomainState_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_DomainState[value]); + append(mStr_DomainState[value]); } template<typename T = const am_ConnectionState_e> void append(const am_ConnectionState_e value) { - if ((int)value >=mStr_ConnectionState.size()) + if (static_cast<std::size_t>(value) >= mStr_ConnectionState.size()) { - append("value for am_ConnectionState_e out of bounds!"); - append(value); - return; + append("value for am_ConnectionState_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_ConnectionState[value]); + append(mStr_ConnectionState[value]); } template<typename T = const am_Availability_e> void append(const am_Availability_e value) { - if ((int)value >= mStr_Availability.size()) + if (static_cast<std::size_t>(value) >= mStr_Availability.size()) { - append("value for am_Availability_e out of bounds!"); - append(value); - return; + append("value for am_Availability_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_Availability[value]); + append(mStr_Availability[value]); } template<typename T = const am_InterruptState_e> void append(const am_InterruptState_e value) { - if ((int)value >=mStr_Interrupt.size()) + if (static_cast<std::size_t>(value) >= mStr_Interrupt.size()) { - append("value for am_InterruptState_e out of bounds!"); - append(value); - return; + append("value for am_InterruptState_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_Interrupt[value]); + append(mStr_Interrupt[value]); } template<typename T = const am_Handle_e> void append(const am_Handle_e value) { - if ((int)value >=mStr_Handle.size()) + if (static_cast<std::size_t>(value) >= mStr_Handle.size()) { - append("value for am_Handle_e out of bounds!"); - append(value); - return; + append("value for am_Handle_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_Handle[value]); + append(mStr_Handle[value]); } template<typename T = const am_Handle_s> void append(const am_Handle_s value) { - append (value.handleType); - append (value.handle); + append (value.handleType); + append (value.handle); } template<typename T = const am_NotificationStatus_e> void append(const am_NotificationStatus_e value) { - if ((int)value >=mStr_NotificationStatus.size()) + if (static_cast<std::size_t>(value) >= mStr_NotificationStatus.size()) { - append("value for am_NotificationStatus_e out of bounds!"); - append(value); - return; + append("value for am_NotificationStatus_e out of bounds!"); + append(static_cast<uint16_t>(value)); + return; } - append(mStr_NotificationStatus[value]); + append(mStr_NotificationStatus[value]); } // Template to print unknown pointer types with their address @@ -357,9 +356,9 @@ public: } private: - /** - * private contructor - */ + /** + * 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(); @@ -367,7 +366,7 @@ private: DltContextData mDltContextData; //!< contextdata NoDltContextData mNoDltContextData; //!<contextdata for std out logging std::map<DltContext*,std::string> mMapContext; //!< a Map for all registered context - bool mDebugEnabled; //!< debug Enabled or not + 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 @@ -388,14 +387,14 @@ template<typename T, typename... TArgs> void log(DltContext* const context, DltLogLevelType loglevel, T value, TArgs... args) { CAmDltWrapper* inst(CAmDltWrapper::instance()); - if (!inst->getEnabled()) + if (!inst->getEnabled()) { - return; - } + return; + } if (!inst->init(loglevel, context)) { - return; - } + return; + } inst->append(value); inst->append(args...); inst->send(); diff --git a/AudioManagerUtilities/src/CAmDbusWrapper.cpp b/AudioManagerUtilities/src/CAmDbusWrapper.cpp index 1f1d5a6..e25439c 100644 --- a/AudioManagerUtilities/src/CAmDbusWrapper.cpp +++ b/AudioManagerUtilities/src/CAmDbusWrapper.cpp @@ -176,7 +176,6 @@ void CAmDbusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const std::string completePath = prefix + "/" + path; dbus_error_init(&mDBusError); - mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError); dbus_connection_register_object_path(mpDbusConnection, completePath.c_str(), vtable, userdata); if (dbus_error_is_set(&mDBusError)) { @@ -196,7 +195,6 @@ void CAmDbusWrapper::registerSignalWatch(DBusHandleMessageFunction handler, cons { logInfo("DBusWrapper::registerSignalWatch register callback:", rule); dbus_error_init(&mDBusError); - mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError); dbus_bus_add_match(mpDbusConnection, rule.c_str(), &mDBusError); dbus_connection_flush(mpDbusConnection); dbus_connection_add_filter(mpDbusConnection, handler, userdata, 0); @@ -389,8 +387,6 @@ dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userD //save the handle with dbus context dbus_timeout_set_data(timeout, handle, NULL); - //save timeout in Socket context - userData = timeout; return (true); } @@ -516,11 +512,19 @@ void CAmDbusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData) void CAmDbusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData) { assert(userData!=NULL); - if (dbus_timeout_get_enabled((DBusTimeout*) userData)) + for (auto && timerHandle : mpListTimerhandles) { - mpSocketHandler->restartTimer(handle); + if (*timerHandle == handle) + { + if (dbus_timeout_get_enabled((DBusTimeout*) userData)) + { + mpSocketHandler->restartTimer(handle); + } + dbus_timeout_handle((DBusTimeout*) userData); + return; + } } - dbus_timeout_handle((DBusTimeout*) userData); + logWarning("CAmDbusWrapper::dbusTimerCallback Unknown timer handle"); } } |