diff --git a/.clang-format b/.clang-format index 18f4a2ebc..26fc951fb 100644 --- a/.clang-format +++ b/.clang-format @@ -1,90 +1,68 @@ --- +# SPDX-License-Identifier: MPL-2.0 +# +# clang-format style for dlt-daemon +# +# Compatible with clang-format 14 and later. +# Install: sudo apt-get install clang-format-14 +# Check: clang-format-14 --dry-run --Werror --style=file +# Fix: clang-format-14 -i --style=file +# Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: false +BasedOnStyle: WebKit +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None AlignOperands: true AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false +AllowShortBlocksOnASingleLine: true AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: false +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: true - IndentBraces: false -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerAllOnOneLineOrOnePerLine: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: WebKit +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: BeforeComma +BreakStringLiterals: true +ColumnLimit: 120 ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 IndentCaseLabels: false IndentWidth: 4 IndentWrappedFunctionNames: false -KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 +MaxEmptyLinesToKeep: 3 NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right +PackConstructorInitializers: BinPack +PointerAlignment: Left ReflowComments: true -SortIncludes: true +SortIncludes: Never SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 +SpaceBeforeRangeBasedForLoopColon: true +SpacesBeforeTrailingComments: 2 SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false +SpacesInContainerLiterals: false +SpacesInParens: Never SpacesInSquareBrackets: false -Standard: Cpp11 +Standard: c++11 TabWidth: 4 -UseTab: Never +PenaltyBreakBeforeFirstCallParameter: 0 +PenaltyReturnTypeOnItsOwnLine: 10000 ... - diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..7fe2fddc9 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,24 @@ +#!/bin/bash +# +# SPDX-License-Identifier: MPL-2.0 +# +# Pre-commit hook for dlt-daemon +# +# Runs clang-format on staged C/C++ files via run_lint.sh. +# This mirrors the CI pipeline so issues are caught before push. +# +# To enable: +# ./run_lint.sh install-hook +# +# To bypass (emergency only): +# git commit --no-verify +# + +set -euo pipefail + +# Run from repo root so relative paths resolve correctly +REPO_ROOT=$(git rev-parse --show-toplevel) +cd "${REPO_ROOT}" + +# Delegate to the shared lint script (check mode only - no auto-fix in hook) +./run_lint.sh check diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 000000000..598c7bca5 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,31 @@ +name: Clang Format + +# Disabled until all clang-format violations are fixed. +# To re-enable, uncomment the on: block below. +# on: +# push: +# branches: [ "master" ] +# pull_request: +# branches: [ "master" ] +on: + workflow_dispatch: + +jobs: + clang-format: + name: Clang Format + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install clang-format-14 + run: | + wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main" | sudo tee /etc/apt/sources.list.d/llvm.list + sudo apt-get update && sudo apt-get install -y clang-format-14 + + - name: Check formatting + run: CHECK_ALL=1 ./run_lint.sh check diff --git a/README.md b/README.md index 7b68d9f02..ce20b8608 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ you can [learn more](#learn-more) about advanced concepts and features. ## Overview COVESA DLT provides a standardized logging and tracing interface with support for two protocol versions: **V1** and **V2**. - + - **Version 1 (V1)** is based on the AUTOSAR Classic Platform specification [AUTOSAR Classic Platform R19-11 DLT](https://www.autosar.org/fileadmin/standards/R19-11/CP/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf), offering a stable and widely adopted diagnostic logging protocol. - **Version 2 (V2)** follows the updated AUTOSAR Classic Platform specification [AUTOSAR Classic Platform R22-11 DLT](https://www.autosar.org/fileadmin/standards/R22-11/CP/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf). Currently released as a Minimum Viable Product (MVP), V2 supports a limited feature set. For more details, refer to [DLT Daemon V2](doc/dlt_daemon_v2.md). @@ -198,6 +198,56 @@ make generate_man Start working, best practice is to commit smaller, compilable pieces during the work that makes it easier to handle later on. +### Code Style + +DLT uses **clang-format 14** to enforce a consistent code style. The style is +defined in [`.clang-format`](.clang-format) and is checked automatically by CI +on every push and pull request. + +#### Install clang-format 14 + +On Ubuntu 20.04 (focal), add the LLVM toolchain repo and install: + +```bash +wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - +echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" | sudo tee /etc/apt/sources.list.d/llvm.list +sudo apt-get update +sudo apt-get install clang-format-14 +``` + +On Ubuntu 22.04 (jammy), clang-format-14 is in the default repos: + +```bash +sudo apt-get install clang-format-14 +``` + +#### Check and fix formatting + +Use the provided helper script: + +```bash +# Install pre-commit hook and fix formatting (default) +./run_lint.sh + +# Check formatting only (dry-run, fails on violations) +./run_lint.sh check + +# Fix formatting only +./run_lint.sh fix +``` + +Or run clang-format directly on specific files: + +```bash +clang-format-14 -i --style=file src/shared/dlt_common.c +``` + +#### Pre-commit hook + +`./run_lint.sh` automatically installs the pre-commit hook (`.githooks/pre-commit`) +and fixes formatting. The hook runs `./run_lint.sh check` on staged C/C++ files +before each commit. To bypass it in an emergency, use `git commit --no-verify`. + If you want to commit your changes, create a [Pull Request](https://github.com/covesa/dlt-daemon/pulls) in Github. Please make sure to follow the diff --git a/include/dlt/dlt-logd-converter.hpp b/include/dlt/dlt-logd-converter.hpp index 07958154d..98132cb51 100644 --- a/include/dlt/dlt-logd-converter.hpp +++ b/include/dlt/dlt-logd-converter.hpp @@ -48,9 +48,9 @@ #include #ifndef DLT_UNIT_TESTS -# include -# include -# include +#include +#include +#include #endif #include @@ -71,13 +71,12 @@ using namespace std; #define T_ABNORMAL_CONFIGURATION_FILE_DIR "abnormal-dlt-logd-converter.conf" -typedef struct -{ - char *appID; - char *ctxID; - char *json_file_dir; - char *default_ctxID; - char *conf_file_dir; +typedef struct { + char* appID; + char* ctxID; + char* json_file_dir; + char* default_ctxID; + char* conf_file_dir; } dlt_logd_configuration; #ifdef DLT_UNIT_TESTS @@ -86,8 +85,7 @@ typedef struct #define NS_PER_SEC 1000000000ULL #define LOGGER_ENTRY_MAX_LEN (5 * 1024) -struct logger_list -{ +struct logger_list { int mode; unsigned int tail; pid_t pid; @@ -159,42 +157,48 @@ struct log_msg { unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; struct logger_entry entry; } __attribute__((aligned(4))); - uint64_t nsec() const { + uint64_t nsec() const + { return static_cast(entry.sec) * NS_PER_SEC + entry.nsec; } - log_id_t id() { + log_id_t id() + { return static_cast(entry.lid); } - char* msg() { + char* msg() + { unsigned short hdr_size = entry.hdr_size; if (hdr_size >= sizeof(struct log_msg) - sizeof(entry)) { - return nullptr; + return nullptr; } return reinterpret_cast(buf) + hdr_size; } - unsigned int len() { return entry.hdr_size + entry.len; } + unsigned int len() + { + return entry.hdr_size + entry.len; + } }; struct dlt_log_container { - DltContext *ctx; + DltContext* ctx; DltLogLevelType log_level; uint32_t ts; - const char *tag; - const char *message; + const char* tag; + const char* message; }; /* Android API faked method for unit test */ string t_load_json_file(); -struct logger *t_android_logger_open(logger_list *logger_list,log_id_t log_id); -struct logger_list *t_android_logger_list_alloc(int mode, unsigned int tail, pid_t pid); -int t_android_logger_list_read(logger_list *logger_list, log_msg *t_log_msg); +struct logger* t_android_logger_open(logger_list* logger_list, log_id_t log_id); +struct logger_list* t_android_logger_list_alloc(int mode, unsigned int tail, pid_t pid); +int t_android_logger_list_read(logger_list* logger_list, log_msg* t_log_msg); #endif /** * Prints manual page for instruction * @param prog_name binary name from stdin * @return void */ -DLT_STATIC void usage(char *prog_name); +DLT_STATIC void usage(char* prog_name); /** * Initializes configuration to default values * @return scenario statement @@ -204,13 +208,13 @@ DLT_STATIC int init_configuration(); * Reads command line options and set the values in provided structure * @return scenario statement */ -DLT_STATIC int read_command_line(int argc, char *argv[]); +DLT_STATIC int read_command_line(int argc, char* argv[]); /** * Reads options from the configuration file * @param file_name configuration file name/path * @return scenario statement */ -DLT_STATIC int load_configuration_file(const char *file_name); +DLT_STATIC int load_configuration_file(const char* file_name); /** * Frees the memory allocated for configuration values. * @return void @@ -227,38 +231,38 @@ DLT_STATIC void json_parser(); * @param tag tag of the application that needs new context ID * @return pointer to DLT context mapped with the corresponding tag */ -DLT_STATIC DltContext* find_tag_in_json(const char *tag); +DLT_STATIC DltContext* find_tag_in_json(const char* tag); /** * Doing initialization for logger. * @param logger_list pointer to a logger list struct * @param log_id identifies a specific log buffer * @return pointer to a logger object logging messages for applications */ -DLT_STATIC struct logger *init_logger(struct logger_list *logger_list, log_id_t log_id); +DLT_STATIC struct logger* init_logger(struct logger_list* logger_list, log_id_t log_id); /** * Doing initialization for logger list. * @param skip_binary_buffers boolean value to use event buffers * @return pointer to a logger list struct */ -DLT_STATIC struct logger_list *init_logger_list(bool skip_binary_buffers); +DLT_STATIC struct logger_list* init_logger_list(bool skip_binary_buffers); /** * Getting a context from an android log message. * @param log_msg struct contains android log data including log messages * @return pointer to DLT context mapped with the corresponding tag */ -DLT_STATIC DltContext *get_log_context_from_log_msg(struct log_msg *log_msg); +DLT_STATIC DltContext* get_log_context_from_log_msg(struct log_msg* log_msg); /** * Getting timestamp from an android log message. * @param log_msg struct contains android log data including log messages * @return timestamp of messages from a logger entry */ -DLT_STATIC uint32_t get_timestamp_from_log_msg(struct log_msg *log_msg); +DLT_STATIC uint32_t get_timestamp_from_log_msg(struct log_msg* log_msg); /** * Getting log level from an android log message. * @param log_msg struct contains android log data including log messages * @return DLT log level */ -DLT_STATIC DltLogLevelType get_log_level_from_log_msg(struct log_msg *log_msg); +DLT_STATIC DltLogLevelType get_log_level_from_log_msg(struct log_msg* log_msg); /** * Handling received signal. * @param signal received signal to handle @@ -270,6 +274,6 @@ void signal_handler(int signal); * @param logger_list pointer to a logger list struct * @return scenario statement */ -DLT_STATIC int logd_parser_loop(struct logger_list *logger_list); +DLT_STATIC int logd_parser_loop(struct logger_list* logger_list); #endif /* DLT_LOGD_CONVERTER_HPP */ diff --git a/include/dlt/dlt.h b/include/dlt/dlt.h index 669c3f375..da0203f7b 100644 --- a/include/dlt/dlt.h +++ b/include/dlt/dlt.h @@ -72,4 +72,3 @@ #include "dlt_user.h" #endif /* DLT_H */ - diff --git a/include/dlt/dlt_client.h b/include/dlt/dlt_client.h index 9846fdb6c..9a5647ea0 100644 --- a/include/dlt/dlt_client.h +++ b/include/dlt/dlt_client.h @@ -65,7 +65,7 @@ */ #ifndef DLT_CLIENT_H -# define DLT_CLIENT_H +#define DLT_CLIENT_H /** * \defgroup clientapi DLT Client API @@ -73,17 +73,16 @@ \{ */ -# include "dlt_types.h" -# include "dlt_common.h" +#include "dlt_types.h" +#include "dlt_common.h" #include // DLTV2 - Definitions for DLT Version 2 -#define DLT_VERSION_MASK 0xE0 -#define DLT_VERSION_SHIFT 5 +#define DLT_VERSION_MASK 0xE0 +#define DLT_VERSION_SHIFT 5 #define DLT_CLIENT_ECU_ID_LEN 1 -typedef enum -{ +typedef enum { DLT_CLIENT_MODE_UNDEFINED = -1, DLT_CLIENT_MODE_TCP, DLT_CLIENT_MODE_SERIAL, @@ -91,33 +90,32 @@ typedef enum DLT_CLIENT_MODE_UDP_MULTICAST } DltClientMode; -typedef struct -{ - DltReceiver receiver; /**< receiver pointer to dlt receiver structure */ - int sock; /**< sock Connection handle/socket */ - char *servIP; /**< servIP IP adress/Hostname of interface */ - char *hostip; /**< hostip IP address of UDP host receiver interface */ - uint16_t port; /**< Port for TCP connections (optional) */ - char *serialDevice; /**< serialDevice Devicename of serial device */ - char *socketPath; /**< socketPath Unix socket path */ - char ecuid[4]; /**< ECU id */ - uint8_t ecuid2len; /**< Version 2 ECU id length */ - char *ecuid2; /**< Version 2 ECU id of variable length*/ - speed_t baudrate; /**< baudrate Baudrate of serial interface, as speed_t */ - DltClientMode mode; /**< mode DltClientMode */ - int send_serial_header; /**< (Boolean) Send DLT messages with serial header */ - int resync_serial_header; /**< (Boolean) Resync to serial header on all connection */ +typedef struct { + DltReceiver receiver; /**< receiver pointer to dlt receiver structure */ + int sock; /**< sock Connection handle/socket */ + char* servIP; /**< servIP IP adress/Hostname of interface */ + char* hostip; /**< hostip IP address of UDP host receiver interface */ + uint16_t port; /**< Port for TCP connections (optional) */ + char* serialDevice; /**< serialDevice Devicename of serial device */ + char* socketPath; /**< socketPath Unix socket path */ + char ecuid[4]; /**< ECU id */ + uint8_t ecuid2len; /**< Version 2 ECU id length */ + char* ecuid2; /**< Version 2 ECU id of variable length*/ + speed_t baudrate; /**< baudrate Baudrate of serial interface, as speed_t */ + DltClientMode mode; /**< mode DltClientMode */ + int send_serial_header; /**< (Boolean) Send DLT messages with serial header */ + int resync_serial_header; /**< (Boolean) Resync to serial header on all connection */ } DltClient; -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data)); +void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage* message, void* data)); -void dlt_client_register_message_callback_v2(int (*registerd_callback)(DltMessageV2 *message, void *data)); +void dlt_client_register_message_callback_v2(int (*registerd_callback)(DltMessageV2* message, void* data)); -void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void *data)); +void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void* data)); /** * Initialising dlt client structure with a specific port @@ -126,7 +124,7 @@ void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)( * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose); +DltReturnValue dlt_client_init_port(DltClient* client, int port, int verbose); /** * Initialising dlt client structure @@ -134,7 +132,7 @@ DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose); * @param verbose if set to true verbose information is printed out. * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_init(DltClient *client, int verbose); +DltReturnValue dlt_client_init(DltClient* client, int verbose); /** * Connect to dlt daemon using the information from the dlt client structure @@ -142,7 +140,7 @@ DltReturnValue dlt_client_init(DltClient *client, int verbose); * @param verbose if set to true verbose information is printed out. * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_connect(DltClient *client, int verbose); +DltReturnValue dlt_client_connect(DltClient* client, int verbose); /** * Cleanup dlt client structure @@ -150,7 +148,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose); * @param verbose if set to true verbose information is printed out. * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_cleanup(DltClient *client, int verbose); +DltReturnValue dlt_client_cleanup(DltClient* client, int verbose); /** * Main Loop of dlt client application @@ -159,7 +157,7 @@ DltReturnValue dlt_client_cleanup(DltClient *client, int verbose); * @param verbose if set to true verbose information is printed out. * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose); +DltReturnValue dlt_client_main_loop(DltClient* client, void* data, int verbose); /** * Main Loop of dlt client application for DLT V2 @@ -168,7 +166,7 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose); * @param verbose if set to true verbose information is printed out. * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbose); +DltReturnValue dlt_client_main_loop_v2(DltClient* client, void* data, int verbose); /** * Send a message to the daemon through the socket. @@ -176,7 +174,7 @@ DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbos * @param msg The message to be send in DLT format. * @return Value from DltReturnValue enum. */ -DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *msg); +DltReturnValue dlt_client_send_message_to_socket(DltClient* client, DltMessage* msg); /** * Send a message to the daemon through the socket for DLT V2. @@ -184,7 +182,7 @@ DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage * * @param msg The message to be send in DLT format. * @return Value from DltReturnValue enum. */ -DltReturnValue dlt_client_send_message_to_socket_v2(DltClient *client, DltMessageV2 *msg); +DltReturnValue dlt_client_send_message_to_socket_v2(DltClient* client, DltMessageV2* msg); /** * Send a control message to the dlt daemon @@ -195,7 +193,7 @@ DltReturnValue dlt_client_send_message_to_socket_v2(DltClient *client, DltMessag * @param size Size of control message data * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size); +DltReturnValue dlt_client_send_ctrl_msg(DltClient* client, char* apid, char* ctid, uint8_t* payload, uint32_t size); /** * Send a control message to the dlt daemon with version 2 format @@ -206,7 +204,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti * @param size Size of control message data * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size); +DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient* client, char* apid, char* ctid, uint8_t* payload, uint32_t size); /** * Send an injection message to the dlt daemon @@ -218,12 +216,8 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * * @param size Size of injection data within buffer * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_inject_msg(DltClient *client, - char *apid, - char *ctid, - uint32_t serviceID, - uint8_t *buffer, - uint32_t size); +DltReturnValue dlt_client_send_inject_msg( + DltClient* client, char* apid, char* ctid, uint32_t serviceID, uint8_t* buffer, uint32_t size); /** * Send an injection message to the dlt daemon for DLT V2 @@ -235,12 +229,8 @@ DltReturnValue dlt_client_send_inject_msg(DltClient *client, * @param size Size of injection data within buffer * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_inject_msg_v2(DltClient *client, - char *apid, - char *ctid, - uint32_t serviceID, - uint8_t *buffer, - uint32_t size); +DltReturnValue dlt_client_send_inject_msg_v2( + DltClient* client, char* apid, char* ctid, uint32_t serviceID, uint8_t* buffer, uint32_t size); /** * Send a set log level message to the dlt daemon @@ -250,7 +240,7 @@ DltReturnValue dlt_client_send_inject_msg_v2(DltClient *client, * @param logLevel Log Level * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel); +DltReturnValue dlt_client_send_log_level(DltClient* client, char* apid, char* ctid, uint8_t logLevel); /** * Send a set log level message to the dlt daemon for DLT V2 @@ -260,49 +250,49 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct * @param logLevel Log Level * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_log_level_v2(DltClient *client, char *apid, char *ctid, uint8_t logLevel); +DltReturnValue dlt_client_send_log_level_v2(DltClient* client, char* apid, char* ctid, uint8_t logLevel); /** * Send a request to get log info message to the dlt daemon * @param client pointer to dlt client structure * @return negative value if there was an error */ -DltReturnValue dlt_client_get_log_info(DltClient *client); +DltReturnValue dlt_client_get_log_info(DltClient* client); /** * Send a request to get log info message to the dlt daemon in version 2 * @param client pointer to dlt client structure * @return negative value if there was an error */ -int dlt_client_get_log_info_v2(DltClient *client); +int dlt_client_get_log_info_v2(DltClient* client); /** * Send a request to get default log level to the dlt daemon * @param client pointer to dlt client structure * @return negative value if there was an error */ -DltReturnValue dlt_client_get_default_log_level(DltClient *client); +DltReturnValue dlt_client_get_default_log_level(DltClient* client); /** * Send a request to get default log level to the dlt daemon in version 2 * @param client pointer to dlt client structure * @return negative value if there was an error */ -DltReturnValue dlt_client_get_default_log_level_v2(DltClient *client); +DltReturnValue dlt_client_get_default_log_level_v2(DltClient* client); /** * Send a request to get software version to the dlt daemon * @param client pointer to dlt client structure * @return negative value if there was an error */ -DltReturnValue dlt_client_get_software_version(DltClient *client); +DltReturnValue dlt_client_get_software_version(DltClient* client); /** * Send a request to get software version to the dlt daemon in version 2 * @param client pointer to dlt client structure * @return negative value if there was an error */ -int dlt_client_get_software_version_v2(DltClient *client); +int dlt_client_get_software_version_v2(DltClient* client); /** * Initialise get log info structure @@ -324,7 +314,7 @@ void dlt_getloginfo_free(void); * @param traceStatus Default Trace Status * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus); +DltReturnValue dlt_client_send_trace_status(DltClient* client, char* apid, char* ctid, uint8_t traceStatus); /** * Send a set trace status message to the dlt daemon in version 2 @@ -334,7 +324,7 @@ DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char * @param traceStatus Default Trace Status * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_trace_status_v2(DltClient *client, char *apid, char *ctid, uint8_t traceStatus); +DltReturnValue dlt_client_send_trace_status_v2(DltClient* client, char* apid, char* ctid, uint8_t traceStatus); /** * Send the default log level to the dlt daemon @@ -342,7 +332,7 @@ DltReturnValue dlt_client_send_trace_status_v2(DltClient *client, char *apid, ch * @param defaultLogLevel Default Log Level * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel); +DltReturnValue dlt_client_send_default_log_level(DltClient* client, uint8_t defaultLogLevel); /** * Send the default log level to the dlt daemon in version 2 @@ -350,7 +340,7 @@ DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defa * @param defaultLogLevel Default Log Level * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_default_log_level_v2(DltClient *client, uint8_t defaultLogLevel); +DltReturnValue dlt_client_send_default_log_level_v2(DltClient* client, uint8_t defaultLogLevel); /** * Send the log level to all contexts registered with dlt daemon @@ -358,7 +348,7 @@ DltReturnValue dlt_client_send_default_log_level_v2(DltClient *client, uint8_t d * @param LogLevel Log Level to be set * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel); +DltReturnValue dlt_client_send_all_log_level(DltClient* client, uint8_t LogLevel); /** * Send the log level to all contexts registered with dlt daemon in version 2 @@ -366,7 +356,7 @@ DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel * @param LogLevel Log Level to be set * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_all_log_level_v2(DltClient *client, uint8_t LogLevel); +DltReturnValue dlt_client_send_all_log_level_v2(DltClient* client, uint8_t LogLevel); /** * Send the default trace status to the dlt daemon @@ -374,7 +364,7 @@ DltReturnValue dlt_client_send_all_log_level_v2(DltClient *client, uint8_t LogLe * @param defaultTraceStatus Default Trace Status * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus); +DltReturnValue dlt_client_send_default_trace_status(DltClient* client, uint8_t defaultTraceStatus); /** * Send the default trace status to the dlt daemon in version 2 @@ -382,7 +372,7 @@ DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t d * @param defaultTraceStatus Default Trace Status * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_default_trace_status_v2(DltClient *client, uint8_t defaultTraceStatus); +DltReturnValue dlt_client_send_default_trace_status_v2(DltClient* client, uint8_t defaultTraceStatus); /** * Send the trace status to all contexts registered with dlt daemon @@ -390,7 +380,7 @@ DltReturnValue dlt_client_send_default_trace_status_v2(DltClient *client, uint8_ * @param traceStatus trace status to be set * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t traceStatus); +DltReturnValue dlt_client_send_all_trace_status(DltClient* client, uint8_t traceStatus); /** * Send the trace status to all contexts registered with dlt daemon in version 2 @@ -398,7 +388,7 @@ DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t trace * @param traceStatus trace status to be set * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_all_trace_status_v2(DltClient *client, uint8_t traceStatus); +DltReturnValue dlt_client_send_all_trace_status_v2(DltClient* client, uint8_t traceStatus); /** * Send the timing pakets status to the dlt daemon @@ -406,7 +396,7 @@ DltReturnValue dlt_client_send_all_trace_status_v2(DltClient *client, uint8_t tr * @param timingPakets Timing pakets enabled * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets); +DltReturnValue dlt_client_send_timing_pakets(DltClient* client, uint8_t timingPakets); /** * Send the timing pakets status to the dlt daemon in version 2 @@ -414,35 +404,35 @@ DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPa * @param timingPakets Timing pakets enabled * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_timing_pakets_v2(DltClient *client, uint8_t timingPakets); +DltReturnValue dlt_client_send_timing_pakets_v2(DltClient* client, uint8_t timingPakets); /** * Send the store config command to the dlt daemon * @param client pointer to dlt client structure * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_store_config(DltClient *client); +DltReturnValue dlt_client_send_store_config(DltClient* client); /** * Send the store config command to the dlt daemon in version 2 * @param client pointer to dlt client structure * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_store_config_v2(DltClient *client); +DltReturnValue dlt_client_send_store_config_v2(DltClient* client); /** * Send the reset to factory default command to the dlt daemon * @param client pointer to dlt client structure * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client); +DltReturnValue dlt_client_send_reset_to_factory_default(DltClient* client); /** * Send the reset to factory default command to the dlt daemon in version 2 * @param client pointer to dlt client structure * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_send_reset_to_factory_default_v2(DltClient *client); +DltReturnValue dlt_client_send_reset_to_factory_default_v2(DltClient* client); /** * Set baudrate within dlt client structure @@ -450,7 +440,7 @@ DltReturnValue dlt_client_send_reset_to_factory_default_v2(DltClient *client); * @param baudrate Baudrate * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate); +DltReturnValue dlt_client_setbaudrate(DltClient* client, int baudrate); /** * Set mode within dlt client structure @@ -458,7 +448,7 @@ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate); * @param mode DltClientMode * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode); +DltReturnValue dlt_client_set_mode(DltClient* client, DltClientMode mode); /** * Set server ip @@ -466,7 +456,7 @@ DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode); * @param ipaddr pointer to command line argument * @return negative value if there was an error */ -int dlt_client_set_server_ip(DltClient *client, char *ipaddr); +int dlt_client_set_server_ip(DltClient* client, char* ipaddr); /** * Set server UDP host receiver interface address @@ -474,7 +464,7 @@ int dlt_client_set_server_ip(DltClient *client, char *ipaddr); * @param hostip pointer to multicast group address * @return negative value if there was an error */ -int dlt_client_set_host_if_address(DltClient *client, char *hostip); +int dlt_client_set_host_if_address(DltClient* client, char* hostip); /** * Set serial device @@ -482,7 +472,7 @@ int dlt_client_set_host_if_address(DltClient *client, char *hostip); * @param serial_device pointer to command line argument * @return negative value if there was an error */ -int dlt_client_set_serial_device(DltClient *client, char *serial_device); +int dlt_client_set_serial_device(DltClient* client, char* serial_device); /** * Set socket path @@ -490,7 +480,7 @@ int dlt_client_set_serial_device(DltClient *client, char *serial_device); * @param socket_path pointer to socket path string * @return negative value if there was an error */ -int dlt_client_set_socket_path(DltClient *client, char *socket_path); +int dlt_client_set_socket_path(DltClient* client, char* socket_path); /** * Parse GET_LOG_INFO response text @@ -498,8 +488,7 @@ int dlt_client_set_socket_path(DltClient *client, char *socket_path); * @param resp_text response text represented by ASCII * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp, - char *resp_text); +DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse* resp, char* resp_text); /** * Parse GET_LOG_INFO response text in version 2 @@ -507,26 +496,25 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo * @param resp_text response text represented by ASCII * @return Value from DltReturnValue enum */ -DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoResponse *resp, - char *resp_text); +DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoResponse* resp, char* resp_text); /** * Free memory allocated for get log info message * @param resp response * @return 0 on success, -1 otherwise */ -int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp); +int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse* resp); /** * Free memory allocated for get log info message in version 2 * @param resp response * @return 0 on success, -1 otherwise */ -int dlt_client_cleanup_get_log_info_v2(DltServiceGetLogInfoResponse *resp); +int dlt_client_cleanup_get_log_info_v2(DltServiceGetLogInfoResponse* resp); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif /** \} diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 30d3ca706..5639654e4 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -65,7 +65,7 @@ * aw 13.01.2010 initial */ #ifndef DLT_COMMON_H -# define DLT_COMMON_H +#define DLT_COMMON_H /** * \defgroup commonapi DLT Common API @@ -78,311 +78,326 @@ #include #pragma GCC diagnostic pop -# include -# include -# ifdef __linux__ -# include -# include -# else -# include -# endif - -# if !defined(_MSC_VER) -# include -# include -# endif - -# if defined(__GNUC__) -# define PURE_FUNCTION __attribute__((pure)) -# define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, a, b))) -# else -# define PURE_FUNCTION /* nothing */ -# define PRINTF_FORMAT(a,b) /* nothing */ -# endif - -# if !defined (__WIN32__) && !defined(_MSC_VER) -# include -# endif - -# include "dlt_types.h" -# include "dlt_protocol.h" -# include "dlt_log.h" - -# define DLT_PACKED __attribute__((aligned(1), packed)) - -# if defined (__MSDOS__) || defined (_MSC_VER) +#include +#include +#ifdef __linux__ +#include +#include +#else +#include +#endif + +#if !defined(_MSC_VER) +#include +#include +#endif + +#if defined(__GNUC__) +#define PURE_FUNCTION __attribute__((pure)) +#define PRINTF_FORMAT(a, b) __attribute__((format(printf, a, b))) +#else +#define PURE_FUNCTION /* nothing */ +#define PRINTF_FORMAT(a, b) /* nothing */ +#endif + +#if !defined(__WIN32__) && !defined(_MSC_VER) +#include +#endif + +#include "dlt_types.h" +#include "dlt_protocol.h" +#include "dlt_log.h" + +#define DLT_PACKED __attribute__((aligned(1), packed)) + +#if defined(__MSDOS__) || defined(_MSC_VER) /* set instead /Zp8 flag in Visual C++ configuration */ -# undef DLT_PACKED -# define DLT_PACKED -# endif +#undef DLT_PACKED +#define DLT_PACKED +#endif /* * Macros to swap the byte order. */ -# define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value) & 0xffffffffull)) << 32) | (DLT_SWAP_32((value) >> 32))) -# define DLT_SWAP_16(value) ((uint16_t)((((value) >> 8) & 0xff) | (((value) << 8) & 0xff00))) -# define DLT_SWAP_32(value) ((((value) >> 24) & 0xff) | (((value) << 8) & 0xff0000) | (((value) >> 8) & 0xff00) | \ - (((value) << 24) & 0xff000000)) +#define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value) & 0xffffffffull)) << 32) | (DLT_SWAP_32((value) >> 32))) +#define DLT_SWAP_16(value) ((uint16_t)((((value) >> 8) & 0xff) | (((value) << 8) & 0xff00))) +#define DLT_SWAP_32(value) \ + ((((value) >> 24) & 0xff) | (((value) << 8) & 0xff0000) | (((value) >> 8) & 0xff00) \ + | (((value) << 24) & 0xff000000)) /* Set Big Endian and Little Endian to a initial value, if not defined */ -# if !defined __USE_BSD -# ifndef LITTLE_ENDIAN -# define LITTLE_ENDIAN 1234 -# endif +#if !defined __USE_BSD +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif -# ifndef BIG_ENDIAN -# define BIG_ENDIAN 4321 -# endif -# endif /* __USE_BSD */ +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif +#endif /* __USE_BSD */ /* If byte order is not defined, default to little endian */ -# if !defined __USE_BSD -# ifndef BYTE_ORDER -# define BYTE_ORDER LITTLE_ENDIAN -# endif -# endif /* __USE_BSD */ +#if !defined __USE_BSD +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif +#endif /* __USE_BSD */ /* Check for byte-order */ -# if (BYTE_ORDER == BIG_ENDIAN) +#if (BYTE_ORDER == BIG_ENDIAN) /* #warning "Big Endian Architecture!" */ -# define DLT_HTOBE_16(x) ((x)) -# define DLT_HTOLE_16(x) DLT_SWAP_16((x)) -# define DLT_BETOH_16(x) ((x)) -# define DLT_LETOH_16(x) DLT_SWAP_16((x)) - -# define DLT_HTOBE_32(x) ((x)) -# define DLT_HTOLE_32(x) DLT_SWAP_32((x)) -# define DLT_BETOH_32(x) ((x)) -# define DLT_LETOH_32(x) DLT_SWAP_32((x)) - -# define DLT_HTOBE_64(x) ((x)) -# define DLT_HTOLE_64(x) DLT_SWAP_64((x)) -# define DLT_BETOH_64(x) ((x)) -# define DLT_LETOH_64(x) DLT_SWAP_64((x)) -# else +#define DLT_HTOBE_16(x) ((x)) +#define DLT_HTOLE_16(x) DLT_SWAP_16((x)) +#define DLT_BETOH_16(x) ((x)) +#define DLT_LETOH_16(x) DLT_SWAP_16((x)) + +#define DLT_HTOBE_32(x) ((x)) +#define DLT_HTOLE_32(x) DLT_SWAP_32((x)) +#define DLT_BETOH_32(x) ((x)) +#define DLT_LETOH_32(x) DLT_SWAP_32((x)) + +#define DLT_HTOBE_64(x) ((x)) +#define DLT_HTOLE_64(x) DLT_SWAP_64((x)) +#define DLT_BETOH_64(x) ((x)) +#define DLT_LETOH_64(x) DLT_SWAP_64((x)) +#else /* #warning "Litte Endian Architecture!" */ -# define DLT_HTOBE_16(x) DLT_SWAP_16((x)) -# define DLT_HTOLE_16(x) ((x)) -# define DLT_BETOH_16(x) DLT_SWAP_16((x)) -# define DLT_LETOH_16(x) ((x)) - -# define DLT_HTOBE_32(x) DLT_SWAP_32((x)) -# define DLT_HTOLE_32(x) ((x)) -# define DLT_BETOH_32(x) DLT_SWAP_32((x)) -# define DLT_LETOH_32(x) ((x)) - -# define DLT_HTOBE_64(x) DLT_SWAP_64((x)) -# define DLT_HTOLE_64(x) ((x)) -# define DLT_BETOH_64(x) DLT_SWAP_64((x)) -# define DLT_LETOH_64(x) ((x)) -# endif - -# define DLT_ENDIAN_GET_16(htyp, x) ((uint16_t)((((htyp) & DLT_HTYP_MSBF) > 0) ? DLT_BETOH_16(x) : DLT_LETOH_16(x))) -# define DLT_ENDIAN_GET_32(htyp, x) ((uint32_t)((((htyp) & DLT_HTYP_MSBF) > 0) ? DLT_BETOH_32(x) : DLT_LETOH_32(x))) -# define DLT_ENDIAN_GET_64(htyp, x) ((uint64_t)((((htyp) & DLT_HTYP_MSBF) > 0) ? DLT_BETOH_64(x) : DLT_LETOH_64(x))) - -# if defined (__WIN32__) || defined (_MSC_VER) -# define LOG_EMERG 0 -# define LOG_ALERT 1 -# define LOG_CRIT 2 -# define LOG_ERR 3 -# define LOG_WARNING 4 -# define LOG_NOTICE 5 -# define LOG_INFO 6 -# define LOG_DEBUG 7 - -# define LOG_PID 0x01 -# define LOG_DAEMON (3 << 3) -# endif +#define DLT_HTOBE_16(x) DLT_SWAP_16((x)) +#define DLT_HTOLE_16(x) ((x)) +#define DLT_BETOH_16(x) DLT_SWAP_16((x)) +#define DLT_LETOH_16(x) ((x)) + +#define DLT_HTOBE_32(x) DLT_SWAP_32((x)) +#define DLT_HTOLE_32(x) ((x)) +#define DLT_BETOH_32(x) DLT_SWAP_32((x)) +#define DLT_LETOH_32(x) ((x)) + +#define DLT_HTOBE_64(x) DLT_SWAP_64((x)) +#define DLT_HTOLE_64(x) ((x)) +#define DLT_BETOH_64(x) DLT_SWAP_64((x)) +#define DLT_LETOH_64(x) ((x)) +#endif + +#define DLT_ENDIAN_GET_16(htyp, x) ((uint16_t)((((htyp) & DLT_HTYP_MSBF) > 0) ? DLT_BETOH_16(x) : DLT_LETOH_16(x))) +#define DLT_ENDIAN_GET_32(htyp, x) ((uint32_t)((((htyp) & DLT_HTYP_MSBF) > 0) ? DLT_BETOH_32(x) : DLT_LETOH_32(x))) +#define DLT_ENDIAN_GET_64(htyp, x) ((uint64_t)((((htyp) & DLT_HTYP_MSBF) > 0) ? DLT_BETOH_64(x) : DLT_LETOH_64(x))) + +#if defined(__WIN32__) || defined(_MSC_VER) +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +#define LOG_PID 0x01 +#define LOG_DAEMON (3 << 3) +#endif /** * The standard TCP Port used for DLT daemon, can be overwritten via -p \ when starting dlt-daemon */ -# define DLT_DAEMON_TCP_PORT 3490 +#define DLT_DAEMON_TCP_PORT 3490 /* DLT Protocol version */ -# define DLTProtocolV1 1 -# define DLTProtocolV2 2 +#define DLTProtocolV1 1 +#define DLTProtocolV2 2 /* Initial value for file descriptor */ -# define DLT_FD_INIT -1 +#define DLT_FD_INIT -1 /* Minimum value for a file descriptor except the POSIX Standards: stdin=0, stdout=1, stderr=2 */ -# define DLT_FD_MINIMUM 3 +#define DLT_FD_MINIMUM 3 /** * The size of a DLT ID */ -# define DLT_ID_SIZE 4 +#define DLT_ID_SIZE 4 /** * The maximum size of a DLT v2 ID (variable length, max 255) */ -# define DLT_V2_ID_SIZE 255 +#define DLT_V2_ID_SIZE 255 /** * The maximum display length for client ID output (truncate if longer) */ -# define DLT_CLIENT_MAX_ID_LENGTH 16 +#define DLT_CLIENT_MAX_ID_LENGTH 16 -# define DLT_SIZE_WEID DLT_ID_SIZE -# define DLT_SIZE_WSID (sizeof(uint32_t)) -# define DLT_SIZE_WTMS (sizeof(uint32_t)) +#define DLT_SIZE_WEID DLT_ID_SIZE +#define DLT_SIZE_WSID (sizeof(uint32_t)) +#define DLT_SIZE_WTMS (sizeof(uint32_t)) -# define DLT_SIZE_VERBOSE_DATA_MSG 11 -# define DLT_SIZE_NONVERBOSE_DATA_MSG 13 -# define DLT_SIZE_CONTROL_MSG 2 +#define DLT_SIZE_VERBOSE_DATA_MSG 11 +#define DLT_SIZE_NONVERBOSE_DATA_MSG 13 +#define DLT_SIZE_CONTROL_MSG 2 /* Size of buffer for text output */ -#define DLT_CONVERT_TEXTBUFSIZE 10024 +#define DLT_CONVERT_TEXTBUFSIZE 10024 /** * Definitions for GET_LOG_INFO */ -# define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ -# define GET_LOG_INFO_LENGTH 13 -# define SERVICE_OPT_LENGTH 3 +#define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ +#define GET_LOG_INFO_LENGTH 13 +#define SERVICE_OPT_LENGTH 3 /** * Get the size of extra header parameters, depends on htyp. */ -# define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp) ((DLT_IS_HTYP_WEID(htyp) ? DLT_SIZE_WEID : 0) + \ - (DLT_IS_HTYP_WSID(htyp) ? DLT_SIZE_WSID : 0) + \ - (DLT_IS_HTYP_WTMS(htyp) ? DLT_SIZE_WTMS : 0)) +#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp) \ + ((DLT_IS_HTYP_WEID(htyp) ? DLT_SIZE_WEID : 0) + (DLT_IS_HTYP_WSID(htyp) ? DLT_SIZE_WSID : 0) \ + + (DLT_IS_HTYP_WTMS(htyp) ? DLT_SIZE_WTMS : 0)) -# if defined (__MSDOS__) || defined (_MSC_VER) -# define __func__ __func__ -# endif +#if defined(__MSDOS__) || defined(_MSC_VER) +#define __func__ __func__ +#endif -# define PRINT_FUNCTION_VERBOSE(_verbose) \ - if (_verbose) \ - dlt_vlog(LOG_INFO, "%s()\n", __func__) +#define PRINT_FUNCTION_VERBOSE(_verbose) \ + if (_verbose) \ + dlt_vlog(LOG_INFO, "%s()\n", __func__) -# ifndef NULL -# define NULL (char *)0 -# endif +#ifndef NULL +#define NULL (char*)0 +#endif -# define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL)) +#define DLT_MSG_IS_CONTROL(MSG) \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + && (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL)) -# define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL) && \ - (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_CONTROL_REQUEST)) +#define DLT_MSG_IS_CONTROL_REQUEST(MSG) \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + && (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL) \ + && (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_CONTROL_REQUEST)) -# define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL) && \ - (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_CONTROL_RESPONSE)) +#define DLT_MSG_IS_CONTROL_RESPONSE(MSG) \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + && (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL) \ + && (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_CONTROL_RESPONSE)) -# define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL) && \ - (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_CONTROL_TIME)) +#define DLT_MSG_IS_CONTROL_TIME(MSG) \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + && (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_CONTROL) \ + && (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_CONTROL_TIME)) -# define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_NW_TRACE)) +#define DLT_MSG_IS_NW_TRACE(MSG) \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + && (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_NW_TRACE)) -# define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_NW_TRACE) && \ - (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_NW_TRACE_MOST)) +#define DLT_MSG_IS_TRACE_MOST(MSG) \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + && (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin) == DLT_TYPE_NW_TRACE) \ + && (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin) == DLT_NW_TRACE_MOST)) -# define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \ - ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ - (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin))))) +#define DLT_MSG_IS_NONVERBOSE(MSG) \ + (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) \ + || ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin))))) -# define DLT_MSG_IS_CONTROL_V2(MSG) (((MSG->baseheaderv2->htyp2 & 0x03)==0x02) && \ - (DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL)) +#define DLT_MSG_IS_CONTROL_V2(MSG) \ + (((MSG->baseheaderv2->htyp2 & 0x03) == 0x02) && (DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL)) -# define DLT_MSG_IS_CONTROL_REQUEST_V2(MSG) ((((MSG)->baseheaderv2->htyp2 & 0x03)==0x02) && \ - (DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL) && \ - (DLT_GET_MSIN_MTIN((MSG)->headerextrav2.msin) == DLT_CONTROL_REQUEST)) +#define DLT_MSG_IS_CONTROL_REQUEST_V2(MSG) \ + ((((MSG)->baseheaderv2->htyp2 & 0x03) == 0x02) \ + && (DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL) \ + && (DLT_GET_MSIN_MTIN((MSG)->headerextrav2.msin) == DLT_CONTROL_REQUEST)) -# define DLT_MSG_IS_CONTROL_TIME_V2(MSG) ((DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL) && \ - (DLT_GET_MSIN_MTIN((MSG)->headerextrav2.msin) == DLT_CONTROL_TIME)) +#define DLT_MSG_IS_CONTROL_TIME_V2(MSG) \ + ((DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL) \ + && (DLT_GET_MSIN_MTIN((MSG)->headerextrav2.msin) == DLT_CONTROL_TIME)) -# define DLT_MSG_IS_CONTROL_RESPONSE_V2(MSG) ((((MSG)->baseheaderv2->htyp2 & 0x03) == 0x02) && \ - (DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL) && \ - (DLT_GET_MSIN_MTIN((MSG)->headerextrav2.msin) == DLT_CONTROL_RESPONSE)) +#define DLT_MSG_IS_CONTROL_RESPONSE_V2(MSG) \ + ((((MSG)->baseheaderv2->htyp2 & 0x03) == 0x02) \ + && (DLT_GET_MSIN_MSTP((MSG)->headerextrav2.msin) == DLT_TYPE_CONTROL) \ + && (DLT_GET_MSIN_MTIN((MSG)->headerextrav2.msin) == DLT_CONTROL_RESPONSE)) -# define DLT_MSG_IS_NONVERBOSE_V2(MSG) ((MSG->baseheaderv2->htyp2 & 0x03)==0x01) +#define DLT_MSG_IS_NONVERBOSE_V2(MSG) ((MSG->baseheaderv2->htyp2 & 0x03) == 0x01) /* * Definitions of DLT message buffer overflow */ -# define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00/**< Buffer overflow has not occured */ -# define DLT_MESSAGE_BUFFER_OVERFLOW 0x01/**< Buffer overflow has occured */ +#define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */ +#define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */ /* * Definition of DLT output variants */ -# define DLT_OUTPUT_HEX 1 -# define DLT_OUTPUT_ASCII 2 -# define DLT_OUTPUT_MIXED_FOR_PLAIN 3 -# define DLT_OUTPUT_MIXED_FOR_HTML 4 -# define DLT_OUTPUT_ASCII_LIMITED 5 - -# define DLT_FILTER_MAX 30 /**< Maximum number of filters */ - -# define DLT_MSG_READ_VALUE(dst, src, length, type) \ - do { \ - if ((length < 0) || ((length) < ((int32_t)sizeof(type)))) \ - { length = -1; } \ - else \ - { dst = *((type *)src); src += sizeof(type); length -= (int32_t)sizeof(type); } \ - } while(false) - -# define DLT_MSG_READ_ID(dst, src, length) \ - do { \ - if ((length < 0) || ((length) < DLT_ID_SIZE)) \ - { length = -1; } \ - else \ - { memcpy(dst, src, DLT_ID_SIZE); src += DLT_ID_SIZE; length -= DLT_ID_SIZE; } \ - } while(false) - -# define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \ - do { \ - if ((maxlength < 0) || (length <= 0) || (dstlength < length) || (maxlength < length)) \ - { \ - maxlength = -1; \ - } \ - else \ - { \ - memcpy(dst, src, length); \ - dlt_clean_string(dst, length); \ - dst[length] = 0; \ - src += length; \ - maxlength -= length; \ - } \ - } while(false) - -# define DLT_MSG_READ_NULL(src, maxlength, length) \ - do { \ - if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) \ - { length = -1; } \ - else \ - { src += length; maxlength -= length; } \ - } while(false) - -# define DLT_HEADER_SHOW_NONE 0x0000 -# define DLT_HEADER_SHOW_TIME 0x0001 -# define DLT_HEADER_SHOW_TMSTP 0x0002 -# define DLT_HEADER_SHOW_MSGCNT 0x0004 -# define DLT_HEADER_SHOW_ECUID 0x0008 -# define DLT_HEADER_SHOW_APID 0x0010 -# define DLT_HEADER_SHOW_CTID 0x0020 -# define DLT_HEADER_SHOW_MSGTYPE 0x0040 -# define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080 -# define DLT_HEADER_SHOW_VNVSTATUS 0x0100 -# define DLT_HEADER_SHOW_NOARG 0x0200 -# define DLT_HEADER_SHOW_FLNA_LNR 0x0400 -# define DLT_HEADER_SHOW_PRLV 0x0800 -# define DLT_HEADER_SHOW_TAG 0x1000 -# define DLT_HEADER_SHOW_ALL 0xFFFF +#define DLT_OUTPUT_HEX 1 +#define DLT_OUTPUT_ASCII 2 +#define DLT_OUTPUT_MIXED_FOR_PLAIN 3 +#define DLT_OUTPUT_MIXED_FOR_HTML 4 +#define DLT_OUTPUT_ASCII_LIMITED 5 + +#define DLT_FILTER_MAX 30 /**< Maximum number of filters */ + +#define DLT_MSG_READ_VALUE(dst, src, length, type) \ + do { \ + if ((length < 0) || ((length) < ((int32_t)sizeof(type)))) { \ + length = -1; \ + } else { \ + dst = *((type*)src); \ + src += sizeof(type); \ + length -= (int32_t)sizeof(type); \ + } \ + } while (false) + +#define DLT_MSG_READ_ID(dst, src, length) \ + do { \ + if ((length < 0) || ((length) < DLT_ID_SIZE)) { \ + length = -1; \ + } else { \ + memcpy(dst, src, DLT_ID_SIZE); \ + src += DLT_ID_SIZE; \ + length -= DLT_ID_SIZE; \ + } \ + } while (false) + +#define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \ + do { \ + if ((maxlength < 0) || (length <= 0) || (dstlength < length) || (maxlength < length)) { \ + maxlength = -1; \ + } else { \ + memcpy(dst, src, length); \ + dlt_clean_string(dst, length); \ + dst[length] = 0; \ + src += length; \ + maxlength -= length; \ + } \ + } while (false) + +#define DLT_MSG_READ_NULL(src, maxlength, length) \ + do { \ + if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) { \ + length = -1; \ + } else { \ + src += length; \ + maxlength -= length; \ + } \ + } while (false) + +#define DLT_HEADER_SHOW_NONE 0x0000 +#define DLT_HEADER_SHOW_TIME 0x0001 +#define DLT_HEADER_SHOW_TMSTP 0x0002 +#define DLT_HEADER_SHOW_MSGCNT 0x0004 +#define DLT_HEADER_SHOW_ECUID 0x0008 +#define DLT_HEADER_SHOW_APID 0x0010 +#define DLT_HEADER_SHOW_CTID 0x0020 +#define DLT_HEADER_SHOW_MSGTYPE 0x0040 +#define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080 +#define DLT_HEADER_SHOW_VNVSTATUS 0x0100 +#define DLT_HEADER_SHOW_NOARG 0x0200 +#define DLT_HEADER_SHOW_FLNA_LNR 0x0400 +#define DLT_HEADER_SHOW_PRLV 0x0800 +#define DLT_HEADER_SHOW_TAG 0x1000 +#define DLT_HEADER_SHOW_ALL 0xFFFF /* dlt_receiver_check_and_get flags */ -# define DLT_RCV_NONE 0 -# define DLT_RCV_SKIP_HEADER (1 << 0) -# define DLT_RCV_REMOVE (1 << 1) +#define DLT_RCV_NONE 0 +#define DLT_RCV_SKIP_HEADER (1 << 0) +#define DLT_RCV_REMOVE (1 << 1) /** * Maximal length of path in DLT @@ -390,41 +405,41 @@ * the actual value, because the least that is supported on any system * that DLT runs on is 1024 bytes. */ -# define DLT_PATH_MAX 1024 +#define DLT_PATH_MAX 1024 /** * Maximal length of mounted path */ -# define DLT_MOUNT_PATH_MAX 1024 +#define DLT_MOUNT_PATH_MAX 1024 /** * Maximal length of an entry */ -# define DLT_ENTRY_MAX 100 +#define DLT_ENTRY_MAX 100 /** * Maximal IPC path len */ -# define DLT_IPC_PATH_MAX 100 +#define DLT_IPC_PATH_MAX 100 /** * Maximal receiver buffer size for application messages */ -# define DLT_RECEIVE_BUFSIZE 65535 +#define DLT_RECEIVE_BUFSIZE 65535 /** * Maximal line length */ -# define DLT_LINE_LEN 1024 +#define DLT_LINE_LEN 1024 /** * Macros support for DLTv2 */ -# define STORAGE_HEADER_V2_FIXED_SIZE 14 -# define BASE_HEADER_V2_FIXED_SIZE 7 -# define EXTENDED_HEADER_V2_FIXED_SIZE 16 -# define DLT_SERVICE_GET_LOG_INFO_REQUEST_FIXED_SIZE_V2 11 -# define DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2 11 +#define STORAGE_HEADER_V2_FIXED_SIZE 14 +#define BASE_HEADER_V2_FIXED_SIZE 7 +#define EXTENDED_HEADER_V2_FIXED_SIZE 16 +#define DLT_SERVICE_GET_LOG_INFO_REQUEST_FIXED_SIZE_V2 11 +#define DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2 11 /** * Macros for network trace @@ -437,27 +452,21 @@ /** * Provision to test static function */ -# ifndef DLT_UNIT_TESTS -# define DLT_STATIC static -# else -# define DLT_STATIC -# endif +#ifndef DLT_UNIT_TESTS +#define DLT_STATIC static +#else +#define DLT_STATIC +#endif /** * Type to specify whether received data is from socket or file/fifo */ -typedef enum -{ - DLT_RECEIVE_SOCKET, - DLT_RECEIVE_UDP_SOCKET, - DLT_RECEIVE_FD -} DltReceiverType; +typedef enum { DLT_RECEIVE_SOCKET, DLT_RECEIVE_UDP_SOCKET, DLT_RECEIVE_FD } DltReceiverType; /** * Type to support DLT Frame Segmentation Type */ -typedef enum -{ +typedef enum { DLT_FIRST_FRAME, DLT_CONSECUTIVE_FRAME, DLT_LAST_FRAME, @@ -496,8 +505,7 @@ typedef char ID4[DLT_ID_SIZE]; /** * Type to support DLT Tag */ -typedef struct -{ +typedef struct { uint8_t taglen; char tagname[DLT_V2_ID_SIZE]; } DltTag; @@ -505,7 +513,7 @@ typedef struct /** * Type to support DLT Segmentation Frame */ -typedef union{ +typedef union { uint8_t firstframe_totallength[8]; uint32_t consecutiveframe_sequencecounter; uint8_t abortframe_abortreason; @@ -514,8 +522,7 @@ typedef union{ /** * The structure of the DLT file storage header. This header is used before each stored DLT message. */ -typedef struct -{ +typedef struct { char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */ uint32_t seconds; /**< seconds since 1.1.1970 */ int32_t microseconds; /**< Microseconds */ @@ -525,97 +532,90 @@ typedef struct /** * The structure of the DLTv2 file storage header. This header is used before each stored DLT message. */ -typedef struct -{ +typedef struct { char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x02 */ uint8_t seconds[5]; /**< 40 bits for seconds since 1.1.1970 in Big Endian */ - int32_t nanoseconds; /**< nanoseconds */ - uint8_t ecidlen; /**< Length of ecu id */ + int32_t nanoseconds; /**< nanoseconds */ + uint8_t ecidlen; /**< Length of ecu id */ char ecid[DLT_V2_ID_SIZE]; /**< ECU id v2 */ } DLT_PACKED DltStorageHeaderV2; /** * The structure of the DLT standard header. This header is used in each DLT message. */ -typedef struct -{ - uint8_t htyp; /**< This parameter contains several informations, see definitions below */ - uint8_t mcnt; /**< The message counter is increased with each sent DLT message */ - uint16_t len; /**< Length of the complete message, without storage header */ +typedef struct { + uint8_t htyp; /**< This parameter contains several informations, see definitions below */ + uint8_t mcnt; /**< The message counter is increased with each sent DLT message */ + uint16_t len; /**< Length of the complete message, without storage header */ } DLT_PACKED DltStandardHeader; /** * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp. */ -typedef struct -{ - char ecu[DLT_ID_SIZE]; /**< ECU id */ - uint32_t seid; /**< Session number */ - uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */ +typedef struct { + char ecu[DLT_ID_SIZE]; /**< ECU id */ + uint32_t seid; /**< Session number */ + uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */ } DLT_PACKED DltStandardHeaderExtra; /** * The structure of the DLTv2 base header. This header is used in each DLT message. */ -typedef struct -{ - uint32_t htyp2; /**< This parameter contains several informations, see definitions below */ - uint8_t mcnt; /**< The message counter is increased with each sent DLT message */ - uint16_t len; /**< Length of the complete message, without storage header */ +typedef struct { + uint32_t htyp2; /**< This parameter contains several informations, see definitions below */ + uint8_t mcnt; /**< The message counter is increased with each sent DLT message */ + uint16_t len; /**< Length of the complete message, without storage header */ } DLT_PACKED DltBaseHeaderV2; /** * The structure of the DLTv2 extra header parameters. Each parameter is sent only if enabled in htyp. */ -typedef struct -{ - uint8_t msin; /**< Message info */ - uint8_t noar; /**< Number of arguments */ - uint32_t nanoseconds; /**< Nanoseconds part of the tmsp2. Invalid value in nanoseconds: [0x3B9A CA00] to [0x3FFF FFFF]; Bit 30 and 31 are reserved in this case. */ - uint8_t seconds[5]; /**< 40 bits for seconds since 1.1.1970 */ - uint32_t msid; /**< Message Id */ +typedef struct { + uint8_t msin; /**< Message info */ + uint8_t noar; /**< Number of arguments */ + uint32_t nanoseconds; /**< Nanoseconds part of the tmsp2. Invalid value in nanoseconds: [0x3B9A CA00] to [0x3FFF + FFFF]; Bit 30 and 31 are reserved in this case. */ + uint8_t seconds[5]; /**< 40 bits for seconds since 1.1.1970 */ + uint32_t msid; /**< Message Id */ } DLT_PACKED DltBaseHeaderExtraV2; /** * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter. */ -typedef struct -{ - uint8_t msin; /**< messsage info */ - uint8_t noar; /**< number of arguments */ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ +typedef struct { + uint8_t msin; /**< messsage info */ + uint8_t noar; /**< number of arguments */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ } DLT_PACKED DltExtendedHeader; /** * The structure of the DLTv2 extended header. This header is only sent if enabled in htyp parameter. */ -typedef struct -{ - uint8_t ecidlen; /**< Length of ecu id */ - char *ecid; - uint8_t apidlen; /**< Length of app id */ - char *apid; - uint8_t ctidlen; /**< Length of context id */ - char *ctid; - uint32_t seid; /**< Session id */ - uint8_t finalen; /**< Length of filename */ - char *fina; - uint32_t linr; /**< Line number */ - uint8_t notg; /**< Number of tags */ - DltTag *tag; - uint8_t prlv; /**< Privacy level */ - uint8_t sgmtinfo; /**< Segmentation info */ - uint8_t frametype; /**< Segmentation frame */ - SegmentationFrame *sgmtdetails; /**< Segmentation details */ +typedef struct { + uint8_t ecidlen; /**< Length of ecu id */ + char* ecid; + uint8_t apidlen; /**< Length of app id */ + char* apid; + uint8_t ctidlen; /**< Length of context id */ + char* ctid; + uint32_t seid; /**< Session id */ + uint8_t finalen; /**< Length of filename */ + char* fina; + uint32_t linr; /**< Line number */ + uint8_t notg; /**< Number of tags */ + DltTag* tag; + uint8_t prlv; /**< Privacy level */ + uint8_t sgmtinfo; /**< Segmentation info */ + uint8_t frametype; /**< Segmentation frame */ + SegmentationFrame* sgmtdetails; /**< Segmentation details */ } DLT_PACKED DltExtendedHeaderV2; /** * The structure to organise the DLT messages. * This structure is used by the corresponding functions. */ -typedef struct DltMessage -{ +typedef struct DltMessage { /* flags */ int8_t found_serialheader; @@ -623,28 +623,28 @@ typedef struct DltMessage int32_t resync_offset; /* size parameters */ - int32_t headersize; /**< size of complete header including storage header */ - int32_t datasize; /**< size of complete payload */ + int32_t headersize; /**< size of complete header including storage header */ + int32_t datasize; /**< size of complete payload */ /* buffer for current loaded message */ - uint8_t headerbuffer[sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra) + sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */ - uint8_t *databuffer; /**< buffer for loading payload */ + uint8_t headerbuffer + [sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra) + + sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */ + uint8_t* databuffer; /**< buffer for loading payload */ int32_t databuffersize; /* header values of current loaded message */ - DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */ - DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */ - DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */ - DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */ + DltStorageHeader* storageheader; /**< pointer to storage header of current loaded header */ + DltStandardHeader* standardheader; /**< pointer to standard header of current loaded header */ + DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */ + DltExtendedHeader* extendedheader; /**< pointer to extended of current loaded header */ } DLT_PACKED DltMessage; /** * The structure to organise the DLT messages. * This structure is used by the corresponding functions. */ -typedef struct DltMessageV2 -{ +typedef struct DltMessageV2 { /* flags */ int8_t found_serialheader; @@ -652,12 +652,12 @@ typedef struct DltMessageV2 int32_t resync_offset; /* size parameters */ - int32_t headersizev2; /**< size of complete header including storage header */ - int32_t datasize; /**< size of complete payload */ + int32_t headersizev2; /**< size of complete header including storage header */ + int32_t datasize; /**< size of complete payload */ /* buffer for current loaded message */ - uint8_t *headerbufferv2; /**< buffer for loading complete header */ - uint8_t *databuffer; /**< buffer for loading payload */ + uint8_t* headerbufferv2; /**< buffer for loading complete header */ + uint8_t* databuffer; /**< buffer for loading payload */ int32_t databuffersize; uint32_t storageheadersizev2; uint32_t baseheadersizev2; @@ -665,267 +665,240 @@ typedef struct DltMessageV2 uint32_t extendedheadersizev2; /* header values of current loaded message */ - DltStorageHeaderV2 storageheaderv2; /**< pointer to storage header of current loaded header */ - DltBaseHeaderV2 *baseheaderv2; /**< pointer to standard header of current loaded header */ - DltBaseHeaderExtraV2 headerextrav2; /**< extra parameters of current loaded header */ - DltExtendedHeaderV2 extendedheaderv2; /**< pointer to extended of current loaded header */ + DltStorageHeaderV2 storageheaderv2; /**< pointer to storage header of current loaded header */ + DltBaseHeaderV2* baseheaderv2; /**< pointer to standard header of current loaded header */ + DltBaseHeaderExtraV2 headerextrav2; /**< extra parameters of current loaded header */ + DltExtendedHeaderV2 extendedheaderv2; /**< pointer to extended of current loaded header */ } DLT_PACKED DltMessageV2; /** * The structure of the DLT Service Get Log Info. */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t options; /**< type of request */ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ - char com[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t options; /**< type of request */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + char com[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceGetLogInfoRequest; /** * The structure of the DLTv2 Service Get Log Info. */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t options; /**< type of request */ - uint8_t apidlen; /**< length of application id */ - char *apid; /**< application id */ - uint8_t ctidlen; /**< length of context id */ - char *ctid; /**< context id */ - char com[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t options; /**< type of request */ + uint8_t apidlen; /**< length of application id */ + char* apid; /**< application id */ + uint8_t ctidlen; /**< length of context id */ + char* ctid; /**< context id */ + char com[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceGetLogInfoRequestV2; -typedef struct -{ - uint32_t service_id; /**< service ID */ +typedef struct { + uint32_t service_id; /**< service ID */ } DLT_PACKED DltServiceGetDefaultLogLevelRequest; /** * The structure of the DLT Service Get Log Info response. */ -typedef struct -{ +typedef struct { char context_id[DLT_ID_SIZE]; uint8_t context_id2len; - char *context_id2; + char* context_id2; int16_t log_level; int16_t trace_status; uint16_t len_context_description; - char *context_description; + char* context_description; } ContextIDsInfoType; -typedef struct -{ +typedef struct { char app_id[DLT_ID_SIZE]; uint8_t app_id2len; - char *app_id2; + char* app_id2; uint16_t count_context_ids; - ContextIDsInfoType *context_id_info; /**< holds info about a specific con id */ + ContextIDsInfoType* context_id_info; /**< holds info about a specific con id */ uint16_t len_app_description; - char *app_description; + char* app_description; } AppIDsType; -typedef struct -{ +typedef struct { uint16_t count_app_ids; - AppIDsType *app_ids; /**< holds info about a specific app id */ + AppIDsType* app_ids; /**< holds info about a specific app id */ } LogInfoType; -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< type of request */ - LogInfoType log_info_type; /**< log info type */ - char com[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< type of request */ + LogInfoType log_info_type; /**< log info type */ + char com[DLT_ID_SIZE]; /**< communication interface */ } DltServiceGetLogInfoResponse; /** * The structure of the DLT Service Set Log Level. */ -typedef struct -{ - - uint32_t service_id; /**< service ID */ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ - uint8_t log_level; /**< log level to be set */ - char com[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + uint8_t log_level; /**< log level to be set */ + char com[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceSetLogLevel; /** * The structure of the DLT Service Set Log Level. */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t apidlen; /**< length of application id */ - char *apid; /**< application id */ - uint8_t ctidlen; /**< length of context id */ - char *ctid; /**< context id */ - uint8_t log_level; /**< log level to be set */ - char com[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t apidlen; /**< length of application id */ + char* apid; /**< application id */ + uint8_t ctidlen; /**< length of context id */ + char* ctid; /**< context id */ + uint8_t log_level; /**< log level to be set */ + char com[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceSetLogLevelV2; /** * The structure of the DLT Service Set Default Log Level. */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t log_level; /**< default log level to be set */ - char com[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t log_level; /**< default log level to be set */ + char com[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceSetDefaultLogLevel; /** * The structure of the DLT Service Set Verbose Mode */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t new_status; /**< new status to be set */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t new_status; /**< new status to be set */ } DLT_PACKED DltServiceSetVerboseMode; /** * The structure of the DLT Service Set Communication Interface Status */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - char com[DLT_ID_SIZE]; /**< communication interface */ - uint8_t new_status; /**< new status to be set */ +typedef struct { + uint32_t service_id; /**< service ID */ + char com[DLT_ID_SIZE]; /**< communication interface */ + uint8_t new_status; /**< new status to be set */ } DLT_PACKED DltServiceSetCommunicationInterfaceStatus; /** * The structure of the DLT Service Set Communication Maximum Bandwidth */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - char com[DLT_ID_SIZE]; /**< communication interface */ - uint32_t max_bandwidth; /**< maximum bandwith */ +typedef struct { + uint32_t service_id; /**< service ID */ + char com[DLT_ID_SIZE]; /**< communication interface */ + uint32_t max_bandwidth; /**< maximum bandwith */ } DLT_PACKED DltServiceSetCommunicationMaximumBandwidth; -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ } DLT_PACKED DltServiceResponse; -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - uint8_t log_level; /**< log level */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint8_t log_level; /**< log level */ } DLT_PACKED DltServiceGetDefaultLogLevelResponse; -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - uint8_t overflow; /**< overflow status */ - uint32_t overflow_counter; /**< overflow counter */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint8_t overflow; /**< overflow status */ + uint32_t overflow_counter; /**< overflow counter */ } DLT_PACKED DltServiceMessageBufferOverflowResponse; -typedef struct -{ - uint32_t service_id; /**< service ID */ +typedef struct { + uint32_t service_id; /**< service ID */ } DLT_PACKED DltServiceGetSoftwareVersion; -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - uint32_t length; /**< length of following payload */ - char *payload; /**< payload */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint32_t length; /**< length of following payload */ + char* payload; /**< payload */ } DLT_PACKED DltServiceGetSoftwareVersionResponse; /** * The structure of the DLT Service Unregister Context. */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ - char comid[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + char comid[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceUnregisterContext; /** * The structure of the DLTv2 Service Unregister Context. */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - uint8_t apidlen; /**< length of application id */ - char *apid; /**< application id */ - uint8_t ctidlen; /**< length of context id */ - char *ctid; /**< context id */ - char comid[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint8_t apidlen; /**< length of application id */ + char* apid; /**< application id */ + uint8_t ctidlen; /**< length of context id */ + char* ctid; /**< context id */ + char comid[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceUnregisterContextV2; /** * The structure of the DLT Service Connection Info */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - uint8_t state; /**< new state */ - char comid[DLT_ID_SIZE]; /**< communication interface */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint8_t state; /**< new state */ + char comid[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceConnectionInfo; /** * The structure of the DLT Service Timezone */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ - int32_t timezone; /**< Timezone in seconds */ - uint8_t isdst; /**< Is daylight saving time */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + int32_t timezone; /**< Timezone in seconds */ + uint8_t isdst; /**< Is daylight saving time */ } DLT_PACKED DltServiceTimezone; /** * The structure of the DLT Service Marker */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< reponse status */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ } DLT_PACKED DltServiceMarker; /** * The structure of the DLT Service Offline Logstorage */ -typedef struct -{ +typedef struct { uint32_t service_id; /**< service ID */ char mount_point[DLT_MOUNT_PATH_MAX]; /**< storage device mount point */ uint8_t connection_type; /**< connection status of the connected device connected/disconnected */ char comid[DLT_ID_SIZE]; /**< communication interface */ } DLT_PACKED DltServiceOfflineLogstorage; -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint32_t connection_status; /**< connect/disconnect */ - char node_id[DLT_ID_SIZE]; /**< passive node ID */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint32_t connection_status; /**< connect/disconnect */ + char node_id[DLT_ID_SIZE]; /**< passive node ID */ } DLT_PACKED DltServicePassiveNodeConnect; /** * The structure of DLT Service Passive Node Connection Status */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< response status */ - uint32_t num_connections; /**< number of connections */ - uint8_t connection_status[DLT_ENTRY_MAX]; /**< list of connection status */ - char node_id[DLT_ENTRY_MAX]; /**< list of passive node IDs */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< response status */ + uint32_t num_connections; /**< number of connections */ + uint8_t connection_status[DLT_ENTRY_MAX]; /**< list of connection status */ + char node_id[DLT_ENTRY_MAX]; /**< list of passive node IDs */ } DLT_PACKED DltServicePassiveNodeConnectionInfo; /** @@ -933,14 +906,13 @@ typedef struct * ID are maximal four characters. Unused values are filled with zeros. * If every value as filter is valid, the id should be empty by having only zero values. */ -typedef struct -{ +typedef struct { char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */ char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */ uint8_t apid2len[DLT_FILTER_MAX]; /**< length of application id */ - char *apid2[DLT_FILTER_MAX]; /**< application id */ + char* apid2[DLT_FILTER_MAX]; /**< application id */ uint8_t ctid2len[DLT_FILTER_MAX]; /**< length of context id */ - char *ctid2[DLT_FILTER_MAX]; /**< context id */ + char* ctid2[DLT_FILTER_MAX]; /**< context id */ int log_level[DLT_FILTER_MAX]; /**< log level */ int32_t payload_max[DLT_FILTER_MAX]; /**< upper border for payload */ int32_t payload_min[DLT_FILTER_MAX]; /**< lower border for payload */ @@ -951,24 +923,23 @@ typedef struct * The structure to organise the access to DLT files. * This structure is used by the corresponding functions. */ -typedef struct sDltFile -{ +typedef struct sDltFile { /* file handle and index for fast access */ - FILE *handle; /**< file handle of opened DLT file */ - long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */ + FILE* handle; /**< file handle of opened DLT file */ + long* index; /**< file positions of all DLT messages for fast access to file, only filtered messages */ /* size parameters */ - int32_t counter; /**< number of messages in DLT file with filter */ - int32_t counter_total; /**< number of messages in DLT file without filter */ - int32_t position; /**< current index to message parsed in DLT file starting at 0 */ - uint64_t file_length; /**< length of the file */ - uint64_t file_position; /**< current position in the file */ + int32_t counter; /**< number of messages in DLT file with filter */ + int32_t counter_total; /**< number of messages in DLT file without filter */ + int32_t position; /**< current index to message parsed in DLT file starting at 0 */ + uint64_t file_length; /**< length of the file */ + uint64_t file_position; /**< current position in the file */ /* error counters */ int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */ /* filter parameters */ - DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */ + DltFilter* filter; /**< pointer to filter list. Zero if no filter is set. */ int32_t filter_counter; /**< number of filter set */ /* current loaded message */ @@ -981,67 +952,61 @@ typedef struct sDltFile * including buffer handling. * This structure is used by the corresponding functions. */ -typedef struct -{ - int32_t lastBytesRcvd; /**< bytes received in last receive call */ - int32_t bytesRcvd; /**< received bytes */ - int32_t totalBytesRcvd; /**< total number of received bytes */ - char *buffer; /**< pointer to receiver buffer */ - char *buf; /**< pointer to position within receiver buffer */ - char *backup_buf; /** pointer to the buffer with partial messages if any **/ - int fd; /**< connection handle */ - DltReceiverType type; /**< type of connection handle */ - int32_t buffersize; /**< size of receiver buffer */ - struct sockaddr_in addr; /**< socket address information */ +typedef struct { + int32_t lastBytesRcvd; /**< bytes received in last receive call */ + int32_t bytesRcvd; /**< received bytes */ + int32_t totalBytesRcvd; /**< total number of received bytes */ + char* buffer; /**< pointer to receiver buffer */ + char* buf; /**< pointer to position within receiver buffer */ + char* backup_buf; /** pointer to the buffer with partial messages if any **/ + int fd; /**< connection handle */ + DltReceiverType type; /**< type of connection handle */ + int32_t buffersize; /**< size of receiver buffer */ + struct sockaddr_in addr; /**< socket address information */ } DltReceiver; -typedef struct -{ - unsigned char *shm; /* pointer to beginning of shared memory */ +typedef struct { + unsigned char* shm; /* pointer to beginning of shared memory */ unsigned int size; /* size of data area in shared memory */ - unsigned char *mem; /* pointer to data area in shared memory */ + unsigned char* mem; /* pointer to data area in shared memory */ - uint32_t min_size; /**< Minimum size of buffer */ - uint32_t max_size; /**< Maximum size of buffer */ - uint32_t step_size; /**< Step size of buffer */ + uint32_t min_size; /**< Minimum size of buffer */ + uint32_t max_size; /**< Maximum size of buffer */ + uint32_t step_size; /**< Step size of buffer */ } DltBuffer; -typedef struct -{ +typedef struct { int write; int read; int count; } DltBufferHead; -# define DLT_BUFFER_HEAD "SHM" +#define DLT_BUFFER_HEAD "SHM" -typedef struct -{ +typedef struct { char head[4]; unsigned char status; int size; } DltBufferBlockHead; -# ifdef DLT_USE_IPv6 -# define DLT_IP_SIZE (INET6_ADDRSTRLEN) -# else -# define DLT_IP_SIZE (INET_ADDRSTRLEN) -# endif -typedef struct DltBindAddress -{ +#ifdef DLT_USE_IPv6 +#define DLT_IP_SIZE (INET6_ADDRSTRLEN) +#else +#define DLT_IP_SIZE (INET_ADDRSTRLEN) +#endif +typedef struct DltBindAddress { char ip[DLT_IP_SIZE]; - struct DltBindAddress *next; + struct DltBindAddress* next; } DltBindAddress_t; -# define DLT_MESSAGE_ERROR_OK 0 -# define DLT_MESSAGE_ERROR_UNKNOWN -1 -# define DLT_MESSAGE_ERROR_SIZE -2 -# define DLT_MESSAGE_ERROR_CONTENT -3 +#define DLT_MESSAGE_ERROR_OK 0 +#define DLT_MESSAGE_ERROR_UNKNOWN -1 +#define DLT_MESSAGE_ERROR_SIZE -2 +#define DLT_MESSAGE_ERROR_CONTENT -3 -# ifdef __cplusplus -extern "C" -{ -# endif +#ifdef __cplusplus +extern "C" { +#endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE @@ -1055,7 +1020,7 @@ extern "C" * Average trace load in this window will be used as trace load * Older time data than this size will be removed from trace load */ -#define DLT_TRACE_LOAD_WINDOW_SIZE (60) +#define DLT_TRACE_LOAD_WINDOW_SIZE (60) /** * Window resolution in unit of timestamp (Default: 10000 x 0.1 msec = 1 sec) @@ -1066,7 +1031,7 @@ extern "C" * FIXME: When timestamp resolution of dlt is changed from 0.1 msec, * then DLT_TRACE_LOAD_WINDOW_RESOLUTION value also has to be updated accordingly. */ -#define DLT_TRACE_LOAD_WINDOW_RESOLUTION (10000) +#define DLT_TRACE_LOAD_WINDOW_RESOLUTION (10000) /* Special Context ID for output soft_limit/hard_limit over warning message (DLT LIMITS) */ #define DLT_TRACE_LOAD_CONTEXT_ID ("DLTL") @@ -1077,14 +1042,14 @@ extern "C" * NOTE: Size of the slot depends on value of DLT_TRACE_LOAD_WINDOW_RESOLUTION * (Default: 10 slots = 10000 x 0.1 msec = 10 sec) */ -#define DLT_SOFT_LIMIT_WARN_FREQUENCY (10) +#define DLT_SOFT_LIMIT_WARN_FREQUENCY (10) /* Frequency in which warning messages are logged in seconds when an application is over the hard limit * Unit of this value is Number of slot of window. * NOTE: Size of the slot depends on value of DLT_TRACE_LOAD_WINDOW_RESOLUTION * (Default: 10 slots = 10000 x 0.1 msec = 10 sec) */ -#define DLT_HARD_LIMIT_WARN_FREQUENCY (10) +#define DLT_HARD_LIMIT_WARN_FREQUENCY (10) /** * Timestamp resolution of 1 second (Default: 10000 -> 1/10000 = 0.0001sec = 0.1msec) @@ -1092,39 +1057,39 @@ extern "C" * FIXME: When timestamp resolution of dlt is changed from 0.1 msec, * then DLT_TIMESTAMP_RESOLUTION value also has to be updated accordingly. */ -#define DLT_TIMESTAMP_RESOLUTION (10000) +#define DLT_TIMESTAMP_RESOLUTION (10000) -typedef struct -{ +typedef struct { // Window for recording total bytes for each slots [bytes] uint64_t window[DLT_TRACE_LOAD_WINDOW_SIZE]; - uint64_t total_bytes_of_window; // Grand total bytes of whole window [bytes] - uint32_t curr_slot; // Current slot No. of window [slot No.] - uint32_t last_slot; // Last slot No. of window [slot No.] - uint32_t curr_abs_slot; // Current absolute slot No. of window [slot No.] - uint32_t last_abs_slot; // Last absolute slot No. of window [slot No.] - uint64_t avg_trace_load; // Average trace load of whole window [bytes/sec] - uint32_t hard_limit_over_counter; // Discarded message counter due to hard limit over [msg] - uint32_t hard_limit_over_bytes; // Discarded message bytes due to hard limit over [msg] - uint32_t slot_left_soft_limit_warn; // Slot left to output next warning of soft limit over [slot No.] - uint32_t slot_left_hard_limit_warn; // Slot left to output next warning of hard limit over [slot No.] - bool is_over_soft_limit; // Flag if trace load has been over soft limit - bool is_over_hard_limit; // Flag if trace load has been over hard limit + uint64_t total_bytes_of_window; // Grand total bytes of whole window [bytes] + uint32_t curr_slot; // Current slot No. of window [slot No.] + uint32_t last_slot; // Last slot No. of window [slot No.] + uint32_t curr_abs_slot; // Current absolute slot No. of window [slot No.] + uint32_t last_abs_slot; // Last absolute slot No. of window [slot No.] + uint64_t avg_trace_load; // Average trace load of whole window [bytes/sec] + uint32_t hard_limit_over_counter; // Discarded message counter due to hard limit over [msg] + uint32_t hard_limit_over_bytes; // Discarded message bytes due to hard limit over [msg] + uint32_t slot_left_soft_limit_warn; // Slot left to output next warning of soft limit over [slot No.] + uint32_t slot_left_hard_limit_warn; // Slot left to output next warning of hard limit over [slot No.] + bool is_over_soft_limit; // Flag if trace load has been over soft limit + bool is_over_hard_limit; // Flag if trace load has been over hard limit } DltTraceLoadStat; /** * The parameter of trace load settings */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< Application id for which the settings are valid */ - uint8_t apid2len; /**< Length of application id of version 2 for which the settings are valid */ - char *apid2; /**< Application id of version 2 for which the settings are valid */ - char ctid[DLT_ID_SIZE]; /**< Context id for which the settings are valid, this is optional */ - uint8_t ctid2len; /**< Length of context id of version 2 for which the settings are valid, this is optional */ - char *ctid2; /**< Context id of version 2 for which the settings are valid, this is optional */ - uint32_t soft_limit; /**< Warning threshold, if load is above soft limit a warning will be logged but message won't be discarded */ - uint32_t hard_limit; /**< limit threshold, if load is above hard limit a warning will be logged and message will be discarded */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< Application id for which the settings are valid */ + uint8_t apid2len; /**< Length of application id of version 2 for which the settings are valid */ + char* apid2; /**< Application id of version 2 for which the settings are valid */ + char ctid[DLT_ID_SIZE]; /**< Context id for which the settings are valid, this is optional */ + uint8_t ctid2len; /**< Length of context id of version 2 for which the settings are valid, this is optional */ + char* ctid2; /**< Context id of version 2 for which the settings are valid, this is optional */ + uint32_t soft_limit; /**< Warning threshold, if load is above soft limit a warning will be logged but message won't + be discarded */ + uint32_t hard_limit; /**< limit threshold, if load is above hard limit a warning will be logged and message will be + discarded */ DltTraceLoadStat tl_stat; } DltTraceLoadSettings; @@ -1137,7 +1102,7 @@ extern pthread_rwlock_t trace_load_rw_lock; /* Precomputation */ static const uint64_t TIMESTAMP_BASED_WINDOW_SIZE = DLT_TRACE_LOAD_WINDOW_SIZE * DLT_TRACE_LOAD_WINDOW_RESOLUTION; -typedef DltReturnValue (DltLogInternal)(DltLogLevelType loglevel, const char *text, void* params); +typedef DltReturnValue(DltLogInternal)(DltLogLevelType loglevel, const char* text, void* params); /** * Check if the trace load is within the limits. @@ -1154,12 +1119,8 @@ typedef DltReturnValue (DltLogInternal)(DltLogLevelType loglevel, const char *te * False means that the message should be discarded. */ bool dlt_check_trace_load( - DltTraceLoadSettings* tl_settings, - int32_t log_level, - uint32_t timestamp, - int32_t size, - DltLogInternal internal_dlt_log, - void *internal_dlt_log_params); + DltTraceLoadSettings* tl_settings, int32_t log_level, uint32_t timestamp, int32_t size, + DltLogInternal internal_dlt_log, void* internal_dlt_log_params); /** * Find the runtime trace load settings for the given application id and context id. @@ -1169,7 +1130,8 @@ bool dlt_check_trace_load( * @param ctid The context id to search for, can be NULL * @return A sorted array with all settings that match the given apid and ctid */ -DltTraceLoadSettings* dlt_find_runtime_trace_load_settings(DltTraceLoadSettings *settings, uint32_t settings_count, const char* apid, const char* ctid); +DltTraceLoadSettings* dlt_find_runtime_trace_load_settings( + DltTraceLoadSettings* settings, uint32_t settings_count, const char* apid, const char* ctid); #endif /** @@ -1177,7 +1139,7 @@ DltTraceLoadSettings* dlt_find_runtime_trace_load_settings(DltTraceLoadSettings * @param ptr pointer to the byte array. * @param size number of bytes to be printed. */ -void dlt_print_hex(uint8_t *ptr, int size); +void dlt_print_hex(uint8_t* ptr, int size); /** * Helper function to print a byte array in hex into a string. * @param text pointer to a ASCII string, in which the text is written @@ -1186,7 +1148,7 @@ void dlt_print_hex(uint8_t *ptr, int size); * @param size number of bytes to be printed. * @return negative value if there was an error */ -DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size); +DltReturnValue dlt_print_hex_string(char* text, int textlength, uint8_t* ptr, int size); /** * Helper function to print a byte array in hex and ascii into a string. * @param text pointer to a ASCII string, in which the text is written @@ -1196,7 +1158,7 @@ DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, in * @param html output is html? 0 - false, 1 - true * @return negative value if there was an error */ -DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, int size, int html); +DltReturnValue dlt_print_mixed_string(char* text, int textlength, uint8_t* ptr, int size, int html); /** * Helper function to print a byte array in ascii into a string. * @param text pointer to a ASCII string, in which the text is written @@ -1205,7 +1167,7 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, * @param size number of bytes to be printed. * @return negative value if there was an error */ -DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, int size); +DltReturnValue dlt_print_char_string(char** text, int textlength, uint8_t* ptr, int size); /** * Helper function to determine a bounded length of a string. @@ -1223,7 +1185,7 @@ PURE_FUNCTION size_t dlt_strnlen_s(const char* str, size_t maxsize); * @param text pointer to ASCII string where to write the id * @param id four byte char array as used in DLT mesages as IDs. */ -void dlt_print_id(char *text, const char *id); +void dlt_print_id(char* text, const char* id); /** * DLTv2 Helper function to print an id. @@ -1231,14 +1193,14 @@ void dlt_print_id(char *text, const char *id); * @param id char array as used in DLT mesages as IDs. * @param length length of string to be printed into ID */ -void dlt_print_id_v2(char *text, const char *id, uint8_t length); +void dlt_print_id_v2(char* text, const char* id, uint8_t length); /** * Helper function to set an ID parameter. * @param id four byte char array as used in DLT mesages as IDs. * @param text string to be copied into char array. */ -void dlt_set_id(char *id, const char *text); +void dlt_set_id(char* id, const char* text); /** * DLTv2 Helper function to set an ID parameter. @@ -1246,14 +1208,14 @@ void dlt_set_id(char *id, const char *text); * @param text string to be copied into char array. * @param len length of string to be copied into ID */ -void dlt_set_id_v2(char *id, const char *text, uint8_t len); +void dlt_set_id_v2(char* id, const char* text, uint8_t len); /** * Helper function to remove not nice to print characters, e.g. NULL or carage return. * @param text pointer to string to be cleaned. * @param length length of string excluding terminating zero. */ -void dlt_clean_string(char *text, int length); +void dlt_clean_string(char* text, int length); /** * Initialise the filter list. @@ -1262,7 +1224,7 @@ void dlt_clean_string(char *text, int length); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_init(DltFilter *filter, int verbose); +DltReturnValue dlt_filter_init(DltFilter* filter, int verbose); /** * Free the used memory by the organising structure of filter. @@ -1270,7 +1232,7 @@ DltReturnValue dlt_filter_init(DltFilter *filter, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_free(DltFilter *filter, int verbose); +DltReturnValue dlt_filter_free(DltFilter* filter, int verbose); /** * Load filter list from file. @@ -1279,7 +1241,7 @@ DltReturnValue dlt_filter_free(DltFilter *filter, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose); +DltReturnValue dlt_filter_load(DltFilter* filter, const char* filename, int verbose); /** * DLTv2 Load filter list from file. @@ -1288,7 +1250,7 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int verbose); +DltReturnValue dlt_filter_load_v2(DltFilter* filter, const char* filename, int verbose); /** * Save filter in space separated list to text file. @@ -1297,7 +1259,7 @@ DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int v * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verbose); +DltReturnValue dlt_filter_save(DltFilter* filter, const char* filename, int verbose); /** * DLTv2 Save filter in space separated list to text file. @@ -1306,7 +1268,7 @@ DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verb * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_save_v2(DltFilter *filter, const char *filename, int verbose); +DltReturnValue dlt_filter_save_v2(DltFilter* filter, const char* filename, int verbose); /** * Find index of filter in filter list @@ -1319,8 +1281,9 @@ DltReturnValue dlt_filter_save_v2(DltFilter *filter, const char *filename, int v * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error (or not found), else return index of filter */ -int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +int dlt_filter_find( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose); /** * DLTv2 Find index of filter in filter list @@ -1333,8 +1296,9 @@ int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error (or not found), else return index of filter */ -int dlt_filter_find_v2(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +int dlt_filter_find_v2( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose); /** * Add new filter to filter list. @@ -1347,8 +1311,9 @@ int dlt_filter_find_v2(DltFilter *filter, const char *apid, const char *ctid, co * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +DltReturnValue dlt_filter_add( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose); /** * DLTv2 Add new filter to filter list. @@ -1361,8 +1326,9 @@ DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *c * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_add_v2(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +DltReturnValue dlt_filter_add_v2( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose); /** * Delete filter from filter list @@ -1375,8 +1341,9 @@ DltReturnValue dlt_filter_add_v2(DltFilter *filter, const char *apid, const char * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +DltReturnValue dlt_filter_delete( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose); /** * DLTv2 Delete filter from filter list @@ -1389,8 +1356,9 @@ DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_filter_delete_v2(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose); +DltReturnValue dlt_filter_delete_v2( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose); /** * Initialise the structure used to access a DLT message. @@ -1399,7 +1367,7 @@ DltReturnValue dlt_filter_delete_v2(DltFilter *filter, const char *apid, const c * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_init(DltMessage *msg, int verbose); +DltReturnValue dlt_message_init(DltMessage* msg, int verbose); /** * DLTv2 Initialise the structure used to access a DLT message. @@ -1408,7 +1376,7 @@ DltReturnValue dlt_message_init(DltMessage *msg, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_init_v2(DltMessageV2 *msg, int verbose); +DltReturnValue dlt_message_init_v2(DltMessageV2* msg, int verbose); /** * Free the used memory by the organising structure of file. @@ -1416,7 +1384,7 @@ DltReturnValue dlt_message_init_v2(DltMessageV2 *msg, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_free(DltMessage *msg, int verbose); +DltReturnValue dlt_message_free(DltMessage* msg, int verbose); /** * DLTv2 Free the used memory by the organising structure of file. @@ -1424,7 +1392,7 @@ DltReturnValue dlt_message_free(DltMessage *msg, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_free_v2(DltMessageV2 *msg, int verbose); +DltReturnValue dlt_message_free_v2(DltMessageV2* msg, int verbose); /** * Print Header into an ASCII string. @@ -1435,7 +1403,7 @@ DltReturnValue dlt_message_free_v2(DltMessageV2 *msg, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_header(DltMessage *msg, char *text, size_t textlength, int verbose); +DltReturnValue dlt_message_header(DltMessage* msg, char* text, size_t textlength, int verbose); /** * DLTv2 Print V2 Header into an ASCII string. @@ -1446,7 +1414,7 @@ DltReturnValue dlt_message_header(DltMessage *msg, char *text, size_t textlength * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_header_v2(DltMessageV2 *msg, char *text, size_t textlength, int verbose); +DltReturnValue dlt_message_header_v2(DltMessageV2* msg, char* text, size_t textlength, int verbose); /** * Print Header into an ASCII string, selective. @@ -1457,7 +1425,7 @@ DltReturnValue dlt_message_header_v2(DltMessageV2 *msg, char *text, size_t textl * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t textlength, int flags, int verbose); +DltReturnValue dlt_message_header_flags(DltMessage* msg, char* text, size_t textlength, int flags, int verbose); /** * Print V2 Header into an ASCII string, selective. @@ -1468,7 +1436,7 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t text * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t textlength, int flags, int verbose); +DltReturnValue dlt_message_header_flags_v2(DltMessageV2* msg, char* text, size_t textlength, int flags, int verbose); /** * Print Payload into an ASCII string. @@ -1479,7 +1447,7 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlength, int type, int verbose); +DltReturnValue dlt_message_payload(DltMessage* msg, char* text, size_t textlength, int type, int verbose); /** * DLTv2 Print Payload into an ASCII string. @@ -1490,7 +1458,7 @@ DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlengt * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t textlength, int type, int verbose); +DltReturnValue dlt_message_payload_v2(DltMessageV2* msg, char* text, size_t textlength, int type, int verbose); /** * Check if message is filtered or not. All filters are applied (logical OR). @@ -1499,7 +1467,7 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text * @param verbose if set to true verbose information is printed out. * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error */ -DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int verbose); +DltReturnValue dlt_message_filter_check(DltMessage* msg, DltFilter* filter, int verbose); /** * DLTv2 Check if message is filtered or not. All filters are applied (logical OR). @@ -1508,7 +1476,7 @@ DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int * @param verbose if set to true verbose information is printed out. * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error */ -DltReturnValue dlt_message_filter_check_v2(DltMessageV2 *msg, DltFilter *filter, int verbose); +DltReturnValue dlt_message_filter_check_v2(DltMessageV2* msg, DltFilter* filter, int verbose); /** * Read message from memory buffer. @@ -1520,7 +1488,7 @@ DltReturnValue dlt_message_filter_check_v2(DltMessageV2 *msg, DltFilter *filter, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose); +int dlt_message_read(DltMessage* msg, uint8_t* buffer, unsigned int length, int resync, int verbose); /** * DLTv2 Read DLT V2 message from memory buffer. @@ -1532,7 +1500,7 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, int resync, int verbose); +int dlt_message_read_v2(DltMessageV2* msg, uint8_t* buffer, unsigned int length, int resync, int verbose); /** * DLTv2 Get storage header parameters for version 2 @@ -1540,7 +1508,7 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_get_storageparameters_v2(DltMessageV2 *msg, int verbose); +DltReturnValue dlt_message_get_storageparameters_v2(DltMessageV2* msg, int verbose); /** * DLTv2 Set storage header parameters for version 2 @@ -1548,7 +1516,7 @@ DltReturnValue dlt_message_get_storageparameters_v2(DltMessageV2 *msg, int verbo * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_set_storageparameters_v2(DltMessageV2 *msg, int verbose); +DltReturnValue dlt_message_set_storageparameters_v2(DltMessageV2* msg, int verbose); /** * Get standard header extra parameters @@ -1556,7 +1524,7 @@ DltReturnValue dlt_message_set_storageparameters_v2(DltMessageV2 *msg, int verbo * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_get_extraparameters(DltMessage *msg, int verbose); +DltReturnValue dlt_message_get_extraparameters(DltMessage* msg, int verbose); /** * DLTv2 Get base header extra parameters for DLT version 2 @@ -1564,7 +1532,7 @@ DltReturnValue dlt_message_get_extraparameters(DltMessage *msg, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_get_extraparameters_v2(DltMessageV2 *msg, int verbose); +DltReturnValue dlt_message_get_extraparameters_v2(DltMessageV2* msg, int verbose); /** * Set standard header extra parameters @@ -1572,7 +1540,7 @@ DltReturnValue dlt_message_get_extraparameters_v2(DltMessageV2 *msg, int verbose * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose); +DltReturnValue dlt_message_set_extraparameters(DltMessage* msg, int verbose); /** * DLTv2 Set base header extra parameters for Version 2 @@ -1580,7 +1548,7 @@ DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_set_extraparameters_v2(DltMessageV2 *msg, int verbose); +DltReturnValue dlt_message_set_extraparameters_v2(DltMessageV2* msg, int verbose); /** * DLTv2 Get size of base header extra parameters for Version 2 @@ -1595,7 +1563,7 @@ uint8_t dlt_message_get_extraparameters_size_v2(DltHtyp2ContentType msgcontent); * @param header_offset Offset of header buffer before baseheader pointer * @return negative value if there was an error */ -DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2 *msg); +DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2* msg); /** * DLTv2 Set extended header parameters for Version 2 @@ -1603,7 +1571,7 @@ DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2 *msg); * @param header_offset Offset of header buffer before baseheader pointer * @return negative value if there was an error */ -uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2 *msg); +uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2* msg); /** * DLTv2 Parse extended parameters from received buffer for DLTv2 messages @@ -1612,7 +1580,8 @@ uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2 *msg); * @param msgcontent message content type * @return Value from DltReturnValue enum */ -DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMessageV2 *msg, uint8_t* buffer, DltHtyp2ContentType msgcontent); +DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2( + DltMessageV2* msg, uint8_t* buffer, DltHtyp2ContentType msgcontent); /** * Initialise the structure used to access a DLT file. @@ -1621,7 +1590,7 @@ DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMess * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_init(DltFile *file, int verbose); +DltReturnValue dlt_file_init(DltFile* file, int verbose); /** * DLTv2 Initialise the structure used to access a DLT file. @@ -1630,7 +1599,7 @@ DltReturnValue dlt_file_init(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_init_v2(DltFile *file, int verbose); +DltReturnValue dlt_file_init_v2(DltFile* file, int verbose); /** * Set a list to filters. @@ -1642,7 +1611,7 @@ DltReturnValue dlt_file_init_v2(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose); +DltReturnValue dlt_file_set_filter(DltFile* file, DltFilter* filter, int verbose); /** * Initialising loading a DLT file. @@ -1651,7 +1620,7 @@ DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose); +DltReturnValue dlt_file_open(DltFile* file, const char* filename, int verbose); /** * This function reads DLT file and parse DLT message one by one. @@ -1663,7 +1632,7 @@ DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose); * @param verbose if set to true verbose information is printed out. * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error */ -DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, int type, int verbose); +DltReturnValue dlt_file_quick_parsing(DltFile* file, const char* filename, int type, int verbose); /** * Find next message in the DLT file and parse them. @@ -1673,7 +1642,7 @@ DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, int t * @param verbose if set to true verbose information is printed out. * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error */ -DltReturnValue dlt_file_read(DltFile *file, int verbose); +DltReturnValue dlt_file_read(DltFile* file, int verbose); /** * Find next message in the DLT file in RAW format (without storage header) and parse them. @@ -1684,7 +1653,7 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error */ -DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose); +DltReturnValue dlt_file_read_raw(DltFile* file, int resync, int verbose); /** * Closing loading a DLT file. @@ -1692,7 +1661,7 @@ DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_close(DltFile *file, int verbose); +DltReturnValue dlt_file_close(DltFile* file, int verbose); /** * Load standard header of a message from file @@ -1700,7 +1669,7 @@ DltReturnValue dlt_file_close(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_read_header(DltFile *file, int verbose); +DltReturnValue dlt_file_read_header(DltFile* file, int verbose); /** * Load standard header of a message from file in RAW format (without storage header) @@ -1709,7 +1678,7 @@ DltReturnValue dlt_file_read_header(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose); +DltReturnValue dlt_file_read_header_raw(DltFile* file, int resync, int verbose); /** * Load, if available in message, extra standard header fields and @@ -1719,7 +1688,7 @@ DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose); +DltReturnValue dlt_file_read_header_extended(DltFile* file, int verbose); /** * Load payload of a message from file @@ -1728,7 +1697,7 @@ DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_read_data(DltFile *file, int verbose); +DltReturnValue dlt_file_read_data(DltFile* file, int verbose); /** * Load headers and payload of a message selected by the index. @@ -1738,7 +1707,7 @@ DltReturnValue dlt_file_read_data(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return number of messages loaded, negative value if there was an error */ -DltReturnValue dlt_file_message(DltFile *file, int index, int verbose); +DltReturnValue dlt_file_message(DltFile* file, int index, int verbose); /** * Free the used memory by the organising structure of file. @@ -1746,7 +1715,7 @@ DltReturnValue dlt_file_message(DltFile *file, int index, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_free(DltFile *file, int verbose); +DltReturnValue dlt_file_free(DltFile* file, int verbose); /** * DLTv2 Free the used memory by the organising structure of file. @@ -1754,14 +1723,14 @@ DltReturnValue dlt_file_free(DltFile *file, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_file_free_v2(DltFile *file, int verbose); +DltReturnValue dlt_file_free_v2(DltFile* file, int verbose); #if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC /** * Set FIFO base direction * @param pipe_dir the pipe direction */ -void dlt_log_set_fifo_basedir(const char *pipe_dir); +void dlt_log_set_fifo_basedir(const char* pipe_dir); #endif /** @@ -1778,14 +1747,14 @@ void dlt_print_with_attributes(bool state); * @param _buffersize size of data buffer for storing the received data * @return negative value if there was an error */ -DltReturnValue dlt_receiver_init(DltReceiver *receiver, int _fd, DltReceiverType type, int _buffersize); +DltReturnValue dlt_receiver_init(DltReceiver* receiver, int _fd, DltReceiverType type, int _buffersize); /** * De-Initialize a dlt receiver structure * @param receiver pointer to dlt receiver structure * @return negative value if there was an error */ -DltReturnValue dlt_receiver_free(DltReceiver *receiver); +DltReturnValue dlt_receiver_free(DltReceiver* receiver); /** * Initialising a dlt receiver structure @@ -1795,21 +1764,21 @@ DltReturnValue dlt_receiver_free(DltReceiver *receiver); * @param buffer data buffer for storing the received data * @return negative value if there was an error and zero if success */ -DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, DltReceiverType type, char **buffer); +DltReturnValue dlt_receiver_init_global_buffer(DltReceiver* receiver, int fd, DltReceiverType type, char** buffer); /** * De-Initialize a dlt receiver structure * @param receiver pointer to dlt receiver structure * @return negative value if there was an error and zero if success */ -DltReturnValue dlt_receiver_free_global_buffer(DltReceiver *receiver); +DltReturnValue dlt_receiver_free_global_buffer(DltReceiver* receiver); /** * Receive data from socket or file/fifo using the dlt receiver structure * @param receiver pointer to dlt receiver structure * @return number of received bytes or negative value if there was an error */ -int dlt_receiver_receive(DltReceiver *receiver); +int dlt_receiver_receive(DltReceiver* receiver); /** * Remove a specific size of bytes from the received data @@ -1817,14 +1786,14 @@ int dlt_receiver_receive(DltReceiver *receiver); * @param size amount of bytes to be removed * @return negative value if there was an error */ -DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size); +DltReturnValue dlt_receiver_remove(DltReceiver* receiver, int size); /** * Move data from last receive call to front of receive buffer * @param receiver pointer to dlt receiver structure * @return negative value if there was an error */ -DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver); +DltReturnValue dlt_receiver_move_to_begin(DltReceiver* receiver); /** * Check whether to_get amount of data is available in receiver and @@ -1834,10 +1803,7 @@ DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver); * @param to_get size of the data to copy in dest * @param skip_header whether if the DltUserHeader must be skipped. */ -int dlt_receiver_check_and_get(DltReceiver *receiver, - void *dest, - unsigned int to_get, - unsigned int skip_header); +int dlt_receiver_check_and_get(DltReceiver* receiver, void* dest, unsigned int to_get, unsigned int skip_header); /** * Fill out storage header of a dlt message @@ -1845,7 +1811,7 @@ int dlt_receiver_check_and_get(DltReceiver *receiver, * @param ecu name of ecu to be set in storage header * @return negative value if there was an error */ -DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu); +DltReturnValue dlt_set_storageheader(DltStorageHeader* storageheader, const char* ecu); /** * DLTv2 Fill out storage header of a dlt message @@ -1854,21 +1820,21 @@ DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char * @param ecu name of ecu to be set in storage header * @return negative value if there was an error */ -DltReturnValue dlt_set_storageheader_v2(DltStorageHeaderV2 *storageheader, uint8_t ecuIDlen, const char *ecu); +DltReturnValue dlt_set_storageheader_v2(DltStorageHeaderV2* storageheader, uint8_t ecuIDlen, const char* ecu); /** * Check if a storage header contains its marker * @param storageheader pointer to storage header of a dlt message * @return 0 no, 1 yes, negative value if there was an error */ -DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader); +DltReturnValue dlt_check_storageheader(DltStorageHeader* storageheader); /** * DLTv2 Check if a storage header contains its marker * @param storageheader pointer to storage header of a dlt message * @return 0 no, 1 yes, negative value if there was an error */ -DltReturnValue dlt_check_storageheader_v2(DltStorageHeaderV2 *storageheader); +DltReturnValue dlt_check_storageheader_v2(DltStorageHeaderV2* storageheader); /** * Checks if received size is big enough for expected data @@ -1887,7 +1853,7 @@ DltReturnValue dlt_check_rcv_data_size(int received, int required); * @param size Maximum size of buffer in bytes * @return negative value if there was an error */ -DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size); +DltReturnValue dlt_buffer_init_static_server(DltBuffer* buf, const unsigned char* ptr, uint32_t size); /** * Initialize static ringbuffer with a size of size. @@ -1898,7 +1864,7 @@ DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char * @param size Maximum size of buffer in bytes * @return negative value if there was an error */ -DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size); +DltReturnValue dlt_buffer_init_static_client(DltBuffer* buf, const unsigned char* ptr, uint32_t size); /** * Initialize dynamic ringbuffer with a size of size. @@ -1912,21 +1878,21 @@ DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char * @param step_size size of which ringbuffer is increased * @return negative value if there was an error */ -DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size, uint32_t step_size); +DltReturnValue dlt_buffer_init_dynamic(DltBuffer* buf, uint32_t min_size, uint32_t max_size, uint32_t step_size); /** * Deinitilaise usage of static ringbuffer * @param buf Pointer to ringbuffer structure * @return negative value if there was an error */ -DltReturnValue dlt_buffer_free_static(DltBuffer *buf); +DltReturnValue dlt_buffer_free_static(DltBuffer* buf); /** * Release and free memory used by dynamic ringbuffer * @param buf Pointer to ringbuffer structure * @return negative value if there was an error */ -DltReturnValue dlt_buffer_free_dynamic(DltBuffer *buf); +DltReturnValue dlt_buffer_free_dynamic(DltBuffer* buf); /** * Check if message fits into buffer. @@ -1934,7 +1900,7 @@ DltReturnValue dlt_buffer_free_dynamic(DltBuffer *buf); * @param needed Needed size * @return DLT_RETURN_OK if enough space, DLT_RETURN_ERROR otherwise */ -DltReturnValue dlt_buffer_check_size(DltBuffer *buf, int needed); +DltReturnValue dlt_buffer_check_size(DltBuffer* buf, int needed); /** * Write one entry to ringbuffer @@ -1943,7 +1909,7 @@ DltReturnValue dlt_buffer_check_size(DltBuffer *buf, int needed); * @param size Size of data in bytes to be written to ringbuffer * @return negative value if there was an error */ -DltReturnValue dlt_buffer_push(DltBuffer *buf, const unsigned char *data, unsigned int size); +DltReturnValue dlt_buffer_push(DltBuffer* buf, const unsigned char* data, unsigned int size); /** * Write up to three entries to ringbuffer. @@ -1957,13 +1923,9 @@ DltReturnValue dlt_buffer_push(DltBuffer *buf, const unsigned char *data, unsign * @param size3 Size of data in bytes to be written to ringbuffer * @return negative value if there was an error */ -DltReturnValue dlt_buffer_push3(DltBuffer *buf, - const unsigned char *data1, - unsigned int size1, - const unsigned char *data2, - unsigned int size2, - const unsigned char *data3, - unsigned int size3); +DltReturnValue dlt_buffer_push3( + DltBuffer* buf, const unsigned char* data1, unsigned int size1, const unsigned char* data2, unsigned int size2, + const unsigned char* data3, unsigned int size3); /** * Read one entry from ringbuffer. @@ -1973,7 +1935,7 @@ DltReturnValue dlt_buffer_push3(DltBuffer *buf, * @param max_size Max size of read data in bytes from ringbuffer * @return size of read data, zero if no data available, negative value if there was an error */ -int dlt_buffer_pull(DltBuffer *buf, unsigned char *data, int max_size); +int dlt_buffer_pull(DltBuffer* buf, unsigned char* data, int max_size); /** * Read one entry from ringbuffer. @@ -1983,26 +1945,26 @@ int dlt_buffer_pull(DltBuffer *buf, unsigned char *data, int max_size); * @param max_size Max size of read data in bytes from ringbuffer * @return size of read data, zero if no data available, negative value if there was an error */ -int dlt_buffer_copy(DltBuffer *buf, unsigned char *data, int max_size); +int dlt_buffer_copy(DltBuffer* buf, unsigned char* data, int max_size); /** * Remove entry from ringbuffer. * @param buf Pointer to ringbuffer structure * @return size of read data, zero if no data available, negative value if there was an error */ -int dlt_buffer_remove(DltBuffer *buf); +int dlt_buffer_remove(DltBuffer* buf); /** * Print information about buffer and log to internal DLT log. * @param buf Pointer to ringbuffer structure */ -void dlt_buffer_info(DltBuffer *buf); +void dlt_buffer_info(DltBuffer* buf); /** * Print status of buffer and log to internal DLT log. * @param buf Pointer to ringbuffer structure */ -void dlt_buffer_status(DltBuffer *buf); +void dlt_buffer_status(DltBuffer* buf); /** * Get total size in bytes of ringbuffer. @@ -2010,23 +1972,23 @@ void dlt_buffer_status(DltBuffer *buf); * @param buf Pointer to ringbuffer structure * @return total size of buffer */ -uint32_t dlt_buffer_get_total_size(DltBuffer *buf); +uint32_t dlt_buffer_get_total_size(DltBuffer* buf); /** * Get used size in bytes of ringbuffer. * @param buf Pointer to ringbuffer structure * @return used size of buffer */ -int dlt_buffer_get_used_size(DltBuffer *buf); +int dlt_buffer_get_used_size(DltBuffer* buf); /** * Get number of entries in ringbuffer. * @param buf Pointer to ringbuffer structure * @return number of entries */ -int dlt_buffer_get_message_count(DltBuffer *buf); +int dlt_buffer_get_message_count(DltBuffer* buf); -# if !defined (__WIN32__) +#if !defined(__WIN32__) /** * Helper function: Setup serial connection @@ -2048,23 +2010,23 @@ speed_t dlt_convert_serial_speed(int baudrate); * @param buf Pointer to buffer * @param size size of buffer */ -void dlt_get_version(char *buf, size_t size); +void dlt_get_version(char* buf, size_t size); /** * Print dlt major version to buffer * @param buf Pointer to buffer * @param size size of buffer */ -void dlt_get_major_version(char *buf, size_t size); +void dlt_get_major_version(char* buf, size_t size); /** * Print dlt minor version to buffer * @param buf Pointer to buffer * @param size size of buffer */ -void dlt_get_minor_version(char *buf, size_t size); +void dlt_get_minor_version(char* buf, size_t size); -# endif +#endif /* Function prototypes which should be used only internally */ /* */ @@ -2099,7 +2061,7 @@ uint32_t dlt_uptime(void); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_header(DltMessage* message, char* text, uint32_t size, int verbose); /** * DLTv2 Print header of a DLT message @@ -2109,7 +2071,7 @@ DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_ * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_header_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_header_v2(DltMessageV2* message, char* text, uint32_t size, int verbose); /** * Print payload of a DLT message as Hex-Output @@ -2119,7 +2081,7 @@ DltReturnValue dlt_message_print_header_v2(DltMessageV2 *message, char *text, ui * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_hex(DltMessage* message, char* text, uint32_t size, int verbose); /** * DLTv2 Print payload of a DLT message as Hex-Output @@ -2129,7 +2091,7 @@ DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t s * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_hex_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_hex_v2(DltMessageV2* message, char* text, uint32_t size, int verbose); /** * Print payload of a DLT message as ASCII-Output @@ -2139,7 +2101,7 @@ DltReturnValue dlt_message_print_hex_v2(DltMessageV2 *message, char *text, uint3 * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_ascii(DltMessage* message, char* text, uint32_t size, int verbose); /** * DLTv2 Print payload of a DLT message as ASCII-Output for version 2 @@ -2149,7 +2111,7 @@ DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_ascii_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_ascii_v2(DltMessageV2* message, char* text, uint32_t size, int verbose); /** * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output @@ -2159,7 +2121,7 @@ DltReturnValue dlt_message_print_ascii_v2(DltMessageV2 *message, char *text, uin * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_mixed_plain(DltMessage* message, char* text, uint32_t size, int verbose); /** * DLTv2 Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output @@ -2169,7 +2131,7 @@ DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, ui * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_mixed_plain_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_mixed_plain_v2(DltMessageV2* message, char* text, uint32_t size, int verbose); /** * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output @@ -2179,7 +2141,7 @@ DltReturnValue dlt_message_print_mixed_plain_v2(DltMessageV2 *message, char *tex * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose); +DltReturnValue dlt_message_print_mixed_html(DltMessage* message, char* text, uint32_t size, int verbose); /** * Decode and print a argument of a DLT message @@ -2193,14 +2155,9 @@ DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uin * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_argument_print(DltMessage *msg, - uint32_t type_info, - uint8_t **ptr, - int32_t *datalength, - char *text, - size_t textlength, - int byteLength, - int verbose); +DltReturnValue dlt_message_argument_print( + DltMessage* msg, uint32_t type_info, uint8_t** ptr, int32_t* datalength, char* text, size_t textlength, + int byteLength, int verbose); /** * DLTv2 Decode and print a argument of a DLT message @@ -2214,14 +2171,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, - uint32_t type_info, - uint8_t **ptr, - int32_t *datalength, - char *text, - size_t textlength, - int byteLength, - int verbose); +DltReturnValue dlt_message_argument_print_v2( + DltMessageV2* msg, uint32_t type_info, uint8_t** ptr, int32_t* datalength, char* text, size_t textlength, + int byteLength, int verbose); /** * Check environment variables. @@ -2236,7 +2188,7 @@ void dlt_check_envvar(void); * @param service_opt int * * @return pointer to resp_text */ -int dlt_set_loginfo_parse_service_id(char *resp_text, uint32_t *service_id, uint8_t *service_opt); +int dlt_set_loginfo_parse_service_id(char* resp_text, uint32_t* service_id, uint8_t* service_opt); /** * Convert get log info from ASCII to uint16 @@ -2245,7 +2197,7 @@ int dlt_set_loginfo_parse_service_id(char *resp_text, uint32_t *service_id, uint * @param rp_count int * @return length */ -uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count); +uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char* rp, int* rp_count); /** * Convert get log info from ASCII to int16_t @@ -2254,7 +2206,7 @@ uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count); * @param rp_count int * @return length */ -int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count); +int16_t dlt_getloginfo_conv_ascii_to_int16_t(char* rp, int* rp_count); /** * Convert get log info from ASCII to uint8_t @@ -2263,7 +2215,7 @@ int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count); * @param rp_count int * @return length */ -uint8_t dlt_getloginfo_conv_ascii_to_uint8_t(char *rp, int *rp_count); +uint8_t dlt_getloginfo_conv_ascii_to_uint8_t(char* rp, int* rp_count); /** @@ -2274,7 +2226,7 @@ uint8_t dlt_getloginfo_conv_ascii_to_uint8_t(char *rp, int *rp_count); * @param wp char Array needs to be 1 byte larger than len to store '\0' * @param len int */ -void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int len); +void dlt_getloginfo_conv_ascii_to_string(char* rp, int* rp_count, char* wp, int len); /** * Convert get log info from ASCII to ID (without '\0' termination) @@ -2285,7 +2237,7 @@ void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int * @param len int * @return position of last read character in wp */ -int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len); +int dlt_getloginfo_conv_ascii_to_id(char* rp, int* rp_count, char* wp, int len); /** * Convert from hex ASCII to binary @@ -2293,7 +2245,7 @@ int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len); * @param binary uint8_t * @param size int */ -void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size); +void dlt_hex_ascii_to_binary(const char* ptr, uint8_t* binary, int* size); /** * Helper function to execute the execvp function in a new child process. @@ -2301,14 +2253,14 @@ void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size); * @param command execution command followed by arguments with NULL-termination * @return negative value if there was an error */ -int dlt_execute_command(char *filename, char *command, ...); +int dlt_execute_command(char* filename, char* command, ...); /** * Return the extension of given file name. * @param filename Only file names without prepended path allowed. * @return pointer to extension */ -const char *get_filename_ext(const char *filename); +const char* get_filename_ext(const char* filename); /** * Extract the base name of given file name (without the extension). @@ -2319,9 +2271,9 @@ const char *get_filename_ext(const char *filename); */ bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif /** \} diff --git a/include/dlt/dlt_common_api.h b/include/dlt/dlt_common_api.h index 809788bc7..6cf61edd8 100644 --- a/include/dlt/dlt_common_api.h +++ b/include/dlt/dlt_common_api.h @@ -91,7 +91,7 @@ * @param APPID context id with maximal four characters * @param DESCRIPTION ASCII string containing description */ -#define DLT_REGISTER_CONTEXT_APP(CONTEXT, CONTEXTID, APPID, DESCRIPTION) \ +#define DLT_REGISTER_CONTEXT_APP(CONTEXT, CONTEXTID, APPID, DESCRIPTION) \ DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION) /** @@ -102,193 +102,67 @@ * @param ARGS variable list of arguments */ /*****************************************/ -#define DLT_LOG0(CONTEXT, LOGLEVEL) \ - DLT_LOG(CONTEXT, LOGLEVEL) +#define DLT_LOG0(CONTEXT, LOGLEVEL) DLT_LOG(CONTEXT, LOGLEVEL) /*****************************************/ -#define DLT_LOG1(CONTEXT, LOGLEVEL, ARGS1) \ - DLT_LOG(CONTEXT, LOGLEVEL, ARGS1) +#define DLT_LOG1(CONTEXT, LOGLEVEL, ARGS1) DLT_LOG(CONTEXT, LOGLEVEL, ARGS1) /*****************************************/ -#define DLT_LOG2(CONTEXT, LOGLEVEL, ARGS1, ARGS2) \ - DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2) +#define DLT_LOG2(CONTEXT, LOGLEVEL, ARGS1, ARGS2) DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2) /*****************************************/ -#define DLT_LOG3(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3) \ - DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3) +#define DLT_LOG3(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3) DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3) /*****************************************/ -#define DLT_LOG4(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4) \ - DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4) +#define DLT_LOG4(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4) DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4) /*****************************************/ -#define DLT_LOG5(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5) \ +#define DLT_LOG5(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5) /*****************************************/ -#define DLT_LOG6(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6) \ +#define DLT_LOG6(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6) /*****************************************/ -#define DLT_LOG7(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7) \ +#define DLT_LOG7(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7) /*****************************************/ -#define DLT_LOG8(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8) \ +#define DLT_LOG8(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8) /*****************************************/ -#define DLT_LOG9(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9) \ +#define DLT_LOG9(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9) /*****************************************/ -#define DLT_LOG10(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10) \ +#define DLT_LOG10(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10) /*****************************************/ -#define DLT_LOG11(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11) \ +#define DLT_LOG11(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11) /*****************************************/ -#define DLT_LOG12(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12) \ +#define DLT_LOG12( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12) \ DLT_LOG(CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12) /*****************************************/ -#define DLT_LOG13(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13) \ - DLT_LOG(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13) -/*****************************************/ -#define DLT_LOG14(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14) \ - DLT_LOG(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14) -/*****************************************/ -#define DLT_LOG15(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15) \ - DLT_LOG(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15) -/*****************************************/ -#define DLT_LOG16(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15, \ - ARGS16) \ - DLT_LOG(CONTEXT, \ - LOGLEVEL, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15, \ - ARGS16) +#define DLT_LOG13( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, ARGS13) \ + DLT_LOG( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13) +/*****************************************/ +#define DLT_LOG14( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, ARGS13, \ + ARGS14) \ + DLT_LOG( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13, ARGS14) +/*****************************************/ +#define DLT_LOG15( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, ARGS13, \ + ARGS14, ARGS15) \ + DLT_LOG( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13, ARGS14, ARGS15) +/*****************************************/ +#define DLT_LOG16( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, ARGS13, \ + ARGS14, ARGS15, ARGS16) \ + DLT_LOG( \ + CONTEXT, LOGLEVEL, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13, ARGS14, ARGS15, ARGS16) /** * Send log message with variable list of messages (intended for non-verbose mode) @@ -301,229 +175,73 @@ * DLT_INT(), DLT_UINT(), DLT_RAW() */ /*****************************************/ -#define DLT_LOG_ID0(CONTEXT, LOGLEVEL, MSGID) \ - DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID) +#define DLT_LOG_ID0(CONTEXT, LOGLEVEL, MSGID) DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID) /*****************************************/ -#define DLT_LOG_ID1(CONTEXT, LOGLEVEL, MSGID, ARGS1) \ - DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1) +#define DLT_LOG_ID1(CONTEXT, LOGLEVEL, MSGID, ARGS1) DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1) /*****************************************/ -#define DLT_LOG_ID2(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2) \ - DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2) +#define DLT_LOG_ID2(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2) DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2) /*****************************************/ -#define DLT_LOG_ID3(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3) \ +#define DLT_LOG_ID3(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3) /*****************************************/ -#define DLT_LOG_ID4(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4) \ +#define DLT_LOG_ID4(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4) /*****************************************/ -#define DLT_LOG_ID5(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5) \ +#define DLT_LOG_ID5(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5) /*****************************************/ -#define DLT_LOG_ID6(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6) \ +#define DLT_LOG_ID6(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6) /*****************************************/ -#define DLT_LOG_ID7(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7) \ +#define DLT_LOG_ID7(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7) /*****************************************/ -#define DLT_LOG_ID8(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8) \ +#define DLT_LOG_ID8(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8) /*****************************************/ -#define DLT_LOG_ID9(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9) \ +#define DLT_LOG_ID9(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9) /*****************************************/ -#define DLT_LOG_ID10(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10) \ +#define DLT_LOG_ID10(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10) /*****************************************/ -#define DLT_LOG_ID11(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11) \ +#define DLT_LOG_ID11( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11) \ DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11) /*****************************************/ -#define DLT_LOG_ID12(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12) \ - DLT_LOG_ID(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12) -/*****************************************/ -#define DLT_LOG_ID13(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13) \ - DLT_LOG_ID(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13) -/*****************************************/ -#define DLT_LOG_ID14(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14) \ - DLT_LOG_ID(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14) -/*****************************************/ -#define DLT_LOG_ID15(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15) \ - DLT_LOG_ID(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15) -/*****************************************/ -#define DLT_LOG_ID16(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15, \ - ARGS16) \ - DLT_LOG_ID(CONTEXT, \ - LOGLEVEL, \ - MSGID, \ - ARGS1, \ - ARGS2, \ - ARGS3, \ - ARGS4, \ - ARGS5, \ - ARGS6, \ - ARGS7, \ - ARGS8, \ - ARGS9, \ - ARGS10, \ - ARGS11, \ - ARGS12, \ - ARGS13, \ - ARGS14, \ - ARGS15, \ - ARGS16) +#define DLT_LOG_ID12( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12) \ + DLT_LOG_ID( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, \ + ARGS12) +/*****************************************/ +#define DLT_LOG_ID13( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13) \ + DLT_LOG_ID( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, \ + ARGS12, ARGS13) +/*****************************************/ +#define DLT_LOG_ID14( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13, ARGS14) \ + DLT_LOG_ID( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, \ + ARGS12, ARGS13, ARGS14) +/*****************************************/ +#define DLT_LOG_ID15( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13, ARGS14, ARGS15) \ + DLT_LOG_ID( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, \ + ARGS12, ARGS13, ARGS14, ARGS15) +/*****************************************/ +#define DLT_LOG_ID16( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, ARGS12, \ + ARGS13, ARGS14, ARGS15, ARGS16) \ + DLT_LOG_ID( \ + CONTEXT, LOGLEVEL, MSGID, ARGS1, ARGS2, ARGS3, ARGS4, ARGS5, ARGS6, ARGS7, ARGS8, ARGS9, ARGS10, ARGS11, \ + ARGS12, ARGS13, ARGS14, ARGS15, ARGS16) /** * Unregister context. @@ -550,4 +268,3 @@ /* UNCHANGED */ #endif /* DLT_COMMON_API_H */ - diff --git a/include/dlt/dlt_cpp_extension.hpp b/include/dlt/dlt_cpp_extension.hpp index 572697fc3..2501b3c2c 100644 --- a/include/dlt/dlt_cpp_extension.hpp +++ b/include/dlt/dlt_cpp_extension.hpp @@ -20,7 +20,7 @@ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt_cpp_extension.hpp -*/ + */ #ifndef DLT_CPP_EXTENSION_HPP #define DLT_CPP_EXTENSION_HPP @@ -33,96 +33,96 @@ #include "dlt.h" template -int32_t logToDlt(DltContextData &log, T const &value) = delete; +int32_t logToDlt(DltContextData& log, T const& value) = delete; template<> -inline int32_t logToDlt(DltContextData &log, int8_t const &value) +inline int32_t logToDlt(DltContextData& log, int8_t const& value) { return dlt_user_log_write_int8(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, int16_t const &value) +inline int32_t logToDlt(DltContextData& log, int16_t const& value) { return dlt_user_log_write_int16(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, int32_t const &value) +inline int32_t logToDlt(DltContextData& log, int32_t const& value) { return dlt_user_log_write_int32(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, int64_t const &value) +inline int32_t logToDlt(DltContextData& log, int64_t const& value) { return dlt_user_log_write_int64(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, uint8_t const &value) +inline int32_t logToDlt(DltContextData& log, uint8_t const& value) { return dlt_user_log_write_uint8(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, uint16_t const &value) +inline int32_t logToDlt(DltContextData& log, uint16_t const& value) { return dlt_user_log_write_uint16(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, uint32_t const &value) +inline int32_t logToDlt(DltContextData& log, uint32_t const& value) { return dlt_user_log_write_uint32(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, uint64_t const &value) +inline int32_t logToDlt(DltContextData& log, uint64_t const& value) { return dlt_user_log_write_uint64(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, float32_t const &value) +inline int32_t logToDlt(DltContextData& log, float32_t const& value) { return dlt_user_log_write_float32(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, double const &value) +inline int32_t logToDlt(DltContextData& log, double const& value) { return dlt_user_log_write_float64(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, bool const &value) +inline int32_t logToDlt(DltContextData& log, bool const& value) { return dlt_user_log_write_bool(&log, value); } -static inline int32_t logToDlt(DltContextData &log, char const * const value) +static inline int32_t logToDlt(DltContextData& log, char const* const value) { return dlt_user_log_write_utf8_string(&log, value); } -static inline int32_t logToDlt(DltContextData &log, char * const value) +static inline int32_t logToDlt(DltContextData& log, char* const value) { return dlt_user_log_write_utf8_string(&log, value); } template<> -inline int32_t logToDlt(DltContextData &log, std::string const &value) +inline int32_t logToDlt(DltContextData& log, std::string const& value) { return dlt_user_log_write_utf8_string(&log, value.c_str()); } /* stl types */ template<> -int32_t logToDlt(DltContextData &log, std::string const &value); +int32_t logToDlt(DltContextData& log, std::string const& value); template> -static inline int32_t logToDlt(DltContextData &log, std::vector<_Tp, _Alloc> const & value) +static inline int32_t logToDlt(DltContextData& log, std::vector<_Tp, _Alloc> const& value) { int result = 0; @@ -136,7 +136,7 @@ static inline int32_t logToDlt(DltContextData &log, std::vector<_Tp, _Alloc> con } template> -static inline int32_t logToDlt(DltContextData &log, std::list<_Tp, _Alloc> const & value) +static inline int32_t logToDlt(DltContextData& log, std::list<_Tp, _Alloc> const& value) { int result = 0; @@ -149,14 +149,14 @@ static inline int32_t logToDlt(DltContextData &log, std::list<_Tp, _Alloc> const return result; } -template, - typename _Alloc = std::allocator>> -static inline int32_t logToDlt(DltContextData &log, std::map<_Key, _Tp, _Compare, _Alloc> const & value) +template< + typename _Key, typename _Tp, typename _Compare = std::less<_Key>, + typename _Alloc = std::allocator>> +static inline int32_t logToDlt(DltContextData& log, std::map<_Key, _Tp, _Compare, _Alloc> const& value) { int result = 0; - for (auto elem : value) - { + for (auto elem : value) { result += logToDlt(log, elem.first); result += logToDlt(log, elem.second); } @@ -167,15 +167,15 @@ static inline int32_t logToDlt(DltContextData &log, std::map<_Key, _Tp, _Compare return result; } -//variadic functions using C11 standard +// variadic functions using C11 standard template -static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA) +static inline int32_t logToDltVariadic(DltContextData& log, First const& valueA) { return logToDlt(log, valueA); } -template -static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA, const Rest&... valueB) +template +static inline int32_t logToDltVariadic(DltContextData& log, First const& valueA, const Rest&... valueB) { int result = logToDlt(log, valueA) + logToDltVariadic(log, valueB...); @@ -186,27 +186,26 @@ static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA, } /** - * @brief macro to write a log message with variable number of arguments and without the need to specify the type of log data + * @brief macro to write a log message with variable number of arguments and without the need to specify the type of log + * data * * The macro can be used with any type that provides a logToDlt function. * * Example: * DLT_LOG_CXX(dltContext, DLT_LV_X, "text", valueA, valueB, ...) */ -#define DLT_LOG_CXX(CONTEXT, LOGLEVEL, ...)\ - do\ - {\ - DltContextData log;\ - if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0)\ - {\ - logToDltVariadic(log, ##__VA_ARGS__);\ - dlt_user_log_write_finish(&log);\ - }\ - }\ - while(false) +#define DLT_LOG_CXX(CONTEXT, LOGLEVEL, ...) \ + do { \ + DltContextData log; \ + if (dlt_user_log_write_start(&CONTEXT, &log, LOGLEVEL) > 0) { \ + logToDltVariadic(log, ##__VA_ARGS__); \ + dlt_user_log_write_finish(&log); \ + } \ + } while (false) /** - * @brief macro to write a log message with variable number of arguments and without the need to specify the type of log data. + * @brief macro to write a log message with variable number of arguments and without the need to specify the type of log + * data. * * The macro can be used with any type that provides a logToDlt function. * This includes all the types that are code generated. @@ -216,17 +215,14 @@ static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA, * Example: * DLT_LOG_FCN_CXX(dltContext, DLT_LV_X, "text", valueA, valueB, ...) */ -#define DLT_LOG_FCN_CXX(CONTEXT, LOGLEVEL, ...) \ - do\ - {\ - DltContextData log;\ - if (dlt_user_log_write_start(&CONTEXT, &log, LOGLEVEL) > 0)\ - {\ - dlt_user_log_write_string(&log, __PRETTY_FUNCTION__);\ - logToDltVariadic(log, ##__VA_ARGS__);\ - dlt_user_log_write_finish(&log);\ - }\ - }\ - while(false) +#define DLT_LOG_FCN_CXX(CONTEXT, LOGLEVEL, ...) \ + do { \ + DltContextData log; \ + if (dlt_user_log_write_start(&CONTEXT, &log, LOGLEVEL) > 0) { \ + dlt_user_log_write_string(&log, __PRETTY_FUNCTION__); \ + logToDltVariadic(log, ##__VA_ARGS__); \ + dlt_user_log_write_finish(&log); \ + } \ + } while (false) #endif /* DLT_CPP_EXTENSION_HPP */ diff --git a/include/dlt/dlt_filetransfer.h b/include/dlt/dlt_filetransfer.h index f5ee5eff2..d7544c245 100644 --- a/include/dlt/dlt_filetransfer.h +++ b/include/dlt/dlt_filetransfer.h @@ -25,10 +25,10 @@ #ifndef DLT_FILETRANSFER_H #define DLT_FILETRANSFER_H -#include /* Needed for LONG_MAX */ -#include /* Needed for struct stat st*/ -#include "dlt.h" /* Needed for DLT Logs */ -#include /* Signal handling */ +#include /* Needed for LONG_MAX */ +#include /* Needed for struct stat st*/ +#include "dlt.h" /* Needed for DLT Logs */ +#include /* Signal handling */ #include "errno.h" @@ -63,14 +63,17 @@ * In the next step some generic informations about the file will be logged to dlt. * Now the header will be logged to dlt. See the method dlt_user_log_file_header for more informations. * Then the method dlt_user_log_data will be called with the parameter to log all packages in a loop with some timeout. - * At last dlt_user_log_end is called to signal that the complete file transfer was okey. This is important for the plugin of the dlt viewer. + * At last dlt_user_log_end is called to signal that the complete file transfer was okey. This is important for the + * plugin of the dlt viewer. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path * @param deleteFlag Flag if the file will be deleted after transfer. 1->delete, 0->notDelete - * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to many messages in a short period of time. + * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to + * many messages in a short period of time. * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, unsigned int timeout); +extern int dlt_user_log_file_complete( + DltContext* fileContext, const char* filename, int deleteFlag, unsigned int timeout); /* !This method gives information about the number of packages the file have */ @@ -82,7 +85,7 @@ extern int dlt_user_log_file_complete(DltContext *fileContext, const char *filen * @param filename Absolute file path * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filename); +extern int dlt_user_log_file_packagesCount(DltContext* fileContext, const char* filename); /* !Logs specific file inforamtions to dlt */ @@ -91,7 +94,7 @@ extern int dlt_user_log_file_packagesCount(DltContext *fileContext, const char * * @param filename Absolute file path * @return Returns 0 if everything was okey.If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename); +extern int dlt_user_log_file_infoAbout(DltContext* fileContext, const char* filename); /* !Transfer the head of the file as a dlt logs. */ @@ -104,7 +107,7 @@ extern int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *file * @param alias Alias for the file. An alternative name to show in the receiving end * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename, const char *alias); +extern int dlt_user_log_file_header_alias(DltContext* fileContext, const char* filename, const char* alias); /* !Transfer the head of the file as a dlt logs. */ /**The head of the file must be logged to dlt because the head contains inforamtion about the file serial number, @@ -115,29 +118,37 @@ extern int dlt_user_log_file_header_alias(DltContext *fileContext, const char *f * @param filename Absolute file path * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_header(DltContext *fileContext, const char *filename); +extern int dlt_user_log_file_header(DltContext* fileContext, const char* filename); //* !Transfer the content data of a file. */ /**See the Mainpages.c for more informations. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path - * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred with a specific timeout - * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. - * @param fileCancelTransferFlag is a bool pointer to cancel the filetransfer on demand. For example in case of application shutdown event outstanding file transfer should abort and return + * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred + * with a specific timeout + * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is + * defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. + * @param fileCancelTransferFlag is a bool pointer to cancel the filetransfer on demand. For example in case of + * application shutdown event outstanding file transfer should abort and return * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_data_cancelable(DltContext *fileContext, const char *filename, int packageToTransfer, unsigned int timeout, bool *const fileCancelTransferFlag); +extern int dlt_user_log_file_data_cancelable( + DltContext* fileContext, const char* filename, int packageToTransfer, unsigned int timeout, + bool* const fileCancelTransferFlag); /* !Transfer the content data of a file. */ /**See the Mainpages.c for more informations. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path - * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred with a specific timeout - * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. + * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred + * with a specific timeout + * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is + * defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, unsigned int timeout); +extern int dlt_user_log_file_data( + DltContext* fileContext, const char* filename, int packageToTransfer, unsigned int timeout); @@ -150,6 +161,6 @@ extern int dlt_user_log_file_data(DltContext *fileContext, const char *filename, * @param deleteFlag Flag to delete the file after the whole file is transferred (logged to dlt).1->delete,0->NotDelete * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_end(DltContext *fileContext, const char *filename, int deleteFlag); +extern int dlt_user_log_file_end(DltContext* fileContext, const char* filename, int deleteFlag); #endif /* DLT_FILETRANSFER_H */ diff --git a/include/dlt/dlt_log.h b/include/dlt/dlt_log.h index 912b6380a..89c6c36ef 100644 --- a/include/dlt/dlt_log.h +++ b/include/dlt/dlt_log.h @@ -30,13 +30,13 @@ #include #include "dlt_types.h" -# if defined(__GNUC__) -# define PURE_FUNCTION __attribute__((pure)) -# define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, a, b))) -# else -# define PURE_FUNCTION /* nothing */ -# define PRINTF_FORMAT(a,b) /* nothing */ -# endif +#if defined(__GNUC__) +#define PURE_FUNCTION __attribute__((pure)) +#define PRINTF_FORMAT(a, b) __attribute__((format(printf, a, b))) +#else +#define PURE_FUNCTION /* nothing */ +#define PRINTF_FORMAT(a, b) /* nothing */ +#endif typedef enum { DLT_LOG_TO_CONSOLE = 0, @@ -48,18 +48,17 @@ typedef enum { /* initialize this variables in dlt_log.c */ extern DltLoggingMode logging_mode; -extern FILE *logging_handle; +extern FILE* logging_handle; -# ifdef __cplusplus -extern "C" -{ -# endif +#ifdef __cplusplus +extern "C" { +#endif /** * Set internal logging filename if mode 2 * @param filename the filename */ -void dlt_log_set_filename(const char *filename); +void dlt_log_set_filename(const char* filename); /** * Set internal logging level @@ -80,7 +79,8 @@ DltReturnValue dlt_log_init(int mode); * @param logging_file_size, maximum size in bytes of one logging file * @param logging_files_max_size, maximum size in bytes of all logging files */ -DltReturnValue dlt_log_init_multiple_logfiles_support(DltLoggingMode mode, bool enable_multiple_logfiles, int logging_file_size, int logging_files_max_size); +DltReturnValue dlt_log_init_multiple_logfiles_support( + DltLoggingMode mode, bool enable_multiple_logfiles, int logging_file_size, int logging_files_max_size); /** * Initialize (external) logging facility for single logfile. @@ -97,7 +97,7 @@ DltReturnValue dlt_log_init_multiple_logfiles(int logging_file_size, int logging * @param format format string for message * @return negative value if there was an error or the total number of characters written is returned on success */ -int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1, 2); +int dlt_user_printf(const char* format, ...) PRINTF_FORMAT(1, 2); /** * Log ASCII string with null-termination to (external) logging facility @@ -105,7 +105,7 @@ int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1, 2); * @param s Pointer to ASCII string with null-termination * @return negative value if there was an error */ -DltReturnValue dlt_log(int prio, const char *s); +DltReturnValue dlt_log(int prio, const char* s); /** * Log with variable arguments to (external) logging facility (like printf) @@ -113,7 +113,7 @@ DltReturnValue dlt_log(int prio, const char *s); * @param format format string for log message * @return negative value if there was an error */ -DltReturnValue dlt_vlog(int prio, const char *format, ...) PRINTF_FORMAT(2, 3); +DltReturnValue dlt_vlog(int prio, const char* format, ...) PRINTF_FORMAT(2, 3); /** * Log size bytes with variable arguments to (external) logging facility (similar to snprintf) @@ -122,7 +122,7 @@ DltReturnValue dlt_vlog(int prio, const char *format, ...) PRINTF_FORMAT(2, 3); * @param format format string for log message * @return negative value if there was an error */ -DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) PRINTF_FORMAT(3, 4); +DltReturnValue dlt_vnlog(int prio, size_t size, const char* format, ...) PRINTF_FORMAT(3, 4); /** * Logs into log files represented by the multiple files buffer. @@ -145,8 +145,8 @@ void dlt_log_free_multiple_logfiles(void); */ bool dlt_is_log_in_multiple_files_active(void); -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif #endif /* DLT_COMMON_LOG_H */ diff --git a/include/dlt/dlt_multiple_files.h b/include/dlt/dlt_multiple_files.h index 8ce261fa6..a59374023 100644 --- a/include/dlt/dlt_multiple_files.h +++ b/include/dlt/dlt_multiple_files.h @@ -41,16 +41,15 @@ * File names differ in timestamp or index (depending on chosen mode). * This buffer is used, e.g. for dlt offline traces and the internal dlt logging (dlt.log) */ -typedef struct -{ - char directory[NAME_MAX + 1];/**< (String) Store DLT messages to local directory */ - char filename[NAME_MAX + 1]; /**< (String) Filename of currently used log file */ - int fileSize; /**< (int) Maximum size in bytes of one file, e.g. for offline trace 1000000 as default */ - int maxSize; /**< (int) Maximum size of all files, e.g. for offline trace 4000000 as default */ - bool filenameTimestampBased; /**< (bool) is filename timestamp based? false = index based (Default: true) */ - char filenameBase[NAME_MAX + 1];/**< (String) Prefix of file name */ - char filenameExt[NAME_MAX + 1];/**< (String) Extension of file name */ - int ohandle; /**< (int) file handle to current output file */ +typedef struct { + char directory[NAME_MAX + 1]; /**< (String) Store DLT messages to local directory */ + char filename[NAME_MAX + 1]; /**< (String) Filename of currently used log file */ + int fileSize; /**< (int) Maximum size in bytes of one file, e.g. for offline trace 1000000 as default */ + int maxSize; /**< (int) Maximum size of all files, e.g. for offline trace 4000000 as default */ + bool filenameTimestampBased; /**< (bool) is filename timestamp based? false = index based (Default: true) */ + char filenameBase[NAME_MAX + 1]; /**< (String) Prefix of file name */ + char filenameExt[NAME_MAX + 1]; /**< (String) Extension of file name */ + int ohandle; /**< (int) file handle to current output file */ } MultipleFilesRingBuffer; /** @@ -69,14 +68,9 @@ typedef struct * @param filename_ext File extension. * @return negative value if there was an error. */ -extern DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer, - const char *directory, - int file_size, - int max_size, - bool filename_timestamp_based, - bool append, - const char *filename_base, - const char *filename_ext); +extern DltReturnValue multiple_files_buffer_init( + MultipleFilesRingBuffer* files_buffer, const char* directory, int file_size, int max_size, + bool filename_timestamp_based, bool append, const char* filename_base, const char* filename_ext); /** * Uninitialise the multiple files buffer. @@ -84,8 +78,8 @@ extern DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_ * This function must be called after usage of multiple files. * @param files_buffer pointer to MultipleFilesRingBuffer struct. * @return negative value if there was an error. -*/ -extern DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer *files_buffer); + */ +extern DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer* files_buffer); /** * Write data into multiple files. @@ -97,17 +91,15 @@ extern DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer * * @param size size in bytes of first data block to be written, 0 if not used. * @return negative value if there was an error. */ -extern DltReturnValue multiple_files_buffer_write(MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - int size); +extern DltReturnValue multiple_files_buffer_write( + MultipleFilesRingBuffer* files_buffer, const unsigned char* data, int size); /** * First the limits are verified. Then the oldest file is deleted and a new file is created on demand. * @param files_buffer pointer to MultipleFilesRingBuffer struct. * @param size size in bytes of data that will be written. */ -void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer *files_buffer, - int size); +void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer* files_buffer, int size); /** * Writes the given data to current file specified by corresponding file handle. @@ -115,15 +107,14 @@ void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer *files_buffer, * @param data pointer to data block to be written, null if not used. * @param size size in bytes of given data block to be written, 0 if not used. */ -DltReturnValue multiple_files_buffer_write_chunk(const MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - int size); +DltReturnValue multiple_files_buffer_write_chunk( + const MultipleFilesRingBuffer* files_buffer, const unsigned char* data, int size); /** * Get size of currently used multiple files buffer. * @return size in bytes. */ -extern ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer *files_buffer); +extern ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer* files_buffer); /** * Provides info about the multiple files storage directory. @@ -133,21 +124,21 @@ extern ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffe * @param oldest pointer to store oldest filename * @return num of files in the directory. */ -unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char *file_name, - char *newest, char *oldest); +unsigned int multiple_files_buffer_storage_dir_info( + const char* path, const char* file_name, char* newest, char* oldest); /** * Creates filename with index. * @param files_buffer pointer to MultipleFilesRingBuffer struct. * @param idx index to be used for file name creation. */ -void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, unsigned int idx); +void multiple_files_buffer_file_name(MultipleFilesRingBuffer* files_buffer, unsigned int idx); /** * Generates index for log file name. * @param file filename supplied to create index. * @return the index to be used for log file name. */ -unsigned int multiple_files_buffer_get_idx_of_log_file(char *file); +unsigned int multiple_files_buffer_get_idx_of_log_file(char* file); -#endif // DLT_MULTIPLE_FILES_H +#endif // DLT_MULTIPLE_FILES_H diff --git a/include/dlt/dlt_offline_trace.h b/include/dlt/dlt_offline_trace.h index 68c7adc7b..51dfe7f14 100644 --- a/include/dlt/dlt_offline_trace.h +++ b/include/dlt/dlt_offline_trace.h @@ -61,7 +61,7 @@ #include "dlt_types.h" #define DLT_OFFLINETRACE_FILENAME_BASE "dlt_offlinetrace" -#define DLT_OFFLINETRACE_FILENAME_EXT ".dlt" +#define DLT_OFFLINETRACE_FILENAME_EXT ".dlt" /** * Write data into offline traces. @@ -77,12 +77,8 @@ * @param size3 size in bytes of third data block to be written, 0 if not used. * @return negative value if there was an error. */ -extern DltReturnValue dlt_offline_trace_write(MultipleFilesRingBuffer *trace, - const unsigned char *data1, - int size1, - const unsigned char *data2, - int size2, - const unsigned char *data3, - int size3); +extern DltReturnValue dlt_offline_trace_write( + MultipleFilesRingBuffer* trace, const unsigned char* data1, int size1, const unsigned char* data2, int size2, + const unsigned char* data3, int size3); #endif /* DLT_OFFLINE_TRACE_H */ diff --git a/include/dlt/dlt_protocol.h b/include/dlt/dlt_protocol.h index 277f236c6..02c32e950 100644 --- a/include/dlt/dlt_protocol.h +++ b/include/dlt/dlt_protocol.h @@ -77,14 +77,14 @@ /* * Definitions of the htyp parameter in standard header. */ -#define DLT_HTYP_UEH 0x01 /**< use extended header */ +#define DLT_HTYP_UEH 0x01 /**< use extended header */ #define DLT_HTYP_MSBF 0x02 /**< MSB first */ #define DLT_HTYP_WEID 0x04 /**< with ECU ID */ #define DLT_HTYP_WSID 0x08 /**< with session ID */ #define DLT_HTYP_WTMS 0x10 /**< with timestamp */ #define DLT_HTYP_VERS 0xe0 /**< version number, 0x1 */ -#define DLT_IS_HTYP_UEH(htyp) ((htyp) & DLT_HTYP_UEH) +#define DLT_IS_HTYP_UEH(htyp) ((htyp) & DLT_HTYP_UEH) #define DLT_IS_HTYP_MSBF(htyp) ((htyp) & DLT_HTYP_MSBF) #define DLT_IS_HTYP_WEID(htyp) ((htyp) & DLT_HTYP_WEID) #define DLT_IS_HTYP_WSID(htyp) ((htyp) & DLT_HTYP_WSID) @@ -102,26 +102,26 @@ #define DLT_MSIN_MSTP_SHIFT 1 /**< shift right offset to get mstp value */ #define DLT_MSIN_MTIN_SHIFT 4 /**< shift right offset to get mtin value */ -#define DLT_IS_MSIN_VERB(msin) ((msin) & DLT_MSIN_VERB) +#define DLT_IS_MSIN_VERB(msin) ((msin) & DLT_MSIN_VERB) #define DLT_GET_MSIN_MSTP(msin) (((msin) & DLT_MSIN_MSTP) >> DLT_MSIN_MSTP_SHIFT) #define DLT_GET_MSIN_MTIN(msin) (((msin) & DLT_MSIN_MTIN) >> DLT_MSIN_MTIN_SHIFT) /* * Definitions of mstp parameter in extended header. */ -#define DLT_TYPE_LOG 0x00 /**< Log message type */ +#define DLT_TYPE_LOG 0x00 /**< Log message type */ #define DLT_TYPE_APP_TRACE 0x01 /**< Application trace message type */ -#define DLT_TYPE_NW_TRACE 0x02 /**< Network trace message type */ -#define DLT_TYPE_CONTROL 0x03 /**< Control message type */ +#define DLT_TYPE_NW_TRACE 0x02 /**< Network trace message type */ +#define DLT_TYPE_CONTROL 0x03 /**< Control message type */ /* * Definitions of msti parameter in extended header. */ -#define DLT_TRACE_VARIABLE 0x01 /**< tracing of a variable */ -#define DLT_TRACE_FUNCTION_IN 0x02 /**< tracing of function calls */ +#define DLT_TRACE_VARIABLE 0x01 /**< tracing of a variable */ +#define DLT_TRACE_FUNCTION_IN 0x02 /**< tracing of function calls */ #define DLT_TRACE_FUNCTION_OUT 0x03 /**< tracing of function return values */ -#define DLT_TRACE_STATE 0x04 /**< tracing of states of a state machine */ -#define DLT_TRACE_VFB 0x05 /**< tracing of virtual function bus */ +#define DLT_TRACE_STATE 0x04 /**< tracing of states of a state machine */ +#define DLT_TRACE_VFB 0x05 /**< tracing of virtual function bus */ /* * Definitions of msbi parameter in extended header. @@ -132,38 +132,37 @@ /* * Definitions of msci parameter in extended header. */ -#define DLT_CONTROL_REQUEST 0x01 /**< Request message */ -#define DLT_CONTROL_RESPONSE 0x02 /**< Response to request message */ -#define DLT_CONTROL_TIME 0x03 /**< keep-alive message */ +#define DLT_CONTROL_REQUEST 0x01 /**< Request message */ +#define DLT_CONTROL_RESPONSE 0x02 /**< Response to request message */ +#define DLT_CONTROL_TIME 0x03 /**< keep-alive message */ -#define DLT_MSIN_CONTROL_REQUEST ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | \ - (DLT_CONTROL_REQUEST << DLT_MSIN_MTIN_SHIFT)) -#define DLT_MSIN_CONTROL_RESPONSE ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | \ - (DLT_CONTROL_RESPONSE << DLT_MSIN_MTIN_SHIFT)) -#define DLT_MSIN_CONTROL_TIME ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | \ - (DLT_CONTROL_TIME << DLT_MSIN_MTIN_SHIFT)) +#define DLT_MSIN_CONTROL_REQUEST \ + ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | (DLT_CONTROL_REQUEST << DLT_MSIN_MTIN_SHIFT)) +#define DLT_MSIN_CONTROL_RESPONSE \ + ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | (DLT_CONTROL_RESPONSE << DLT_MSIN_MTIN_SHIFT)) +#define DLT_MSIN_CONTROL_TIME ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | (DLT_CONTROL_TIME << DLT_MSIN_MTIN_SHIFT)) /* * Definitions of the htyp2 parameter in base header. */ -#define DLT_HTYP2_WEID 0x04 /**< with ECU ID */ -#define DLT_HTYP2_WACID 0x08 /**< with application and context ID */ -#define DLT_HTYP2_WSID 0x10 /**< with session ID */ -#define DLT_HTYP2_VERS 0xe0 /**< version number, 0x2 */ -#define DLT_HTYP2_WSFLN 0x100 /**< with source filename and line number */ -#define DLT_HTYP2_WTGS 0x200 /**< with tags */ -#define DLT_HTYP2_WPVL 0x400 /**< with privacy level */ -#define DLT_HTYP2_WSGM 0x800 /**< with segmentation */ -#define DLT_HTYP2_EH 0xF1C /**< Extended header flags */ - -#define DLT_IS_HTYP2_WEID(htyp2) ((htyp2) & DLT_HTYP2_WEID) +#define DLT_HTYP2_WEID 0x04 /**< with ECU ID */ +#define DLT_HTYP2_WACID 0x08 /**< with application and context ID */ +#define DLT_HTYP2_WSID 0x10 /**< with session ID */ +#define DLT_HTYP2_VERS 0xe0 /**< version number, 0x2 */ +#define DLT_HTYP2_WSFLN 0x100 /**< with source filename and line number */ +#define DLT_HTYP2_WTGS 0x200 /**< with tags */ +#define DLT_HTYP2_WPVL 0x400 /**< with privacy level */ +#define DLT_HTYP2_WSGM 0x800 /**< with segmentation */ +#define DLT_HTYP2_EH 0xF1C /**< Extended header flags */ + +#define DLT_IS_HTYP2_WEID(htyp2) ((htyp2) & DLT_HTYP2_WEID) #define DLT_IS_HTYP2_WACID(htyp2) ((htyp2) & DLT_HTYP2_WACID) -#define DLT_IS_HTYP2_WSID(htyp2) ((htyp2) & DLT_HTYP2_WSID) +#define DLT_IS_HTYP2_WSID(htyp2) ((htyp2) & DLT_HTYP2_WSID) #define DLT_IS_HTYP2_WSFLN(htyp2) ((htyp2) & DLT_HTYP2_WSFLN) -#define DLT_IS_HTYP2_WTGS(htyp2) ((htyp2) & DLT_HTYP2_WTGS) -#define DLT_IS_HTYP2_WPVL(htyp2) ((htyp2) & DLT_HTYP2_WPVL) -#define DLT_IS_HTYP2_WSGM(htyp2) ((htyp2) & DLT_HTYP2_WSGM) -#define DLT_IS_HTYP2_EH(htyp2) ((htyp2) & DLT_HTYP2_EH) +#define DLT_IS_HTYP2_WTGS(htyp2) ((htyp2) & DLT_HTYP2_WTGS) +#define DLT_IS_HTYP2_WPVL(htyp2) ((htyp2) & DLT_HTYP2_WPVL) +#define DLT_IS_HTYP2_WSGM(htyp2) ((htyp2) & DLT_HTYP2_WSGM) +#define DLT_IS_HTYP2_EH(htyp2) ((htyp2) & DLT_HTYP2_EH) #define DLT_HTYP2_PROTOCOL_VERSION2 (2 << 5) @@ -176,7 +175,8 @@ typedef enum { /* * Definitions of types of arguments in payload. */ -#define DLT_TYPE_INFO_TYLE 0x0000000f /**< Length of standard data: 1 = 8bit, 2 = 16bit, 3 = 32 bit, 4 = 64 bit, 5 = 128 bit */ +#define DLT_TYPE_INFO_TYLE \ + 0x0000000f /**< Length of standard data: 1 = 8bit, 2 = 16bit, 3 = 32 bit, 4 = 64 bit, 5 = 128 bit */ #define DLT_TYPE_INFO_BOOL 0x00000010 /**< Boolean data */ #define DLT_TYPE_INFO_SINT 0x00000020 /**< Signed integer data */ #define DLT_TYPE_INFO_UINT 0x00000040 /**< Unsigned integer data */ @@ -190,16 +190,16 @@ typedef enum { #define DLT_TYPE_INFO_STRU 0x00004000 /**< Struct */ #define DLT_TYPE_INFO_SCOD 0x00038000 /**< coding of the type string: 0 = ASCII, 1 = UTF-8 */ -#define DLT_TYLE_8BIT 0x00000001 -#define DLT_TYLE_16BIT 0x00000002 -#define DLT_TYLE_32BIT 0x00000003 -#define DLT_TYLE_64BIT 0x00000004 -#define DLT_TYLE_128BIT 0x00000005 +#define DLT_TYLE_8BIT 0x00000001 +#define DLT_TYLE_16BIT 0x00000002 +#define DLT_TYLE_32BIT 0x00000003 +#define DLT_TYLE_64BIT 0x00000004 +#define DLT_TYLE_128BIT 0x00000005 -#define DLT_SCOD_ASCII 0x00000000 -#define DLT_SCOD_UTF8 0x00008000 -#define DLT_SCOD_HEX 0x00010000 -#define DLT_SCOD_BIN 0x00018000 +#define DLT_SCOD_ASCII 0x00000000 +#define DLT_SCOD_UTF8 0x00008000 +#define DLT_SCOD_HEX 0x00010000 +#define DLT_SCOD_BIN 0x00018000 /* * Definitions of DLT services. @@ -250,26 +250,26 @@ enum dlt_user_services { }; /* Need to be adapted if another service is added */ -extern const char *const dlt_service_names[]; -extern const char *const dlt_user_service_names[]; +extern const char* const dlt_service_names[]; +extern const char* const dlt_user_service_names[]; -extern const char *dlt_get_service_name(unsigned int id); +extern const char* dlt_get_service_name(unsigned int id); /* * Definitions of DLT service response status */ -#define DLT_SERVICE_RESPONSE_OK 0x00 /**< Control message response: OK */ +#define DLT_SERVICE_RESPONSE_OK 0x00 /**< Control message response: OK */ #define DLT_SERVICE_RESPONSE_NOT_SUPPORTED 0x01 /**< Control message response: Not supported */ -#define DLT_SERVICE_RESPONSE_ERROR 0x02 /**< Control message response: Error */ -#define DLT_SERVICE_RESPONSE_PERM_DENIED 0x03 /**< Control message response: Permission denied */ -#define DLT_SERVICE_RESPONSE_WARNING 0x04 /**< Control message response: warning */ -#define DLT_SERVICE_RESPONSE_LAST 0x05 /**< Used as max value */ +#define DLT_SERVICE_RESPONSE_ERROR 0x02 /**< Control message response: Error */ +#define DLT_SERVICE_RESPONSE_PERM_DENIED 0x03 /**< Control message response: Permission denied */ +#define DLT_SERVICE_RESPONSE_WARNING 0x04 /**< Control message response: warning */ +#define DLT_SERVICE_RESPONSE_LAST 0x05 /**< Used as max value */ /* * Definitions of DLT service connection state */ #define DLT_CONNECTION_STATUS_DISCONNECTED 0x01 /**< Client is disconnected */ -#define DLT_CONNECTION_STATUS_CONNECTED 0x02 /**< Client is connected */ +#define DLT_CONNECTION_STATUS_CONNECTED 0x02 /**< Client is connected */ /* * Definitions of DLT GET_LOG_INFO status diff --git a/include/dlt/dlt_shm.h b/include/dlt/dlt_shm.h index 7bd54a7c7..cf7eb7a69 100644 --- a/include/dlt/dlt_shm.h +++ b/include/dlt/dlt_shm.h @@ -63,17 +63,15 @@ * size is extended during creation to fit segment size. * client retrieves real size from file descriptor of shared memory. */ -#define DLT_SHM_SIZE 100000 +#define DLT_SHM_SIZE 100000 -typedef struct -{ - int shmfd; /* file descriptor of shared memory */ - sem_t *sem; /* pointer to semaphore */ +typedef struct { + int shmfd; /* file descriptor of shared memory */ + sem_t* sem; /* pointer to semaphore */ DltBuffer buffer; } DltShm; -typedef struct -{ +typedef struct { char head[4]; unsigned char status; int size; @@ -89,7 +87,7 @@ typedef struct * @param name the name of the shm, must be the same for server and client * @return negative value if there was an error */ -extern DltReturnValue dlt_shm_init_client(DltShm *buf, const char *name); +extern DltReturnValue dlt_shm_init_client(DltShm* buf, const char* name); /** * Initialise the shared memory on the server side. @@ -99,7 +97,7 @@ extern DltReturnValue dlt_shm_init_client(DltShm *buf, const char *name); * @param size the requested size of the shm * @return negative value if there was an error */ -extern DltReturnValue dlt_shm_init_server(DltShm *buf, const char *name, int size); +extern DltReturnValue dlt_shm_init_server(DltShm* buf, const char* name, int size); /** * Push data from client onto the shm. @@ -112,13 +110,9 @@ extern DltReturnValue dlt_shm_init_server(DltShm *buf, const char *name, int siz * @param size3 size in bytes of third data block to be written, 0 if not used * @return negative value if there was an error */ -extern int dlt_shm_push(DltShm *buf, - const unsigned char *data1, - unsigned int size1, - const unsigned char *data2, - unsigned int size2, - const unsigned char *data3, - unsigned int size3); +extern int dlt_shm_push( + DltShm* buf, const unsigned char* data1, unsigned int size1, const unsigned char* data2, unsigned int size2, + const unsigned char* data3, unsigned int size3); /** * Pull data from shm. @@ -129,7 +123,7 @@ extern int dlt_shm_push(DltShm *buf, * @param size maximum size to be written into buffer * @return negative value if there was an error */ -extern int dlt_shm_pull(DltShm *buf, unsigned char *data, int size); +extern int dlt_shm_pull(DltShm* buf, unsigned char* data, int size); /** * Copy message from shm. @@ -140,7 +134,7 @@ extern int dlt_shm_pull(DltShm *buf, unsigned char *data, int size); * @param size maximum size to be written into buffer * @return negative value if there was an error */ -extern int dlt_shm_copy(DltShm *buf, unsigned char *data, int size); +extern int dlt_shm_copy(DltShm* buf, unsigned char* data, int size); /** * Delete message from shm. @@ -149,61 +143,61 @@ extern int dlt_shm_copy(DltShm *buf, unsigned char *data, int size); * @param buf pointer to shm structure * @return negative value if there was an error */ -extern int dlt_shm_remove(DltShm *buf); +extern int dlt_shm_remove(DltShm* buf); /** * Print information about shm. * @param buf pointer to shm structure */ -extern void dlt_shm_info(DltShm *buf); +extern void dlt_shm_info(DltShm* buf); /** * Print status about shm. * @param buf pointer to shm structure */ -extern void dlt_shm_status(DltShm *buf); +extern void dlt_shm_status(DltShm* buf); /** * Deinitialise the shared memory on the client side. * @param buf pointer to shm structure * @return negative value if there was an error */ -extern DltReturnValue dlt_shm_free_client(DltShm *buf); +extern DltReturnValue dlt_shm_free_client(DltShm* buf); /** * Returns the total size of the shm. * @param buf pointer to shm structure * @return size of the shared memory. */ -extern int dlt_shm_get_total_size(DltShm *buf); +extern int dlt_shm_get_total_size(DltShm* buf); /** * Returns the used size in the shm. * @param buf pointer to shm structure * @return size of the shared memory. */ -extern int dlt_shm_get_used_size(DltShm *buf); +extern int dlt_shm_get_used_size(DltShm* buf); /** * Returns the number of messages in the shm. * @param buf pointer to shm structure * @return size of the shared memory. */ -extern int dlt_shm_get_message_count(DltShm *buf); +extern int dlt_shm_get_message_count(DltShm* buf); /** * Reset pointers and counters when shm corrupted. * @param buf pointer to shm structure * @return size of the shared memory. */ -extern int dlt_shm_reset(DltShm *buf); +extern int dlt_shm_reset(DltShm* buf); /** * Recover to find next valid message. * @param buf pointer to shm structure * @return size of the shared memory. */ -extern int dlt_shm_recover(DltShm *buf); +extern int dlt_shm_recover(DltShm* buf); /** * Deinitialise the shared memory on the server side. @@ -211,6 +205,6 @@ extern int dlt_shm_recover(DltShm *buf); * @param name name of the shared memory * @return negative value if there was an error */ -extern DltReturnValue dlt_shm_free_server(DltShm *buf, const char *name); +extern DltReturnValue dlt_shm_free_server(DltShm* buf, const char* name); #endif /* DLT_SHM_H */ diff --git a/include/dlt/dlt_types.h b/include/dlt/dlt_types.h index a60fd3f22..5ceaa62eb 100644 --- a/include/dlt/dlt_types.h +++ b/include/dlt/dlt_types.h @@ -71,18 +71,17 @@ typedef unsigned __int8 uint8_t; typedef int pid_t; typedef unsigned int speed_t; -# define UINT16_MAX 0xFFFF +#define UINT16_MAX 0xFFFF -# include +#include #else -# include +#include #endif /** * Definitions of DLT return values */ -typedef enum -{ +typedef enum { #ifdef DLT_TRACE_LOAD_CTRL_ENABLE DLT_RETURN_LOAD_EXCEEDED = -9, #endif @@ -101,55 +100,51 @@ typedef enum /** * 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 */ - DLT_LOG_MAX /**< maximum value, used for range check */ +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 */ + DLT_LOG_MAX /**< maximum value, used for range check */ } DltLogLevelType; /** * Definitions of DLT Format */ -typedef enum -{ - DLT_FORMAT_DEFAULT = 0x00, /**< no sepecial format */ - DLT_FORMAT_HEX8 = 0x01, /**< Hex 8 */ - DLT_FORMAT_HEX16 = 0x02, /**< Hex 16 */ - DLT_FORMAT_HEX32 = 0x03, /**< Hex 32 */ - DLT_FORMAT_HEX64 = 0x04, /**< Hex 64 */ - DLT_FORMAT_BIN8 = 0x05, /**< Binary 8 */ - DLT_FORMAT_BIN16 = 0x06, /**< Binary 16 */ - DLT_FORMAT_MAX /**< maximum value, used for range check */ +typedef enum { + DLT_FORMAT_DEFAULT = 0x00, /**< no sepecial format */ + DLT_FORMAT_HEX8 = 0x01, /**< Hex 8 */ + DLT_FORMAT_HEX16 = 0x02, /**< Hex 16 */ + DLT_FORMAT_HEX32 = 0x03, /**< Hex 32 */ + DLT_FORMAT_HEX64 = 0x04, /**< Hex 64 */ + DLT_FORMAT_BIN8 = 0x05, /**< Binary 8 */ + DLT_FORMAT_BIN16 = 0x06, /**< Binary 16 */ + DLT_FORMAT_MAX /**< maximum value, used for range check */ } DltFormatType; /** * Definitions 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 */ - DLT_TRACE_STATUS_MAX /**< maximum value, used for range check */ +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 */ + DLT_TRACE_STATUS_MAX /**< maximum value, used for range check */ } DltTraceStatusType; /** * Definitions for dlt_user_trace_network/DLT_TRACE_NETWORK() * as defined in the DLT protocol */ -typedef enum -{ - DLT_NW_TRACE_IPC = 0x01, /**< Interprocess communication */ - DLT_NW_TRACE_CAN = 0x02, /**< Controller Area Network Bus */ - DLT_NW_TRACE_FLEXRAY = 0x03, /**< Flexray Bus */ - DLT_NW_TRACE_MOST = 0x04, /**< Media Oriented System Transport Bus */ +typedef enum { + DLT_NW_TRACE_IPC = 0x01, /**< Interprocess communication */ + DLT_NW_TRACE_CAN = 0x02, /**< Controller Area Network Bus */ + DLT_NW_TRACE_FLEXRAY = 0x03, /**< Flexray Bus */ + DLT_NW_TRACE_MOST = 0x04, /**< Media Oriented System Transport Bus */ DLT_NW_TRACE_RESERVED0 = 0x05, DLT_NW_TRACE_RESERVED1 = 0x06, DLT_NW_TRACE_RESERVED2 = 0x07, @@ -160,29 +155,28 @@ typedef enum DLT_NW_TRACE_USER_DEFINED4 = 0x0C, DLT_NW_TRACE_USER_DEFINED5 = 0x0D, DLT_NW_TRACE_USER_DEFINED6 = 0x0E, - DLT_NW_TRACE_RESEND = 0x0F, /**< Mark a resend */ - DLT_NW_TRACE_MAX /**< maximum value, used for range check */ + DLT_NW_TRACE_RESEND = 0x0F, /**< Mark a resend */ + DLT_NW_TRACE_MAX /**< maximum value, used for range check */ } DltNetworkTraceType; /** * This are the log modes. */ -typedef enum -{ +typedef enum { DLT_USER_MODE_UNDEFINED = -1, DLT_USER_MODE_OFF = 0, DLT_USER_MODE_EXTERNAL, DLT_USER_MODE_INTERNAL, DLT_USER_MODE_BOTH, - DLT_USER_MODE_MAX /**< maximum value, used for range check */ + DLT_USER_MODE_MAX /**< maximum value, used for range check */ } DltUserLogMode; /** * Definition of Maintain Logstorage Loglevel modes */ #define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF -1 -#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF 0 -#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON 1 +#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF 0 +#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON 1 typedef float float32_t; typedef double float64_t; @@ -191,21 +185,12 @@ typedef double float64_t; /** * Definition Library connection state */ -typedef enum -{ - DLT_USER_NOT_CONNECTED = 0, - DLT_USER_CONNECTED, - DLT_USER_RETRY_CONNECT -} DltUserConnectionState; +typedef enum { DLT_USER_NOT_CONNECTED = 0, DLT_USER_CONNECTED, DLT_USER_RETRY_CONNECT } DltUserConnectionState; #endif /** * Definition of timestamp types */ -typedef enum -{ - DLT_AUTO_TIMESTAMP = 0, - DLT_USER_TIMESTAMP -} DltTimestampType; +typedef enum { DLT_AUTO_TIMESTAMP = 0, DLT_USER_TIMESTAMP } DltTimestampType; -#endif /* DLT_TYPES_H */ +#endif /* DLT_TYPES_H */ diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index 36c4bd193..bbe413840 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -80,8 +80,8 @@ */ /************************************************************************************************** -* The folowing macros define a macro interface for DLT -**************************************************************************************************/ + * The folowing macros define a macro interface for DLT + **************************************************************************************************/ /** * Create an object for a new context. @@ -91,8 +91,7 @@ * remove the semicolon when using the macro. * Example: DLT_DECLARE_CONTEXT(hContext) */ -#define DLT_DECLARE_CONTEXT(CONTEXT) \ - DltContext CONTEXT; +#define DLT_DECLARE_CONTEXT(CONTEXT) DltContext CONTEXT; /** * Use an object of a new context created in another module. @@ -102,65 +101,80 @@ * remove the semicolon when using the macro. * Example: DLT_IMPORT_CONTEXT(hContext) */ -#define DLT_IMPORT_CONTEXT(CONTEXT) \ - extern DltContext CONTEXT; +#define DLT_IMPORT_CONTEXT(CONTEXT) extern DltContext CONTEXT; /** * Register application. * @param APPID application id with maximal four characters * @param DESCRIPTION ASCII string containing description */ -#define DLT_REGISTER_APP(APPID, DESCRIPTION) do { \ - (void)dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION); \ - (void)dlt_register_app(APPID, DESCRIPTION); } while(false) +#define DLT_REGISTER_APP(APPID, DESCRIPTION) \ + do { \ + (void)dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION); \ + (void)dlt_register_app(APPID, DESCRIPTION); \ + } while (false) /** * DLTv2 Register application. * @param APPID application id * @param DESCRIPTION ASCII string containing description */ -#define DLT_REGISTER_APP_V2(APPID, DESCRIPTION) do { \ - (void)dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION); \ - (void)dlt_register_app_v2(APPID, DESCRIPTION); } while(false) +#define DLT_REGISTER_APP_V2(APPID, DESCRIPTION) \ + do { \ + (void)dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION); \ + (void)dlt_register_app_v2(APPID, DESCRIPTION); \ + } while (false) /** * Unregister application. */ -#define DLT_UNREGISTER_APP() do { \ - (void)dlt_unregister_app(); } while(false) +#define DLT_UNREGISTER_APP() \ + do { \ + (void)dlt_unregister_app(); \ + } while (false) /** * DLTv2 Unregister application. */ -#define DLT_UNREGISTER_APP_V2() do { \ - (void)dlt_unregister_app_v2(); } while(false) +#define DLT_UNREGISTER_APP_V2() \ + do { \ + (void)dlt_unregister_app_v2(); \ + } while (false) /** * Unregister application and flush the logs buffered in startup buffer if any. */ -#define DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS() do { \ - (void)dlt_unregister_app_flush_buffered_logs(); } while(false) +#define DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS() \ + do { \ + (void)dlt_unregister_app_flush_buffered_logs(); \ + } while (false) /** * DLTv2 Unregister application and flush the logs buffered in startup buffer if any. */ -#define DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS_V2() do { \ - (void)dlt_unregister_app_flush_buffered_logs_v2(); } while(false) +#define DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS_V2() \ + do { \ + (void)dlt_unregister_app_flush_buffered_logs_v2(); \ + } while (false) /** * To Get application ID. * @Param APPID character pointer of minimum 4 bytes */ -#define DLT_GET_APPID(APPID) do{\ - dlt_get_appid(APPID);} while(false) +#define DLT_GET_APPID(APPID) \ + do { \ + dlt_get_appid(APPID); \ + } while (false) /** * DLTv2 To Get application ID. * @Param APPID character pointer */ -#define DLT_GET_APPID_V2(APPID) do{\ - dlt_get_appid_v2(&APPID);} while(false) +#define DLT_GET_APPID_V2(APPID) \ + do { \ + dlt_get_appid_v2(&APPID); \ + } while (false) /** * Register context (with default log level and default trace status) @@ -168,8 +182,10 @@ * @param CONTEXTID context id with maximal four characters * @param DESCRIPTION ASCII string containing description */ -#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION) do { \ - (void)dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION); } while (false) +#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION) \ + do { \ + (void)dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION); \ + } while (false) /** * DLTv2 Register context (with default log level and default trace status) @@ -177,8 +193,10 @@ * @param CONTEXTID context id * @param DESCRIPTION ASCII string containing description */ -#define DLT_REGISTER_CONTEXT_V2(CONTEXT, CONTEXTID, DESCRIPTION) do { \ - (void)dlt_register_context_v2(&(CONTEXT), CONTEXTID, DESCRIPTION); } while (false) +#define DLT_REGISTER_CONTEXT_V2(CONTEXT, CONTEXTID, DESCRIPTION) \ + do { \ + (void)dlt_register_context_v2(&(CONTEXT), CONTEXTID, DESCRIPTION); \ + } while (false) /** * Register context with pre-defined log level and pre-defined trace status. @@ -190,8 +208,10 @@ * @param TRACESTATUS trace status to be pre-set for this context * (DLT_TRACE_STATUS_DEFAULT is not allowed here) */ -#define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT, CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS) do { \ - (void)dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); } while (false) +#define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT, CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS) \ + do { \ + (void)dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); \ + } while (false) /** * DLTv2 Register context with pre-defined log level and pre-defined trace status. @@ -203,8 +223,10 @@ * @param TRACESTATUS trace status to be pre-set for this context * (DLT_TRACE_STATUS_DEFAULT is not allowed here) */ -#define DLT_REGISTER_CONTEXT_LL_TS_V2(CONTEXT, CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS) do { \ - (void)dlt_register_context_ll_ts_v2(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); } while (false) +#define DLT_REGISTER_CONTEXT_LL_TS_V2(CONTEXT, CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS) \ + do { \ + (void)dlt_register_context_ll_ts_v2(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); \ + } while (false) /** * Register context (with default log level and default trace status and log level change callback) @@ -213,8 +235,10 @@ * @param DESCRIPTION ASCII string containing description * @param CBK log level change callback to be registered */ -#define DLT_REGISTER_CONTEXT_LLCCB(CONTEXT, CONTEXTID, DESCRIPTION, CBK) do { \ - (void)dlt_register_context_llccb(&(CONTEXT), CONTEXTID, DESCRIPTION, CBK); } while(false) +#define DLT_REGISTER_CONTEXT_LLCCB(CONTEXT, CONTEXTID, DESCRIPTION, CBK) \ + do { \ + (void)dlt_register_context_llccb(&(CONTEXT), CONTEXTID, DESCRIPTION, CBK); \ + } while (false) /** * DLTv2 Register context (with default log level and default trace status and log level change callback) @@ -223,22 +247,28 @@ * @param DESCRIPTION ASCII string containing description * @param CBK log level change callback to be registered */ -#define DLT_REGISTER_CONTEXT_LLCCB_V2(CONTEXT, CONTEXTID, DESCRIPTION, CBK) do { \ - (void)dlt_register_context_llccb_v2(&(CONTEXT), CONTEXTID, DESCRIPTION, CBK); } while(false) +#define DLT_REGISTER_CONTEXT_LLCCB_V2(CONTEXT, CONTEXTID, DESCRIPTION, CBK) \ + do { \ + (void)dlt_register_context_llccb_v2(&(CONTEXT), CONTEXTID, DESCRIPTION, CBK); \ + } while (false) /** * Unregister context. * @param CONTEXT object containing information about one special logging context */ -#define DLT_UNREGISTER_CONTEXT(CONTEXT) do { \ - (void)dlt_unregister_context(&(CONTEXT)); } while(false) +#define DLT_UNREGISTER_CONTEXT(CONTEXT) \ + do { \ + (void)dlt_unregister_context(&(CONTEXT)); \ + } while (false) /** * DLTv2 Unregister context. * @param CONTEXT object containing information about one special logging context */ -#define DLT_UNREGISTER_CONTEXT_V2(CONTEXT) do { \ - (void)dlt_unregister_context_v2(&(CONTEXT)); } while(false) +#define DLT_UNREGISTER_CONTEXT_V2(CONTEXT) \ + do { \ + (void)dlt_unregister_context_v2(&(CONTEXT)); \ + } while (false) /** * Register callback function called when injection message was received @@ -246,8 +276,10 @@ * @param SERVICEID service id of the injection message * @param CALLBACK function pointer to callback function */ -#define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) do { \ - (void)dlt_register_injection_callback(&(CONTEXT), SERVICEID, CALLBACK); } while(false) +#define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) \ + do { \ + (void)dlt_register_injection_callback(&(CONTEXT), SERVICEID, CALLBACK); \ + } while (false) /** * Register callback function called when injection message was received @@ -256,24 +288,30 @@ * @param CALLBACK function pointer to callback function * @param PRIV_DATA data specific to context */ -#define DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(CONTEXT, SERVICEID, CALLBACK, PRIV_DATA) do { \ - (void)dlt_register_injection_callback_with_id(&(CONTEXT), SERVICEID, CALLBACK, PRIV_DATA); } while(false) +#define DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(CONTEXT, SERVICEID, CALLBACK, PRIV_DATA) \ + do { \ + (void)dlt_register_injection_callback_with_id(&(CONTEXT), SERVICEID, CALLBACK, PRIV_DATA); \ + } while (false) /** * Register callback function called when log level of context was changed * @param CONTEXT object containing information about one special logging context * @param CALLBACK function pointer to callback function */ -#define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(CONTEXT, CALLBACK) do { \ - (void)dlt_register_log_level_changed_callback(&(CONTEXT), CALLBACK); } while(false) +#define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(CONTEXT, CALLBACK) \ + do { \ + (void)dlt_register_log_level_changed_callback(&(CONTEXT), CALLBACK); \ + } while (false) /** * DLTv2 Register callback function called when log level of context was changed * @param CONTEXT object containing information about one special logging context * @param CALLBACK function pointer to callback function */ -#define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK_V2(CONTEXT, CALLBACK) do { \ - (void)dlt_register_log_level_changed_callback_v2(&(CONTEXT), CALLBACK); } while(false) +#define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK_V2(CONTEXT, CALLBACK) \ + do { \ + (void)dlt_register_log_level_changed_callback_v2(&(CONTEXT), CALLBACK); \ + } while (false) /** * Send log message with variable list of messages (intended for verbose mode) @@ -288,16 +326,15 @@ /* DLT_LOG is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG(CONTEXT, LOGLEVEL, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ +#define DLT_LOG(CONTEXT, LOGLEVEL, ...) \ + do { \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ + if (dlt_local == DLT_RETURN_TRUE) { \ + __VA_ARGS__; \ + (void)dlt_user_log_write_finish(&log_local); \ + } \ } while (false) #endif @@ -314,16 +351,15 @@ /* DLT_LOG_V2 is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG_V2(CONTEXT, LOGLEVEL, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - (void)dlt_user_log_write_finish_v2(&log_local); \ - } \ +#define DLT_LOG_V2(CONTEXT, LOGLEVEL, ...) \ + do { \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ + if (dlt_local == DLT_RETURN_TRUE) { \ + __VA_ARGS__; \ + (void)dlt_user_log_write_finish_v2(&log_local); \ + } \ } while (false) #endif @@ -341,18 +377,17 @@ /* DLT_LOG_TS is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG_TS(CONTEXT, LOGLEVEL, TS, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - log_local.use_timestamp = DLT_USER_TIMESTAMP; \ - log_local.user_timestamp = (uint32_t) TS; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ +#define DLT_LOG_TS(CONTEXT, LOGLEVEL, TS, ...) \ + do { \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \ + if (dlt_local == DLT_RETURN_TRUE) { \ + __VA_ARGS__; \ + log_local.use_timestamp = DLT_USER_TIMESTAMP; \ + log_local.user_timestamp = (uint32_t)TS; \ + (void)dlt_user_log_write_finish(&log_local); \ + } \ } while (false) #endif @@ -372,17 +407,16 @@ /* DLT_LOG_ID is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ - } while(false) +#define DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ...) \ + do { \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \ + if (dlt_local == DLT_RETURN_TRUE) { \ + __VA_ARGS__; \ + (void)dlt_user_log_write_finish(&log_local); \ + } \ + } while (false) #endif /** @@ -402,19 +436,18 @@ /* DLT_LOG_ID_TS is not supported by MS Visual C++ */ /* use function interface instead */ #else -# define DLT_LOG_ID_TS(CONTEXT, LOGLEVEL, MSGID, TS, ...) \ - do { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \ - if (dlt_local == DLT_RETURN_TRUE) \ - { \ - __VA_ARGS__; \ - log_local.use_timestamp = DLT_USER_TIMESTAMP; \ - log_local.user_timestamp = (uint32_t) TS; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ - } while(false) +#define DLT_LOG_ID_TS(CONTEXT, LOGLEVEL, MSGID, TS, ...) \ + do { \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \ + if (dlt_local == DLT_RETURN_TRUE) { \ + __VA_ARGS__; \ + log_local.use_timestamp = DLT_USER_TIMESTAMP; \ + log_local.user_timestamp = (uint32_t)TS; \ + (void)dlt_user_log_write_finish(&log_local); \ + } \ + } while (false) #endif /** @@ -422,29 +455,25 @@ * @param FILENAME filename string * @param LINR int line number */ -#define DLT_WITH_FILENAME_LINENUMBER(FILENAME, LINR) \ - (void)dlt_with_filename_and_line_number(FILENAME, LINR) +#define DLT_WITH_FILENAME_LINENUMBER(FILENAME, LINR) (void)dlt_with_filename_and_line_number(FILENAME, LINR) /** * Send log with tags * @param Tag list of string tags, minimum 1 tag to be provided */ -#define DLT_WITH_TAGS(TAG, ...) \ - (void)dlt_with_tags(TAG, __VA_ARGS__, NULL) +#define DLT_WITH_TAGS(TAG, ...) (void)dlt_with_tags(TAG, __VA_ARGS__, NULL) /** * Send privacy level in logs * @param prlv uint privacy level */ -#define DLT_WITH_PRIVACYLEVEL(PRLV) \ - (void)dlt_with_prlv(PRLV) +#define DLT_WITH_PRIVACYLEVEL(PRLV) (void)dlt_with_prlv(PRLV) /** * Add string parameter to the log messsage. * @param TEXT ASCII string */ -#define DLT_STRING(TEXT) \ - (void)dlt_user_log_write_string(&log_local, TEXT) +#define DLT_STRING(TEXT) (void)dlt_user_log_write_string(&log_local, TEXT) /** * Add string parameter with given length to the log messsage. @@ -454,15 +483,13 @@ * @param TEXT ASCII string * @param LEN length in bytes to take from @a TEXT */ -#define DLT_SIZED_STRING(TEXT, LEN) \ - (void)dlt_user_log_write_sized_string(&log_local, TEXT, LEN) +#define DLT_SIZED_STRING(TEXT, LEN) (void)dlt_user_log_write_sized_string(&log_local, TEXT, LEN) /** * Add constant string parameter to the log messsage. * @param TEXT Constant ASCII string */ -#define DLT_CSTRING(TEXT) \ - (void)dlt_user_log_write_constant_string(&log_local, TEXT) +#define DLT_CSTRING(TEXT) (void)dlt_user_log_write_constant_string(&log_local, TEXT) /** * Add constant string parameter with given length to the log messsage. @@ -472,15 +499,13 @@ * @param TEXT Constant ASCII string * @param LEN length in bytes to take from @a TEXT */ -#define DLT_SIZED_CSTRING(TEXT, LEN) \ - (void)dlt_user_log_write_sized_constant_string(&log_local, TEXT, LEN) +#define DLT_SIZED_CSTRING(TEXT, LEN) (void)dlt_user_log_write_sized_constant_string(&log_local, TEXT, LEN) /** * Add utf8-encoded string parameter to the log messsage. * @param TEXT UTF8-encoded string */ -#define DLT_UTF8(TEXT) \ - (void)dlt_user_log_write_utf8_string(&log_local, TEXT) +#define DLT_UTF8(TEXT) (void)dlt_user_log_write_utf8_string(&log_local, TEXT) /** * Add utf8-encoded string parameter with given length to the log messsage. @@ -490,15 +515,13 @@ * @param TEXT UTF8-encoded string * @param LEN length in bytes to take from @a TEXT */ -#define DLT_SIZED_UTF8(TEXT, LEN) \ - (void)dlt_user_log_write_sized_utf8_string(&log_local, TEXT, LEN) +#define DLT_SIZED_UTF8(TEXT, LEN) (void)dlt_user_log_write_sized_utf8_string(&log_local, TEXT, LEN) /** * Add constant utf8-encoded string parameter to the log messsage. * @param TEXT Constant UTF8-encoded string */ -#define DLT_CUTF8(TEXT) \ - (void)dlt_user_log_write_constant_utf8_string(&log_local, TEXT) +#define DLT_CUTF8(TEXT) (void)dlt_user_log_write_constant_utf8_string(&log_local, TEXT) /** * Add constant utf8-encoded string parameter with given length to the log messsage. @@ -508,16 +531,14 @@ * @param TEXT Constant UTF8-encoded string * @param LEN length in bytes to take from @a TEXT */ -#define DLT_SIZED_CUTF8(TEXT, LEN) \ - (void)dlt_user_log_write_sized_constant_utf8_string(&log_local, TEXT, LEN) +#define DLT_SIZED_CUTF8(TEXT, LEN) (void)dlt_user_log_write_sized_constant_utf8_string(&log_local, TEXT, LEN) /** * Add string parameter with "name" attribute to the log messsage. * @param TEXT ASCII string * @param NAME "name" attribute */ -#define DLT_STRING_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_string_attr(&log_local, TEXT, NAME) +#define DLT_STRING_ATTR(TEXT, NAME) (void)dlt_user_log_write_string_attr(&log_local, TEXT, NAME) /** * Add string parameter with given length and "name" attribute to the log messsage. @@ -528,16 +549,14 @@ * @param LEN length in bytes to take from @a TEXT * @param NAME "name" attribute */ -#define DLT_SIZED_STRING_ATTR(TEXT, LEN, NAME) \ - (void)dlt_user_log_write_sized_string_attr(&log_local, TEXT, LEN, NAME) +#define DLT_SIZED_STRING_ATTR(TEXT, LEN, NAME) (void)dlt_user_log_write_sized_string_attr(&log_local, TEXT, LEN, NAME) /** * Add constant string parameter with "name" attribute to the log messsage. * @param TEXT Constant ASCII string * @param NAME "name" attribute */ -#define DLT_CSTRING_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_constant_string_attr(&log_local, TEXT, NAME) +#define DLT_CSTRING_ATTR(TEXT, NAME) (void)dlt_user_log_write_constant_string_attr(&log_local, TEXT, NAME) /** * Add constant string parameter with given length and "name" attribute to the log messsage. @@ -548,7 +567,7 @@ * @param LEN length in bytes to take from @a TEXT * @param NAME "name" attribute */ -#define DLT_SIZED_CSTRING_ATTR(TEXT, LEN, NAME) \ +#define DLT_SIZED_CSTRING_ATTR(TEXT, LEN, NAME) \ (void)dlt_user_log_write_sized_constant_string_attr(&log_local, TEXT, LEN, NAME) /** @@ -556,8 +575,7 @@ * @param TEXT UTF8-encoded string * @param NAME "name" attribute */ -#define DLT_UTF8_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_utf8_string_attr(&log_local, TEXT, NAME) +#define DLT_UTF8_ATTR(TEXT, NAME) (void)dlt_user_log_write_utf8_string_attr(&log_local, TEXT, NAME) /** * Add utf8-encoded string parameter with given length and "name" attribute to the log messsage. @@ -568,7 +586,7 @@ * @param LEN length in bytes to take from @a TEXT * @param NAME "name" attribute */ -#define DLT_SIZED_UTF8_ATTR(TEXT, LEN, NAME) \ +#define DLT_SIZED_UTF8_ATTR(TEXT, LEN, NAME) \ (void)dlt_user_log_write_sized_utf8_string_attr(&log_local, TEXT, LEN, ATTR) /** @@ -576,8 +594,7 @@ * @param TEXT Constant UTF8-encoded string * @param NAME "name" attribute */ -#define DLT_CUTF8_ATTR(TEXT, NAME) \ - (void)dlt_user_log_write_constant_utf8_string_attr(&log_local, TEXT, NAME) +#define DLT_CUTF8_ATTR(TEXT, NAME) (void)dlt_user_log_write_constant_utf8_string_attr(&log_local, TEXT, NAME) /** * Add constant utf8-encoded string parameter with given length and "name" attribute to the log messsage. @@ -588,37 +605,33 @@ * @param LEN length in bytes to take from @a TEXT * @param NAME "name" attribute */ -#define DLT_SIZED_CUTF8_ATTR(TEXT, LEN, NAME) \ +#define DLT_SIZED_CUTF8_ATTR(TEXT, LEN, NAME) \ (void)dlt_user_log_write_sized_constant_utf8_string_attr(&log_local, TEXT, LEN, NAME) /** * Add boolean parameter to the log messsage. * @param BOOL_VAR Boolean value (mapped to uint8) */ -#define DLT_BOOL(BOOL_VAR) \ - (void)dlt_user_log_write_bool(&log_local, BOOL_VAR) +#define DLT_BOOL(BOOL_VAR) (void)dlt_user_log_write_bool(&log_local, BOOL_VAR) /** * Add boolean parameter with "name" attribute to the log messsage. * @param BOOL_VAR Boolean value (mapped to uint8) * @param NAME "name" attribute */ -#define DLT_BOOL_ATTR(BOOL_VAR, NAME) \ - (void)dlt_user_log_write_bool_attr(&log_local, BOOL_VAR, NAME) +#define DLT_BOOL_ATTR(BOOL_VAR, NAME) (void)dlt_user_log_write_bool_attr(&log_local, BOOL_VAR, NAME) /** * Add float32 parameter to the log messsage. * @param FLOAT32_VAR Float32 value (mapped to float) */ -#define DLT_FLOAT32(FLOAT32_VAR) \ - (void)dlt_user_log_write_float32(&log_local, FLOAT32_VAR) +#define DLT_FLOAT32(FLOAT32_VAR) (void)dlt_user_log_write_float32(&log_local, FLOAT32_VAR) /** * Add float64 parameter to the log messsage. * @param FLOAT64_VAR Float64 value (mapped to double) */ -#define DLT_FLOAT64(FLOAT64_VAR) \ - (void)dlt_user_log_write_float64(&log_local, FLOAT64_VAR) +#define DLT_FLOAT64(FLOAT64_VAR) (void)dlt_user_log_write_float64(&log_local, FLOAT64_VAR) /** * Add float32 parameter with attributes to the log messsage. @@ -626,7 +639,7 @@ * @param NAME "name" attribute * @param UNIT "unit" attribute */ -#define DLT_FLOAT32_ATTR(FLOAT32_VAR, NAME, UNIT) \ +#define DLT_FLOAT32_ATTR(FLOAT32_VAR, NAME, UNIT) \ (void)dlt_user_log_write_float32_attr(&log_local, FLOAT32_VAR, NAME, UNIT) /** @@ -635,27 +648,22 @@ * @param NAME "name" attribute * @param UNIT "unit" attribute */ -#define DLT_FLOAT64_ATTR(FLOAT64_VAR, NAME, UNIT) \ +#define DLT_FLOAT64_ATTR(FLOAT64_VAR, NAME, UNIT) \ (void)dlt_user_log_write_float64_attr(&log_local, FLOAT64_VAR, NAME, UNIT) /** * Add integer parameter to the log messsage. * @param INT_VAR integer value */ -#define DLT_INT(INT_VAR) \ - (void)dlt_user_log_write_int(&log_local, INT_VAR) +#define DLT_INT(INT_VAR) (void)dlt_user_log_write_int(&log_local, INT_VAR) -#define DLT_INT8(INT_VAR) \ - (void)dlt_user_log_write_int8(&log_local, INT_VAR) +#define DLT_INT8(INT_VAR) (void)dlt_user_log_write_int8(&log_local, INT_VAR) -#define DLT_INT16(INT_VAR) \ - (void)dlt_user_log_write_int16(&log_local, INT_VAR) +#define DLT_INT16(INT_VAR) (void)dlt_user_log_write_int16(&log_local, INT_VAR) -#define DLT_INT32(INT_VAR) \ - (void)dlt_user_log_write_int32(&log_local, INT_VAR) +#define DLT_INT32(INT_VAR) (void)dlt_user_log_write_int32(&log_local, INT_VAR) -#define DLT_INT64(INT_VAR) \ - (void)dlt_user_log_write_int64(&log_local, INT_VAR) +#define DLT_INT64(INT_VAR) (void)dlt_user_log_write_int64(&log_local, INT_VAR) /** * Add integer parameter with attributes to the log messsage. @@ -663,39 +671,29 @@ * @param NAME "name" attribute * @param UNIT "unit" attribute */ -#define DLT_INT_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int_attr(&log_local, INT_VAR, NAME, UNIT) +#define DLT_INT_ATTR(INT_VAR, NAME, UNIT) (void)dlt_user_log_write_int_attr(&log_local, INT_VAR, NAME, UNIT) -#define DLT_INT8_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int8_attr(&log_local, INT_VAR, NAME, UNIT) +#define DLT_INT8_ATTR(INT_VAR, NAME, UNIT) (void)dlt_user_log_write_int8_attr(&log_local, INT_VAR, NAME, UNIT) -#define DLT_INT16_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int16_attr(&log_local, INT_VAR, NAME, UNIT) +#define DLT_INT16_ATTR(INT_VAR, NAME, UNIT) (void)dlt_user_log_write_int16_attr(&log_local, INT_VAR, NAME, UNIT) -#define DLT_INT32_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int32_attr(&log_local, INT_VAR, NAME, UNIT) +#define DLT_INT32_ATTR(INT_VAR, NAME, UNIT) (void)dlt_user_log_write_int32_attr(&log_local, INT_VAR, NAME, UNIT) -#define DLT_INT64_ATTR(INT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_int64_attr(&log_local, INT_VAR, NAME, UNIT) +#define DLT_INT64_ATTR(INT_VAR, NAME, UNIT) (void)dlt_user_log_write_int64_attr(&log_local, INT_VAR, NAME, UNIT) /** * Add unsigned integer parameter to the log messsage. * @param UINT_VAR unsigned integer value */ -#define DLT_UINT(UINT_VAR) \ - (void)dlt_user_log_write_uint(&log_local, UINT_VAR) +#define DLT_UINT(UINT_VAR) (void)dlt_user_log_write_uint(&log_local, UINT_VAR) -#define DLT_UINT8(UINT_VAR) \ - (void)dlt_user_log_write_uint8(&log_local, UINT_VAR) +#define DLT_UINT8(UINT_VAR) (void)dlt_user_log_write_uint8(&log_local, UINT_VAR) -#define DLT_UINT16(UINT_VAR) \ - (void)dlt_user_log_write_uint16(&log_local, UINT_VAR) +#define DLT_UINT16(UINT_VAR) (void)dlt_user_log_write_uint16(&log_local, UINT_VAR) -#define DLT_UINT32(UINT_VAR) \ - (void)dlt_user_log_write_uint32(&log_local, UINT_VAR) +#define DLT_UINT32(UINT_VAR) (void)dlt_user_log_write_uint32(&log_local, UINT_VAR) -#define DLT_UINT64(UINT_VAR) \ - (void)dlt_user_log_write_uint64(&log_local, UINT_VAR) +#define DLT_UINT64(UINT_VAR) (void)dlt_user_log_write_uint64(&log_local, UINT_VAR) /** * Add unsigned integer parameter with attributes to the log messsage. @@ -703,40 +701,28 @@ * @param NAME "name" attribute * @param UNIT "unit" attribute */ -#define DLT_UINT_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint_attr(&log_local, UINT_VAR, NAME, UNIT) +#define DLT_UINT_ATTR(UINT_VAR, NAME, UNIT) (void)dlt_user_log_write_uint_attr(&log_local, UINT_VAR, NAME, UNIT) -#define DLT_UINT8_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint8_attr(&log_local, UINT_VAR, NAME, UNIT) +#define DLT_UINT8_ATTR(UINT_VAR, NAME, UNIT) (void)dlt_user_log_write_uint8_attr(&log_local, UINT_VAR, NAME, UNIT) -#define DLT_UINT16_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint16_attr(&log_local, UINT_VAR, NAME, UNIT) +#define DLT_UINT16_ATTR(UINT_VAR, NAME, UNIT) (void)dlt_user_log_write_uint16_attr(&log_local, UINT_VAR, NAME, UNIT) -#define DLT_UINT32_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint32_attr(&log_local, UINT_VAR, NAME, UNIT) +#define DLT_UINT32_ATTR(UINT_VAR, NAME, UNIT) (void)dlt_user_log_write_uint32_attr(&log_local, UINT_VAR, NAME, UNIT) -#define DLT_UINT64_ATTR(UINT_VAR, NAME, UNIT) \ - (void)dlt_user_log_write_uint64_attr(&log_local, UINT_VAR, NAME, UNIT) +#define DLT_UINT64_ATTR(UINT_VAR, NAME, UNIT) (void)dlt_user_log_write_uint64_attr(&log_local, UINT_VAR, NAME, UNIT) /** * Add binary memory block to the log messages. * @param BUF pointer to memory block * @param LEN length of memory block */ -#define DLT_RAW(BUF, LEN) \ - (void)dlt_user_log_write_raw(&log_local, BUF, LEN) -#define DLT_HEX8(UINT_VAR) \ - (void)dlt_user_log_write_uint8_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX8) -#define DLT_HEX16(UINT_VAR) \ - (void)dlt_user_log_write_uint16_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX16) -#define DLT_HEX32(UINT_VAR) \ - (void)dlt_user_log_write_uint32_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX32) -#define DLT_HEX64(UINT_VAR) \ - (void)dlt_user_log_write_uint64_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX64) -#define DLT_BIN8(UINT_VAR) \ - (void)dlt_user_log_write_uint8_formatted(&log_local, UINT_VAR, DLT_FORMAT_BIN8) -#define DLT_BIN16(UINT_VAR) \ - (void)dlt_user_log_write_uint16_formatted(&log_local, UINT_VAR, DLT_FORMAT_BIN16) +#define DLT_RAW(BUF, LEN) (void)dlt_user_log_write_raw(&log_local, BUF, LEN) +#define DLT_HEX8(UINT_VAR) (void)dlt_user_log_write_uint8_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX8) +#define DLT_HEX16(UINT_VAR) (void)dlt_user_log_write_uint16_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX16) +#define DLT_HEX32(UINT_VAR) (void)dlt_user_log_write_uint32_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX32) +#define DLT_HEX64(UINT_VAR) (void)dlt_user_log_write_uint64_formatted(&log_local, UINT_VAR, DLT_FORMAT_HEX64) +#define DLT_BIN8(UINT_VAR) (void)dlt_user_log_write_uint8_formatted(&log_local, UINT_VAR, DLT_FORMAT_BIN8) +#define DLT_BIN16(UINT_VAR) (void)dlt_user_log_write_uint16_formatted(&log_local, UINT_VAR, DLT_FORMAT_BIN16) /** * Add binary memory block with "name" attribute to the log messages. @@ -744,14 +730,12 @@ * @param LEN length of memory block * @param NAME "name" attribute */ -#define DLT_RAW_ATTR(BUF, LEN, NAME) \ - (void)dlt_user_log_write_raw_attr(&log_local, BUF, LEN, NAME) +#define DLT_RAW_ATTR(BUF, LEN, NAME) (void)dlt_user_log_write_raw_attr(&log_local, BUF, LEN, NAME) /** * Architecture independent macro to print pointers */ -#define DLT_PTR(PTR_VAR) \ - (void)dlt_user_log_write_ptr(&log_local, PTR_VAR) +#define DLT_PTR(PTR_VAR) (void)dlt_user_log_write_ptr(&log_local, PTR_VAR) /** * Trace network message @@ -762,13 +746,12 @@ * @param PAYLOADLEN length of network message payload * @param PAYLOAD pointer to network message payload */ -#define DLT_TRACE_NETWORK(CONTEXT, TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD) \ - do { \ - if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr) == DLT_TRACE_STATUS_ON) \ - { \ - (void)dlt_user_trace_network(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD); \ - } \ - } while(false) +#define DLT_TRACE_NETWORK(CONTEXT, TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD) \ + do { \ + if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr) == DLT_TRACE_STATUS_ON) { \ + (void)dlt_user_trace_network(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD); \ + } \ + } while (false) /** * Trace network message, allow truncation @@ -779,13 +762,12 @@ * @param PAYLOADLEN length of network message payload * @param PAYLOAD pointer to network message payload */ -#define DLT_TRACE_NETWORK_TRUNCATED(CONTEXT, TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD) \ - do { \ - if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr) == DLT_TRACE_STATUS_ON) \ - { \ - (void)dlt_user_trace_network_truncated(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD, 1); \ - } \ - } while(false) +#define DLT_TRACE_NETWORK_TRUNCATED(CONTEXT, TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD) \ + do { \ + if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr) == DLT_TRACE_STATUS_ON) { \ + (void)dlt_user_trace_network_truncated(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD, 1); \ + } \ + } while (false) /** * Trace network message, segment large messages @@ -796,13 +778,12 @@ * @param PAYLOADLEN length of network message payload * @param PAYLOAD pointer to network message payload */ -#define DLT_TRACE_NETWORK_SEGMENTED(CONTEXT, TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD) \ - do { \ - if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr) == DLT_TRACE_STATUS_ON) \ - { \ - (void)dlt_user_trace_network_segmented(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD); \ - } \ - } while(false) +#define DLT_TRACE_NETWORK_SEGMENTED(CONTEXT, TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD) \ + do { \ + if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr) == DLT_TRACE_STATUS_ON) { \ + (void)dlt_user_trace_network_segmented(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD); \ + } \ + } while (false) /** * Send log message with string parameter. @@ -810,13 +791,12 @@ * @param LOGLEVEL the log level of the log message * @param TEXT ASCII string */ -#define DLT_LOG_STRING(CONTEXT, LOGLEVEL, TEXT) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \ - } \ - } while(false) +#define DLT_LOG_STRING(CONTEXT, LOGLEVEL, TEXT) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \ + } \ + } while (false) /** * DLTv2 Send log message with string parameter. @@ -824,13 +804,12 @@ * @param LOGLEVEL the log level of the log message * @param TEXT ASCII string */ -#define DLT_LOG_STRING_V2(CONTEXT, LOGLEVEL, TEXT) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_string_v2(&(CONTEXT), LOGLEVEL, TEXT); \ - } \ - } while(false) +#define DLT_LOG_STRING_V2(CONTEXT, LOGLEVEL, TEXT) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_string_v2(&(CONTEXT), LOGLEVEL, TEXT); \ + } \ + } while (false) /** * Send log message with string parameter and integer parameter. @@ -839,13 +818,12 @@ * @param TEXT ASCII string * @param INT_VAR integer value */ -#define DLT_LOG_STRING_INT(CONTEXT, LOGLEVEL, TEXT, INT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \ - } \ - } while(false) +#define DLT_LOG_STRING_INT(CONTEXT, LOGLEVEL, TEXT, INT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \ + } \ + } while (false) /** * DLTv2 Send log message with string parameter and integer parameter. @@ -854,13 +832,12 @@ * @param TEXT ASCII string * @param INT_VAR integer value */ -#define DLT_LOG_STRING_INT_V2(CONTEXT, LOGLEVEL, TEXT, INT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_string_int_v2(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \ - } \ - } while(false) +#define DLT_LOG_STRING_INT_V2(CONTEXT, LOGLEVEL, TEXT, INT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_string_int_v2(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \ + } \ + } while (false) /** * Send log message with string parameter and unsigned integer parameter. @@ -869,13 +846,12 @@ * @param TEXT ASCII string * @param UINT_VAR unsigned integer value */ -#define DLT_LOG_STRING_UINT(CONTEXT, LOGLEVEL, TEXT, UINT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_string_uint(&(CONTEXT), LOGLEVEL, TEXT, UINT_VAR); \ - } \ - } while(false) +#define DLT_LOG_STRING_UINT(CONTEXT, LOGLEVEL, TEXT, UINT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_string_uint(&(CONTEXT), LOGLEVEL, TEXT, UINT_VAR); \ + } \ + } while (false) /** * DLTv2 Send log message with string parameter and unsigned integer parameter. @@ -884,13 +860,12 @@ * @param TEXT ASCII string * @param UINT_VAR unsigned integer value */ -#define DLT_LOG_STRING_UINT_V2(CONTEXT, LOGLEVEL, TEXT, UINT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_string_uint_v2(&(CONTEXT), LOGLEVEL, TEXT, UINT_VAR); \ - } \ - } while(false) +#define DLT_LOG_STRING_UINT_V2(CONTEXT, LOGLEVEL, TEXT, UINT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_string_uint_v2(&(CONTEXT), LOGLEVEL, TEXT, UINT_VAR); \ + } \ + } while (false) /** * Send log message with unsigned integer parameter. @@ -898,13 +873,12 @@ * @param LOGLEVEL the log level of the log message * @param UINT_VAR unsigned integer value */ -#define DLT_LOG_UINT(CONTEXT, LOGLEVEL, UINT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_uint(&(CONTEXT), LOGLEVEL, UINT_VAR); \ - } \ - } while(false) +#define DLT_LOG_UINT(CONTEXT, LOGLEVEL, UINT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_uint(&(CONTEXT), LOGLEVEL, UINT_VAR); \ + } \ + } while (false) /** * DLTv2 Send log message with unsigned integer parameter. @@ -912,13 +886,12 @@ * @param LOGLEVEL the log level of the log message * @param UINT_VAR unsigned integer value */ -#define DLT_LOG_UINT_V2(CONTEXT, LOGLEVEL, UINT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_uint_v2(&(CONTEXT), LOGLEVEL, UINT_VAR); \ - } \ - } while(false) +#define DLT_LOG_UINT_V2(CONTEXT, LOGLEVEL, UINT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_uint_v2(&(CONTEXT), LOGLEVEL, UINT_VAR); \ + } \ + } while (false) /** * Send log message with integer parameter. @@ -926,13 +899,12 @@ * @param LOGLEVEL the log level of the log message * @param INT_VAR integer value */ -#define DLT_LOG_INT(CONTEXT, LOGLEVEL, INT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_int(&(CONTEXT), LOGLEVEL, INT_VAR); \ - } \ - } while(false) +#define DLT_LOG_INT(CONTEXT, LOGLEVEL, INT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_int(&(CONTEXT), LOGLEVEL, INT_VAR); \ + } \ + } while (false) /** * DLTv2 Send log message with integer parameter. @@ -940,13 +912,12 @@ * @param LOGLEVEL the log level of the log message * @param INT_VAR integer value */ -#define DLT_LOG_INT_V2(CONTEXT, LOGLEVEL, INT_VAR) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_int_v2(&(CONTEXT), LOGLEVEL, INT_VAR); \ - } \ - } while(false) +#define DLT_LOG_INT_V2(CONTEXT, LOGLEVEL, INT_VAR) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_int_v2(&(CONTEXT), LOGLEVEL, INT_VAR); \ + } \ + } while (false) /** * Send log message with binary memory block. @@ -955,13 +926,12 @@ * @param BUF pointer to memory block * @param LEN length of memory block */ -#define DLT_LOG_RAW(CONTEXT, LOGLEVEL, BUF, LEN) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_raw(&(CONTEXT), LOGLEVEL, BUF, LEN); \ - } \ - } while(false) +#define DLT_LOG_RAW(CONTEXT, LOGLEVEL, BUF, LEN) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_raw(&(CONTEXT), LOGLEVEL, BUF, LEN); \ + } \ + } while (false) /** * DLTv2 Send log message with binary memory block. @@ -970,35 +940,38 @@ * @param BUF pointer to memory block * @param LEN length of memory block */ -#define DLT_LOG_RAW_V2(CONTEXT, LOGLEVEL, BUF, LEN) \ - do { \ - if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) \ - { \ - (void)dlt_log_raw_v2(&(CONTEXT), LOGLEVEL, BUF, LEN); \ - } \ - } while(false) +#define DLT_LOG_RAW_V2(CONTEXT, LOGLEVEL, BUF, LEN) \ + do { \ + if (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) { \ + (void)dlt_log_raw_v2(&(CONTEXT), LOGLEVEL, BUF, LEN); \ + } \ + } while (false) /** * Send log message with marker. */ -#define DLT_LOG_MARKER() \ - do { \ - (void)dlt_log_marker(); \ - } while(false) +#define DLT_LOG_MARKER() \ + do { \ + (void)dlt_log_marker(); \ + } while (false) /** * Switch to verbose mode * */ -#define DLT_VERBOSE_MODE() do { \ - (void)dlt_verbose_mode(); } while(false) +#define DLT_VERBOSE_MODE() \ + do { \ + (void)dlt_verbose_mode(); \ + } while (false) /** * Switch to non-verbose mode * */ -#define DLT_NONVERBOSE_MODE() do { \ - (void)dlt_nonverbose_mode(); } while(false) +#define DLT_NONVERBOSE_MODE() \ + do { \ + (void)dlt_nonverbose_mode(); \ + } while (false) /** * Set maximum logged log level and trace status of application @@ -1006,22 +979,28 @@ * @param LOGLEVEL This is the log level to be set for the whole application * @param TRACESTATUS This is the trace status to be set for the whole application */ -#define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) do { \ - (void)dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS); } while(false) +#define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) \ + do { \ + (void)dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS); \ + } while (false) /** * Enable local printing of messages * */ -#define DLT_ENABLE_LOCAL_PRINT() do { \ - (void)dlt_enable_local_print(); } while(false) +#define DLT_ENABLE_LOCAL_PRINT() \ + do { \ + (void)dlt_enable_local_print(); \ + } while (false) /** * Disable local printing of messages * */ -#define DLT_DISABLE_LOCAL_PRINT() do { \ - (void)dlt_disable_local_print(); } while(false) +#define DLT_DISABLE_LOCAL_PRINT() \ + do { \ + (void)dlt_disable_local_print(); \ + } while (false) /** * Check if log level is enabled @@ -1029,7 +1008,7 @@ * @param CONTEXT object containing information about one special logging context * @param LOGLEVEL the log level of the log message */ -#define DLT_IS_LOG_LEVEL_ENABLED(CONTEXT, LOGLEVEL) \ +#define DLT_IS_LOG_LEVEL_ENABLED(CONTEXT, LOGLEVEL) \ (dlt_user_is_logLevel_enabled(&CONTEXT, LOGLEVEL) == DLT_RETURN_TRUE) /** diff --git a/run_lint.sh b/run_lint.sh new file mode 100755 index 000000000..a6f73f3b7 --- /dev/null +++ b/run_lint.sh @@ -0,0 +1,219 @@ +#!/bin/bash +# +# SPDX-License-Identifier: MPL-2.0 +# +# run_lint.sh - clang-format helper for dlt-daemon +# +# Usage: +# ./run_lint.sh - install pre-commit hook and fix formatting (default) +# ./run_lint.sh check - check formatting (dry-run, fails on violations) +# ./run_lint.sh fix - fix formatting in-place +# ./run_lint.sh install-hook - configure git to use .githooks/pre-commit +# +# In CI, set CHECK_ALL=1 to check all tracked files: +# CHECK_ALL=1 ./run_lint.sh check +# +# clang-tidy support can be added later. +# + +set -euo pipefail + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +# --------------------------------------------------------------------------- +# Configuration +# --------------------------------------------------------------------------- + +# clang-format binary: prefer version-pinned clang-format-14, then newer versions +CLANG_FORMAT="${CLANG_FORMAT:-}" +if [ -z "${CLANG_FORMAT}" ]; then + for cf in clang-format-14 clang-format-16 clang-format-17 clang-format-18 clang-format; do + if command -v "$cf" >/dev/null 2>&1; then + CLANG_FORMAT="$(command -v "$cf")" + break + fi + done +fi + +# File patterns to check +FILE_PATTERN='^(src|include|tests)/.*\.(c|cc|cpp|cxx|h|hh|hpp|hxx)$' + +# Directories excluded from formatting checks +EXCLUDE_PATTERNS=( + '^src/android/' + '^src/dlt-qnx-system/' + '^src/core_dump_handler/' + '^src/dbus/' + '^src/kpi/' + '^src/tests/' + '^qnx/' + '^googletest/' + '^doc/' + '^build/' +) +EXCLUDE_REGEX="$(IFS='|'; echo "${EXCLUDE_PATTERNS[*]}")" + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- + +print_header() +{ + echo + echo "==================================================" + echo "$1" + echo "==================================================" +} + +get_files() +{ + # If files are passed as arguments, use them + if [ "$#" -gt 0 ]; then + printf '%s\n' "$@" + elif [ "${CHECK_ALL:-0}" = "1" ]; then + # CI mode: check all tracked files + git ls-files + else + # Default: collect staged files (for pre-commit hook) + git diff --cached --name-only --diff-filter=ACM + fi | grep -E "${FILE_PATTERN}" \ + | grep -Ev "${EXCLUDE_REGEX}" \ + || true +} + +# --------------------------------------------------------------------------- +# clang-format +# --------------------------------------------------------------------------- + +run_clang_format() +{ + local mode="$1" # "check" or "fix" + shift + + if [ -z "${CLANG_FORMAT}" ]; then + echo -e "${YELLOW}WARNING: clang-format not found, skipping format check${NC}" + echo "Install with: sudo apt-get install clang-format-14" + return 0 + fi + + print_header "CLANG-FORMAT (${mode})" + + local files + files=$(get_files "$@") + + if [ -z "${files}" ]; then + echo "No C/C++ files to check." + return 0 + fi + + local failed=0 + + if [ "${mode}" = "fix" ]; then + while IFS= read -r file; do + [ -z "${file}" ] && continue + echo "Formatting ${file}" + "${CLANG_FORMAT}" --style=file -i "${file}" + done <<< "${files}" + echo -e "${GREEN}Formatting complete${NC}" + else + while IFS= read -r file; do + [ -z "${file}" ] && continue + if ! "${CLANG_FORMAT}" --style=file --dry-run --Werror "${file}" 2>/dev/null; then + echo " FAIL: ${file}" + failed=1 + fi + done <<< "${files}" + + if [ "${failed}" -ne 0 ]; then + echo "" + echo -e "${RED}FAIL: One or more files are not formatted${NC}" + echo "Fix with:" + echo " ./run_lint.sh fix" + echo "Or for specific files:" + echo " clang-format-14 -i " + return 1 + fi + + echo -e "${GREEN}PASS${NC}" + fi +} + +# --------------------------------------------------------------------------- +# Install pre-commit hook +# --------------------------------------------------------------------------- + +install_hook() +{ + local repo_root + repo_root=$(git rev-parse --show-toplevel) + local hooks_dir="${repo_root}/.githooks" + + if [ ! -d "${hooks_dir}" ]; then + echo -e "${RED}ERROR: ${hooks_dir} does not exist${NC}" + return 1 + fi + + git config core.hooksPath .githooks + echo -e "${GREEN}Pre-commit hook installed${NC}" + echo " git config core.hooksPath .githooks" + echo "" + echo "To bypass (emergency only):" + echo " git commit --no-verify" + echo "To uninstall:" + echo " git config --unset core.hooksPath" +} + +# --------------------------------------------------------------------------- +# Main +# --------------------------------------------------------------------------- + +main() +{ + local mode="auto" + local files=() + + # Parse arguments: first arg is a subcommand if it matches one, + # otherwise treat all args as file paths (auto mode) + if [ "$#" -gt 0 ]; then + case "$1" in + auto|check|fix|install-hook) + mode="$1" + shift + files=("$@") + ;; + *) + files=("$@") + ;; + esac + fi + + case "${mode}" in + auto) + # Default: install hook, then fix formatting + install_hook + run_clang_format "fix" "${files[@]+"${files[@]}"}" + ;; + check) + run_clang_format "check" "${files[@]+"${files[@]}"}" + ;; + fix) + run_clang_format "fix" "${files[@]+"${files[@]}"}" + ;; + install-hook) + install_hook + ;; + *) + echo "Usage: $0 [auto|check|fix|install-hook] [file...]" + echo " auto - install hook and fix formatting (default)" + echo " check - check formatting (dry-run, fails on violations)" + echo " fix - fix formatting in-place" + echo " install-hook - configure git to use .githooks/pre-commit" + exit 1 + ;; + esac +} + +main "$@" diff --git a/scripts/pre-commit.sample b/scripts/pre-commit.sample deleted file mode 100755 index 5324c3b46..000000000 --- a/scripts/pre-commit.sample +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -gitclangformat=$(which git-clang-format) - -if [ "$gitclangformat" == "" ] -then - gitclangformat=$(find /usr/bin/ -name "git-clang-format*") -fi - -against=`git rev-parse --verify HEAD 2>&1` - -if [ $against == "" ] -then - # Initial commit: diff against an empty tree object - against=5394c6fa5bf40d9bc8619026cbc4c306211a8499 -fi - -$gitclangformat $against -f -q - -if [ $? != 0 ] -then - echo "Format error!" - echo "Use git clang-format" - exit 1 -fi - -# Now update format changes and commit -git add $(git diff --name-only --cached) diff --git a/src/adaptor/dlt-adaptor-stdin.c b/src/adaptor/dlt-adaptor-stdin.c index 0d502a20c..f603cca61 100644 --- a/src/adaptor/dlt-adaptor-stdin.c +++ b/src/adaptor/dlt-adaptor-stdin.c @@ -73,15 +73,15 @@ #define MAXSTRLEN 1024 -#define PS_DLT_APP_DESC "stdin adaptor application" -#define PS_DLT_CONTEXT_DESC "stdin adaptor context" +#define PS_DLT_APP_DESC "stdin adaptor application" +#define PS_DLT_CONTEXT_DESC "stdin adaptor context" #define PS_DLT_APP "SINA" #define PS_DLT_CONTEXT "SINC" DLT_DECLARE_CONTEXT(mycontext) -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { char str[MAXSTRLEN]; int opt; @@ -98,28 +98,23 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "a:c:bht:v:")) != -1) switch (opt) { - case 'a': - { + case 'a': { dlt_set_id(apid, optarg); break; } - case 'c': - { + case 'c': { dlt_set_id(ctid, optarg); break; } - case 'b': - { + case 'b': { bflag = 1; break; } - case 't': - { + case 't': { timeout = atoi(optarg); break; } - case 'h': - { + case 'h': { dlt_get_version(version, 255); printf("Usage: dlt-adaptor-stdin [options]\n"); @@ -131,45 +126,35 @@ int main(int argc, char *argv[]) printf(" -b - Flush buffered logs before unregistering app\n"); printf(" -t timeout - Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n"); printf( - " -v verbosity level - Set verbosity level (Default: INFO, values: FATAL ERROR WARN INFO DEBUG VERBOSE)\n"); + " -v verbosity level - Set verbosity level (Default: INFO, values: FATAL ERROR WARN INFO DEBUG " + "VERBOSE)\n"); printf(" -h - This help\n"); return 0; break; } - case 'v': - { + case 'v': { if (!strcmp(optarg, "FATAL")) { verbosity = DLT_LOG_FATAL; break; - } - else if (!strcmp(optarg, "ERROR")) - { + } else if (!strcmp(optarg, "ERROR")) { verbosity = DLT_LOG_ERROR; break; - } - else if (!strcmp(optarg, "WARN")) - { + } else if (!strcmp(optarg, "WARN")) { verbosity = DLT_LOG_WARN; break; - } - else if (!strcmp(optarg, "INFO")) - { + } else if (!strcmp(optarg, "INFO")) { verbosity = DLT_LOG_INFO; break; - } - else if (!strcmp(optarg, "DEBUG")) - { + } else if (!strcmp(optarg, "DEBUG")) { verbosity = DLT_LOG_DEBUG; break; - } - else if (!strcmp(optarg, "VERBOSE")) - { + } else if (!strcmp(optarg, "VERBOSE")) { verbosity = DLT_LOG_VERBOSE; break; - } - else { + } else { printf( - "Wrong verbosity level, setting to INFO. Accepted values are: FATAL ERROR WARN INFO DEBUG VERBOSE\n"); + "Wrong verbosity level, setting to INFO. Accepted values are: FATAL ERROR WARN INFO DEBUG " + "VERBOSE\n"); verbosity = DLT_LOG_INFO; break; } diff --git a/src/adaptor/dlt-adaptor-udp.c b/src/adaptor/dlt-adaptor-udp.c index cfe4660e4..82f3cd160 100644 --- a/src/adaptor/dlt-adaptor-udp.c +++ b/src/adaptor/dlt-adaptor-udp.c @@ -80,19 +80,19 @@ /* Port number, to which the syslogd-ng sends its log messages */ -#define RCVPORT 47111 +#define RCVPORT 47111 -#define MAXSTRLEN 1024 +#define MAXSTRLEN 1024 -#define PU_DLT_APP_DESC "udp adaptor application" -#define PU_DLT_CONTEXT_DESC "udp adaptor context" +#define PU_DLT_APP_DESC "udp adaptor application" +#define PU_DLT_CONTEXT_DESC "udp adaptor context" #define PU_DLT_APP "UDPA" #define PU_DLT_CONTEXT "UDPC" DLT_DECLARE_CONTEXT(mycontext) -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int sock; int bytes_read; @@ -113,18 +113,15 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "a:c:hp:v:")) != -1) switch (opt) { - case 'a': - { + case 'a': { dlt_set_id(apid, optarg); break; } - case 'c': - { + case 'c': { dlt_set_id(ctid, optarg); break; } - case 'h': - { + case 'h': { dlt_get_version(version, 255); printf("Usage: dlt-adaptor-udp [options]\n"); @@ -135,50 +132,39 @@ int main(int argc, char *argv[]) printf("-c ctid - Set context id to ctid (default: UDPC)\n"); printf("-p - Set receive port number for UDP messages (default: %d) \n", port); printf( - "-v verbosity level - Set verbosity level (Default: INFO, values: FATAL ERROR WARN INFO DEBUG VERBOSE)\n"); + "-v verbosity level - Set verbosity level (Default: INFO, values: FATAL ERROR WARN INFO DEBUG " + "VERBOSE)\n"); printf("-h - This help\n"); return 0; break; } - case 'p': - { + case 'p': { port = atoi(optarg); break; } - case 'v': - { + case 'v': { if (!strcmp(optarg, "FATAL")) { verbosity = DLT_LOG_FATAL; break; - } - else if (!strcmp(optarg, "ERROR")) - { + } else if (!strcmp(optarg, "ERROR")) { verbosity = DLT_LOG_ERROR; break; - } - else if (!strcmp(optarg, "WARN")) - { + } else if (!strcmp(optarg, "WARN")) { verbosity = DLT_LOG_WARN; break; - } - else if (!strcmp(optarg, "INFO")) - { + } else if (!strcmp(optarg, "INFO")) { verbosity = DLT_LOG_INFO; break; - } - else if (!strcmp(optarg, "DEBUG")) - { + } else if (!strcmp(optarg, "DEBUG")) { verbosity = DLT_LOG_DEBUG; break; - } - else if (!strcmp(optarg, "VERBOSE")) - { + } else if (!strcmp(optarg, "VERBOSE")) { verbosity = DLT_LOG_VERBOSE; break; - } - else { + } else { printf( - "Wrong verbosity level, setting to INFO. Accepted values are: FATAL ERROR WARN INFO DEBUG VERBOSE\n"); + "Wrong verbosity level, setting to INFO. Accepted values are: FATAL ERROR WARN INFO DEBUG " + "VERBOSE\n"); verbosity = DLT_LOG_INFO; break; } @@ -189,7 +175,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Unknown option '%c'\n", optopt); exit(3); - return 3;/*for parasoft */ + return 3; /*for parasoft */ } } @@ -214,8 +200,7 @@ int main(int argc, char *argv[]) server_addr.sin_port = htons((uint16_t)port); server_addr.sin_addr.s_addr = INADDR_ANY; memset(&(server_addr.sin_zero), 0, 8); - if (bind(sock, (struct sockaddr *)&server_addr, - sizeof(struct sockaddr)) == -1) { + if (bind(sock, (struct sockaddr*)&server_addr, sizeof(struct sockaddr)) == -1) { perror("Bind"); return -1; } @@ -228,14 +213,12 @@ int main(int argc, char *argv[]) while (1) { bytes_read = 0; - bytes_read = (int)recvfrom(sock, recv_data, MAXSTRLEN, 0, - (struct sockaddr *)&client_addr, &addr_len); + bytes_read = (int)recvfrom(sock, recv_data, MAXSTRLEN, 0, (struct sockaddr*)&client_addr, &addr_len); if (bytes_read == -1) { if (errno == EINTR) { continue; - } - else { + } else { DLT_UNREGISTER_CONTEXT(mycontext); DLT_UNREGISTER_APP(); exit(1); diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c index 5acb363c3..3f77cfe54 100644 --- a/src/console/dlt-control-common.c +++ b/src/console/dlt-control-common.c @@ -47,7 +47,7 @@ ** cl Christoph Lipka ADIT ** ** fb Frederic Berat ADIT ** *******************************************************************************/ -#define pr_fmt(fmt) "Common control: "fmt +#define pr_fmt(fmt) "Common control: " fmt #include #include @@ -65,16 +65,16 @@ #include "dlt-control-common.h" #ifdef EXTENDED_FILTERING - # if defined(__linux__) || defined(__ANDROID_API__) - # include /* for json filter parsing on Linux and Android */ - # endif - # ifdef __QNX__ - # include /* for json filter parsing on QNX */ - # endif +#if defined(__linux__) || defined(__ANDROID_API__) +#include /* for json filter parsing on Linux and Android */ +#endif +#ifdef __QNX__ +#include /* for json filter parsing on QNX */ +#endif #endif -#define DLT_CTRL_APID "DLTC" -#define DLT_CTRL_CTID "DLTC" +#define DLT_CTRL_APID "DLTC" +#define DLT_CTRL_CTID "DLTC" /** @brief Analyze the daemon answer * @@ -86,7 +86,7 @@ * * @return User defined. */ -static int (*response_analyzer_cb)(char *, void *, int); +static int (*response_analyzer_cb)(char*, void*, int); static pthread_t daemon_connect_thread; static DltClient g_client; @@ -97,7 +97,7 @@ static pthread_cond_t answer_cond = PTHREAD_COND_INITIALIZER; static int local_verbose; static char local_ecuid[DLT_CTRL_ECUID_LEN]; /* Name of ECU */ static int local_timeout; -static char local_filename[DLT_MOUNT_PATH_MAX]= {0}; /* Path to dlt.conf */ +static char local_filename[DLT_MOUNT_PATH_MAX] = {0}; /* Path to dlt.conf */ int get_verbosity(void) { @@ -109,14 +109,14 @@ void set_verbosity(int v) local_verbose = !!v; } -char *get_ecuid(void) +char* get_ecuid(void) { return local_ecuid; } -void set_ecuid(char *ecuid) +void set_ecuid(char* ecuid) { - char *ecuid_conf = NULL; + char* ecuid_conf = NULL; if (local_ecuid != ecuid) { /* If user pass NULL, read ECUId from dlt.conf */ @@ -124,15 +124,13 @@ void set_ecuid(char *ecuid) if (dlt_parse_config_param("ECUId", &ecuid_conf) == 0) { memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); strncpy(local_ecuid, ecuid_conf, DLT_CTRL_ECUID_LEN); - local_ecuid[DLT_CTRL_ECUID_LEN -1] = '\0'; - if (ecuid_conf !=NULL) + local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0'; + if (ecuid_conf != NULL) free(ecuid_conf); - } - else { + } else { pr_error("Cannot read ECUid from dlt.conf\n"); } - } - else { + } else { /* Set user passed ECUID */ memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN); strncpy(local_ecuid, ecuid, DLT_CTRL_ECUID_LEN); @@ -141,14 +139,13 @@ void set_ecuid(char *ecuid) } } -void set_conf(char *file_path) +void set_conf(char* file_path) { if (file_path != NULL) { memset(local_filename, 0, DLT_MOUNT_PATH_MAX); strncpy(local_filename, file_path, DLT_MOUNT_PATH_MAX); local_filename[DLT_MOUNT_PATH_MAX - 1] = '\0'; - } - else { + } else { pr_error("Argument is NULL\n"); } } @@ -165,8 +162,7 @@ void set_timeout(int t) if (t > 1) local_timeout = t; else - pr_error("Timeout to small. Set to default: %d", - DLT_CTRL_TIMEOUT); + pr_error("Timeout to small. Set to default: %d", DLT_CTRL_TIMEOUT); } void set_send_serial_header(const int value) @@ -179,15 +175,15 @@ void set_resync_serial_header(const int value) g_client.resync_serial_header = value; } -int dlt_parse_config_param(char *config_id, char **config_data) +int dlt_parse_config_param(char* config_id, char** config_data) { - FILE *pFile = NULL; + FILE* pFile = NULL; int value_length = DLT_LINE_LEN; - char line[DLT_LINE_LEN - 1] = { 0 }; - char token[DLT_LINE_LEN] = { 0 }; - char value[DLT_LINE_LEN] = { 0 }; - char *pch = NULL; - const char *filename = NULL; + char line[DLT_LINE_LEN - 1] = {0}; + char token[DLT_LINE_LEN] = {0}; + char value[DLT_LINE_LEN] = {0}; + char* pch = NULL; + const char* filename = NULL; if (*config_data != NULL) *config_data = NULL; @@ -213,8 +209,7 @@ int dlt_parse_config_param(char *config_id, char **config_data) if (token[0] == 0) { strncpy(token, pch, sizeof(token) - 1); token[sizeof(token) - 1] = 0; - } - else { + } else { strncpy(value, pch, sizeof(value) - 1); value[sizeof(value) - 1] = 0; break; @@ -225,23 +220,18 @@ int dlt_parse_config_param(char *config_id, char **config_data) if (token[0] && value[0]) { if (strcmp(token, config_id) == 0) { - *(config_data) = (char *) - calloc(DLT_DAEMON_FLAG_MAX, sizeof(char)); - memcpy(*config_data, - value, - DLT_DAEMON_FLAG_MAX - 1); + *(config_data) = (char*)calloc(DLT_DAEMON_FLAG_MAX, sizeof(char)); + memcpy(*config_data, value, DLT_DAEMON_FLAG_MAX - 1); } } } - } - else { + } else { break; } } - fclose (pFile); - } - else { + fclose(pFile); + } else { fprintf(stderr, "Cannot open configuration file: %s\n", filename); } @@ -260,7 +250,7 @@ int dlt_parse_config_param(char *config_id, char **config_data) * * @return 0 on success, -1 otherwise. */ -static int prepare_extra_headers(DltMessage *msg, uint8_t *header) +static int prepare_extra_headers(DltMessage* msg, uint8_t* header) { uint32_t shift = 0; @@ -269,9 +259,8 @@ static int prepare_extra_headers(DltMessage *msg, uint8_t *header) if (!msg || !header) return -1; - shift = (uint32_t) (sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + shift = (uint32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); /* Set header extra parameters */ dlt_set_id(msg->headerextra.ecu, get_ecuid()); @@ -285,7 +274,7 @@ static int prepare_extra_headers(DltMessage *msg, uint8_t *header) } /* prepare extended header */ - msg->extendedheader = (DltExtendedHeader *)(header + shift); + msg->extendedheader = (DltExtendedHeader*)(header + shift); msg->extendedheader->msin = DLT_MSIN_CONTROL_REQUEST; @@ -307,7 +296,7 @@ static int prepare_extra_headers(DltMessage *msg, uint8_t *header) * * @return 0 on success, -1 otherwise. */ -static int prepare_headers(DltMessage *msg, uint8_t *header) +static int prepare_headers(DltMessage* msg, uint8_t* header) { uint32_t len = 0; @@ -316,7 +305,7 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) if (!msg || !header) return -1; - msg->storageheader = (DltStorageHeader *)header; + msg->storageheader = (DltStorageHeader*)header; if (dlt_set_storageheader(msg->storageheader, "") == -1) { pr_error("Storage header initialization failed.\n"); @@ -324,11 +313,9 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) } /* prepare standard header */ - msg->standardheader = - (DltStandardHeader *)(header + sizeof(DltStorageHeader)); + msg->standardheader = (DltStandardHeader*)(header + sizeof(DltStorageHeader)); - msg->standardheader->htyp = DLT_HTYP_WEID | - DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; + msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; #if (BYTE_ORDER == BIG_ENDIAN) msg->standardheader->htyp = (msg->standardheader->htyp | DLT_HTYP_MSBF); @@ -337,10 +324,8 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) msg->standardheader->mcnt = 0; /* prepare length information */ - msg->headersize = (int32_t)(sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + msg->headersize = (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); len = (uint32_t)(msg->headersize - (int32_t)sizeof(DltStorageHeader) + msg->datasize); @@ -363,9 +348,9 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) * * @return 0 on success, -1 otherwise. */ -static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data) +static DltMessage* dlt_control_prepare_message(DltControlMsgBody* data) { - DltMessage *msg = NULL; + DltMessage* msg = NULL; pr_verbose("Preparing message.\n"); @@ -391,7 +376,7 @@ static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data) msg->databuffersize = msg->datasize = (int32_t)data->size; /* Allocate memory for Dlt Message's buffer */ - msg->databuffer = (uint8_t *)calloc(1, data->size); + msg->databuffer = (uint8_t*)calloc(1, data->size); if (msg->databuffer == NULL) { pr_error("Cannot allocate memory for data buffer\n"); @@ -430,13 +415,13 @@ static DltMessage *dlt_control_prepare_message(DltControlMsgBody *data) * * @return 0 on success, -1 otherwise. */ -static int dlt_control_init_connection(DltClient *client, void *cb) +static int dlt_control_init_connection(DltClient* client, void* cb) { union { - void *ptr; - int (*callback)(DltMessage *message, void *data); + void* ptr; + int (*callback)(DltMessage* message, void* data); } callback_converter; - int (*callback)(DltMessage *message, void *data); + int (*callback)(DltMessage* message, void* data); callback_converter.ptr = cb; callback = callback_converter.callback; @@ -479,7 +464,7 @@ static int dlt_control_init_connection(DltClient *client, void *cb) * * @return The thread parameter given as argument. */ -static void *dlt_control_listen_to_daemon(void *data) +static void* dlt_control_listen_to_daemon(void* data) { pr_verbose("Ready to receive DLT answers.\n"); dlt_client_main_loop(&g_client, NULL, get_verbosity()); @@ -503,9 +488,9 @@ static void *dlt_control_listen_to_daemon(void *data) * * @return The analyzer return value or -1 on early errors. */ -static int dlt_control_callback(DltMessage *message, void *data) +static int dlt_control_callback(DltMessage* message, void* data) { - char text[DLT_RECEIVE_BUFSIZE] = { 0 }; + char text[DLT_RECEIVE_BUFSIZE] = {0}; (void)data; if (message == NULL) { @@ -522,18 +507,13 @@ static int dlt_control_callback(DltMessage *message, void *data) dlt_message_header(message, text, DLT_RECEIVE_BUFSIZE, get_verbosity()); /* Extracting payload */ - dlt_message_payload(message, text, - DLT_RECEIVE_BUFSIZE, - DLT_OUTPUT_ASCII, - get_verbosity()); + dlt_message_payload(message, text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, get_verbosity()); /* * Checking payload with the provided callback and return the result */ pthread_mutex_lock(&answer_lock); - callback_return = response_analyzer_cb(text, - message->databuffer, - (int) message->datasize); + callback_return = response_analyzer_cb(text, message->databuffer, (int)message->datasize); pthread_cond_signal(&answer_cond); pthread_mutex_unlock(&answer_lock); @@ -553,10 +533,10 @@ static int dlt_control_callback(DltMessage *message, void *data) * * @return The user response analyzer return value, -1 in case of early error. */ -int dlt_control_send_message(DltControlMsgBody *body, int timeout) +int dlt_control_send_message(DltControlMsgBody* body, int timeout) { struct timespec t; - DltMessage *msg = NULL; + DltMessage* msg = NULL; if (!body) { pr_error("%s: Invalid input.\n", __func__); @@ -583,8 +563,7 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) /* Re-init the return value */ callback_return = -1; - if (dlt_client_send_message_to_socket(&g_client, msg) != DLT_RETURN_OK) - { + if (dlt_client_send_message_to_socket(&g_client, msg) != DLT_RETURN_OK) { pr_error("Sending message to daemon failed\n"); dlt_message_free(msg, get_verbosity()); free(msg); @@ -595,9 +574,9 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) } /* - * When a timeouts occurs, pthread_cond_timedwait() - * shall nonetheless release and re-acquire the mutex referenced by mutex - */ + * When a timeouts occurs, pthread_cond_timedwait() + * shall nonetheless release and re-acquire the mutex referenced by mutex + */ pthread_cond_timedwait(&answer_cond, &answer_lock, &t); pthread_mutex_unlock(&answer_lock); @@ -622,9 +601,7 @@ int dlt_control_send_message(DltControlMsgBody *body, int timeout) * * @return 0 on success, -1 otherwise. */ -int dlt_control_init(int (*response_analyzer)(char *, void *, int), - char *ecuid, - int verbosity) +int dlt_control_init(int (*response_analyzer)(char*, void*, int), char* ecuid, int verbosity) { if (!response_analyzer || !ecuid) { pr_error("%s: Invalid input.\n", __func__); @@ -632,8 +609,8 @@ int dlt_control_init(int (*response_analyzer)(char *, void *, int), } union { - void *ptr; - int (*callback)(DltMessage *message, void *data); + void* ptr; + int (*callback)(DltMessage* message, void* data); } callback_converter; response_analyzer_cb = response_analyzer; @@ -649,10 +626,7 @@ int dlt_control_init(int (*response_analyzer)(char *, void *, int), } /* Contact DLT daemon */ - if (pthread_create(&daemon_connect_thread, - NULL, - dlt_control_listen_to_daemon, - NULL) != 0) { + if (pthread_create(&daemon_connect_thread, NULL, dlt_control_listen_to_daemon, NULL) != 0) { pr_error("Cannot create thread to communicate with DLT daemon.\n"); return -1; } @@ -688,23 +662,23 @@ int dlt_control_deinit(void) #ifdef EXTENDED_FILTERING /* EXTENDED_FILTERING */ -# if defined(__linux__) || defined(__ANDROID_API__) -DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int verbose) +#if defined(__linux__) || defined(__ANDROID_API__) +DltReturnValue dlt_json_filter_load(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if(verbose) + if (verbose) pr_verbose("dlt_json_filter_load()\n"); - FILE *handle; - char buffer[JSON_FILTER_SIZE*DLT_FILTER_MAX]; - struct json_object *j_parsed_json; - struct json_object *j_app_id; - struct json_object *j_context_id; - struct json_object *j_log_level; - struct json_object *j_payload_min; - struct json_object *j_payload_max; + FILE* handle; + char buffer[JSON_FILTER_SIZE * DLT_FILTER_MAX]; + struct json_object* j_parsed_json; + struct json_object* j_app_id; + struct json_object* j_context_id; + struct json_object* j_log_level; + struct json_object* j_payload_min; + struct json_object* j_payload_max; enum json_tokener_error jerr; char app_id[DLT_ID_SIZE + 1] = ""; @@ -740,8 +714,7 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int json_object_object_foreach(j_parsed_json, key, val) { if (iterator >= DLT_FILTER_MAX) { - pr_error("Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", - DLT_FILTER_MAX); + pr_error("Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", DLT_FILTER_MAX); break; } @@ -793,21 +766,21 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int return DLT_RETURN_OK; } -# endif /* __Linux__ */ +#endif /* __Linux__ */ -# ifdef __QNX__ -DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int verbose) +#ifdef __QNX__ +DltReturnValue dlt_json_filter_load(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if(verbose) + if (verbose) pr_verbose("dlt_json_filter_load()\n"); - json_decoder_t *j_decoder = json_decoder_create(); + json_decoder_t* j_decoder = json_decoder_create(); - const char *s_app_id; - const char *s_context_id; + const char* s_app_id; + const char* s_context_id; int32_t log_level = 0; int32_t payload_max = INT32_MAX; int32_t payload_min = 0; @@ -826,8 +799,7 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int while (!end_of_json) { if (iterator >= DLT_FILTER_MAX) { - pr_error("Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", - DLT_FILTER_MAX); + pr_error("Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", DLT_FILTER_MAX); break; } @@ -857,11 +829,11 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int char app_id[DLT_ID_SIZE]; char context_id[DLT_ID_SIZE]; - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstringop-truncation" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(app_id, s_app_id, DLT_ID_SIZE); strncpy(context_id, s_context_id, DLT_ID_SIZE); - #pragma GCC diagnostic pop +#pragma GCC diagnostic pop dlt_filter_add(filter, app_id, context_id, log_level, payload_min, payload_max, verbose); @@ -880,23 +852,23 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int return DLT_RETURN_OK; } -# endif /* __QNX__ */ +#endif /* __QNX__ */ #endif /* EXTENDED_FILTERING */ #ifdef EXTENDED_FILTERING /* EXTENDED_FILTERING */ -# if defined(__linux__) || defined(__ANDROID_API__) -DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose) +#if defined(__linux__) || defined(__ANDROID_API__) +DltReturnValue dlt_json_filter_save(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if(verbose) + if (verbose) pr_verbose("dlt_json_filter_save()\n"); - struct json_object *json_filter_obj = json_object_new_object(); + struct json_object* json_filter_obj = json_object_new_object(); for (int num = 0; num < filter->counter; num++) { - struct json_object *tmp_json_obj = json_object_new_object(); + struct json_object* tmp_json_obj = json_object_new_object(); char filter_name[JSON_FILTER_NAME_SIZE + 1]; snprintf(filter_name, sizeof(filter_name), "filter%i", num); @@ -906,8 +878,8 @@ DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int json_object_object_add(tmp_json_obj, "AppId", json_object_new_string(filter->apid[num])); if (filter->ctid[num][DLT_ID_SIZE - 1] != 0) - json_object_object_add(tmp_json_obj, "ContextId", - json_object_new_string_len(filter->ctid[num], DLT_ID_SIZE)); + json_object_object_add( + tmp_json_obj, "ContextId", json_object_new_string_len(filter->ctid[num], DLT_ID_SIZE)); else json_object_object_add(tmp_json_obj, "ContextId", json_object_new_string(filter->ctid[num])); @@ -923,21 +895,21 @@ DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int return DLT_RETURN_OK; } -# endif /* __Linux__ */ +#endif /* __Linux__ */ -# ifdef __QNX__ -DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose) +#ifdef __QNX__ +DltReturnValue dlt_json_filter_save(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if(verbose) + if (verbose) pr_verbose("dlt_json_filter_save()\n"); char s_app_id[DLT_ID_SIZE + 1]; char s_context_id[DLT_ID_SIZE + 1]; - json_encoder_t *j_encoder = json_encoder_create(); + json_encoder_t* j_encoder = json_encoder_create(); json_encoder_start_object(j_encoder, NULL); for (int num = 0; num < filter->counter; num++) { @@ -967,7 +939,7 @@ DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int json_encoder_end_object(j_encoder); printf("Saving current filter into '%s'\n", filename); - FILE *handle = fopen(filename, "w"); + FILE* handle = fopen(filename, "w"); int filter_buffer_size = 100 * (filter->counter); char filter_buffer[filter_buffer_size]; snprintf(filter_buffer, filter_buffer_size, json_encoder_buffer(j_encoder)); @@ -978,5 +950,5 @@ DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int return DLT_RETURN_OK; } -# endif /* __QNX__ */ +#endif /* __QNX__ */ #endif /* EXTENDED_FILTERING */ diff --git a/src/console/dlt-control-common.h b/src/console/dlt-control-common.h index dc4fde202..59ca680ce 100644 --- a/src/console/dlt-control-common.h +++ b/src/console/dlt-control-common.h @@ -35,19 +35,27 @@ #define JSON_FILTER_SIZE 200 /* Size in bytes, that the definition of one filter with all parameters needs */ #ifndef pr_fmt -# define pr_fmt(fmt) fmt +#define pr_fmt(fmt) fmt #endif #ifndef USE_STDOUT -# define PRINT_OUT stderr +#define PRINT_OUT stderr #else -# define PRINT_OUT stdout +#define PRINT_OUT stdout #endif -#define pr_error(fmt, ...) \ - do { fprintf(PRINT_OUT, pr_fmt(fmt), ## __VA_ARGS__); fflush(PRINT_OUT); } while(0) -#define pr_verbose(fmt, ...) \ - do { if (get_verbosity()) { fprintf(PRINT_OUT, pr_fmt(fmt), ## __VA_ARGS__); fflush(PRINT_OUT); } } while(0) +#define pr_error(fmt, ...) \ + do { \ + fprintf(PRINT_OUT, pr_fmt(fmt), ##__VA_ARGS__); \ + fflush(PRINT_OUT); \ + } while (0) +#define pr_verbose(fmt, ...) \ + do { \ + if (get_verbosity()) { \ + fprintf(PRINT_OUT, pr_fmt(fmt), ##__VA_ARGS__); \ + fflush(PRINT_OUT); \ + } \ + } while (0) #define DLT_CTRL_DEFAULT_ECUID "ECU1" @@ -57,10 +65,9 @@ #define NANOSEC_PER_SEC 1000000000 /* To be used as Dlt Message body when sending to DLT daemon */ -typedef struct -{ - void *data; /**< data to be send to DLT Daemon */ - uint32_t size; /**< size of that data */ +typedef struct { + void* data; /**< data to be send to DLT Daemon */ + uint32_t size; /**< size of that data */ } DltControlMsgBody; /* As verbosity, ecuid, timeout, send_serial_header, resync_serial_header are @@ -70,10 +77,10 @@ typedef struct int get_verbosity(void); void set_verbosity(int); -char *get_ecuid(void); -void set_ecuid(char *); +char* get_ecuid(void); +void set_ecuid(char*); -void set_conf(char *); +void set_conf(char*); int get_timeout(void); void set_timeout(int); @@ -82,15 +89,13 @@ void set_send_serial_header(const int value); void set_resync_serial_header(const int value); /* Parse dlt.conf file and return the value of requested configuration */ -int dlt_parse_config_param(char *config_id, char **config_data); +int dlt_parse_config_param(char* config_id, char** config_data); /* Initialize the connection to the daemon */ -int dlt_control_init(int (*response_analyser)(char *, void *, int), - char *ecuid, - int verbosity); +int dlt_control_init(int (*response_analyser)(char*, void*, int), char* ecuid, int verbosity); /* Send a message to the daemon. The call is not thread safe. */ -int dlt_control_send_message(DltControlMsgBody *, int); +int dlt_control_send_message(DltControlMsgBody*, int); /* Destroys the connection to the daemon */ int dlt_control_deinit(void); @@ -103,7 +108,7 @@ int dlt_control_deinit(void); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int verbose); +DltReturnValue dlt_json_filter_load(DltFilter* filter, const char* filename, int verbose); /** * Save filter in json format to file. * @param filter pointer to structure of organising DLT filter @@ -111,6 +116,6 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose); +DltReturnValue dlt_json_filter_save(DltFilter* filter, const char* filename, int verbose); #endif #endif diff --git a/src/console/dlt-control-v2.c b/src/console/dlt-control-v2.c index ab1cd87e3..bd25cb3ce 100644 --- a/src/console/dlt-control-v2.c +++ b/src/console/dlt-control-v2.c @@ -64,47 +64,46 @@ * sg 12.11.2025 initial */ -#include /* for isprint() */ -#include /* for atoi() */ -#include /* for writev() */ -#include /* for open() */ +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for writev() */ +#include /* for open() */ #include "dlt_client.h" #include "dlt_user.h" #include "dlt-control-common.h" -#define DLT_GLOGINFO_APID_NUM_MAX 150 -#define DLT_GLOGINFO_DATA_MAX 800 -#define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ -#define DLT_INVALID_LOG_LEVEL 0xF -#define DLT_INVALID_TRACE_STATUS 0xF +#define DLT_GLOGINFO_APID_NUM_MAX 150 +#define DLT_GLOGINFO_DATA_MAX 800 +#define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ +#define DLT_INVALID_LOG_LEVEL 0xF +#define DLT_INVALID_TRACE_STATUS 0xF /* Option of GET_LOG_INFO */ -#define DLT_SERVICE_GET_LOG_INFO_OPT7 7 /* get Apid, ApDescription, Ctid, CtDescription, loglevel, tracestatus */ -#define LOG_ERR 3 +#define DLT_SERVICE_GET_LOG_INFO_OPT7 7 /* get Apid, ApDescription, Ctid, CtDescription, loglevel, tracestatus */ +#define LOG_ERR 3 /** * The structure of the DLT Service header */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< response status */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< response status */ } DLT_PACKED DltServiceHeader; DltClient g_dltclient; /* Function prototypes */ -int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data); +int dlt_receive_message_callback_v2(DltMessageV2* message, void* data); typedef struct { int vflag; int yflag; - char *evalue; + char* evalue; - char *avalue; - char *cvalue; + char* avalue; + char* cvalue; int svalue; - char *mvalue; - char *xvalue; + char* mvalue; + char* xvalue; int tvalue; int lvalue; int rvalue; @@ -120,7 +119,7 @@ typedef struct { int sendSerialHeaderFlag; int resyncSerialHeaderFlag; uint8_t ecuidlen; - char *ecuid; + char* ecuid; DltFile file; DltFilter filter; } DltReceiveData; @@ -185,16 +184,14 @@ void usage() */ void dlt_process_get_log_info_v2(void) { - char *apid = NULL; - char *ctid = NULL; + char* apid = NULL; + char* ctid = NULL; AppIDsType app; ContextIDsInfoType con; int i = 0; int j = 0; - DltServiceGetLogInfoResponse *resp = - (DltServiceGetLogInfoResponse *)calloc(1, - sizeof(DltServiceGetLogInfoResponse)); + DltServiceGetLogInfoResponse* resp = (DltServiceGetLogInfoResponse*)calloc(1, sizeof(DltServiceGetLogInfoResponse)); if (NULL == resp) { fprintf(stderr, "ERROR: calloc for resp data failed.\n"); @@ -213,20 +210,19 @@ void dlt_process_get_log_info_v2(void) return; } - if (dlt_client_main_loop_v2(&g_dltclient, (void *)resp, 0) == DLT_RETURN_TRUE) + if (dlt_client_main_loop_v2(&g_dltclient, (void*)resp, 0) == DLT_RETURN_TRUE) fprintf(stdout, "DLT-daemon's response is invalid.\n"); - if (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO && - resp->status >= GET_LOG_INFO_STATUS_MIN && - resp->status <= GET_LOG_INFO_STATUS_MAX) { + if (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO && resp->status >= GET_LOG_INFO_STATUS_MIN + && resp->status <= GET_LOG_INFO_STATUS_MAX) { for (i = 0; i < resp->log_info_type.count_app_ids; i++) { app = resp->log_info_type.app_ids[i]; - if(app.app_id2 == NULL){ + if (app.app_id2 == NULL) { dlt_vlog(LOG_ERR, "%s: Application id is null\n", __func__); dlt_client_cleanup_get_log_info_v2(resp); return; } - apid = (char *)malloc((size_t)(app.app_id2len + 1)); + apid = (char*)malloc((size_t)(app.app_id2len + 1)); if (apid == NULL) { dlt_vlog(LOG_ERR, "%s: malloc failed for application id\n", __func__); dlt_client_cleanup_get_log_info_v2(resp); @@ -243,12 +239,12 @@ void dlt_process_get_log_info_v2(void) for (j = 0; j < app.count_context_ids; j++) { con = app.context_id_info[j]; - if(con.context_id2 == NULL){ + if (con.context_id2 == NULL) { dlt_vlog(LOG_ERR, "%s: context id is null\n", __func__); dlt_client_cleanup_get_log_info_v2(resp); return; } - ctid = (char *)malloc((size_t)(con.context_id2len + 1)); + ctid = (char*)malloc((size_t)(con.context_id2len + 1)); if (ctid == NULL) { dlt_vlog(LOG_ERR, "%s: malloc failed for context id\n", __func__); dlt_client_cleanup_get_log_info_v2(resp); @@ -258,16 +254,9 @@ void dlt_process_get_log_info_v2(void) memset(ctid + con.context_id2len, '\0', 1); if (con.context_description != 0) { - printf("CTID:%s %2d %2d %s\n", - ctid, - con.log_level, - con.trace_status, - con.context_description); - }else { - printf("CTID:%s %2d %2d\n", - ctid, - con.log_level, - con.trace_status); + printf("CTID:%s %2d %2d %s\n", ctid, con.log_level, con.trace_status, con.context_description); + } else { + printf("CTID:%s %2d %2d\n", ctid, con.log_level, con.trace_status); } free(ctid); ctid = NULL; @@ -286,9 +275,8 @@ void dlt_process_get_log_info_v2(void) */ void dlt_process_get_software_version_v2(void) { - DltServiceGetSoftwareVersionResponse *resp = - (DltServiceGetSoftwareVersionResponse *)calloc(1, - sizeof(DltServiceGetSoftwareVersionResponse)); + DltServiceGetSoftwareVersionResponse* resp = + (DltServiceGetSoftwareVersionResponse*)calloc(1, sizeof(DltServiceGetSoftwareVersionResponse)); if (NULL == resp) { fprintf(stderr, "ERROR: calloc for resp data failed.\n"); @@ -307,13 +295,11 @@ void dlt_process_get_software_version_v2(void) return; } - if (dlt_client_main_loop_v2(&g_dltclient, (void *)resp, 0) == DLT_RETURN_TRUE) + if (dlt_client_main_loop_v2(&g_dltclient, (void*)resp, 0) == DLT_RETURN_TRUE) fprintf(stdout, "DLT-daemon's response is invalid.\n"); - if (resp->service_id == DLT_SERVICE_ID_GET_SOFTWARE_VERSION && - resp->status == DLT_SERVICE_RESPONSE_OK && - resp->payload != NULL) - { + if (resp->service_id == DLT_SERVICE_ID_GET_SOFTWARE_VERSION && resp->status == DLT_SERVICE_RESPONSE_OK + && resp->payload != NULL) { printf("%s\n", resp->payload); free(resp->payload); resp->payload = NULL; @@ -326,13 +312,13 @@ void dlt_process_get_software_version_v2(void) /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { DltReceiveData dltdata; int c; int ret; int index; - char *endptr = NULL; + char* endptr = NULL; struct timespec ts; /* Initialize dltdata */ @@ -345,8 +331,7 @@ int main(int argc, char *argv[]) .ivalue = -1, .oflag = -1, .gflag = -1, - .port = 3490 - }; + .port = 3490}; /* Fetch command line arguments */ opterr = 0; @@ -354,158 +339,132 @@ int main(int argc, char *argv[]) /* Default return value */ ret = 0; - while ((c = getopt (argc, argv, "vhSRye:b:a:c:s:m:x:t:l:r:d:f:i:ogjkup:")) != -1) + while ((c = getopt(argc, argv, "vhSRye:b:a:c:s:m:x:t:l:r:d:f:i:ogjkup:")) != -1) switch (c) { - case 'v': - { + case 'v': { dltdata.vflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'S': - { + case 'S': { dltdata.sendSerialHeaderFlag = 1; break; } - case 'R': - { + case 'R': { dltdata.resyncSerialHeaderFlag = 1; break; } - case 'y': - { + case 'y': { dltdata.yflag = DLT_CLIENT_MODE_SERIAL; break; } - case 'e': - { + case 'e': { dltdata.evalue = optarg; break; } - case 'b': - { + case 'b': { dltdata.bvalue = atoi(optarg); break; } - case 'a': - { + case 'a': { dltdata.avalue = optarg; break; } - case 'c': - { + case 'c': { dltdata.cvalue = optarg; break; } - case 's': - { + case 's': { dltdata.svalue = atoi(optarg); break; } - case 'm': - { + case 'm': { dltdata.mvalue = optarg; break; } - case 'x': - { + case 'x': { dltdata.xvalue = optarg; break; } - case 't': - { + case 't': { dltdata.tvalue = atoi(optarg); break; } - case 'l': - { - dltdata.lvalue = (int) strtol(optarg, &endptr, 10); + case 'l': { + dltdata.lvalue = (int)strtol(optarg, &endptr, 10); if ((dltdata.lvalue < DLT_LOG_DEFAULT) || (dltdata.lvalue > DLT_LOG_VERBOSE)) { - fprintf (stderr, "invalid log level, supported log level 0-6\n"); + fprintf(stderr, "invalid log level, supported log level 0-6\n"); return -1; } break; } - case 'r': - { - dltdata.rvalue = (int) strtol(optarg, &endptr, 10); + case 'r': { + dltdata.rvalue = (int)strtol(optarg, &endptr, 10); if ((dltdata.rvalue < DLT_TRACE_STATUS_DEFAULT) || (dltdata.rvalue > DLT_TRACE_STATUS_ON)) { - fprintf (stderr, "invalid trace status, supported trace status -1, 0, 1\n"); + fprintf(stderr, "invalid trace status, supported trace status -1, 0, 1\n"); return -1; } break; } - case 'd': - { + case 'd': { dltdata.dvalue = atoi(optarg); break; } - case 'f': - { + case 'f': { dltdata.fvalue = atoi(optarg); break; } - case 'i': - { + case 'i': { dltdata.ivalue = atoi(optarg); break; } - case 'o': - { + case 'o': { dltdata.oflag = 1; break; } - case 'g': - { + case 'g': { dltdata.gflag = 1; break; } - case 'j': - { + case 'j': { dltdata.jvalue = 1; break; } - case 'k': - { + case 'k': { dltdata.kvalue = 1; break; } - case 'u': - { + case 'u': { dltdata.yflag = DLT_CLIENT_MODE_UNIX; break; } - case 'p': - { + case 'p': { dltdata.port = atoi(optarg); break; } - case '?': - { + case '?': { if ((optopt == 'o') || (optopt == 'f')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1; /*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -518,21 +477,17 @@ int main(int argc, char *argv[]) /* Setup DLT Client structure */ if (dltdata.yflag == DLT_CLIENT_MODE_SERIAL) { g_dltclient.mode = DLT_CLIENT_MODE_SERIAL; - } - else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX) - { + } else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX) { g_dltclient.mode = DLT_CLIENT_MODE_UNIX; g_dltclient.socketPath = NULL; - if (dlt_parse_config_param("ControlSocketPath", - &g_dltclient.socketPath) == DLT_RETURN_ERROR) { + if (dlt_parse_config_param("ControlSocketPath", &g_dltclient.socketPath) == DLT_RETURN_ERROR) { /* Failed to read from conf, copy default */ if (dlt_client_set_socket_path(&g_dltclient, DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH) == -1) { pr_error("set socket path didn't succeed\n"); return -1; } } - } - else { + } else { g_dltclient.mode = DLT_CLIENT_MODE_TCP; } @@ -551,9 +506,7 @@ int main(int argc, char *argv[]) dlt_client_cleanup(&g_dltclient, dltdata.vflag); return -1; } - } - else if (g_dltclient.mode == DLT_CLIENT_MODE_SERIAL) - { + } else if (g_dltclient.mode == DLT_CLIENT_MODE_SERIAL) { for (index = optind; index < argc; index++) if (dlt_client_set_serial_device(&g_dltclient, argv[index]) == -1) { pr_error("set serial device didn't succeed\n"); @@ -585,18 +538,16 @@ int main(int argc, char *argv[]) dlt_set_id_v2(dltdata.ecuid, dltdata.evalue, dltdata.ecuidlen); g_dltclient.ecuid2len = dltdata.ecuidlen; dlt_set_id_v2(g_dltclient.ecuid2, dltdata.evalue, g_dltclient.ecuid2len); - } - else { + } else { dltdata.evalue = NULL; if (dlt_parse_config_param("ECUId", &dltdata.evalue) == 0) { - dltdata.ecuidlen = (uint8_t)strlen(dltdata.evalue); - dlt_set_id_v2(dltdata.ecuid, dltdata.evalue, dltdata.ecuidlen); - g_dltclient.ecuid2len = dltdata.ecuidlen; - dlt_set_id_v2(g_dltclient.ecuid2, dltdata.evalue, dltdata.ecuidlen); - free (dltdata.evalue); - } - else { + dltdata.ecuidlen = (uint8_t)strlen(dltdata.evalue); + dlt_set_id_v2(dltdata.ecuid, dltdata.evalue, dltdata.ecuidlen); + g_dltclient.ecuid2len = dltdata.ecuidlen; + dlt_set_id_v2(g_dltclient.ecuid2, dltdata.evalue, dltdata.ecuidlen); + free(dltdata.evalue); + } else { fprintf(stderr, "ERROR: Failed to read ECUId from dlt.conf \n"); } } @@ -613,18 +564,14 @@ int main(int argc, char *argv[]) printf("Message: %s\n", dltdata.mvalue); /* send control message in ascii */ - if (dlt_client_send_inject_msg_v2(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint32_t) dltdata.svalue, - (uint8_t *)dltdata.mvalue, - (uint32_t) strlen(dltdata.mvalue)) != DLT_RETURN_OK) { + if (dlt_client_send_inject_msg_v2( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint32_t)dltdata.svalue, (uint8_t*)dltdata.mvalue, + (uint32_t)strlen(dltdata.mvalue)) + != DLT_RETURN_OK) { fprintf(stderr, "ERROR: Could not send inject message\n"); ret = -1; } - } - else if (dltdata.xvalue && dltdata.avalue && dltdata.cvalue) - { + } else if (dltdata.xvalue && dltdata.avalue && dltdata.cvalue) { /* Hex */ uint8_t buffer[1024]; int size = 1024; @@ -637,16 +584,13 @@ int main(int argc, char *argv[]) printf("Size: %d\n", size); /* send control message in hex */ - if (dlt_client_send_inject_msg_v2(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint32_t) dltdata.svalue, - buffer, (uint32_t)size) != DLT_RETURN_OK) { + if (dlt_client_send_inject_msg_v2( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint32_t)dltdata.svalue, buffer, (uint32_t)size) + != DLT_RETURN_OK) { fprintf(stderr, "ERROR: Could not send inject message\n"); ret = -1; } - } - else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ + } else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ { if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) { if (dltdata.vflag) { @@ -654,13 +598,11 @@ int main(int argc, char *argv[]) printf("Loglevel: %d\n", dltdata.lvalue); } - if (0 != dlt_client_send_all_log_level_v2(&g_dltclient, - (uint8_t) dltdata.lvalue)) { + if (0 != dlt_client_send_all_log_level_v2(&g_dltclient, (uint8_t)dltdata.lvalue)) { fprintf(stderr, "ERROR: Could not send log level\n"); ret = -1; } - } - else { + } else { /* log level */ if (dltdata.vflag) { printf("Set log level:\n"); @@ -670,30 +612,25 @@ int main(int argc, char *argv[]) } /* send control message*/ - if (0 != dlt_client_send_log_level_v2(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint8_t) dltdata.lvalue)) { + if (0 + != dlt_client_send_log_level_v2( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint8_t)dltdata.lvalue)) { fprintf(stderr, "ERROR: Could not send log level\n"); ret = -1; } } - } - else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS) - { + } else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS) { if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) { if (dltdata.vflag) { printf("Set all trace status:\n"); printf("Tracestatus: %d\n", dltdata.rvalue); } - if (0 != dlt_client_send_all_trace_status_v2(&g_dltclient, - (uint8_t) dltdata.rvalue)) { + if (0 != dlt_client_send_all_trace_status_v2(&g_dltclient, (uint8_t)dltdata.rvalue)) { fprintf(stderr, "ERROR: Could not send trace status\n"); ret = -1; } - } - else { + } else { /* trace status */ if (dltdata.vflag) { printf("Set trace status:\n"); @@ -703,81 +640,66 @@ int main(int argc, char *argv[]) } /* send control message*/ - if (0 != dlt_client_send_trace_status_v2(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint8_t) dltdata.rvalue)) { + if (0 + != dlt_client_send_trace_status_v2( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint8_t)dltdata.rvalue)) { fprintf(stderr, "ERROR: Could not send trace status\n"); ret = -1; } } - } - else if (dltdata.dvalue != -1) - { + } else if (dltdata.dvalue != -1) { /* default log level */ printf("Set default log level:\n"); printf("Loglevel: %d\n", dltdata.dvalue); /* send control message in*/ - if (dlt_client_send_default_log_level_v2(&g_dltclient, (uint8_t) dltdata.dvalue) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send default log level\n"); + if (dlt_client_send_default_log_level_v2(&g_dltclient, (uint8_t)dltdata.dvalue) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Could not send default log level\n"); ret = -1; } - } - else if (dltdata.fvalue != -1) - { + } else if (dltdata.fvalue != -1) { /* default trace status */ printf("Set default trace status:\n"); printf("TraceStatus: %d\n", dltdata.fvalue); /* send control message in*/ - if (dlt_client_send_default_trace_status_v2(&g_dltclient, (uint8_t) dltdata.fvalue) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send default trace status\n"); + if (dlt_client_send_default_trace_status_v2(&g_dltclient, (uint8_t)dltdata.fvalue) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Could not send default trace status\n"); ret = -1; } - } - else if (dltdata.ivalue != -1) - { + } else if (dltdata.ivalue != -1) { /* timing pakets */ printf("Set timing pakets:\n"); printf("Timing packets: %d\n", dltdata.ivalue); /* send control message in*/ - if (dlt_client_send_timing_pakets_v2(&g_dltclient, (uint8_t) dltdata.ivalue) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send timing packets\n"); + if (dlt_client_send_timing_pakets_v2(&g_dltclient, (uint8_t)dltdata.ivalue) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Could not send timing packets\n"); ret = -1; } - } - else if (dltdata.oflag != -1) - { + } else if (dltdata.oflag != -1) { /* default trace status */ printf("Store config\n"); /* send control message in*/ if (dlt_client_send_store_config_v2(&g_dltclient) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send store config\n"); + fprintf(stderr, "ERROR: Could not send store config\n"); ret = -1; } - } - else if (dltdata.gflag != -1) - { + } else if (dltdata.gflag != -1) { /* reset to factory default */ printf("Reset to factory default\n"); /* send control message in*/ if (dlt_client_send_reset_to_factory_default_v2(&g_dltclient) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send reset to factory default\n"); + fprintf(stderr, "ERROR: Could not send reset to factory default\n"); ret = -1; } - } - else if (dltdata.jvalue == 1) - { + } else if (dltdata.jvalue == 1) { /* get log info */ printf("Get log info:\n"); dlt_process_get_log_info_v2(); - } - else if (dltdata.kvalue == 1) - { + } else if (dltdata.kvalue == 1) { /* Get software version */ printf("Get software version:\n"); dlt_process_get_software_version_v2(); @@ -807,129 +729,113 @@ int main(int argc, char *argv[]) return ret; } -int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data) +int dlt_receive_message_callback_v2(DltMessageV2* message, void* data) { static char resp_text[DLT_RECEIVE_BUFSIZE]; int ret = DLT_RETURN_OK; uint32_t id = 0; uint32_t uint32_tmp = 0; - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; - DltServiceHeader *req_header = NULL; + DltServiceHeader* req_header = NULL; - if ((message == NULL) || (data == NULL) || - !DLT_MSG_IS_CONTROL_V2(message)) + if ((message == NULL) || (data == NULL) || !DLT_MSG_IS_CONTROL_V2(message)) return -1; /* get request service id */ - req_header = (DltServiceHeader *)data; + req_header = (DltServiceHeader*)data; /* get response service id */ ptr = message->databuffer; - datalength =(int32_t) message->datasize; + datalength = (int32_t)message->datasize; DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); id = uint32_tmp; - if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_LAST_ENTRY) && - (id == req_header->service_id)) { + if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_LAST_ENTRY) && (id == req_header->service_id)) { switch (id) { - case DLT_SERVICE_ID_GET_LOG_INFO: - { - DltServiceGetLogInfoResponse *resp = - (DltServiceGetLogInfoResponse *)data; - - /* prepare storage header */ - if (DLT_IS_HTYP_WEID(message->baseheaderv2->htyp2)) - dlt_set_storageheader_v2(&(message->storageheaderv2), message->extendedheaderv2.ecidlen, - message->extendedheaderv2.ecid); - else - dlt_set_storageheader_v2(&(message->storageheaderv2), 4, "LCTL"); - message->storageheadersizev2 = (uint32_t)(STORAGE_HEADER_V2_FIXED_SIZE + message->storageheaderv2.ecidlen); - - /* Add Storage Header to Header Buffer and update header size*/ - uint8_t temp_buffer[message->headersizev2]; - memcpy(temp_buffer, message->headerbufferv2, (size_t)message->headersizev2); - free(message->headerbufferv2); - message->headersizev2 = message->headersizev2 + (int32_t)message->storageheadersizev2; - - message->headerbufferv2 = (uint8_t *)malloc((size_t)message->headersizev2); - - if (dlt_message_set_storageparameters_v2(message, 0) != DLT_RETURN_OK) - return -1; + case DLT_SERVICE_ID_GET_LOG_INFO: { + DltServiceGetLogInfoResponse* resp = (DltServiceGetLogInfoResponse*)data; - memcpy(message->headerbufferv2 + message->storageheadersizev2, temp_buffer, (size_t)(message->headersizev2 - (int32_t)message->storageheadersizev2)); + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(message->baseheaderv2->htyp2)) + dlt_set_storageheader_v2( + &(message->storageheaderv2), message->extendedheaderv2.ecidlen, message->extendedheaderv2.ecid); + else + dlt_set_storageheader_v2(&(message->storageheaderv2), 4, "LCTL"); + message->storageheadersizev2 = (uint32_t)(STORAGE_HEADER_V2_FIXED_SIZE + message->storageheaderv2.ecidlen); - /* get response data */ - ret = dlt_message_header_v2(message, resp_text, - DLT_RECEIVE_BUFSIZE, 0); + /* Add Storage Header to Header Buffer and update header size*/ + uint8_t temp_buffer[message->headersizev2]; + memcpy(temp_buffer, message->headerbufferv2, (size_t)message->headersizev2); + free(message->headerbufferv2); + message->headersizev2 = message->headersizev2 + (int32_t)message->storageheadersizev2; - if (ret < 0) { - fprintf(stderr, - "GET_LOG_INFO message_header result failed.\n"); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + message->headerbufferv2 = (uint8_t*)malloc((size_t)message->headersizev2); - ret = dlt_message_payload_v2(message, resp_text, - DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); + if (dlt_message_set_storageparameters_v2(message, 0) != DLT_RETURN_OK) + return -1; - if (ret < 0) { - fprintf(stderr, - "GET_LOG_INFO message_payload result failed.\n"); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + memcpy( + message->headerbufferv2 + message->storageheadersizev2, temp_buffer, + (size_t)(message->headersizev2 - (int32_t)message->storageheadersizev2)); - ret = dlt_set_loginfo_parse_service_id(resp_text, - &resp->service_id, &resp->status); + /* get response data */ + ret = dlt_message_header_v2(message, resp_text, DLT_RECEIVE_BUFSIZE, 0); - if ((ret == 0) && - (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { - ret = dlt_client_parse_get_log_info_resp_text_v2(resp, - resp_text); + if (ret < 0) { + fprintf(stderr, "GET_LOG_INFO message_header result failed.\n"); + dlt_client_cleanup(&g_dltclient, 0); + return -1; + } - if (ret != 0) - { - fprintf(stderr, "GET_LOG_INFO failed [status=%d]\n", - resp->status); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + ret = dlt_message_payload_v2(message, resp_text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); - dlt_client_cleanup(&g_dltclient, 0); - } - break; + if (ret < 0) { + fprintf(stderr, "GET_LOG_INFO message_payload result failed.\n"); + dlt_client_cleanup(&g_dltclient, 0); + return -1; } - case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: - { - DltServiceGetSoftwareVersionResponse *resp = - (DltServiceGetSoftwareVersionResponse *)data; - - resp->service_id = id; - DLT_MSG_READ_VALUE(resp->status, ptr, datalength, uint8_t); - DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); - resp->length = uint32_tmp; - - if (resp->status != DLT_SERVICE_RESPONSE_OK) { - fprintf(stderr, "GET_SOFTWARE_VERSION failed [status=%d]\n", - resp->status); + + ret = dlt_set_loginfo_parse_service_id(resp_text, &resp->service_id, &resp->status); + + if ((ret == 0) && (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { + ret = dlt_client_parse_get_log_info_resp_text_v2(resp, resp_text); + + if (ret != 0) { + fprintf(stderr, "GET_LOG_INFO failed [status=%d]\n", resp->status); dlt_client_cleanup(&g_dltclient, 0); return -1; } - resp->payload = (char *)calloc(resp->length + 1, sizeof(char)); - if (resp->payload != NULL) - memcpy(resp->payload, message->databuffer + - message->datasize - resp->length, resp->length); - dlt_client_cleanup(&g_dltclient, 0); - break; } - default: - { - break; + break; + } + case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: { + DltServiceGetSoftwareVersionResponse* resp = (DltServiceGetSoftwareVersionResponse*)data; + + resp->service_id = id; + DLT_MSG_READ_VALUE(resp->status, ptr, datalength, uint8_t); + DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); + resp->length = uint32_tmp; + + if (resp->status != DLT_SERVICE_RESPONSE_OK) { + fprintf(stderr, "GET_SOFTWARE_VERSION failed [status=%d]\n", resp->status); + dlt_client_cleanup(&g_dltclient, 0); + return -1; } + + resp->payload = (char*)calloc(resp->length + 1, sizeof(char)); + if (resp->payload != NULL) + memcpy(resp->payload, message->databuffer + message->datasize - resp->length, resp->length); + + dlt_client_cleanup(&g_dltclient, 0); + break; + } + default: { + break; + } } } diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c index 658c78d44..e913c5b71 100644 --- a/src/console/dlt-control.c +++ b/src/console/dlt-control.c @@ -52,47 +52,46 @@ ** aw Alexander Wenzel BMW ** *******************************************************************************/ -#include /* for isprint() */ -#include /* for atoi() */ -#include /* for writev() */ -#include /* for open() */ +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for writev() */ +#include /* for open() */ #include "dlt_client.h" #include "dlt_user.h" #include "dlt-control-common.h" -#define DLT_GLOGINFO_APID_NUM_MAX 150 -#define DLT_GLOGINFO_DATA_MAX 800 -#define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ -#define DLT_INVALID_LOG_LEVEL 0xF -#define DLT_INVALID_TRACE_STATUS 0xF +#define DLT_GLOGINFO_APID_NUM_MAX 150 +#define DLT_GLOGINFO_DATA_MAX 800 +#define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ +#define DLT_INVALID_LOG_LEVEL 0xF +#define DLT_INVALID_TRACE_STATUS 0xF /* Option of GET_LOG_INFO */ -#define DLT_SERVICE_GET_LOG_INFO_OPT7 7 /* get Apid, ApDescription, Ctid, CtDescription, loglevel, tracestatus */ +#define DLT_SERVICE_GET_LOG_INFO_OPT7 7 /* get Apid, ApDescription, Ctid, CtDescription, loglevel, tracestatus */ /** * The structure of the DLT Service header */ -typedef struct -{ - uint32_t service_id; /**< service ID */ - uint8_t status; /**< response status */ +typedef struct { + uint32_t service_id; /**< service ID */ + uint8_t status; /**< response status */ } DLT_PACKED DltServiceHeader; DltClient g_dltclient; /* Function prototypes */ -int dlt_receive_message_callback(DltMessage *message, void *data); +int dlt_receive_message_callback(DltMessage* message, void* data); typedef struct { int vflag; int yflag; - char *evalue; + char* evalue; - char *avalue; - char *cvalue; + char* avalue; + char* cvalue; int svalue; - char *mvalue; - char *xvalue; + char* mvalue; + char* xvalue; int tvalue; int lvalue; int rvalue; @@ -172,16 +171,14 @@ void usage(void) */ void dlt_process_get_log_info(void) { - char apid[DLT_ID_SIZE + 1] = { 0 }; - char ctid[DLT_ID_SIZE + 1] = { 0 }; + char apid[DLT_ID_SIZE + 1] = {0}; + char ctid[DLT_ID_SIZE + 1] = {0}; AppIDsType app; ContextIDsInfoType con; int i = 0; int j = 0; - DltServiceGetLogInfoResponse *resp = - (DltServiceGetLogInfoResponse *)calloc(1, - sizeof(DltServiceGetLogInfoResponse)); + DltServiceGetLogInfoResponse* resp = (DltServiceGetLogInfoResponse*)calloc(1, sizeof(DltServiceGetLogInfoResponse)); if (NULL == resp) { fprintf(stderr, "ERROR: calloc for resp data failed.\n"); @@ -200,12 +197,11 @@ void dlt_process_get_log_info(void) return; } - if (dlt_client_main_loop(&g_dltclient, (void *)resp, 0) == DLT_RETURN_TRUE) + if (dlt_client_main_loop(&g_dltclient, (void*)resp, 0) == DLT_RETURN_TRUE) fprintf(stdout, "DLT-daemon's response is invalid.\n"); - if (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO && - resp->status >= GET_LOG_INFO_STATUS_MIN && - resp->status <= GET_LOG_INFO_STATUS_MAX) { + if (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO && resp->status >= GET_LOG_INFO_STATUS_MIN + && resp->status <= GET_LOG_INFO_STATUS_MAX) { for (i = 0; i < resp->log_info_type.count_app_ids; i++) { app = resp->log_info_type.app_ids[i]; @@ -222,16 +218,9 @@ void dlt_process_get_log_info(void) dlt_print_id(ctid, con.context_id); if (con.context_description != 0) - printf("CTID:%4.4s %2d %2d %s\n", - ctid, - con.log_level, - con.trace_status, - con.context_description); + printf("CTID:%4.4s %2d %2d %s\n", ctid, con.log_level, con.trace_status, con.context_description); else - printf("CTID:%4.4s %2d %2d\n", - ctid, - con.log_level, - con.trace_status); + printf("CTID:%4.4s %2d %2d\n", ctid, con.log_level, con.trace_status); } } } @@ -245,9 +234,8 @@ void dlt_process_get_log_info(void) */ void dlt_process_get_software_version(void) { - DltServiceGetSoftwareVersionResponse *resp = - (DltServiceGetSoftwareVersionResponse *)calloc(1, - sizeof(DltServiceGetSoftwareVersionResponse)); + DltServiceGetSoftwareVersionResponse* resp = + (DltServiceGetSoftwareVersionResponse*)calloc(1, sizeof(DltServiceGetSoftwareVersionResponse)); if (NULL == resp) { fprintf(stderr, "ERROR: calloc for resp data failed.\n"); @@ -266,13 +254,11 @@ void dlt_process_get_software_version(void) return; } - if (dlt_client_main_loop(&g_dltclient, (void *)resp, 0) == DLT_RETURN_TRUE) + if (dlt_client_main_loop(&g_dltclient, (void*)resp, 0) == DLT_RETURN_TRUE) fprintf(stdout, "DLT-daemon's response is invalid.\n"); - if (resp->service_id == DLT_SERVICE_ID_GET_SOFTWARE_VERSION && - resp->status == DLT_SERVICE_RESPONSE_OK && - resp->payload != NULL) - { + if (resp->service_id == DLT_SERVICE_ID_GET_SOFTWARE_VERSION && resp->status == DLT_SERVICE_RESPONSE_OK + && resp->payload != NULL) { printf("%s\n", resp->payload); free(resp->payload); resp->payload = NULL; @@ -285,13 +271,13 @@ void dlt_process_get_software_version(void) /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { DltReceiveData dltdata; int c; int ret; int index; - char *endptr = NULL; + char* endptr = NULL; struct timespec ts; /* Initialize dltdata */ @@ -304,8 +290,7 @@ int main(int argc, char *argv[]) .ivalue = -1, .oflag = -1, .gflag = -1, - .port = 3490 - }; + .port = 3490}; /* Fetch command line arguments */ opterr = 0; @@ -313,170 +298,144 @@ int main(int argc, char *argv[]) /* Default return value */ ret = 0; - while ((c = getopt (argc, argv, "vhSRye:b:a:c:s:m:x:t:l:r:d:f:i:ogjkup:")) != -1) + while ((c = getopt(argc, argv, "vhSRye:b:a:c:s:m:x:t:l:r:d:f:i:ogjkup:")) != -1) switch (c) { - case 'v': - { + case 'v': { dltdata.vflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'S': - { + case 'S': { dltdata.sendSerialHeaderFlag = 1; break; } - case 'R': - { + case 'R': { dltdata.resyncSerialHeaderFlag = 1; break; } - case 'y': - { + case 'y': { dltdata.yflag = DLT_CLIENT_MODE_SERIAL; break; } - case 'e': - { + case 'e': { dltdata.evalue = optarg; break; } - case 'b': - { + case 'b': { dltdata.bvalue = atoi(optarg); break; } - case 'a': - { + case 'a': { dltdata.avalue = optarg; if (strlen(dltdata.avalue) > DLT_ID_SIZE) { - fprintf (stderr, "Invalid application id\n"); + fprintf(stderr, "Invalid application id\n"); return -1; } break; } - case 'c': - { + case 'c': { dltdata.cvalue = optarg; if (strlen(dltdata.cvalue) > DLT_ID_SIZE) { - fprintf (stderr, "Invalid context id\n"); + fprintf(stderr, "Invalid context id\n"); return -1; } break; } - case 's': - { + case 's': { dltdata.svalue = atoi(optarg); break; } - case 'm': - { + case 'm': { dltdata.mvalue = optarg; break; } - case 'x': - { + case 'x': { dltdata.xvalue = optarg; break; } - case 't': - { + case 't': { dltdata.tvalue = atoi(optarg); break; } - case 'l': - { - dltdata.lvalue = (int) strtol(optarg, &endptr, 10); + case 'l': { + dltdata.lvalue = (int)strtol(optarg, &endptr, 10); if ((dltdata.lvalue < DLT_LOG_DEFAULT) || (dltdata.lvalue > DLT_LOG_VERBOSE)) { - fprintf (stderr, "invalid log level, supported log level 0-6\n"); + fprintf(stderr, "invalid log level, supported log level 0-6\n"); return -1; } break; } - case 'r': - { - dltdata.rvalue = (int) strtol(optarg, &endptr, 10); + case 'r': { + dltdata.rvalue = (int)strtol(optarg, &endptr, 10); if ((dltdata.rvalue < DLT_TRACE_STATUS_DEFAULT) || (dltdata.rvalue > DLT_TRACE_STATUS_ON)) { - fprintf (stderr, "invalid trace status, supported trace status -1, 0, 1\n"); + fprintf(stderr, "invalid trace status, supported trace status -1, 0, 1\n"); return -1; } break; } - case 'd': - { + case 'd': { dltdata.dvalue = atoi(optarg); break; } - case 'f': - { + case 'f': { dltdata.fvalue = atoi(optarg); break; } - case 'i': - { + case 'i': { dltdata.ivalue = atoi(optarg); break; } - case 'o': - { + case 'o': { dltdata.oflag = 1; break; } - case 'g': - { + case 'g': { dltdata.gflag = 1; break; } - case 'j': - { + case 'j': { dltdata.jvalue = 1; break; } - case 'k': - { + case 'k': { dltdata.kvalue = 1; break; } - case 'u': - { + case 'u': { dltdata.yflag = DLT_CLIENT_MODE_UNIX; break; } - case 'p': - { + case 'p': { dltdata.port = atoi(optarg); break; } - case '?': - { + case '?': { if ((optopt == 'o') || (optopt == 'f')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1; /*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -489,21 +448,17 @@ int main(int argc, char *argv[]) /* Setup DLT Client structure */ if (dltdata.yflag == DLT_CLIENT_MODE_SERIAL) { g_dltclient.mode = DLT_CLIENT_MODE_SERIAL; - } - else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX) - { + } else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX) { g_dltclient.mode = DLT_CLIENT_MODE_UNIX; g_dltclient.socketPath = NULL; - if (dlt_parse_config_param("ControlSocketPath", - &g_dltclient.socketPath) == DLT_RETURN_ERROR) { + if (dlt_parse_config_param("ControlSocketPath", &g_dltclient.socketPath) == DLT_RETURN_ERROR) { /* Failed to read from conf, copy default */ if (dlt_client_set_socket_path(&g_dltclient, DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH) == -1) { pr_error("set socket path didn't succeed\n"); return -1; } } - } - else { + } else { g_dltclient.mode = DLT_CLIENT_MODE_TCP; } @@ -522,9 +477,7 @@ int main(int argc, char *argv[]) dlt_client_cleanup(&g_dltclient, dltdata.vflag); return -1; } - } - else if (g_dltclient.mode == DLT_CLIENT_MODE_SERIAL) - { + } else if (g_dltclient.mode == DLT_CLIENT_MODE_SERIAL) { for (index = optind; index < argc; index++) if (dlt_client_set_serial_device(&g_dltclient, argv[index]) == -1) { pr_error("set serial device didn't succeed\n"); @@ -554,16 +507,14 @@ int main(int argc, char *argv[]) if (dltdata.evalue) { dlt_set_id(dltdata.ecuid, dltdata.evalue); dlt_set_id(g_dltclient.ecuid, dltdata.evalue); - } - else { + } else { dltdata.evalue = NULL; if (dlt_parse_config_param("ECUId", &dltdata.evalue) == 0) { dlt_set_id(dltdata.ecuid, dltdata.evalue); dlt_set_id(g_dltclient.ecuid, dltdata.evalue); - free (dltdata.evalue); - } - else { + free(dltdata.evalue); + } else { fprintf(stderr, "ERROR: Failed to read ECUId from dlt.conf \n"); } } @@ -580,18 +531,14 @@ int main(int argc, char *argv[]) printf("Message: %s\n", dltdata.mvalue); /* send control message in ascii */ - if (dlt_client_send_inject_msg(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint32_t) dltdata.svalue, - (uint8_t *)dltdata.mvalue, - (uint32_t) strlen(dltdata.mvalue)) != DLT_RETURN_OK) { + if (dlt_client_send_inject_msg( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint32_t)dltdata.svalue, (uint8_t*)dltdata.mvalue, + (uint32_t)strlen(dltdata.mvalue)) + != DLT_RETURN_OK) { fprintf(stderr, "ERROR: Could not send inject message\n"); ret = -1; } - } - else if (dltdata.xvalue && dltdata.avalue && dltdata.cvalue) - { + } else if (dltdata.xvalue && dltdata.avalue && dltdata.cvalue) { /* Hex */ uint8_t buffer[1024]; int size = 1024; @@ -604,16 +551,13 @@ int main(int argc, char *argv[]) printf("Size: %d\n", size); /* send control message in hex */ - if (dlt_client_send_inject_msg(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint32_t) dltdata.svalue, - buffer, (uint32_t)size) != DLT_RETURN_OK) { + if (dlt_client_send_inject_msg( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint32_t)dltdata.svalue, buffer, (uint32_t)size) + != DLT_RETURN_OK) { fprintf(stderr, "ERROR: Could not send inject message\n"); ret = -1; } - } - else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ + } else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/ { if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) { if (dltdata.vflag) { @@ -621,13 +565,11 @@ int main(int argc, char *argv[]) printf("Loglevel: %d\n", dltdata.lvalue); } - if (0 != dlt_client_send_all_log_level(&g_dltclient, - (uint8_t) dltdata.lvalue)) { + if (0 != dlt_client_send_all_log_level(&g_dltclient, (uint8_t)dltdata.lvalue)) { fprintf(stderr, "ERROR: Could not send log level\n"); ret = -1; } - } - else { + } else { /* log level */ if (dltdata.vflag) { printf("Set log level:\n"); @@ -637,30 +579,25 @@ int main(int argc, char *argv[]) } /* send control message*/ - if (0 != dlt_client_send_log_level(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint8_t) dltdata.lvalue)) { + if (0 + != dlt_client_send_log_level( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint8_t)dltdata.lvalue)) { fprintf(stderr, "ERROR: Could not send log level\n"); ret = -1; } } - } - else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS) - { + } else if (dltdata.rvalue != DLT_INVALID_TRACE_STATUS) { if ((dltdata.avalue == 0) && (dltdata.cvalue == 0)) { if (dltdata.vflag) { printf("Set all trace status:\n"); printf("Tracestatus: %d\n", dltdata.rvalue); } - if (0 != dlt_client_send_all_trace_status(&g_dltclient, - (uint8_t) dltdata.rvalue)) { + if (0 != dlt_client_send_all_trace_status(&g_dltclient, (uint8_t)dltdata.rvalue)) { fprintf(stderr, "ERROR: Could not send trace status\n"); ret = -1; } - } - else { + } else { /* trace status */ if (dltdata.vflag) { printf("Set trace status:\n"); @@ -670,81 +607,66 @@ int main(int argc, char *argv[]) } /* send control message*/ - if (0 != dlt_client_send_trace_status(&g_dltclient, - dltdata.avalue, - dltdata.cvalue, - (uint8_t) dltdata.rvalue)) { + if (0 + != dlt_client_send_trace_status( + &g_dltclient, dltdata.avalue, dltdata.cvalue, (uint8_t)dltdata.rvalue)) { fprintf(stderr, "ERROR: Could not send trace status\n"); ret = -1; } } - } - else if (dltdata.dvalue != -1) - { + } else if (dltdata.dvalue != -1) { /* default log level */ printf("Set default log level:\n"); printf("Loglevel: %d\n", dltdata.dvalue); /* send control message in*/ - if (dlt_client_send_default_log_level(&g_dltclient, (uint8_t) dltdata.dvalue) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send default log level\n"); + if (dlt_client_send_default_log_level(&g_dltclient, (uint8_t)dltdata.dvalue) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Could not send default log level\n"); ret = -1; } - } - else if (dltdata.fvalue != -1) - { + } else if (dltdata.fvalue != -1) { /* default trace status */ printf("Set default trace status:\n"); printf("TraceStatus: %d\n", dltdata.fvalue); /* send control message in*/ - if (dlt_client_send_default_trace_status(&g_dltclient, (uint8_t) dltdata.fvalue) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send default trace status\n"); + if (dlt_client_send_default_trace_status(&g_dltclient, (uint8_t)dltdata.fvalue) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Could not send default trace status\n"); ret = -1; } - } - else if (dltdata.ivalue != -1) - { + } else if (dltdata.ivalue != -1) { /* timing pakets */ printf("Set timing pakets:\n"); printf("Timing packets: %d\n", dltdata.ivalue); /* send control message in*/ - if (dlt_client_send_timing_pakets(&g_dltclient, (uint8_t) dltdata.ivalue) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send timing packets\n"); + if (dlt_client_send_timing_pakets(&g_dltclient, (uint8_t)dltdata.ivalue) != DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Could not send timing packets\n"); ret = -1; } - } - else if (dltdata.oflag != -1) - { + } else if (dltdata.oflag != -1) { /* default trace status */ printf("Store config\n"); /* send control message in*/ if (dlt_client_send_store_config(&g_dltclient) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send store config\n"); + fprintf(stderr, "ERROR: Could not send store config\n"); ret = -1; } - } - else if (dltdata.gflag != -1) - { + } else if (dltdata.gflag != -1) { /* reset to factory default */ printf("Reset to factory default\n"); /* send control message in*/ if (dlt_client_send_reset_to_factory_default(&g_dltclient) != DLT_RETURN_OK) { - fprintf (stderr, "ERROR: Could not send reset to factory default\n"); + fprintf(stderr, "ERROR: Could not send reset to factory default\n"); ret = -1; } - } - else if (dltdata.jvalue == 1) - { + } else if (dltdata.jvalue == 1) { /* get log info */ printf("Get log info:\n"); dlt_process_get_log_info(); - } - else if (dltdata.kvalue == 1) - { + } else if (dltdata.kvalue == 1) { /* Get software version */ printf("Get software version:\n"); dlt_process_get_software_version(); @@ -774,116 +696,96 @@ int main(int argc, char *argv[]) return ret; } -int dlt_receive_message_callback(DltMessage *message, void *data) +int dlt_receive_message_callback(DltMessage* message, void* data) { static char resp_text[DLT_RECEIVE_BUFSIZE]; int ret = DLT_RETURN_OK; uint32_t id = 0; uint32_t uint32_tmp = 0; - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; - DltServiceHeader *req_header = NULL; + DltServiceHeader* req_header = NULL; - if ((message == NULL) || (data == NULL) || - !DLT_MSG_IS_CONTROL_RESPONSE(message)) + if ((message == NULL) || (data == NULL) || !DLT_MSG_IS_CONTROL_RESPONSE(message)) return -1; /* get request service id */ - req_header = (DltServiceHeader *)data; + req_header = (DltServiceHeader*)data; /* get response service id */ ptr = message->databuffer; - datalength =(int32_t) message->datasize; + datalength = (int32_t)message->datasize; DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); id = DLT_ENDIAN_GET_32(message->standardheader->htyp, uint32_tmp); - if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_LAST_ENTRY) && - (id == req_header->service_id)) { + if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_LAST_ENTRY) && (id == req_header->service_id)) { switch (id) { - case DLT_SERVICE_ID_GET_LOG_INFO: - { - DltServiceGetLogInfoResponse *resp = - (DltServiceGetLogInfoResponse *)data; - - /* prepare storage header */ - if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) - dlt_set_storageheader(message->storageheader, - message->headerextra.ecu); - else - dlt_set_storageheader(message->storageheader, "LCTL"); + case DLT_SERVICE_ID_GET_LOG_INFO: { + DltServiceGetLogInfoResponse* resp = (DltServiceGetLogInfoResponse*)data; - /* get response data */ - ret = dlt_message_header(message, resp_text, - DLT_RECEIVE_BUFSIZE, 0); + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) + dlt_set_storageheader(message->storageheader, message->headerextra.ecu); + else + dlt_set_storageheader(message->storageheader, "LCTL"); - if (ret < 0) { - fprintf(stderr, - "GET_LOG_INFO message_header result failed.\n"); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + /* get response data */ + ret = dlt_message_header(message, resp_text, DLT_RECEIVE_BUFSIZE, 0); - ret = dlt_message_payload(message, resp_text, - DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); + if (ret < 0) { + fprintf(stderr, "GET_LOG_INFO message_header result failed.\n"); + dlt_client_cleanup(&g_dltclient, 0); + return -1; + } - if (ret < 0) { - fprintf(stderr, - "GET_LOG_INFO message_payload result failed.\n"); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + ret = dlt_message_payload(message, resp_text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0); - ret = dlt_set_loginfo_parse_service_id(resp_text, - &resp->service_id, &resp->status); + if (ret < 0) { + fprintf(stderr, "GET_LOG_INFO message_payload result failed.\n"); + dlt_client_cleanup(&g_dltclient, 0); + return -1; + } - if ((ret == 0) && - (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { - ret = dlt_client_parse_get_log_info_resp_text(resp, - resp_text); + ret = dlt_set_loginfo_parse_service_id(resp_text, &resp->service_id, &resp->status); - if (ret != 0) - { - fprintf(stderr, "GET_LOG_INFO failed [status=%d]\n", - resp->status); - dlt_client_cleanup(&g_dltclient, 0); - return -1; - } + if ((ret == 0) && (resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO)) { + ret = dlt_client_parse_get_log_info_resp_text(resp, resp_text); - dlt_client_cleanup(&g_dltclient, 0); - } - break; - } - case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: - { - DltServiceGetSoftwareVersionResponse *resp = - (DltServiceGetSoftwareVersionResponse *)data; - - resp->service_id = id; - DLT_MSG_READ_VALUE(resp->status, ptr, datalength, uint8_t); - DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); - resp->length = DLT_ENDIAN_GET_32(message->standardheader->htyp, - uint32_tmp); - - if (resp->status != DLT_SERVICE_RESPONSE_OK) { - fprintf(stderr, "GET_SOFTWARE_VERSION failed [status=%d]\n", - resp->status); + if (ret != 0) { + fprintf(stderr, "GET_LOG_INFO failed [status=%d]\n", resp->status); dlt_client_cleanup(&g_dltclient, 0); return -1; } - resp->payload = (char *)calloc(resp->length + 1, sizeof(char)); - if (resp->payload != NULL) - memcpy(resp->payload, message->databuffer + - message->datasize - resp->length, resp->length); - dlt_client_cleanup(&g_dltclient, 0); - break; } - default: - { - break; + break; + } + case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: { + DltServiceGetSoftwareVersionResponse* resp = (DltServiceGetSoftwareVersionResponse*)data; + + resp->service_id = id; + DLT_MSG_READ_VALUE(resp->status, ptr, datalength, uint8_t); + DLT_MSG_READ_VALUE(uint32_tmp, ptr, datalength, uint32_t); + resp->length = DLT_ENDIAN_GET_32(message->standardheader->htyp, uint32_tmp); + + if (resp->status != DLT_SERVICE_RESPONSE_OK) { + fprintf(stderr, "GET_SOFTWARE_VERSION failed [status=%d]\n", resp->status); + dlt_client_cleanup(&g_dltclient, 0); + return -1; } + + resp->payload = (char*)calloc(resp->length + 1, sizeof(char)); + if (resp->payload != NULL) + memcpy(resp->payload, message->databuffer + message->datasize - resp->length, resp->length); + + dlt_client_cleanup(&g_dltclient, 0); + break; + } + default: { + break; + } } } diff --git a/src/console/dlt-convert-v2.c b/src/console/dlt-convert-v2.c index 05dbe2d25..dab8f3c4c 100644 --- a/src/console/dlt-convert-v2.c +++ b/src/console/dlt-convert-v2.c @@ -66,14 +66,14 @@ #include #include -#include /* write() */ +#include /* write() */ #include "dlt_common.h" -#define COMMAND_SIZE 1024 /* Size of command buffer */ -#define FILENAME_SIZE 1024 /* Size of filename buffer */ -#define DLT_EXTENSION "dlt" -#define DLT_CONVERT_V2_WS "/tmp/dlt_convert_v2_workspace/" +#define COMMAND_SIZE 1024 /* Size of command buffer */ +#define FILENAME_SIZE 1024 /* Size of filename buffer */ +#define DLT_EXTENSION "dlt" +#define DLT_CONVERT_V2_WS "/tmp/dlt_convert_v2_workspace/" /* Index grows in blocks of this many entries */ #define DLT_CVT_V2_INDEX_ALLOC 1000 @@ -85,22 +85,22 @@ * we implement the same pattern here using dlt_message_read_v2 directly. */ typedef struct { - FILE *handle; - long *index; /* file offset of each accepted message */ - int32_t counter; /* messages accepted by filter */ - int32_t counter_total; /* total messages seen */ - DltMessageV2 msgv2; /* parsed representation of the current message */ - uint8_t *raw_buffer; /* raw bytes of the current message (as on disk) */ - uint32_t raw_buf_size; /* allocated size of raw_buffer */ - uint32_t raw_msg_size; /* actual byte count of the current message */ - DltFilter *filter; /* optional filter (NULL = accept all) */ + FILE* handle; + long* index; /* file offset of each accepted message */ + int32_t counter; /* messages accepted by filter */ + int32_t counter_total; /* total messages seen */ + DltMessageV2 msgv2; /* parsed representation of the current message */ + uint8_t* raw_buffer; /* raw bytes of the current message (as on disk) */ + uint32_t raw_buf_size; /* allocated size of raw_buffer */ + uint32_t raw_msg_size; /* actual byte count of the current message */ + DltFilter* filter; /* optional filter (NULL = accept all) */ } DltConvertFileV2; /* ------------------------------------------------------------------------- * Internal helpers * ---------------------------------------------------------------------- */ -static DltReturnValue dlt_cvt_file_v2_init(DltConvertFileV2 *file, int verbose) +static DltReturnValue dlt_cvt_file_v2_init(DltConvertFileV2* file, int verbose) { if (file == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -109,20 +109,18 @@ static DltReturnValue dlt_cvt_file_v2_init(DltConvertFileV2 *file, int verbose) return dlt_message_init_v2(&file->msgv2, verbose); } -static void dlt_cvt_file_v2_set_filter(DltConvertFileV2 *file, DltFilter *filter) +static void dlt_cvt_file_v2_set_filter(DltConvertFileV2* file, DltFilter* filter) { if (file != NULL) file->filter = filter; } -static DltReturnValue dlt_cvt_file_v2_open(DltConvertFileV2 *file, - const char *filename, - int verbose) +static DltReturnValue dlt_cvt_file_v2_open(DltConvertFileV2* file, const char* filename, int verbose) { if ((file == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - file->counter = 0; + file->counter = 0; file->counter_total = 0; if (file->handle) @@ -150,30 +148,28 @@ static DltReturnValue dlt_cvt_file_v2_open(DltConvertFileV2 *file, * * Returns DLT_RETURN_OK on success, DLT_RETURN_ERROR on EOF or parse error. */ -static DltReturnValue dlt_cvt_file_v2_read_one(DltConvertFileV2 *file, int verbose) +static DltReturnValue dlt_cvt_file_v2_read_one(DltConvertFileV2* file, int verbose) { uint8_t fixed_buf[STORAGE_HEADER_V2_FIXED_SIZE]; uint8_t base_buf[BASE_HEADER_V2_FIXED_SIZE]; - DltBaseHeaderV2 *bh; + DltBaseHeaderV2* bh; uint32_t storageheadersizev2; uint16_t len; uint32_t total_size; - uint8_t ecidlen; + uint8_t ecidlen; /* --- Step 1: read the fixed part of the storage header (14 bytes) --- */ - if (fread(fixed_buf, 1, STORAGE_HEADER_V2_FIXED_SIZE, file->handle) - != STORAGE_HEADER_V2_FIXED_SIZE) - return DLT_RETURN_ERROR; /* EOF or short read */ + if (fread(fixed_buf, 1, STORAGE_HEADER_V2_FIXED_SIZE, file->handle) != STORAGE_HEADER_V2_FIXED_SIZE) + return DLT_RETURN_ERROR; /* EOF or short read */ /* Verify DLT v2 pattern: 'D','L','T',0x02 */ - if (fixed_buf[0] != 'D' || fixed_buf[1] != 'L' || - fixed_buf[2] != 'T' || fixed_buf[3] != 0x02) { + if (fixed_buf[0] != 'D' || fixed_buf[1] != 'L' || fixed_buf[2] != 'T' || fixed_buf[3] != 0x02) { fprintf(stderr, "ERROR: Not a DLT v2 storage header at current position\n"); return DLT_RETURN_ERROR; } /* ecidlen is at byte offset 13 within the storage header */ - ecidlen = fixed_buf[13]; + ecidlen = fixed_buf[13]; storageheadersizev2 = (uint32_t)(STORAGE_HEADER_V2_FIXED_SIZE + ecidlen); /* Skip the variable-length ECU ID field inside the storage header */ @@ -181,29 +177,25 @@ static DltReturnValue dlt_cvt_file_v2_read_one(DltConvertFileV2 *file, int verbo return DLT_RETURN_ERROR; /* --- Step 2: read the base header (7 bytes) to obtain message length --- */ - if (fread(base_buf, 1, BASE_HEADER_V2_FIXED_SIZE, file->handle) - != BASE_HEADER_V2_FIXED_SIZE) + if (fread(base_buf, 1, BASE_HEADER_V2_FIXED_SIZE, file->handle) != BASE_HEADER_V2_FIXED_SIZE) return DLT_RETURN_ERROR; - bh = (DltBaseHeaderV2 *)base_buf; - len = DLT_BETOH_16(bh->len); /* big-endian: size excluding storage hdr */ - total_size = storageheadersizev2 + (uint32_t)len; + bh = (DltBaseHeaderV2*)base_buf; + len = DLT_BETOH_16(bh->len); /* big-endian: size excluding storage hdr */ + total_size = storageheadersizev2 + (uint32_t)len; /* --- Step 3: seek back to the start of the message and read everything --- */ - if (fseek(file->handle, - -((long)storageheadersizev2 + (long)BASE_HEADER_V2_FIXED_SIZE), - SEEK_CUR) != 0) + if (fseek(file->handle, -((long)storageheadersizev2 + (long)BASE_HEADER_V2_FIXED_SIZE), SEEK_CUR) != 0) return DLT_RETURN_ERROR; /* Grow the raw buffer if the current message is larger than previous ones */ if (total_size > file->raw_buf_size) { free(file->raw_buffer); - file->raw_buffer = (uint8_t *)malloc(total_size); + file->raw_buffer = (uint8_t*)malloc(total_size); if (file->raw_buffer == NULL) { file->raw_buf_size = 0; - fprintf(stderr, "ERROR: Cannot allocate %u bytes for message buffer\n", - total_size); + fprintf(stderr, "ERROR: Cannot allocate %u bytes for message buffer\n", total_size); return DLT_RETURN_ERROR; } @@ -216,8 +208,7 @@ static DltReturnValue dlt_cvt_file_v2_read_one(DltConvertFileV2 *file, int verbo return DLT_RETURN_ERROR; /* --- Step 4: parse the raw bytes into file->msgv2 --- */ - if (dlt_message_read_v2(&file->msgv2, file->raw_buffer, total_size, 0, verbose) - != DLT_MESSAGE_ERROR_OK) + if (dlt_message_read_v2(&file->msgv2, file->raw_buffer, total_size, 0, verbose) != DLT_MESSAGE_ERROR_OK) return DLT_RETURN_ERROR; return DLT_RETURN_OK; @@ -232,10 +223,10 @@ static DltReturnValue dlt_cvt_file_v2_read_one(DltConvertFileV2 *file, int verbo * DLT_RETURN_OK – message read but filtered out (index NOT updated) * DLT_RETURN_ERROR – EOF or parse error (stop reading loop) */ -static DltReturnValue dlt_cvt_file_v2_read(DltConvertFileV2 *file, int verbose) +static DltReturnValue dlt_cvt_file_v2_read(DltConvertFileV2* file, int verbose) { - long start_pos; - long *ptr; + long start_pos; + long* ptr; if (file == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -245,10 +236,8 @@ static DltReturnValue dlt_cvt_file_v2_read(DltConvertFileV2 *file, int verbose) /* Grow the position index in blocks of DLT_CVT_V2_INDEX_ALLOC */ if (file->counter % DLT_CVT_V2_INDEX_ALLOC == 0) { - ptr = (long *)malloc( - (size_t)((file->counter / DLT_CVT_V2_INDEX_ALLOC) + 1) - * (size_t)DLT_CVT_V2_INDEX_ALLOC - * sizeof(long)); + ptr = (long*)malloc( + (size_t)((file->counter / DLT_CVT_V2_INDEX_ALLOC) + 1) * (size_t)DLT_CVT_V2_INDEX_ALLOC * sizeof(long)); if (ptr == NULL) return DLT_RETURN_ERROR; @@ -271,13 +260,12 @@ static DltReturnValue dlt_cvt_file_v2_read(DltConvertFileV2 *file, int verbose) file->counter_total++; if (file->filter) { - if (dlt_message_filter_check_v2(&file->msgv2, file->filter, verbose) - == DLT_RETURN_TRUE) { + if (dlt_message_filter_check_v2(&file->msgv2, file->filter, verbose) == DLT_RETURN_TRUE) { file->index[file->counter] = start_pos; file->counter++; return DLT_RETURN_TRUE; } - return DLT_RETURN_OK; /* filtered out – keep scanning */ + return DLT_RETURN_OK; /* filtered out – keep scanning */ } /* No filter: accept every message */ @@ -290,9 +278,7 @@ static DltReturnValue dlt_cvt_file_v2_read(DltConvertFileV2 *file, int verbose) * dlt_cvt_file_v2_message - seek to message `num` (0-based, filter-adjusted * index) and populate file->msgv2 / raw_buffer. */ -static DltReturnValue dlt_cvt_file_v2_message(DltConvertFileV2 *file, - int32_t num, - int verbose) +static DltReturnValue dlt_cvt_file_v2_message(DltConvertFileV2* file, int32_t num, int verbose) { if ((file == NULL) || (num < 0) || (num >= file->counter)) return DLT_RETURN_WRONG_PARAMETER; @@ -303,7 +289,7 @@ static DltReturnValue dlt_cvt_file_v2_message(DltConvertFileV2 *file, return dlt_cvt_file_v2_read_one(file, verbose); } -static DltReturnValue dlt_cvt_file_v2_free(DltConvertFileV2 *file, int verbose) +static DltReturnValue dlt_cvt_file_v2_free(DltConvertFileV2* file, int verbose) { if (file == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -319,7 +305,7 @@ static DltReturnValue dlt_cvt_file_v2_free(DltConvertFileV2 *file, int verbose) } free(file->raw_buffer); - file->raw_buffer = NULL; + file->raw_buffer = NULL; file->raw_buf_size = 0; file->raw_msg_size = 0; @@ -329,11 +315,11 @@ static DltReturnValue dlt_cvt_file_v2_free(DltConvertFileV2 *file, int verbose) /* ------------------------------------------------------------------------- * empty_dir – remove all files inside a directory (shared with dlt-convert) * ---------------------------------------------------------------------- */ -static void empty_dir(const char *dir) +static void empty_dir(const char* dir) { - struct dirent **files = { 0 }; + struct dirent** files = {0}; struct stat st; - char tmp_filename[FILENAME_SIZE] = { 0 }; + char tmp_filename[FILENAME_SIZE] = {0}; if (dir == NULL) { fprintf(stderr, "ERROR: %s: invalid arguments\n", __func__); @@ -356,26 +342,20 @@ static void empty_dir(const char *dir) free(files[i]); free(files); return; - } - else if (n == 2) { + } else if (n == 2) { printf("%s is already empty\n", dir); - } - else { + } else { for (int i = 2; i < n; i++) { memset(tmp_filename, 0, FILENAME_SIZE); /* Validate filename to prevent path traversal */ - if (strstr(files[i]->d_name, "/") == NULL && - strstr(files[i]->d_name, "..") == NULL) { + if (strstr(files[i]->d_name, "/") == NULL && strstr(files[i]->d_name, "..") == NULL) { /* Limit d_name to 993 chars to guarantee the result fits in * FILENAME_SIZE (1024) together with the 30-char prefix and NUL. */ - snprintf(tmp_filename, FILENAME_SIZE, "%s%.993s", - dir, files[i]->d_name); + snprintf(tmp_filename, FILENAME_SIZE, "%s%.993s", dir, files[i]->d_name); if (remove(tmp_filename) != 0) - fprintf(stderr, "ERROR: Failed to delete %s: %s\n", - tmp_filename, strerror(errno)); + fprintf(stderr, "ERROR: Failed to delete %s: %s\n", tmp_filename, strerror(errno)); } else { - fprintf(stderr, "WARNING: Skipping suspicious filename: %s\n", - files[i]->d_name); + fprintf(stderr, "WARNING: Skipping suspicious filename: %s\n", files[i]->d_name); } } } @@ -385,12 +365,10 @@ static void empty_dir(const char *dir) files[i] = NULL; } free(files); - } - else { + } else { fprintf(stderr, "ERROR: %s is not a directory\n", dir); } - } - else { + } else { fprintf(stderr, "ERROR: Failed to stat %s: %s\n", dir, strerror(errno)); } } @@ -430,7 +408,7 @@ static void usage(void) /* ------------------------------------------------------------------------- * main * ---------------------------------------------------------------------- */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int vflag = 0; int cflag = 0; @@ -440,28 +418,28 @@ int main(int argc, char *argv[]) int mflag = 0; int wflag = 0; int tflag = 0; - char *fvalue = NULL; - char *bvalue = NULL; - char *evalue = NULL; - char *ovalue = NULL; + char* fvalue = NULL; + char* bvalue = NULL; + char* evalue = NULL; + char* ovalue = NULL; int index; int c; DltConvertFileV2 file; - DltFilter filter; + DltFilter filter; int ohandle = -1; int num, begin, end; - char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 }; + char text[DLT_CONVERT_TEXTBUFSIZE] = {0}; /* For handling compressed files */ - char tmp_filename[FILENAME_SIZE] = { 0 }; + char tmp_filename[FILENAME_SIZE] = {0}; struct stat st; memset(&st, 0, sizeof(struct stat)); - struct dirent **files = { 0 }; + struct dirent** files = {0}; int n = 0; ssize_t bytes_written = 0; @@ -471,73 +449,59 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "vcashxmwtf:b:e:o:")) != -1) { switch (c) { - case 'v': - { + case 'v': { vflag = 1; break; } - case 'c': - { + case 'c': { cflag = 1; break; } - case 'a': - { + case 'a': { aflag = 1; break; } - case 's': - { + case 's': { sflag = 1; break; } - case 'x': - { + case 'x': { xflag = 1; break; } - case 'm': - { + case 'm': { mflag = 1; break; } - case 'w': - { + case 'w': { wflag = 1; break; } - case 't': - { + case 't': { tflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'b': - { + case 'b': { bvalue = optarg; break; } - case 'e': - { + case 'e': { evalue = optarg; break; } - case 'o': - { + case 'o': { ovalue = optarg; break; } - case '?': - { + case '?': { if ((optopt == 'f') || (optopt == 'b') || (optopt == 'e') || (optopt == 'o')) fprintf(stderr, "Option -%c requires an argument.\n", optopt); else if (isprint(optopt)) @@ -548,9 +512,8 @@ int main(int argc, char *argv[]) usage(); return -1; } - default: - { - return -1; /* for parasoft */ + default: { + return -1; /* for parasoft */ } } } @@ -595,8 +558,7 @@ int main(int argc, char *argv[]) dlt_cvt_file_v2_free(&file, vflag); return -1; } - } - else { + } else { if (S_ISDIR(st.st_mode)) empty_dir(DLT_CONVERT_V2_WS); else @@ -604,23 +566,20 @@ int main(int argc, char *argv[]) } for (index = optind; index < argc; index++) { - const char *file_ext = get_filename_ext(argv[index]); + const char* file_ext = get_filename_ext(argv[index]); if (file_ext && strcmp(file_ext, DLT_EXTENSION) != 0) { - syserr = dlt_execute_command(NULL, "tar", "xf", argv[index], - "-C", DLT_CONVERT_V2_WS, NULL); + syserr = dlt_execute_command(NULL, "tar", "xf", argv[index], "-C", DLT_CONVERT_V2_WS, NULL); if (syserr != 0) - fprintf(stderr, - "ERROR: Failed to uncompress %s to %s [%d]\n", - argv[index], DLT_CONVERT_V2_WS, WIFEXITED(syserr)); - } - else { - syserr = dlt_execute_command(NULL, "cp", argv[index], - DLT_CONVERT_V2_WS, NULL); + fprintf( + stderr, "ERROR: Failed to uncompress %s to %s [%d]\n", argv[index], DLT_CONVERT_V2_WS, + WIFEXITED(syserr)); + } else { + syserr = dlt_execute_command(NULL, "cp", argv[index], DLT_CONVERT_V2_WS, NULL); if (syserr != 0) - fprintf(stderr, - "ERROR: Failed to copy %s to %s [%d]\n", - argv[index], DLT_CONVERT_V2_WS, WIFEXITED(syserr)); + fprintf( + stderr, "ERROR: Failed to copy %s to %s [%d]\n", argv[index], DLT_CONVERT_V2_WS, + WIFEXITED(syserr)); } } @@ -647,8 +606,7 @@ int main(int argc, char *argv[]) memset(tmp_filename, 0, FILENAME_SIZE); /* Limit d_name to 993 chars to guarantee the result fits in * FILENAME_SIZE (1024) together with the 30-char prefix and NUL. */ - snprintf(tmp_filename, FILENAME_SIZE, "%s%.993s", - DLT_CONVERT_V2_WS, files[index - optind + 2]->d_name); + snprintf(tmp_filename, FILENAME_SIZE, "%s%.993s", DLT_CONVERT_V2_WS, files[index - optind + 2]->d_name); argv[index] = tmp_filename; } @@ -669,9 +627,7 @@ int main(int argc, char *argv[]) end = file.counter - 1; if ((begin < 0) || (begin >= file.counter)) { - fprintf(stderr, - "ERROR: Selected first message %d is out of range!\n", - begin); + fprintf(stderr, "ERROR: Selected first message %d is out of range!\n", begin); if (ovalue) { close(ohandle); @@ -683,9 +639,7 @@ int main(int argc, char *argv[]) } if ((end < 0) || (end >= file.counter) || (end < begin)) { - fprintf(stderr, - "ERROR: Selected end message %d is out of range!\n", - end); + fprintf(stderr, "ERROR: Selected end message %d is out of range!\n", end); if (ovalue) { close(ohandle); @@ -702,42 +656,30 @@ int main(int argc, char *argv[]) if (xflag) { printf("%d ", num); - if (dlt_message_print_hex_v2(&file.msgv2, text, - DLT_CONVERT_TEXTBUFSIZE, - vflag) < DLT_RETURN_OK) + if (dlt_message_print_hex_v2(&file.msgv2, text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) continue; - } - else if (aflag) { + } else if (aflag) { printf("%d ", num); - if (dlt_message_header_v2(&file.msgv2, text, - DLT_CONVERT_TEXTBUFSIZE, - vflag) < DLT_RETURN_OK) + if (dlt_message_header_v2(&file.msgv2, text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) continue; printf("%s ", text); - if (dlt_message_payload_v2(&file.msgv2, text, - DLT_CONVERT_TEXTBUFSIZE, - DLT_OUTPUT_ASCII, - vflag) < DLT_RETURN_OK) + if (dlt_message_payload_v2(&file.msgv2, text, DLT_CONVERT_TEXTBUFSIZE, DLT_OUTPUT_ASCII, vflag) + < DLT_RETURN_OK) continue; printf("[%s]\n", text); - } - else if (mflag) { + } else if (mflag) { printf("%d ", num); - if (dlt_message_print_mixed_plain_v2(&file.msgv2, text, - DLT_CONVERT_TEXTBUFSIZE, - vflag) < DLT_RETURN_OK) + if (dlt_message_print_mixed_plain_v2(&file.msgv2, text, DLT_CONVERT_TEXTBUFSIZE, vflag) + < DLT_RETURN_OK) continue; - } - else if (sflag) { + } else if (sflag) { printf("%d ", num); - if (dlt_message_header_v2(&file.msgv2, text, - DLT_CONVERT_TEXTBUFSIZE, - vflag) < DLT_RETURN_OK) + if (dlt_message_header_v2(&file.msgv2, text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) continue; printf("%s \n", text); @@ -751,9 +693,7 @@ int main(int argc, char *argv[]) bytes_written = write(ohandle, file.raw_buffer, file.raw_msg_size); if (bytes_written < 0) { - fprintf(stderr, - "ERROR: write to output file failed: %s\n", - strerror(errno)); + fprintf(stderr, "ERROR: write to output file failed: %s\n", strerror(errno)); close(ohandle); ohandle = -1; dlt_cvt_file_v2_free(&file, vflag); @@ -770,11 +710,10 @@ int main(int argc, char *argv[]) if (end == (file.counter - 1)) { /* No new messages yet – sleep briefly */ struct timespec req; - req.tv_sec = 0; - req.tv_nsec = 100000000; /* 100 ms */ + req.tv_sec = 0; + req.tv_nsec = 100000000; /* 100 ms */ nanosleep(&req, NULL); - } - else { + } else { /* New messages found – extend the range */ end = file.counter - 1; break; diff --git a/src/console/dlt-convert.c b/src/console/dlt-convert.c index 30aaa11ad..22de10766 100644 --- a/src/console/dlt-convert.c +++ b/src/console/dlt-convert.c @@ -90,10 +90,10 @@ #include "dlt_common.h" -#define COMMAND_SIZE 1024 /* Size of command */ -#define FILENAME_SIZE 1024 /* Size of filename */ -#define DLT_EXTENSION "dlt" -#define DLT_CONVERT_WS "/tmp/dlt_convert_workspace/" +#define COMMAND_SIZE 1024 /* Size of command */ +#define FILENAME_SIZE 1024 /* Size of filename */ +#define DLT_EXTENSION "dlt" +#define DLT_CONVERT_WS "/tmp/dlt_convert_workspace/" /** * Print usage information of tool. @@ -127,11 +127,11 @@ void usage(void) printf(" -t Handling input compressed files (tar.gz)\n"); } -void empty_dir(const char *dir) +void empty_dir(const char* dir) { - struct dirent **files = { 0 }; + struct dirent** files = {0}; struct stat st; - char tmp_filename[FILENAME_SIZE] = { 0 }; + char tmp_filename[FILENAME_SIZE] = {0}; if (dir == NULL) { fprintf(stderr, "ERROR: %s: invalid arguments\n", __func__); @@ -150,8 +150,7 @@ void empty_dir(const char *dir) } /* Do not include /. and /.. */ if (n < 2) { - fprintf(stderr, "ERROR: Failed to scan %s with error %s\n", - dir, strerror(errno)); + fprintf(stderr, "ERROR: Failed to scan %s with error %s\n", dir, strerror(errno)); if (files) { for (int i = 0; i < n; i++) if (files[i]) @@ -159,8 +158,7 @@ void empty_dir(const char *dir) free(files); } return; - } - else if (n == 2) + } else if (n == 2) printf("%s is already empty\n", dir); else { for (int i = 2; i < n; i++) { @@ -169,15 +167,15 @@ void empty_dir(const char *dir) if (strstr(files[i]->d_name, "/") == NULL && strstr(files[i]->d_name, "..") == NULL) { snprintf(tmp_filename, FILENAME_SIZE, "%s%s", dir, files[i]->d_name); if (remove(tmp_filename) != 0) - fprintf(stderr, "ERROR: Failed to delete %s with error %s\n", - tmp_filename, strerror(errno)); + fprintf( + stderr, "ERROR: Failed to delete %s with error %s\n", tmp_filename, strerror(errno)); } else { fprintf(stderr, "WARNING: Skipping suspicious filename: %s\n", files[i]->d_name); } } } if (files) { - for (int i = 0; i < n ; i++) + for (int i = 0; i < n; i++) if (files[i]) { free(files[i]); files[i] = NULL; @@ -185,18 +183,16 @@ void empty_dir(const char *dir) free(files); files = NULL; } - } - else + } else fprintf(stderr, "ERROR: %s is not a directory\n", dir); - } - else + } else fprintf(stderr, "ERROR: Failed to stat %s with error %s\n", dir, strerror(errno)); } /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int vflag = 0; int cflag = 0; @@ -206,10 +202,10 @@ int main(int argc, char *argv[]) int mflag = 0; int wflag = 0; int tflag = 0; - char *fvalue = 0; - char *bvalue = 0; - char *evalue = 0; - char *ovalue = 0; + char* fvalue = 0; + char* bvalue = 0; + char* evalue = 0; + char* ovalue = 0; int index; int c; @@ -221,13 +217,13 @@ int main(int argc, char *argv[]) int num, begin, end; - char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 }; + char text[DLT_CONVERT_TEXTBUFSIZE] = {0}; /* For handling compressed files */ - char tmp_filename[FILENAME_SIZE] = { 0 }; + char tmp_filename[FILENAME_SIZE] = {0}; struct stat st; memset(&st, 0, sizeof(struct stat)); - struct dirent **files = { 0 }; + struct dirent** files = {0}; int n = 0; struct iovec iov[2]; @@ -236,90 +232,74 @@ int main(int argc, char *argv[]) opterr = 0; - while ((c = getopt (argc, argv, "vcashxmwtf:b:e:o:")) != -1) { - switch (c) - { - case 'v': - { + while ((c = getopt(argc, argv, "vcashxmwtf:b:e:o:")) != -1) { + switch (c) { + case 'v': { vflag = 1; break; } - case 'c': - { + case 'c': { cflag = 1; break; } - case 'a': - { + case 'a': { aflag = 1; break; } - case 's': - { + case 's': { sflag = 1; break; } - case 'x': - { + case 'x': { xflag = 1; break; } - case 'm': - { + case 'm': { mflag = 1; break; } - case 'w': - { + case 'w': { wflag = 1; break; } - case 't': - { + case 't': { tflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'b': - { + case 'b': { bvalue = optarg; break; } - case 'e': - { + case 'e': { evalue = optarg; break; } - case 'o': - { + case 'o': { ovalue = optarg; break; } - case '?': - { + case '?': { if ((optopt == 'f') || (optopt == 'b') || (optopt == 'e') || (optopt == 'o')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - return -1; /*for parasoft */ + default: { + return -1; /*for parasoft */ } } } @@ -351,15 +331,14 @@ int main(int argc, char *argv[]) /* Prepare the temp dir to untar compressed files */ if (mkdir(DLT_CONVERT_WS, 0700) != 0) { if (errno != EEXIST) { - fprintf(stderr,"ERROR: Cannot create temp dir %s!\n", DLT_CONVERT_WS); + fprintf(stderr, "ERROR: Cannot create temp dir %s!\n", DLT_CONVERT_WS); if (ovalue) { close(ohandle); ohandle = -1; } return -1; } - } - else { + } else { if (S_ISDIR(st.st_mode)) empty_dir(DLT_CONVERT_WS); else @@ -370,25 +349,25 @@ int main(int argc, char *argv[]) /* Check extension of input file * If it is a compressed file, uncompress it */ - const char *file_ext = get_filename_ext(argv[index]); + const char* file_ext = get_filename_ext(argv[index]); if (file_ext && strcmp(file_ext, DLT_EXTENSION) != 0) { syserr = dlt_execute_command(NULL, "tar", "xf", argv[index], "-C", DLT_CONVERT_WS, NULL); if (syserr != 0) - fprintf(stderr, "ERROR: Failed to uncompress %s to %s with error [%d]\n", - argv[index], DLT_CONVERT_WS, WIFEXITED(syserr)); - } - else { + fprintf( + stderr, "ERROR: Failed to uncompress %s to %s with error [%d]\n", argv[index], DLT_CONVERT_WS, + WIFEXITED(syserr)); + } else { syserr = dlt_execute_command(NULL, "cp", argv[index], DLT_CONVERT_WS, NULL); if (syserr != 0) - fprintf(stderr, "ERROR: Failed to copy %s to %s with error [%d]\n", - argv[index], DLT_CONVERT_WS, WIFEXITED(syserr)); + fprintf( + stderr, "ERROR: Failed to copy %s to %s with error [%d]\n", argv[index], DLT_CONVERT_WS, + WIFEXITED(syserr)); } - } n = scandir(DLT_CONVERT_WS, &files, NULL, alphasort); if (n == -1) { - fprintf(stderr,"ERROR: Cannot scan temp dir %s!\n", DLT_CONVERT_WS); + fprintf(stderr, "ERROR: Cannot scan temp dir %s!\n", DLT_CONVERT_WS); if (ovalue) { close(ohandle); ohandle = -1; @@ -404,13 +383,12 @@ int main(int argc, char *argv[]) if (tflag) { memset(tmp_filename, 0, FILENAME_SIZE); #if defined(__GNUC__) && __GNUC__ >= 7 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wformat-truncation" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation" #endif - snprintf(tmp_filename, FILENAME_SIZE, "%s%s", - DLT_CONVERT_WS, files[index - optind + 2]->d_name); + snprintf(tmp_filename, FILENAME_SIZE, "%s%s", DLT_CONVERT_WS, files[index - optind + 2]->d_name); #if defined(__GNUC__) && __GNUC__ >= 7 -# pragma GCC diagnostic pop +#pragma GCC diagnostic pop #endif argv[index] = tmp_filename; @@ -418,8 +396,7 @@ int main(int argc, char *argv[]) /* load, analyze data file and create index list */ if (dlt_file_open(&file, argv[index], vflag) >= DLT_RETURN_OK) { - while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) { - } + while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) { } } if (aflag || sflag || xflag || mflag || ovalue) { @@ -461,8 +438,7 @@ int main(int argc, char *argv[]) printf("%d ", num); if (dlt_message_print_hex(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) continue; - } - else if (aflag) { + } else if (aflag) { printf("%d ", num); if (dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) @@ -470,17 +446,17 @@ int main(int argc, char *argv[]) printf("%s ", text); - if (dlt_message_payload(&file.msg, text, DLT_CONVERT_TEXTBUFSIZE, DLT_OUTPUT_ASCII, vflag) < DLT_RETURN_OK) + if (dlt_message_payload(&file.msg, text, DLT_CONVERT_TEXTBUFSIZE, DLT_OUTPUT_ASCII, vflag) + < DLT_RETURN_OK) continue; printf("[%s]\n", text); - } - else if (mflag) { + } else if (mflag) { printf("%d ", num); - if (dlt_message_print_mixed_plain(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) + if (dlt_message_print_mixed_plain(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) + < DLT_RETURN_OK) continue; - } - else if (sflag) { + } else if (sflag) { printf("%d ", num); if (dlt_message_header(&(file.msg), text, DLT_CONVERT_TEXTBUFSIZE, vflag) < DLT_RETURN_OK) @@ -492,11 +468,11 @@ int main(int argc, char *argv[]) /* if file output enabled write message */ if (ovalue) { iov[0].iov_base = file.msg.headerbuffer; - iov[0].iov_len = (uint32_t) file.msg.headersize; + iov[0].iov_len = (uint32_t)file.msg.headersize; iov[1].iov_base = file.msg.databuffer; - iov[1].iov_len = (uint32_t) file.msg.datasize; + iov[1].iov_len = (uint32_t)file.msg.datasize; - bytes_written =(int) writev(ohandle, iov, 2); + bytes_written = (int)writev(ohandle, iov, 2); if (0 > bytes_written) { printf("in main: writev(ohandle, iov, 2); returned an error!"); @@ -510,8 +486,7 @@ int main(int argc, char *argv[]) /* check for new messages if follow flag set */ if (wflag && (num == end)) { while (1) { - while (dlt_file_read(&file, 0) >= 0){ - } + while (dlt_file_read(&file, 0) >= 0) { } if (end == (file.counter - 1)) { /* Sleep if no new message was received */ @@ -519,8 +494,7 @@ int main(int argc, char *argv[]) req.tv_sec = 0; req.tv_nsec = 100000000; nanosleep(&req, NULL); - } - else { + } else { /* set new end of log file and continue reading */ end = file.counter - 1; break; @@ -546,7 +520,7 @@ int main(int argc, char *argv[]) if (tflag) { empty_dir(DLT_CONVERT_WS); if (files) { - for (int i = 0; i < n ; i++) + for (int i = 0; i < n; i++) if (files[i]) free(files[i]); diff --git a/src/console/dlt-passive-node-ctrl.c b/src/console/dlt-passive-node-ctrl.c index 633229ca1..febd52934 100644 --- a/src/console/dlt-passive-node-ctrl.c +++ b/src/console/dlt-passive-node-ctrl.c @@ -56,14 +56,14 @@ #include "dlt-control-common.h" #include "dlt_daemon_connection_types.h" -#define MAX_RESPONSE_LENGTH 32 +#define MAX_RESPONSE_LENGTH 32 -#define DLT_NODE_CONNECT 1 -#define DLT_NODE_DISCONNECT 0 -#define DLT_NODE_CONNECT_UNDEF 999 +#define DLT_NODE_CONNECT 1 +#define DLT_NODE_DISCONNECT 0 +#define DLT_NODE_CONNECT_UNDEF 999 -#define DLT_GATEWAY_CONNECTED 2 -#define DLT_NODE_CONNECTED_STR "Connected" +#define DLT_GATEWAY_CONNECTED 2 +#define DLT_NODE_CONNECTED_STR "Connected" #define DLT_NODE_DISCONNECTED_STR "Disconnected" #define UNDEFINED 999 @@ -76,7 +76,7 @@ static struct PassiveNodeOptions { } g_options = { .command = UNDEFINED, .connection_state = UNDEFINED, - .node_id = { '\0' }, + .node_id = {'\0'}, }; unsigned int get_command(void) @@ -99,26 +99,24 @@ void set_connection_state(unsigned int s) if ((s == DLT_NODE_CONNECT) || (s == DLT_NODE_DISCONNECT)) { g_options.connection_state = s; set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECT); - } - else { + } else { pr_error("Connection status %u invalid\n", s); exit(-1); } } -void set_node_id(char *id) +void set_node_id(char* id) { if (id == 0) { pr_error("node identifier is NULL\n"); exit(-1); - } - else { + } else { strncpy(g_options.node_id, id, DLT_ID_SIZE - 1); g_options.node_id[DLT_ID_SIZE - 1] = '\0'; } } -char *get_node_id() +char* get_node_id() { return g_options.node_id; } @@ -128,17 +126,17 @@ char *get_node_id() * * @param info DltServicePassiveNodeConnectionInfo */ -static void dlt_print_passive_node_status( - DltServicePassiveNodeConnectionInfo *info) +static void dlt_print_passive_node_status(DltServicePassiveNodeConnectionInfo* info) { unsigned int i = 0; - char *status; + char* status; if (info == NULL) return; - printf("\nPassive Node connection status:\n" - "---------------------------------\n"); + printf( + "\nPassive Node connection status:\n" + "---------------------------------\n"); for (i = 0; i < info->num_connections; i++) { if (info->connection_status[i] == DLT_GATEWAY_CONNECTED) @@ -165,20 +163,15 @@ static void dlt_print_passive_node_status( * @param len Length of received DLT message * @return 0 if daemon returns 'ok' message, -1 otherwise */ -static int dlt_passive_node_analyze_response(char *answer, - void *payload, - int len) +static int dlt_passive_node_analyze_response(char* answer, void* payload, int len) { int ret = -1; - char resp_ok[MAX_RESPONSE_LENGTH] = { 0 }; + char resp_ok[MAX_RESPONSE_LENGTH] = {0}; if ((answer == NULL) || (payload == NULL)) return -1; - snprintf(resp_ok, - MAX_RESPONSE_LENGTH, - "service(%u), ok", - get_command()); + snprintf(resp_ok, MAX_RESPONSE_LENGTH, "service(%u), ok", get_command()); pr_verbose("Response received: '%s'\n", answer); pr_verbose("Response expected: '%s'\n", resp_ok); @@ -189,14 +182,10 @@ static int dlt_passive_node_analyze_response(char *answer, if (get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS) { if ((int)sizeof(DltServicePassiveNodeConnectionInfo) > len) { pr_error("Received payload is smaller than expected\n"); - pr_verbose("Expected: %zu,\nreceived: %d", - sizeof(DltServicePassiveNodeConnectionInfo), - len); + pr_verbose("Expected: %zu,\nreceived: %d", sizeof(DltServicePassiveNodeConnectionInfo), len); ret = -1; - } - else { - DltServicePassiveNodeConnectionInfo *info = - (DltServicePassiveNodeConnectionInfo *)(payload); + } else { + DltServicePassiveNodeConnectionInfo* info = (DltServicePassiveNodeConnectionInfo*)(payload); dlt_print_passive_node_status(info); } @@ -211,10 +200,10 @@ static int dlt_passive_node_analyze_response(char *answer, * * @return Pointer ot DltControlMsgBody, NULL otherwise */ -DltControlMsgBody *dlt_passive_node_prepare_message_body() +DltControlMsgBody* dlt_passive_node_prepare_message_body() { - DltControlMsgBody *mb = calloc(1, sizeof(DltControlMsgBody)); - char *ecuid = get_node_id(); + DltControlMsgBody* mb = calloc(1, sizeof(DltControlMsgBody)); + char* ecuid = get_node_id(); if (mb == NULL) return NULL; @@ -228,14 +217,12 @@ DltControlMsgBody *dlt_passive_node_prepare_message_body() } mb->size = sizeof(DltServicePassiveNodeConnect); - DltServicePassiveNodeConnect *serv = (DltServicePassiveNodeConnect *) - mb->data; + DltServicePassiveNodeConnect* serv = (DltServicePassiveNodeConnect*)mb->data; serv->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT; serv->connection_status = get_connection_state(); memcpy(serv->node_id, ecuid, DLT_ID_SIZE); - } - else { /* DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS */ + } else { /* DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS */ mb->data = calloc(1, sizeof(DltServicePassiveNodeConnectionInfo)); if (mb->data == NULL) { @@ -244,8 +231,7 @@ DltControlMsgBody *dlt_passive_node_prepare_message_body() } mb->size = sizeof(DltServicePassiveNodeConnectionInfo); - DltServicePassiveNodeConnectionInfo *serv = - (DltServicePassiveNodeConnectionInfo *)mb->data; + DltServicePassiveNodeConnectionInfo* serv = (DltServicePassiveNodeConnectionInfo*)mb->data; serv->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS; } @@ -255,7 +241,7 @@ DltControlMsgBody *dlt_passive_node_prepare_message_body() /** * @brief Destroy message body */ -void dlt_passive_node_destroy_message_body(DltControlMsgBody *msg_body) +void dlt_passive_node_destroy_message_body(DltControlMsgBody* msg_body) { if (msg_body == NULL) return; @@ -276,15 +262,13 @@ static int dlt_passive_node_ctrl_single_request() int ret = -1; /* Initializing the communication with the daemon */ - if (dlt_control_init(dlt_passive_node_analyze_response, - get_ecuid(), - get_verbosity()) != 0) { + if (dlt_control_init(dlt_passive_node_analyze_response, get_ecuid(), get_verbosity()) != 0) { pr_error("Failed to initialize connection with the daemon.\n"); return ret; } /* prepare message body */ - DltControlMsgBody *msg_body = NULL; + DltControlMsgBody* msg_body = NULL; msg_body = dlt_passive_node_prepare_message_body(); if (msg_body == NULL) { @@ -304,16 +288,16 @@ static int dlt_passive_node_ctrl_single_request() static void usage() { printf("Usage: dlt-passive-node-ctrl [options]\n"); - printf("Send a trigger to DLT daemon to (dis)connect a passive node " - "or get current passive node status \n"); + printf( + "Send a trigger to DLT daemon to (dis)connect a passive node " + "or get current passive node status \n"); printf("\n"); printf("Options:\n"); printf(" -c Connection status (1 - connect, 0 - disconnect)\n"); printf(" -h Usage\n"); printf(" -n passive Node identifier (e.g. ECU2)\n"); printf(" -s Show passive node(s) connection status\n"); - printf(" -t Specify connection timeout (Default: %ds)\n", - DLT_CTRL_TIMEOUT); + printf(" -t Specify connection timeout (Default: %ds)\n", DLT_CTRL_TIMEOUT); printf(" -S Send message with serial header (Default: Without serial header)\n"); printf(" -R Enable resync serial header\n"); printf(" -v Set verbose flag (Default:%d)\n", get_verbosity()); @@ -328,7 +312,7 @@ static void usage() * @param argv argument table * @return 0 on success, -1 otherwise */ -static int parse_args(int argc, char *argv[]) +static int parse_args(int argc, char* argv[]) { int c = 0; int state = -1; @@ -342,10 +326,9 @@ static int parse_args(int argc, char *argv[]) state = (int)strtol(optarg, NULL, 10); if ((state == DLT_NODE_CONNECT) || (state == DLT_NODE_DISCONNECT)) { - set_connection_state((unsigned int) state); + set_connection_state((unsigned int)state); set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECT); - } - else { + } else { pr_error("unknown connection state: %d\n", state); return -1; } @@ -361,15 +344,13 @@ static int parse_args(int argc, char *argv[]) set_command(DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS); break; case 't': - set_timeout((int) strtol(optarg, NULL, 10)); + set_timeout((int)strtol(optarg, NULL, 10)); break; - case 'S': - { + case 'S': { set_send_serial_header(1); break; } - case 'R': - { + case 'R': { set_resync_serial_header(1); break; } @@ -403,7 +384,7 @@ static int parse_args(int argc, char *argv[]) * @param argv argument table * @return 0 on success, -1 otherwise */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int ret = 0; @@ -416,10 +397,9 @@ int main(int argc, char *argv[]) if (parse_args(argc, argv) != 0) return -1; - if ((get_command() == UNDEFINED) || - ((get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECT) && - (g_options.node_id[0] == '\0') && - (g_options.connection_state == DLT_NODE_CONNECT_UNDEF))) { + if ((get_command() == UNDEFINED) + || ((get_command() == DLT_SERVICE_ID_PASSIVE_NODE_CONNECT) && (g_options.node_id[0] == '\0') + && (g_options.connection_state == DLT_NODE_CONNECT_UNDEF))) { pr_error("No valid parameter configuration given!\n"); usage(); return -1; diff --git a/src/console/dlt-receive-v2.c b/src/console/dlt-receive-v2.c index 3df240acc..5f9b7015b 100644 --- a/src/console/dlt-receive-v2.c +++ b/src/console/dlt-receive-v2.c @@ -64,11 +64,11 @@ * sg 12.11.2025 initial */ -#include /* for isprint() */ -#include /* for atoi() */ -#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ -#include /* for open() */ -#include /* for writev() */ +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ +#include /* for writev() */ #include #include #include @@ -76,9 +76,9 @@ #include #include #ifdef __linux__ -# include +#include #else -# include +#include #endif #include #include "dlt_log.h" @@ -105,11 +105,10 @@ void signal_handler(int signal) /* This case should never happen! */ break; } /* switch */ - } /* Function prototypes */ -int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data); +int dlt_receive_message_callback_v2(DltMessageV2* message, void* data); typedef struct { int aflag; @@ -120,25 +119,25 @@ typedef struct { int yflag; int uflag; int rflag; - char *ovalue; - char *ovaluebase; /* ovalue without ".dlt" */ - char *fvalue; /* filename for space separated filter file ( ) */ - char *jvalue; /* filename for json filter file */ - char *evalue; + char* ovalue; + char* ovaluebase; /* ovalue without ".dlt" */ + char* fvalue; /* filename for space separated filter file ( ) */ + char* jvalue; /* filename for json filter file */ + char* evalue; int bvalue; int rvalue; int sendSerialHeaderFlag; int resyncSerialHeaderFlag; int64_t climit; uint8_t ecuidlen; - char *ecuid; + char* ecuid; int ohandle; int64_t totalbytes; /* bytes written so far into the output file, used to check the file size limit */ - int part_num; /* number of current output file if limit was exceeded */ + int part_num; /* number of current output file if limit was exceeded */ DltFile file; DltFilter filter; int port; - char *ifaddr; + char* ifaddr; } DltReceiveData; /** @@ -180,7 +179,7 @@ void usage() } -int64_t convert_arg_to_byte_size(char *arg) +int64_t convert_arg_to_byte_size(char* arg) { size_t i; int64_t factor; @@ -218,16 +217,19 @@ int64_t convert_arg_to_byte_size(char *arg) /* * open output file */ -int dlt_receive_open_output_file(DltReceiveData *dltdata) +int dlt_receive_open_output_file(DltReceiveData* dltdata) { /* if (file_already_exists) */ glob_t outer; - if (glob(dltdata->ovalue, + if (glob( + dltdata->ovalue, #ifndef __ANDROID_API__ - GLOB_TILDE | + GLOB_TILDE | #endif - GLOB_NOSORT, NULL, &outer) == 0) { + GLOB_NOSORT, + NULL, &outer) + == 0) { if (dltdata->vflag) dlt_vlog(LOG_INFO, "File %s already exists, need to rename first\n", dltdata->ovalue); @@ -244,11 +246,14 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) * foo.1000.dlt * foo.11.dlt */ - if (glob(pattern, + if (glob( + pattern, #ifndef __ANDROID_API__ - GLOB_TILDE | + GLOB_TILDE | #endif - GLOB_NOSORT, NULL, &inner) == 0) { + GLOB_NOSORT, + NULL, &inner) + == 0) { /* search for the highest number used */ size_t i; @@ -266,21 +271,18 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) globfree(&inner); ++dltdata->part_num; - } char filename[PATH_MAX + 1]; filename[PATH_MAX] = 0; - snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, - dltdata->part_num); + snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num); if (rename(dltdata->ovalue, filename) != 0) - dlt_vlog(LOG_ERR, "ERROR: rename %s to %s failed with error %s\n", - dltdata->ovalue, filename, strerror(errno)); + dlt_vlog( + LOG_ERR, "ERROR: rename %s to %s failed with error %s\n", dltdata->ovalue, filename, strerror(errno)); else if (dltdata->vflag) { - dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n", - dltdata->ovalue, filename); + dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n", dltdata->ovalue, filename); ++dltdata->part_num; } } /* if (file_already_exists) */ @@ -292,7 +294,7 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) } -void dlt_receive_close_output_file(DltReceiveData *dltdata) +void dlt_receive_close_output_file(DltReceiveData* dltdata) { if (dltdata->ohandle) { close(dltdata->ohandle); @@ -304,7 +306,7 @@ void dlt_receive_close_output_file(DltReceiveData *dltdata) /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { DltReceiveData dltdata; memset(&dltdata, 0, sizeof(dltdata)); @@ -334,94 +336,81 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:r:")) != -1) switch (c) { - case 'v': - { + case 'v': { dltdata.vflag = 1; break; } - case 'a': - { + case 'a': { dltdata.aflag = 1; break; } - case 's': - { + case 's': { dltdata.sflag = 1; break; } - case 'x': - { + case 'x': { dltdata.xflag = 1; break; } - case 'm': - { + case 'm': { dltdata.mflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'S': - { + case 'S': { dltdata.sendSerialHeaderFlag = 1; break; } - case 'R': - { + case 'R': { dltdata.resyncSerialHeaderFlag = 1; break; } - case 'y': - { + case 'y': { dltdata.yflag = 1; break; } - case 'u': - { + case 'u': { dltdata.uflag = 1; break; } - case 'i': - { + case 'i': { dltdata.ifaddr = optarg; break; } - case 'f': - { + case 'f': { dltdata.fvalue = optarg; break; } - case 'j': - { - #ifdef EXTENDED_FILTERING + case 'j': { +#ifdef EXTENDED_FILTERING dltdata.jvalue = optarg; break; - #else - fprintf (stderr, - "Extended filtering is not supported. Please build with the corresponding cmake option to use it.\n"); +#else + fprintf( + stderr, + "Extended filtering is not supported. Please build with the corresponding cmake option to use it.\n"); return -1; - #endif +#endif } case 'r': { dltdata.rflag = 1; dltdata.rvalue = atoi(optarg); break; } - case 'o': - { + case 'o': { dltdata.ovalue = optarg; size_t to_copy = strlen(dltdata.ovalue); if (strcmp(&dltdata.ovalue[to_copy - 4], ".dlt") == 0) to_copy = to_copy - 4; - dltdata.ovaluebase = (char *)calloc(1, to_copy + 1); + dltdata.ovaluebase = (char*)calloc(1, to_copy + 1); if (dltdata.ovaluebase == NULL) { - fprintf (stderr, "Memory allocation failed.\n"); + fprintf(stderr, "Memory allocation failed.\n"); return -1; } @@ -429,28 +418,24 @@ int main(int argc, char *argv[]) memcpy(dltdata.ovaluebase, dltdata.ovalue, to_copy); break; } - case 'e': - { + case 'e': { dltdata.evalue = optarg; break; } - case 'b': - { + case 'b': { dltdata.bvalue = atoi(optarg); break; } - case 'p': - { + case 'p': { dltdata.port = atoi(optarg); break; } - case 'c': - { + case 'c': { dltdata.climit = convert_arg_to_byte_size(optarg); if (dltdata.climit < -1) { - fprintf (stderr, "Invalid argument for option -c.\n"); + fprintf(stderr, "Invalid argument for option -c.\n"); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; @@ -458,23 +443,21 @@ int main(int argc, char *argv[]) break; } - case '?': - { + case '?': { if ((optopt == 'o') || (optopt == 'f') || (optopt == 'c')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1; /*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -485,21 +468,20 @@ int main(int argc, char *argv[]) dlt_client_register_message_callback_v2(dlt_receive_message_callback_v2); /* Setup DLT Client structure */ - if(dltdata.uflag) { + if (dltdata.uflag) { dltclient.mode = DLT_CLIENT_MODE_UDP_MULTICAST; - } - else { + } else { dltclient.mode = dltdata.yflag; } if (dltclient.mode == DLT_CLIENT_MODE_TCP || dltclient.mode == DLT_CLIENT_MODE_UDP_MULTICAST) { dltclient.port = (uint16_t)dltdata.port; - unsigned int servIPLength = 1; // Counting the terminating 0 byte + unsigned int servIPLength = 1; // Counting the terminating 0 byte for (index = optind; index < argc; index++) { servIPLength += (unsigned int)strlen(argv[index]); if (index > optind) { - servIPLength++; // For the comma delimiter + servIPLength++; // For the comma delimiter } } if (servIPLength > 1) { @@ -534,8 +516,7 @@ int main(int argc, char *argv[]) return -1; } } - } - else { + } else { for (index = optind; index < argc; index++) if (dlt_client_set_serial_device(&dltclient, argv[index]) == -1) { fprintf(stderr, "set serial device didn't succeed\n"); @@ -571,7 +552,7 @@ int main(int argc, char *argv[]) dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); } - #ifdef EXTENDED_FILTERING +#ifdef EXTENDED_FILTERING if (dltdata.jvalue) { /* To Update: dlt_json_filter_load_v2 */ @@ -583,16 +564,14 @@ int main(int argc, char *argv[]) dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); } - #endif +#endif /* open DLT output file */ if (dltdata.ovalue) { if (dltdata.climit > -1) { - dlt_vlog(LOG_INFO, "Using file size limit of %" PRId64 "bytes\n", - dltdata.climit); + dlt_vlog(LOG_INFO, "Using file size limit of %" PRId64 "bytes\n", dltdata.climit); dltdata.ohandle = dlt_receive_open_output_file(&dltdata); - } - else { /* in case no limit for the output file is given, we simply overwrite any existing file */ + } else { /* in case no limit for the output file is given, we simply overwrite any existing file */ dltdata.ohandle = open(dltdata.ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } @@ -607,14 +586,14 @@ int main(int argc, char *argv[]) dltdata.ecuidlen = (uint8_t)strlen(dltdata.evalue); dltdata.ecuid = NULL; dlt_set_id_v2(dltdata.ecuid, dltdata.evalue, dltdata.ecuidlen); - }else { + } else { dltdata.ecuidlen = (uint8_t)strlen(DLT_RECEIVE_ECU_ID); dltdata.ecuid = NULL; - dlt_set_id_v2(dltdata.ecuid, DLT_RECEIVE_ECU_ID, dltdata.ecuidlen);} + dlt_set_id_v2(dltdata.ecuid, DLT_RECEIVE_ECU_ID, dltdata.ecuidlen); + } while (true) { /* Attempt to connect to TCP socket or open serial device */ if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) { - /* Dlt Client Main Loop */ dlt_client_main_loop_v2(&dltclient, &dltdata, dltdata.vflag); @@ -644,9 +623,9 @@ int main(int argc, char *argv[]) return 0; } -int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data) +int dlt_receive_message_callback_v2(DltMessageV2* message, void* data) { - DltReceiveData *dltdata; + DltReceiveData* dltdata; static char text[DLT_RECEIVE_BUFSIZE]; struct iovec iov[2]; int bytes_written; @@ -654,11 +633,12 @@ int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data) if ((message == 0) || (data == 0)) return -1; - dltdata = (DltReceiveData *)data; + dltdata = (DltReceiveData*)data; /* prepare storage header */ if (DLT_IS_HTYP2_WEID(message->baseheaderv2->htyp2)) - dlt_set_storageheader_v2(&(message->storageheaderv2), message->extendedheaderv2.ecidlen, message->extendedheaderv2.ecid); + dlt_set_storageheader_v2( + &(message->storageheaderv2), message->extendedheaderv2.ecidlen, message->extendedheaderv2.ecid); else dlt_set_storageheader_v2(&(message->storageheaderv2), dltdata->ecuidlen, dltdata->ecuid); @@ -670,35 +650,29 @@ int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data) free(message->headerbufferv2); message->headersizev2 = message->headersizev2 + (int32_t)message->storageheadersizev2; - message->headerbufferv2 = (uint8_t *)malloc((size_t)message->headersizev2); + message->headerbufferv2 = (uint8_t*)malloc((size_t)message->headersizev2); if (dlt_message_set_storageparameters_v2(message, 0) != DLT_RETURN_OK) return -1; - memcpy(message->headerbufferv2 + message->storageheadersizev2, temp_buffer, (size_t)(message->headersizev2 - (int32_t)message->storageheadersizev2)); - - if (((dltdata->fvalue || dltdata->jvalue) == 0) || - (dlt_message_filter_check_v2(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE)) { + memcpy( + message->headerbufferv2 + message->storageheadersizev2, temp_buffer, + (size_t)(message->headersizev2 - (int32_t)message->storageheadersizev2)); + if (((dltdata->fvalue || dltdata->jvalue) == 0) + || (dlt_message_filter_check_v2(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE)) { /* if no filter set or filter is matching display message */ if (dltdata->xflag) { dlt_message_print_hex_v2(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); - } - else if (dltdata->aflag) - { + } else if (dltdata->aflag) { dlt_message_header_v2(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); printf("%s ", text); dlt_message_payload_v2(message, text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, dltdata->vflag); printf("[%s]\n", text); - } - else if (dltdata->mflag) - { + } else if (dltdata->mflag) { dlt_message_print_mixed_plain_v2(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); - } - else if (dltdata->sflag) - { - + } else if (dltdata->sflag) { dlt_message_header_v2(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); printf("%s \n", text); @@ -718,7 +692,8 @@ int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data) if (dlt_receive_open_output_file(dltdata) < 0) { printf( - "ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n"); + "ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was " + "reached!\n"); return -1; } diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index 4181d8344..24fb49c99 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -66,11 +66,11 @@ * aw 13.01.2010 initial */ -#include /* for isprint() */ -#include /* for atoi() */ -#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ -#include /* for open() */ -#include /* for writev() */ +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ +#include /* for writev() */ #include #include #include @@ -78,9 +78,9 @@ #include #include #ifdef __linux__ -# include +#include #else -# include +#include #endif #include #include "dlt_log.h" @@ -107,11 +107,10 @@ void signal_handler(int signal) /* This case should never happen! */ break; } /* switch */ - } /* Function prototypes */ -int dlt_receive_message_callback(DltMessage *message, void *data); +int dlt_receive_message_callback(DltMessage* message, void* data); typedef struct { int aflag; @@ -122,11 +121,11 @@ typedef struct { int yflag; int uflag; int rflag; - char *ovalue; - char *ovaluebase; /* ovalue without ".dlt" */ - char *fvalue; /* filename for space separated filter file ( ) */ - char *jvalue; /* filename for json filter file */ - char *evalue; + char* ovalue; + char* ovaluebase; /* ovalue without ".dlt" */ + char* fvalue; /* filename for space separated filter file ( ) */ + char* jvalue; /* filename for json filter file */ + char* evalue; int bvalue; int rvalue; int sendSerialHeaderFlag; @@ -135,11 +134,11 @@ typedef struct { char ecuid[4]; int ohandle; int64_t totalbytes; /* bytes written so far into the output file, used to check the file size limit */ - int part_num; /* number of current output file if limit was exceeded */ + int part_num; /* number of current output file if limit was exceeded */ DltFile file; DltFilter filter; int port; - char *ifaddr; + char* ifaddr; } DltReceiveData; /** @@ -181,7 +180,7 @@ void usage(void) } -int64_t convert_arg_to_byte_size(char *arg) +int64_t convert_arg_to_byte_size(char* arg) { size_t i; int64_t factor; @@ -221,10 +220,10 @@ int64_t convert_arg_to_byte_size(char *arg) min_size += 2048 /* DLT_USER_BUF_MAX_SIZE */; if (min_size > result) { - dlt_vlog(LOG_ERR, - "ERROR: Specified limit: %" PRId64 "is smaller than a the size of a single message: %" PRId64 "!\n", - result, - min_size); + dlt_vlog( + LOG_ERR, + "ERROR: Specified limit: %" PRId64 "is smaller than a the size of a single message: %" PRId64 "!\n", result, + min_size); result = -2; } @@ -235,16 +234,19 @@ int64_t convert_arg_to_byte_size(char *arg) /* * open output file */ -int dlt_receive_open_output_file(DltReceiveData *dltdata) +int dlt_receive_open_output_file(DltReceiveData* dltdata) { /* if (file_already_exists) */ glob_t outer; - if (glob(dltdata->ovalue, + if (glob( + dltdata->ovalue, #ifndef __ANDROID_API__ - GLOB_TILDE | + GLOB_TILDE | #endif - GLOB_NOSORT, NULL, &outer) == 0) { + GLOB_NOSORT, + NULL, &outer) + == 0) { if (dltdata->vflag) dlt_vlog(LOG_INFO, "File %s already exists, need to rename first\n", dltdata->ovalue); @@ -261,11 +263,14 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) * foo.1000.dlt * foo.11.dlt */ - if (glob(pattern, + if (glob( + pattern, #ifndef __ANDROID_API__ - GLOB_TILDE | + GLOB_TILDE | #endif - GLOB_NOSORT, NULL, &inner) == 0) { + GLOB_NOSORT, + NULL, &inner) + == 0) { /* search for the highest number used */ size_t i; @@ -283,21 +288,18 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) globfree(&inner); ++dltdata->part_num; - } char filename[PATH_MAX + 1]; filename[PATH_MAX] = 0; - snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, - dltdata->part_num); + snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num); if (rename(dltdata->ovalue, filename) != 0) - dlt_vlog(LOG_ERR, "ERROR: rename %s to %s failed with error %s\n", - dltdata->ovalue, filename, strerror(errno)); + dlt_vlog( + LOG_ERR, "ERROR: rename %s to %s failed with error %s\n", dltdata->ovalue, filename, strerror(errno)); else if (dltdata->vflag) { - dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n", - dltdata->ovalue, filename); + dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n", dltdata->ovalue, filename); ++dltdata->part_num; } } /* if (file_already_exists) */ @@ -309,7 +311,7 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) } -void dlt_receive_close_output_file(DltReceiveData *dltdata) +void dlt_receive_close_output_file(DltReceiveData* dltdata) { if (dltdata->ohandle) { close(dltdata->ohandle); @@ -321,7 +323,7 @@ void dlt_receive_close_output_file(DltReceiveData *dltdata) /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { DltReceiveData dltdata; memset(&dltdata, 0, sizeof(dltdata)); @@ -351,94 +353,81 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:r:")) != -1) switch (c) { - case 'v': - { + case 'v': { dltdata.vflag = 1; break; } - case 'a': - { + case 'a': { dltdata.aflag = 1; break; } - case 's': - { + case 's': { dltdata.sflag = 1; break; } - case 'x': - { + case 'x': { dltdata.xflag = 1; break; } - case 'm': - { + case 'm': { dltdata.mflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'S': - { + case 'S': { dltdata.sendSerialHeaderFlag = 1; break; } - case 'R': - { + case 'R': { dltdata.resyncSerialHeaderFlag = 1; break; } - case 'y': - { + case 'y': { dltdata.yflag = 1; break; } - case 'u': - { + case 'u': { dltdata.uflag = 1; break; } - case 'i': - { + case 'i': { dltdata.ifaddr = optarg; break; } - case 'f': - { + case 'f': { dltdata.fvalue = optarg; break; } - case 'j': - { - #ifdef EXTENDED_FILTERING + case 'j': { +#ifdef EXTENDED_FILTERING dltdata.jvalue = optarg; break; - #else - fprintf (stderr, - "Extended filtering is not supported. Please build with the corresponding cmake option to use it.\n"); +#else + fprintf( + stderr, + "Extended filtering is not supported. Please build with the corresponding cmake option to use it.\n"); return -1; - #endif +#endif } case 'r': { dltdata.rflag = 1; dltdata.rvalue = atoi(optarg); break; } - case 'o': - { + case 'o': { dltdata.ovalue = optarg; size_t to_copy = strlen(dltdata.ovalue); if (strcmp(&dltdata.ovalue[to_copy - 4], ".dlt") == 0) to_copy = to_copy - 4; - dltdata.ovaluebase = (char *)calloc(1, to_copy + 1); + dltdata.ovaluebase = (char*)calloc(1, to_copy + 1); if (dltdata.ovaluebase == NULL) { - fprintf (stderr, "Memory allocation failed.\n"); + fprintf(stderr, "Memory allocation failed.\n"); return -1; } @@ -446,28 +435,24 @@ int main(int argc, char *argv[]) memcpy(dltdata.ovaluebase, dltdata.ovalue, to_copy); break; } - case 'e': - { + case 'e': { dltdata.evalue = optarg; break; } - case 'b': - { + case 'b': { dltdata.bvalue = atoi(optarg); break; } - case 'p': - { + case 'p': { dltdata.port = atoi(optarg); break; } - case 'c': - { + case 'c': { dltdata.climit = convert_arg_to_byte_size(optarg); if (dltdata.climit < -1) { - fprintf (stderr, "Invalid argument for option -c.\n"); + fprintf(stderr, "Invalid argument for option -c.\n"); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; @@ -475,23 +460,21 @@ int main(int argc, char *argv[]) break; } - case '?': - { + case '?': { if ((optopt == 'o') || (optopt == 'f') || (optopt == 'c')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1; /*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -502,21 +485,20 @@ int main(int argc, char *argv[]) dlt_client_register_message_callback(dlt_receive_message_callback); /* Setup DLT Client structure */ - if(dltdata.uflag) { + if (dltdata.uflag) { dltclient.mode = DLT_CLIENT_MODE_UDP_MULTICAST; - } - else { + } else { dltclient.mode = dltdata.yflag; } if (dltclient.mode == DLT_CLIENT_MODE_TCP || dltclient.mode == DLT_CLIENT_MODE_UDP_MULTICAST) { dltclient.port = (uint16_t)dltdata.port; - unsigned int servIPLength = 1; // Counting the terminating 0 byte + unsigned int servIPLength = 1; // Counting the terminating 0 byte for (index = optind; index < argc; index++) { servIPLength += (unsigned int)strlen(argv[index]); if (index > optind) { - servIPLength++; // For the comma delimiter + servIPLength++; // For the comma delimiter } } if (servIPLength > 1) { @@ -551,8 +533,7 @@ int main(int argc, char *argv[]) return -1; } } - } - else { + } else { for (index = optind; index < argc; index++) if (dlt_client_set_serial_device(&dltclient, argv[index]) == -1) { fprintf(stderr, "set serial device didn't succeed\n"); @@ -588,7 +569,7 @@ int main(int argc, char *argv[]) dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); } - #ifdef EXTENDED_FILTERING +#ifdef EXTENDED_FILTERING if (dltdata.jvalue) { if (dlt_json_filter_load(&(dltdata.filter), dltdata.jvalue, dltdata.vflag) < DLT_RETURN_OK) { @@ -599,16 +580,14 @@ int main(int argc, char *argv[]) dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag); } - #endif +#endif /* open DLT output file */ if (dltdata.ovalue) { if (dltdata.climit > -1) { - dlt_vlog(LOG_INFO, "Using file size limit of %" PRId64 "bytes\n", - dltdata.climit); + dlt_vlog(LOG_INFO, "Using file size limit of %" PRId64 "bytes\n", dltdata.climit); dltdata.ohandle = dlt_receive_open_output_file(&dltdata); - } - else { /* in case no limit for the output file is given, we simply overwrite any existing file */ + } else { /* in case no limit for the output file is given, we simply overwrite any existing file */ dltdata.ohandle = open(dltdata.ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } @@ -621,13 +600,13 @@ int main(int argc, char *argv[]) if (dltdata.evalue) dlt_set_id(dltdata.ecuid, dltdata.evalue); - else{ - dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID);} + else { + dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID); + } while (true) { /* Attempt to connect to TCP socket or open serial device */ if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) { - /* Dlt Client Main Loop */ dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); @@ -657,9 +636,9 @@ int main(int argc, char *argv[]) return 0; } -int dlt_receive_message_callback(DltMessage *message, void *data) +int dlt_receive_message_callback(DltMessage* message, void* data) { - DltReceiveData *dltdata; + DltReceiveData* dltdata; static char text[DLT_RECEIVE_BUFSIZE]; struct iovec iov[2]; @@ -668,7 +647,7 @@ int dlt_receive_message_callback(DltMessage *message, void *data) if ((message == 0) || (data == 0)) return -1; - dltdata = (DltReceiveData *)data; + dltdata = (DltReceiveData*)data; /* prepare storage header */ if (DLT_IS_HTYP_WEID(message->standardheader->htyp)) @@ -676,15 +655,12 @@ int dlt_receive_message_callback(DltMessage *message, void *data) else dlt_set_storageheader(message->storageheader, dltdata->ecuid); - if (((dltdata->fvalue || dltdata->jvalue) == 0) || - (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE)) { + if (((dltdata->fvalue || dltdata->jvalue) == 0) + || (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE)) { /* if no filter set or filter is matching display message */ if (dltdata->xflag) { dlt_message_print_hex(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); - } - else if (dltdata->aflag) - { - + } else if (dltdata->aflag) { dlt_message_header(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); printf("%s ", text); @@ -692,14 +668,9 @@ int dlt_receive_message_callback(DltMessage *message, void *data) dlt_message_payload(message, text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, dltdata->vflag); printf("[%s]\n", text); - } - else if (dltdata->mflag) - { + } else if (dltdata->mflag) { dlt_message_print_mixed_plain(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); - } - else if (dltdata->sflag) - { - + } else if (dltdata->sflag) { dlt_message_header(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); printf("%s \n", text); @@ -720,7 +691,8 @@ int dlt_receive_message_callback(DltMessage *message, void *data) if (dlt_receive_open_output_file(dltdata) < 0) { printf( - "ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n"); + "ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was " + "reached!\n"); return -1; } diff --git a/src/console/dlt-sortbytimestamp.c b/src/console/dlt-sortbytimestamp.c index 83122c50d..fb0a3821e 100644 --- a/src/console/dlt-sortbytimestamp.c +++ b/src/console/dlt-sortbytimestamp.c @@ -73,9 +73,9 @@ #include "dlt_common.h" -#define DLT_VERBUFSIZE 255 +#define DLT_VERBUFSIZE 255 #define FIFTY_SEC_IN_MSEC 500000 -#define THREE_MIN_IN_SEC 180 +#define THREE_MIN_IN_SEC 180 typedef struct sTimestampIndex { int num; @@ -88,11 +88,12 @@ int verbosity = 0; /** * Print information, conditional upon requested verbosity level */ -void verbose(int level, char *msg, ...) PRINTF_FORMAT(2, 3); -void verbose(int level, char *msg, ...) { +void verbose(int level, char* msg, ...) PRINTF_FORMAT(2, 3); +void verbose(int level, char* msg, ...) +{ if (level <= verbosity) { if (verbosity > 1) { /* timestamp */ - time_t tnow = time((time_t *)0); + time_t tnow = time((time_t*)0); if (tnow != -1) { char snow[50]; @@ -103,9 +104,9 @@ void verbose(int level, char *msg, ...) { } } - int len = (int) strlen(msg); + int len = (int)strlen(msg); va_list args; - va_start (args, msg); + va_start(args, msg); vprintf(msg, args); va_end(args); @@ -119,11 +120,12 @@ void verbose(int level, char *msg, ...) { * Comparison function for use with qsort * Used for time stamp */ -int compare_index_timestamps(const void *a, const void *b) { +int compare_index_timestamps(const void* a, const void* b) +{ int ret = -1; - if (((const TimestampIndex *)a)->tmsp > ((const TimestampIndex *)b)->tmsp) + if (((const TimestampIndex*)a)->tmsp > ((const TimestampIndex*)b)->tmsp) ret = 1; - else if (((const TimestampIndex *)a)->tmsp == ((const TimestampIndex *)b)->tmsp) + else if (((const TimestampIndex*)a)->tmsp == ((const TimestampIndex*)b)->tmsp) ret = 0; return ret; @@ -133,11 +135,12 @@ int compare_index_timestamps(const void *a, const void *b) { * Comparison function for use with qsort * Used for system time */ -int compare_index_systime(const void *a, const void *b) { +int compare_index_systime(const void* a, const void* b) +{ int ret = -1; - if(((const TimestampIndex *) a)->systmsp > ((const TimestampIndex *) b)->systmsp) + if (((const TimestampIndex*)a)->systmsp > ((const TimestampIndex*)b)->systmsp) ret = 1; - else if(((const TimestampIndex *) a)->systmsp == ((const TimestampIndex *) b)->systmsp) + else if (((const TimestampIndex*)a)->systmsp == ((const TimestampIndex*)b)->systmsp) ret = 0; return ret; @@ -146,8 +149,8 @@ int compare_index_systime(const void *a, const void *b) { /** * Write the messages in the order specified by the given index */ -void write_messages(int ohandle, DltFile *file, - TimestampIndex *timestamps, uint32_t message_count) { +void write_messages(int ohandle, DltFile* file, TimestampIndex* timestamps, uint32_t message_count) +{ struct iovec iov[2]; ssize_t bytes_written; uint32_t i = 0; @@ -174,9 +177,7 @@ void write_messages(int ohandle, DltFile *file, last_errno = errno; if (0 > bytes_written) { - printf("%s: returned an error [%s]!\n", - __func__, - strerror(last_errno)); + printf("%s: returned an error [%s]!\n", __func__, strerror(last_errno)); if (ohandle > 0) { close(ohandle); ohandle = -1; @@ -185,16 +186,17 @@ void write_messages(int ohandle, DltFile *file, timestamps = NULL; } dlt_file_free(file, 0); - exit (-1); + exit(-1); } - verbose (2, "\n"); + verbose(2, "\n"); } /** * Print usage information of tool. */ -void usage() { +void usage() +{ char version[DLT_VERBUFSIZE]; dlt_get_version(version, DLT_VERBUFSIZE); @@ -217,17 +219,18 @@ void usage() { /** * Main function of tool. */ -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) +{ int vflag = 0; int cflag = 0; - char *fvalue = 0; - char *bvalue = 0; - char *evalue = 0; - char *ivalue = 0; - char *ovalue = 0; - - TimestampIndex *timestamp_index = 0; - TimestampIndex *temp_timestamp_index = 0; + char* fvalue = 0; + char* bvalue = 0; + char* evalue = 0; + char* ivalue = 0; + char* ovalue = 0; + + TimestampIndex* timestamp_index = 0; + TimestampIndex* temp_timestamp_index = 0; uint32_t message_count = 0; uint32_t count = 0; @@ -249,55 +252,47 @@ int main(int argc, char *argv[]) { verbose(1, "Configuring\n"); - while ((c = getopt (argc, argv, "vchf:b:e:")) != -1) { + while ((c = getopt(argc, argv, "vchf:b:e:")) != -1) { switch (c) { - case 'v': - { + case 'v': { verbosity += 1; break; } - case 'c': - { + case 'c': { cflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'b': - { + case 'b': { bvalue = optarg; break; } - case 'e': - { + case 'e': { evalue = optarg; break; } - case '?': - { + case '?': { if ((optopt == 'f') || (optopt == 'b') || (optopt == 'e')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { + default: { usage(); - return -1; /*for parasoft */ + return -1; /*for parasoft */ } } } @@ -306,7 +301,7 @@ int main(int argc, char *argv[]) { if (verbosity > 2) vflag = 1; - verbose (1, "Initializing\n"); + verbose(1, "Initializing\n"); /* Initialize structure to use DLT file */ dlt_file_init(&file, vflag); @@ -345,8 +340,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "ERROR: Output file %s cannot be opened!\n", ovalue); return -1; } - } - else { + } else { dlt_file_free(&file, vflag); fprintf(stderr, "ERROR: Need an output file!\n"); return -1; @@ -356,8 +350,7 @@ int main(int argc, char *argv[]) { /* load, analyze data file and create index list */ if (dlt_file_open(&file, ivalue, vflag) >= DLT_RETURN_OK) { - while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) { - } + while (dlt_file_read(&file, vflag) >= DLT_RETURN_OK) { } } if (cflag) { @@ -377,8 +370,7 @@ int main(int argc, char *argv[]) { else end = file.counter - 1; - if ((begin < 0) || (end < 0) || (begin > end) || - (begin >= file.counter) || (end >= file.counter)) { + if ((begin < 0) || (end < 0) || (begin > end) || (begin >= file.counter) || (end >= file.counter)) { fprintf(stderr, "ERROR: Selected message [begin-end]-[%d-%d] is out of range!\n", begin, end); dlt_file_free(&file, vflag); close(ohandle); @@ -389,9 +381,9 @@ int main(int argc, char *argv[]) { verbose(1, "Allocating memory\n"); - message_count = (uint32_t) (1 + end - begin); + message_count = (uint32_t)(1 + end - begin); - timestamp_index = (TimestampIndex *) malloc(sizeof(TimestampIndex) * (message_count + 1)); + timestamp_index = (TimestampIndex*)malloc(sizeof(TimestampIndex) * (message_count + 1)); if (timestamp_index == NULL) { fprintf(stderr, "ERROR: Failed to allocate memory for message index!\n"); @@ -417,12 +409,13 @@ int main(int argc, char *argv[]) { timestamp_index[message_count + 1].tmsp = timestamp_index[0].tmsp; verbose(1, "Sorting\n"); - qsort((void *) timestamp_index, message_count, sizeof(TimestampIndex), compare_index_systime); + qsort((void*)timestamp_index, message_count, sizeof(TimestampIndex), compare_index_systime); for (num = begin; num <= end; num++) { int curr_idx = num - begin; delta_tmsp = (uint32_t)llabs((int64_t)timestamp_index[curr_idx + 1].tmsp - timestamp_index[curr_idx].tmsp); - delta_systime = (uint32_t)llabs((int64_t)timestamp_index[curr_idx + 1].systmsp - timestamp_index[curr_idx].systmsp); + delta_systime = + (uint32_t)llabs((int64_t)timestamp_index[curr_idx + 1].systmsp - timestamp_index[curr_idx].systmsp); /* * Here is a try to detect a new cycle of boot in system. @@ -430,9 +423,9 @@ int main(int argc, char *argv[]) { * timestamp is larger than 15 secs should be identified as a new boot cycle. */ count++; - if(delta_tmsp > FIFTY_SEC_IN_MSEC || delta_systime >= THREE_MIN_IN_SEC) { + if (delta_tmsp > FIFTY_SEC_IN_MSEC || delta_systime >= THREE_MIN_IN_SEC) { verbose(1, "Detected a new cycle of boot\n"); - temp_timestamp_index = (TimestampIndex *) malloc(sizeof(TimestampIndex) * count); + temp_timestamp_index = (TimestampIndex*)malloc(sizeof(TimestampIndex) * count); if (temp_timestamp_index == NULL) { fprintf(stderr, "ERROR: Failed to allocate memory for array\n"); @@ -442,12 +435,9 @@ int main(int argc, char *argv[]) { } for (i = 0; i < count; i++) { - memcpy((void*) &temp_timestamp_index[i], - (void*) ×tamp_index[start + i], - sizeof(TimestampIndex)); + memcpy((void*)&temp_timestamp_index[i], (void*)×tamp_index[start + i], sizeof(TimestampIndex)); } - qsort((void *) temp_timestamp_index, count, sizeof(TimestampIndex), - compare_index_timestamps); + qsort((void*)temp_timestamp_index, count, sizeof(TimestampIndex), compare_index_timestamps); write_messages(ohandle, &file, temp_timestamp_index, count); free(temp_timestamp_index); @@ -463,8 +453,7 @@ int main(int argc, char *argv[]) { * all messages out. */ if (count == message_count) { - qsort((void *) timestamp_index, message_count + 1, - sizeof(TimestampIndex), compare_index_timestamps); + qsort((void*)timestamp_index, message_count + 1, sizeof(TimestampIndex), compare_index_timestamps); write_messages(ohandle, &file, timestamp_index, count); } diff --git a/src/console/logstorage/dlt-logstorage-common.c b/src/console/logstorage/dlt-logstorage-common.c index 9ead0132b..010db3480 100644 --- a/src/console/logstorage/dlt-logstorage-common.c +++ b/src/console/logstorage/dlt-logstorage-common.c @@ -49,7 +49,7 @@ ** cl Christoph Lipka ADIT ** ** fb Frederic Berat ADIT ** *******************************************************************************/ -#define pr_fmt(fmt) "Logstorage common: "fmt +#define pr_fmt(fmt) "Logstorage common: " fmt #include #include @@ -69,16 +69,16 @@ #include "dlt-logstorage-common.h" #ifdef DLT_LOGSTORAGE_CTRL_UDEV_ENABLE -# include "dlt-logstorage-udev.h" +#include "dlt-logstorage-udev.h" #endif #include "dlt-logstorage-prop.h" static struct LogstorageOptions { - int event_type; /**< EVENT_UNMOUNTING/EVENT_MOUNTED */ + int event_type; /**< EVENT_UNMOUNTING/EVENT_MOUNTED */ char device_path[DLT_MOUNT_PATH_MAX]; /**< Default Mount path */ - DltLogstorageHandler handler_type; /**< be controlled by udev or prop */ - long timeout; /**< Default timeout */ + DltLogstorageHandler handler_type; /**< be controlled by udev or prop */ + long timeout; /**< Default timeout */ } g_options = { .event_type = EVENT_MOUNTED, .handler_type = CTRL_NOHANDLER, @@ -89,7 +89,7 @@ DltLogstorageHandler get_handler_type(void) return g_options.handler_type; } -void set_handler_type(char *type) +void set_handler_type(char* type) { g_options.handler_type = CTRL_UDEV; @@ -104,15 +104,15 @@ int get_default_event_type(void) void set_default_event_type(long type) { - g_options.event_type = (int) type; + g_options.event_type = (int)type; } -char *get_default_path(void) +char* get_default_path(void) { return g_options.device_path; } -void set_default_path(char *path) +void set_default_path(char* path) { memset(g_options.device_path, 0, DLT_MOUNT_PATH_MAX); @@ -123,15 +123,15 @@ void set_default_path(char *path) /* Used by the handlers */ static DltLogstorageCtrl lctrl; -DltLogstorageCtrl *get_logstorage_control(void) +DltLogstorageCtrl* get_logstorage_control(void) { return &lctrl; } -void *dlt_logstorage_get_handler_cb(void) +void* dlt_logstorage_get_handler_cb(void) { union { - void *ptr; + void* ptr; int (*callback)(void); } callback_converter; @@ -191,9 +191,9 @@ int dlt_logstorage_deinit_handler(void) * * @return 1 if the file is found, 0 otherwise. */ -int dlt_logstorage_check_config_file(char *mnt_point) +int dlt_logstorage_check_config_file(char* mnt_point) { - struct dirent **files = NULL; + struct dirent** files = NULL; int n; int i = 0; int ret = 0; @@ -237,7 +237,7 @@ int dlt_logstorage_check_config_file(char *mnt_point) * * @return 1 if the file is writable, 0 otherwise. */ -int dlt_logstorage_check_directory_permission(char *mnt_point) +int dlt_logstorage_check_directory_permission(char* mnt_point) { if (mnt_point == NULL) { pr_error("Given mount point is NULL\n"); @@ -258,11 +258,9 @@ int dlt_logstorage_check_directory_permission(char *mnt_point) * * @return The body once built or NULL. */ -static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body, - int conn_type, - char *path) +static DltControlMsgBody* prepare_message_body(DltControlMsgBody** body, int conn_type, char* path) { - DltServiceOfflineLogstorage *serv = NULL; + DltServiceOfflineLogstorage* serv = NULL; if (path == NULL) { pr_error("Mount path is uninitialized.\n"); @@ -289,10 +287,10 @@ static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body, (*body)->size = sizeof(DltServiceOfflineLogstorage); - serv = (DltServiceOfflineLogstorage *)(*body)->data; + serv = (DltServiceOfflineLogstorage*)(*body)->data; serv->service_id = DLT_SERVICE_ID_OFFLINE_LOGSTORAGE; - serv->connection_type = (uint8_t) conn_type; + serv->connection_type = (uint8_t)conn_type; /* mount_point is DLT_MOUNT_PATH_MAX + 1 long, * and the memory is already zeroed. */ @@ -310,10 +308,10 @@ static DltControlMsgBody *prepare_message_body(DltControlMsgBody **body, * * @return 0 On success, -1 otherwise. */ -int dlt_logstorage_send_event(int type, char *mount_point) +int dlt_logstorage_send_event(int type, char* mount_point) { int ret = 0; - DltControlMsgBody *msg_body = NULL; + DltControlMsgBody* msg_body = NULL; /* mount_point is checked against NULL in the preparation */ if (!prepare_message_body(&msg_body, type, mount_point)) { diff --git a/src/console/logstorage/dlt-logstorage-common.h b/src/console/logstorage/dlt-logstorage-common.h index 0a695dfaa..cf776474a 100644 --- a/src/console/logstorage/dlt-logstorage-common.h +++ b/src/console/logstorage/dlt-logstorage-common.h @@ -25,22 +25,21 @@ #define CONF_NAME "dlt_logstorage.conf" -#define EVENT_UNMOUNTING 0 -#define EVENT_MOUNTED 1 -#define EVENT_SYNC_CACHE 2 +#define EVENT_UNMOUNTING 0 +#define EVENT_MOUNTED 1 +#define EVENT_SYNC_CACHE 2 -typedef enum -{ +typedef enum { CTRL_NOHANDLER = 0, /**< one shot application */ CTRL_UDEV, /**< Handles udev events */ CTRL_PROPRIETARY /**< Handles proprietary event */ } DltLogstorageHandler; DltLogstorageHandler get_handler_type(void); -void set_handler_type(char *); +void set_handler_type(char*); -char *get_default_path(void); -void set_default_path(char *); +char* get_default_path(void); +void set_default_path(char*); int get_default_event_type(void); void set_default_event_type(long type); @@ -48,12 +47,12 @@ void set_default_event_type(long type); typedef struct { int fd; int (*callback)(void); /* callback for event handling */ - void *prvt; /* Private data */ + void* prvt; /* Private data */ } DltLogstorageCtrl; /* Get a reference to the logstorage control instance */ -DltLogstorageCtrl *get_logstorage_control(void); -void *dlt_logstorage_get_handler_cb(void); +DltLogstorageCtrl* get_logstorage_control(void); +void* dlt_logstorage_get_handler_cb(void); int dlt_logstorage_get_handler_fd(void); int dlt_logstorage_init_handler(void); int dlt_logstorage_deinit_handler(void); @@ -66,7 +65,7 @@ int dlt_logstorage_deinit_handler(void); * * @return 0 on success, -1 on error */ -int dlt_logstorage_send_event(int, char *); +int dlt_logstorage_send_event(int, char*); /** @brief Search for config file in given mount point * @@ -77,7 +76,7 @@ int dlt_logstorage_send_event(int, char *); * * @return 1 if the file is found, 0 otherwise. */ -int dlt_logstorage_check_config_file(char *); +int dlt_logstorage_check_config_file(char*); /** @brief Check if given mount point is writable * @@ -85,6 +84,6 @@ int dlt_logstorage_check_config_file(char *); * * @return 1 if the file is writable, 0 otherwise. */ -int dlt_logstorage_check_directory_permission(char *mnt_point); +int dlt_logstorage_check_directory_permission(char* mnt_point); #endif diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c index c300453b1..eebeed8e7 100644 --- a/src/console/logstorage/dlt-logstorage-ctrl.c +++ b/src/console/logstorage/dlt-logstorage-ctrl.c @@ -51,7 +51,7 @@ ** fb Frederic Berat ADIT ** *******************************************************************************/ -#define pr_fmt(fmt) "Logstorage control: "fmt +#define pr_fmt(fmt) "Logstorage control: " fmt #include #include @@ -64,7 +64,7 @@ #include #if defined(__linux__) -# include "sd-daemon.h" +#include "sd-daemon.h" #endif #include "dlt_protocol.h" @@ -73,14 +73,14 @@ #include "dlt-logstorage-common.h" #include "dlt-logstorage-ctrl.h" -#define POLL_TIME_OUT 500 +#define POLL_TIME_OUT 500 #define EV_MASK_REJECTED (POLLERR | POLLHUP | POLLNVAL) #define DLT_LOGSTORAGE_CTRL_EXIT 1 static int must_exit; struct dlt_event { struct pollfd pfd; - void *func; + void* func; }; /** @brief Triggers the application exit @@ -122,7 +122,7 @@ static void catch_signal(int signo) */ static void install_signal_handler(void) { - int signals[] = { SIGINT, SIGQUIT, SIGTERM, 0 }; + int signals[] = {SIGINT, SIGQUIT, SIGTERM, 0}; unsigned int i; struct sigaction sa; @@ -134,8 +134,7 @@ static void install_signal_handler(void) sa.sa_handler = catch_signal; if (sigaction(signals[i], &sa, NULL) < 0) - pr_error("Failed to install signal %u handler. Error: %s\n", - signals[i], strerror(errno)); + pr_error("Failed to install signal %u handler. Error: %s\n", signals[i], strerror(errno)); } } @@ -150,12 +149,12 @@ static void install_signal_handler(void) * @param len The answer payload length * @return 0 on success, -1 otherwise. */ -static int analyze_response(char *data, void *payload, int len) +static int analyze_response(char* data, void* payload, int len) { int ret = -1; - char resp_ok[MAX_RESPONSE_LENGTH] = { 0 }; - char resp_warning[MAX_RESPONSE_LENGTH] = { 0 }; - char resp_perm_denied[MAX_RESPONSE_LENGTH] = { 0 }; + char resp_ok[MAX_RESPONSE_LENGTH] = {0}; + char resp_warning[MAX_RESPONSE_LENGTH] = {0}; + char resp_perm_denied[MAX_RESPONSE_LENGTH] = {0}; if ((data == NULL) || (payload == NULL)) return -1; @@ -164,20 +163,11 @@ static int analyze_response(char *data, void *payload, int len) (void)payload; (void)len; - snprintf(resp_ok, - MAX_RESPONSE_LENGTH, - "service(%d), ok", - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); + snprintf(resp_ok, MAX_RESPONSE_LENGTH, "service(%d), ok", DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); - snprintf(resp_warning, - MAX_RESPONSE_LENGTH, - "service(%d), warning", - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); + snprintf(resp_warning, MAX_RESPONSE_LENGTH, "service(%d), warning", DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); - snprintf(resp_perm_denied, - MAX_RESPONSE_LENGTH, - "service(%d), perm_denied", - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); + snprintf(resp_perm_denied, MAX_RESPONSE_LENGTH, "service(%d), perm_denied", DLT_SERVICE_ID_OFFLINE_LOGSTORAGE); if (strncmp(data, resp_ok, strlen(resp_ok)) == 0) ret = 0; @@ -209,9 +199,7 @@ static int analyze_response(char *data, void *payload, int len) * * @return 0 on success, -1 if the parameters are invalid. */ -static int dlt_logstorage_ctrl_add_event(struct dlt_event *ev_hdl, - int fd, - void *cb) +static int dlt_logstorage_ctrl_add_event(struct dlt_event* ev_hdl, int fd, void* cb) { if ((fd < 0) || !cb || !ev_hdl) { pr_error("Wrong parameter to add event (%d %p)\n", fd, cb); @@ -233,11 +221,11 @@ static int dlt_logstorage_ctrl_add_event(struct dlt_event *ev_hdl, * * @return 0 on success, -1 otherwise. */ -static int dlt_logstorage_ctrl_execute_event_loop(struct dlt_event *ev) +static int dlt_logstorage_ctrl_execute_event_loop(struct dlt_event* ev) { int ret = 0; union { - void *ptr; + void* ptr; int (*callback)(void); } callback_converter; int (*callback)(void); @@ -301,23 +289,17 @@ static int dlt_logstorage_ctrl_execute_event_loop(struct dlt_event *ev) static int dlt_logstorage_ctrl_setup_event_loop(void) { int ret = 0; - struct dlt_event ev_hdl = { - .pfd = { - .fd = -1, - .events = POLLIN - } - }; + struct dlt_event ev_hdl = {.pfd = {.fd = -1, .events = POLLIN}}; install_signal_handler(); pr_verbose("Creating poll instance.\n"); /* Initializing the communication with the daemon */ - while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && - !dlt_logstorage_must_exit()) { + while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && !dlt_logstorage_must_exit()) { pr_error("Failed to initialize connection with the daemon.\n"); pr_error("Retrying to connect in %ds.\n", get_timeout()); - sleep((unsigned int) get_timeout()); + sleep((unsigned int)get_timeout()); } if (dlt_logstorage_must_exit()) { @@ -333,9 +315,7 @@ static int dlt_logstorage_ctrl_setup_event_loop(void) return -1; } - if (dlt_logstorage_ctrl_add_event(&ev_hdl, - dlt_logstorage_get_handler_fd(), - dlt_logstorage_get_handler_cb()) < 0) { + if (dlt_logstorage_ctrl_add_event(&ev_hdl, dlt_logstorage_get_handler_fd(), dlt_logstorage_get_handler_cb()) < 0) { pr_error("add_event error: %s\n", strerror(errno)); dlt_logstorage_exit(); } @@ -362,9 +342,7 @@ static int dlt_logstorage_ctrl_single_request() if (get_default_event_type() != EVENT_SYNC_CACHE) { /* Check if a 'CONF_NAME' file is present at the given path */ if (!dlt_logstorage_check_config_file(get_default_path())) { - pr_error("No '%s' file available at: %s\n", - CONF_NAME, - get_default_path()); + pr_error("No '%s' file available at: %s\n", CONF_NAME, get_default_path()); return -1; } @@ -375,19 +353,15 @@ static int dlt_logstorage_ctrl_single_request() } /* Initializing the communication with the daemon */ - while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && - !dlt_logstorage_must_exit()) { + while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && !dlt_logstorage_must_exit()) { pr_error("Failed to initialize connection with the daemon.\n"); pr_error("Retrying to connect in %ds.\n", get_timeout()); - sleep( (unsigned int) get_timeout()); + sleep((unsigned int)get_timeout()); } - pr_verbose("event type is [%d]\t device path is [%s]\n", - get_default_event_type(), - get_default_path()); + pr_verbose("event type is [%d]\t device path is [%s]\n", get_default_event_type(), get_default_path()); - ret = dlt_logstorage_send_event(get_default_event_type(), - get_default_path()); + ret = dlt_logstorage_send_event(get_default_event_type(), get_default_path()); dlt_control_deinit(); @@ -399,8 +373,9 @@ static int dlt_logstorage_ctrl_single_request() static void usage(void) { printf("Usage: dlt-logstorage-ctrl [options]\n"); - printf("Send a trigger to DLT daemon to connect/disconnect" - "a certain logstorage device\n"); + printf( + "Send a trigger to DLT daemon to connect/disconnect" + "a certain logstorage device\n"); printf("\n"); printf("Options:\n"); printf(" -c --command Connection type: connect = 1, disconnect = 0\n"); @@ -412,8 +387,7 @@ static void usage(void) printf(" -p --path Mount point path\n"); printf(" -s[path] --snapshot=path Sync Logstorage cache\n"); printf(" Don't use -s together with -d and -c\n"); - printf(" -t Specify connection timeout (Default: %ds)\n", - DLT_CTRL_TIMEOUT); + printf(" -t Specify connection timeout (Default: %ds)\n", DLT_CTRL_TIMEOUT); printf(" -S --send-header Send message with serial header (Default: Without serial header)\n"); printf(" -R --resync-header Enable resync serial header\n"); printf(" -v --verbose Set verbose flag (Default:%d)\n", get_verbosity()); @@ -422,18 +396,17 @@ static void usage(void) } static struct option long_options[] = { - {"command", required_argument, 0, 'c'}, - {"daemonize", optional_argument, 0, 'd'}, - {"ecuid", required_argument, 0, 'e'}, - {"help", no_argument, 0, 'h'}, - {"path", required_argument, 0, 'p'}, - {"snapshot", optional_argument, 0, 's'}, - {"timeout", required_argument, 0, 't'}, - {"send-header", no_argument, 0, 'S'}, - {"resync-header", no_argument, 0, 'R'}, - {"verbose", no_argument, 0, 'v'}, - {0, 0, 0, 0} -}; + {"command", required_argument, 0, 'c'}, + {"daemonize", optional_argument, 0, 'd'}, + {"ecuid", required_argument, 0, 'e'}, + {"help", no_argument, 0, 'h'}, + {"path", required_argument, 0, 'p'}, + {"snapshot", optional_argument, 0, 's'}, + {"timeout", required_argument, 0, 't'}, + {"send-header", no_argument, 0, 'S'}, + {"resync-header", no_argument, 0, 'R'}, + {"verbose", no_argument, 0, 'v'}, + {0, 0, 0, 0}}; /** @brief Parses the application arguments * @@ -444,16 +417,12 @@ static struct option long_options[] = { * * @return 0 on success, -1 otherwise */ -static int parse_args(int argc, char *argv[]) +static int parse_args(int argc, char* argv[]) { int c = -1; int long_index = 0; - while ((c = getopt_long(argc, - argv, - ":s::t:hSRe:p:d::c:vC:", - long_options, - &long_index)) != -1) + while ((c = getopt_long(argc, argv, ":s::t:hSRe:p:d::c:vC:", long_options, &long_index)) != -1) switch (c) { case 's': set_default_event_type(EVENT_SYNC_CACHE); @@ -467,15 +436,13 @@ static int parse_args(int argc, char *argv[]) break; case 't': if (optarg != NULL) - set_timeout((int) strtol(optarg, NULL, 10)); + set_timeout((int)strtol(optarg, NULL, 10)); break; - case 'S': - { + case 'S': { set_send_serial_header(1); break; } - case 'R': - { + case 'R': { set_resync_serial_header(1); break; } @@ -531,8 +498,7 @@ static int parse_args(int argc, char *argv[]) - if ((get_default_event_type() == EVENT_SYNC_CACHE) && - (get_handler_type() != CTRL_NOHANDLER)) { + if ((get_default_event_type() == EVENT_SYNC_CACHE) && (get_handler_type() != CTRL_NOHANDLER)) { pr_error("Sync caches not available in daemon mode\n"); return -1; } @@ -545,7 +511,7 @@ static int parse_args(int argc, char *argv[]) } #if !defined(DLT_SYSTEMD_ENABLE) -int sd_notify(int unset_environment, char *state) +int sd_notify(int unset_environment, char* state) { /* Satisfy Compiler for warnings */ (void)unset_environment; @@ -563,7 +529,7 @@ int sd_notify(int unset_environment, char *state) * * @return 0 on success, -1 otherwise */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int ret = 0; @@ -584,8 +550,7 @@ int main(int argc, char *argv[]) if (ret < 0) pr_error("Message failed to be send. Please check DLT config.\n"); - } - else { + } else { pr_verbose("Entering in daemon mode.\n"); /* Let's daemonize */ @@ -595,8 +560,8 @@ int main(int argc, char *argv[]) /* No message can be sent or Systemd is not available. * Daemonizing manually. */ - - // This does the same thing as daemon(1, 1) but is not deprecated + + // This does the same thing as daemon(1, 1) but is not deprecated pid_t pid = fork(); if (pid < 0) { pr_error("Failed to fork: %s\n", strerror(errno)); diff --git a/src/console/logstorage/dlt-logstorage-list.c b/src/console/logstorage/dlt-logstorage-list.c index 18f0f18ba..8e07a04e3 100644 --- a/src/console/logstorage/dlt-logstorage-list.c +++ b/src/console/logstorage/dlt-logstorage-list.c @@ -52,7 +52,7 @@ ** cl Christoph Lipka ADIT ** ** fb Frederic Berat ADIT ** *******************************************************************************/ -#define pr_fmt(fmt) "Log storage list: "fmt +#define pr_fmt(fmt) "Log storage list: " fmt #include #include @@ -63,13 +63,12 @@ #include "dlt-control-common.h" #include "dlt-logstorage-common.h" -static struct LogstorageDeviceInfo -{ - char *dev_node; /**< The device node */ - char *mnt_point; /**< Mount point for this device */ - struct LogstorageDeviceInfo *prev; /**< Previous element of the list */ - struct LogstorageDeviceInfo *next; /**< Next element of the list */ -} *g_info; +static struct LogstorageDeviceInfo { + char* dev_node; /**< The device node */ + char* mnt_point; /**< Mount point for this device */ + struct LogstorageDeviceInfo* prev; /**< Previous element of the list */ + struct LogstorageDeviceInfo* next; /**< Next element of the list */ +}* g_info; /** @brief Prints the device list in verbose mode * @@ -78,11 +77,11 @@ static struct LogstorageDeviceInfo */ void print_list(void) { - struct LogstorageDeviceInfo *ptr = g_info; + struct LogstorageDeviceInfo* ptr = g_info; pr_verbose(" -------Device list-------\n"); while (ptr != NULL) { - pr_verbose("%p:\t[%s][%s] \n", (void *)ptr, ptr->dev_node, ptr->mnt_point); + pr_verbose("%p:\t[%s][%s] \n", (void*)ptr, ptr->dev_node, ptr->mnt_point); ptr = ptr->next; } @@ -100,9 +99,9 @@ void print_list(void) * * @return The element of the list found, NULL either. */ -static struct LogstorageDeviceInfo *logstorage_find_dev_info(const char *node) +static struct LogstorageDeviceInfo* logstorage_find_dev_info(const char* node) { - struct LogstorageDeviceInfo *ptr = g_info; + struct LogstorageDeviceInfo* ptr = g_info; if (!node) return NULL; @@ -111,10 +110,9 @@ static struct LogstorageDeviceInfo *logstorage_find_dev_info(const char *node) while (ptr != NULL) { if (strncmp(ptr->dev_node, node, DLT_MOUNT_PATH_MAX) == 0) { - pr_verbose("%s found in %p.\n", node, (void *)ptr); + pr_verbose("%s found in %p.\n", node, (void*)ptr); break; - } - else { + } else { ptr = ptr->next; } } @@ -132,9 +130,9 @@ static struct LogstorageDeviceInfo *logstorage_find_dev_info(const char *node) * * @return 0 on success, -1 in case of error. */ -int logstorage_store_dev_info(const char *node, const char *path) +int logstorage_store_dev_info(const char* node, const char* path) { - struct LogstorageDeviceInfo *ptr = NULL; + struct LogstorageDeviceInfo* ptr = NULL; size_t path_len = 0; if ((node == NULL) || (path == NULL)) { @@ -161,7 +159,7 @@ int logstorage_store_dev_info(const char *node, const char *path) if (path_len > DLT_MOUNT_PATH_MAX) path_len = (size_t)DLT_MOUNT_PATH_MAX; - ptr->mnt_point = (char *)calloc(1, path_len + 1); + ptr->mnt_point = (char*)calloc(1, path_len + 1); if (ptr->mnt_point == NULL) { pr_error("memory allocation failed for mnt_point\n"); @@ -198,10 +196,10 @@ int logstorage_store_dev_info(const char *node, const char *path) * * @return the mount point if the node is found, NULL either. */ -char *logstorage_delete_dev_info(const char *node) +char* logstorage_delete_dev_info(const char* node) { - struct LogstorageDeviceInfo *del = NULL; - char *ret = NULL; + struct LogstorageDeviceInfo* del = NULL; + char* ret = NULL; del = logstorage_find_dev_info(node); diff --git a/src/console/logstorage/dlt-logstorage-list.h b/src/console/logstorage/dlt-logstorage-list.h index 17bf88424..db7d68b78 100644 --- a/src/console/logstorage/dlt-logstorage-list.h +++ b/src/console/logstorage/dlt-logstorage-list.h @@ -24,8 +24,8 @@ #define _DLT_LOGSTORAGE_LIST_H_ /* Return 0 it the node as been added (or is already present) */ -int logstorage_store_dev_info(const char *node, const char *path); +int logstorage_store_dev_info(const char* node, const char* path); /* Returns the mount point if node has been found and deleted. NULL either */ -char *logstorage_delete_dev_info(const char *node); +char* logstorage_delete_dev_info(const char* node); #endif diff --git a/src/console/logstorage/dlt-logstorage-prop.h b/src/console/logstorage/dlt-logstorage-prop.h index 384878b7c..b1055e05e 100644 --- a/src/console/logstorage/dlt-logstorage-prop.h +++ b/src/console/logstorage/dlt-logstorage-prop.h @@ -43,9 +43,10 @@ static inline int dlt_logstorage_prop_deinit(void) * * @return 0 */ -static inline int check_proprietary_handling(char *type) +static inline int check_proprietary_handling(char* type) { - (void)type; return 0; + (void)type; + return 0; } #else /** @@ -67,7 +68,7 @@ int dlt_logstorage_prop_deinit(void); * * @return 1 if yes, 0 either. */ -int check_proprietary_handling(char *); +int check_proprietary_handling(char*); #endif /* HAS_PROPRIETARY_LOGSTORAGE */ #endif /* _DLT_LOGSTORAGE_PROP_H_ */ diff --git a/src/console/logstorage/dlt-logstorage-udev.c b/src/console/logstorage/dlt-logstorage-udev.c index 35d5836d6..5aa08c04b 100644 --- a/src/console/logstorage/dlt-logstorage-udev.c +++ b/src/console/logstorage/dlt-logstorage-udev.c @@ -50,7 +50,7 @@ ** fb Frederic Berat ADIT ** *******************************************************************************/ -#define pr_fmt(fmt) "Udev control: "fmt +#define pr_fmt(fmt) "Udev control: " fmt #include #include @@ -68,8 +68,8 @@ #include "dlt-logstorage-udev.h" typedef struct { - struct udev *udev; /**< Udev instance */ - struct udev_monitor *mon; /**< Udev monitor instance */ + struct udev* udev; /**< Udev instance */ + struct udev_monitor* mon; /**< Udev monitor instance */ } LogstorageCtrlUdev; /** @brief Get mount point of a device node @@ -81,11 +81,11 @@ typedef struct { * * @return mount path or NULL on error */ -static char *dlt_logstorage_udev_get_mount_point(char *dev_node) +static char* dlt_logstorage_udev_get_mount_point(char* dev_node) { - struct mntent *ent; - FILE *f; - char *mnt_point = NULL; + struct mntent* ent; + FILE* f; + char* mnt_point = NULL; if (dev_node == NULL) return NULL; @@ -135,11 +135,11 @@ static char *dlt_logstorage_udev_get_mount_point(char *dev_node) * * @return 0 on success, -1 if an error occured. */ -static int check_mountpoint_from_partition(int event, struct udev_device *part) +static int check_mountpoint_from_partition(int event, struct udev_device* part) { int logstorage_dev = 0; - char *mnt_point = NULL; - char *dev_node = NULL; + char* mnt_point = NULL; + char* dev_node = NULL; int ret = 0; if (!part) { @@ -167,13 +167,11 @@ static int check_mountpoint_from_partition(int event, struct udev_device *part) if (logstorage_dev) { /* Configuration file available, add node to internal list */ logstorage_store_dev_info(dev_node, mnt_point); - } - else { + } else { free(mnt_point); mnt_point = NULL; } - } - else { + } else { /* remove device information */ mnt_point = logstorage_delete_dev_info(dev_node); } @@ -200,11 +198,11 @@ static int check_mountpoint_from_partition(int event, struct udev_device *part) */ static int logstorage_udev_udevd_callback(void) { - const char *action; + const char* action; int ret = 0; - DltLogstorageCtrl *lctrl = get_logstorage_control(); - LogstorageCtrlUdev *prvt = NULL; - struct udev_device *partition = NULL; + DltLogstorageCtrl* lctrl = get_logstorage_control(); + LogstorageCtrlUdev* prvt = NULL; + struct udev_device* partition = NULL; struct timespec ts; if (!lctrl) { @@ -212,7 +210,7 @@ static int logstorage_udev_udevd_callback(void) return -1; } - prvt = (LogstorageCtrlUdev *)lctrl->prvt; + prvt = (LogstorageCtrlUdev*)lctrl->prvt; if ((!prvt) || (!prvt->mon)) { pr_error("Not able to get private data.\n"); @@ -234,9 +232,7 @@ static int logstorage_udev_udevd_callback(void) return -1; } - pr_verbose("%s action received from udev for %s.\n", - action, - udev_device_get_devnode(partition)); + pr_verbose("%s action received from udev for %s.\n", action, udev_device_get_devnode(partition)); if (strncmp(action, "add", sizeof("add")) == 0) { /*TODO: This can be replaced by polling on /proc/mount. @@ -247,12 +243,10 @@ static int logstorage_udev_udevd_callback(void) * and/or for hot unplug (without unmount). */ ts.tv_sec = 0; - ts.tv_nsec = (long int) 500 * NANOSEC_PER_MILLISEC; + ts.tv_nsec = (long int)500 * NANOSEC_PER_MILLISEC; nanosleep(&ts, NULL); ret = check_mountpoint_from_partition(EVENT_MOUNTED, partition); - } - else if (strncmp(action, "remove", sizeof("remove")) == 0) - { + } else if (strncmp(action, "remove", sizeof("remove")) == 0) { ret = check_mountpoint_from_partition(EVENT_UNMOUNTING, partition); } @@ -270,7 +264,7 @@ static int logstorage_udev_udevd_callback(void) * * @return 0 on success, -1 otherwise. */ -static int dlt_logstorage_udev_check_mounted(struct udev *udev) +static int dlt_logstorage_udev_check_mounted(struct udev* udev) { if (udev == NULL) { pr_error("%s: udev structure is NULL\n", __func__); @@ -278,9 +272,9 @@ static int dlt_logstorage_udev_check_mounted(struct udev *udev) } /* Create a list of the devices in the 'partition' subsystem. */ - struct udev_enumerate *enumerate = udev_enumerate_new(udev); - struct udev_list_entry *devices = NULL; - struct udev_list_entry *dev_list_entry = NULL; + struct udev_enumerate* enumerate = udev_enumerate_new(udev); + struct udev_list_entry* devices = NULL; + struct udev_list_entry* dev_list_entry = NULL; if (!enumerate) { pr_error("Can't enumerate devices.\n"); @@ -296,8 +290,8 @@ static int dlt_logstorage_udev_check_mounted(struct udev *udev) /* For each list entry, get the corresponding device */ udev_list_entry_foreach(dev_list_entry, devices) { - const char *path; - struct udev_device *partition = NULL; + const char* path; + struct udev_device* partition = NULL; /* Get the filename of the /sys entry for the device * and create a udev_device object representing it @@ -308,10 +302,8 @@ static int dlt_logstorage_udev_check_mounted(struct udev *udev) if (!partition) continue; - pr_verbose("Found device %s %s %s.\n", - path, - udev_device_get_devnode(partition), - udev_device_get_devtype(partition)); + pr_verbose( + "Found device %s %s %s.\n", path, udev_device_get_devnode(partition), udev_device_get_devtype(partition)); /* Check the device and clean-up */ check_mountpoint_from_partition(EVENT_MOUNTED, partition); @@ -332,13 +324,13 @@ static int dlt_logstorage_udev_check_mounted(struct udev *udev) */ int dlt_logstorage_udev_deinit(void) { - DltLogstorageCtrl *lctrl = get_logstorage_control(); - LogstorageCtrlUdev *prvt = NULL; + DltLogstorageCtrl* lctrl = get_logstorage_control(); + LogstorageCtrlUdev* prvt = NULL; if (!lctrl) return -1; - prvt = (LogstorageCtrlUdev *)lctrl->prvt; + prvt = (LogstorageCtrlUdev*)lctrl->prvt; if (prvt == NULL) return -1; @@ -365,8 +357,8 @@ int dlt_logstorage_udev_init(void) { int ret = 0; - DltLogstorageCtrl *lctrl = get_logstorage_control(); - LogstorageCtrlUdev *prvt = NULL; + DltLogstorageCtrl* lctrl = get_logstorage_control(); + LogstorageCtrlUdev* prvt = NULL; pr_verbose("Initializing.\n"); @@ -382,7 +374,7 @@ int dlt_logstorage_udev_init(void) return -1; } - prvt = (LogstorageCtrlUdev *)lctrl->prvt; + prvt = (LogstorageCtrlUdev*)lctrl->prvt; /* Initialize udev object */ prvt->udev = udev_new(); @@ -404,9 +396,7 @@ int dlt_logstorage_udev_init(void) return -1; } - ret = udev_monitor_filter_add_match_subsystem_devtype(prvt->mon, - "block", - NULL); + ret = udev_monitor_filter_add_match_subsystem_devtype(prvt->mon, "block", NULL); if (ret) { pr_error("Cannot attach filter to monitor: %s.\n", strerror(-ret)); diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 5378eff25..06b0351f6 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -30,10 +30,10 @@ #include /* for printf() and fprintf() */ #include /* for socket(), connect(), (), and recv() */ #include -#include /* for sockaddr_in and inet_addr() */ -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() and access */ +#include /* for sockaddr_in and inet_addr() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() and access */ #include #include #include @@ -42,23 +42,23 @@ #include #ifdef linux -# include +#include #endif #include #include #include #if defined(linux) && defined(__NR_statx) -# include +#include #endif #ifdef DLT_DAEMON_VSOCK_IPC_ENABLE -# ifdef linux -# include -# endif -# ifdef __QNX__ -# include -# endif +#ifdef linux +#include +#endif +#ifdef __QNX__ +#include +#endif #endif #include @@ -93,10 +93,10 @@ #include "dlt_gateway.h" #ifdef UDP_CONNECTION_SUPPORT -# include "dlt_daemon_udp_socket.h" +#include "dlt_daemon_udp_socket.h" #endif #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE) -# include "sd-daemon.h" +#include "sd-daemon.h" #endif /** @@ -108,25 +108,22 @@ #define DLT_DAEMON_APP_ID "DLTD" #define DLT_DAEMON_CTX_ID "INTM" -static int dlt_daemon_log_internal(DltDaemon *daemon, - DltDaemonLocal *daemon_local, char *str, - DltLogLevelType level, const char *app_id, - const char *ctx_id, int verbose); +static int dlt_daemon_log_internal( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* str, DltLogLevelType level, const char* app_id, + const char* ctx_id, int verbose); -static int dlt_daemon_check_numeric_setting(char *token, - char *value, - unsigned long *data); +static int dlt_daemon_check_numeric_setting(char* token, char* value, unsigned long* data); #ifdef DLT_TRACE_LOAD_CTRL_ENABLE struct DltTraceLoadLogParams { - DltDaemon *daemon; - DltDaemonLocal *daemon_local; + DltDaemon* daemon; + DltDaemonLocal* daemon_local; int verbose; - char *app_id; + char* app_id; }; -static DltReturnValue dlt_daemon_output_internal_msg(DltLogLevelType loglevel, const char *text, void *params); +static DltReturnValue dlt_daemon_output_internal_msg(DltLogLevelType loglevel, const char* text, void* params); static void dlt_trace_load_free(DltDaemon* daemon); pthread_rwlock_t trace_load_rw_lock; @@ -147,8 +144,7 @@ static char dlt_timer_conn_types[DLT_TIMER_UNKNOWN + 1] = { [DLT_TIMER_SYSTEMD] = DLT_CONNECTION_SYSTEMD_TIMER, #endif [DLT_TIMER_GATEWAY] = DLT_CONNECTION_GATEWAY_TIMER, - [DLT_TIMER_UNKNOWN] = DLT_CONNECTION_TYPE_MAX -}; + [DLT_TIMER_UNKNOWN] = DLT_CONNECTION_TYPE_MAX}; static char dlt_timer_names[DLT_TIMER_UNKNOWN + 1][32] = { [DLT_TIMER_PACKET] = "Timing packet", @@ -157,8 +153,7 @@ static char dlt_timer_names[DLT_TIMER_UNKNOWN + 1][32] = { [DLT_TIMER_SYSTEMD] = "Systemd watchdog", #endif [DLT_TIMER_GATEWAY] = "Gateway", - [DLT_TIMER_UNKNOWN] = "Unknown timer" -}; + [DLT_TIMER_UNKNOWN] = "Unknown timer"}; #ifdef __QNX__ static int dlt_timer_pipes[DLT_TIMER_UNKNOWN][2] = { @@ -168,8 +163,7 @@ static int dlt_timer_pipes[DLT_TIMER_UNKNOWN][2] = { #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE [DLT_TIMER_SYSTEMD] = {DLT_FD_INIT, DLT_FD_INIT}, #endif - [DLT_TIMER_GATEWAY] = {DLT_FD_INIT, DLT_FD_INIT} -}; + [DLT_TIMER_GATEWAY] = {DLT_FD_INIT, DLT_FD_INIT}}; static pthread_t timer_threads[DLT_TIMER_UNKNOWN] = { [DLT_TIMER_PACKET] = 0, @@ -177,17 +171,15 @@ static pthread_t timer_threads[DLT_TIMER_UNKNOWN] = { #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE [DLT_TIMER_SYSTEMD] = 0, #endif - [DLT_TIMER_GATEWAY] = 0 -}; + [DLT_TIMER_GATEWAY] = 0}; -static DltDaemonPeriodicData *timer_data[DLT_TIMER_UNKNOWN] = { +static DltDaemonPeriodicData* timer_data[DLT_TIMER_UNKNOWN] = { [DLT_TIMER_PACKET] = NULL, [DLT_TIMER_ECU] = NULL, #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE [DLT_TIMER_SYSTEMD] = NULL, #endif - [DLT_TIMER_GATEWAY] = NULL -}; + [DLT_TIMER_GATEWAY] = NULL}; void close_pipes(int fds[2]) { @@ -202,7 +194,7 @@ void close_pipes(int fds[2]) } } -#endif // __QNX__ +#endif // __QNX__ /** * Print usage information of tool. @@ -213,7 +205,8 @@ void usage() dlt_get_version(version, DLT_DAEMON_TEXTBUFSIZE); /*printf("DLT logging daemon %s %s\n", _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE); */ - /*printf("Compile options: %s %s %s %s",_DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, _DLT_SHM_ENABLE); */ + /*printf("Compile options: %s %s %s %s",_DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, + * _DLT_SHM_ENABLE); */ printf("%s", version); printf("Usage: dlt-daemon [options]\n"); printf("Options:\n"); @@ -240,7 +233,8 @@ void usage() printf(" port need to be started with the environment variable\n"); printf(" DLT_DAEMON_TCP_PORT set appropriately)\n"); #ifdef DLT_LOG_LEVEL_APP_CONFIG - printf(" -a filename The filename for load default app id log levels (Default: " CONFIGURATION_FILES_DIR "/dlt-log-levels.conf)\n"); + printf(" -a filename The filename for load default app id log levels (Default: " CONFIGURATION_FILES_DIR + "/dlt-log-levels.conf)\n"); #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE @@ -253,16 +247,16 @@ void usage() /** * Option handling */ -int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) +int option_handling(DltDaemonLocal* daemon_local, int argc, char* argv[]) { int c; char options[255]; memset(options, 0, sizeof options); - const char *const default_options = "hdc:t:p:x:"; + const char* const default_options = "hdc:t:p:x:"; strcpy(options, default_options); if (daemon_local == 0) { - fprintf (stderr, "Invalid parameter passed to option_handling()\n"); + fprintf(stderr, "Invalid parameter passed to option_handling()\n"); return -1; } @@ -293,101 +287,90 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) #endif while ((c = getopt(argc, argv, options)) != -1) switch (c) { - case 'x': - { - int proto = atoi(optarg); - if (proto == 1 || proto == 2) { - daemon_local->flags.protocolVersion = proto; - } else { - fprintf(stderr, "Invalid protocol version '%s'. Use 1 or 2.\n", optarg); - return -1; - } - break; - } - case 'd': - { + case 'x': { + int proto = atoi(optarg); + if (proto == 1 || proto == 2) { + daemon_local->flags.protocolVersion = proto; + } else { + fprintf(stderr, "Invalid protocol version '%s'. Use 1 or 2.\n", optarg); + return -1; + } + break; + } + case 'd': { daemon_local->flags.dflag = 1; break; } - case 'c': - { + case 'c': { strncpy(daemon_local->flags.cvalue, optarg, NAME_MAX); break; } #ifdef DLT_LOG_LEVEL_APP_CONFIG - case 'a': - { + case 'a': { strncpy(daemon_local->flags.avalue, optarg, NAME_MAX); break; } #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - case 'l': - { + case 'l': { strncpy(daemon_local->flags.lvalue, optarg, NAME_MAX); break; } #endif #ifdef DLT_DAEMON_USE_FIFO_IPC - case 't': - { + case 't': { dlt_log_set_fifo_basedir(optarg); break; } #endif #ifdef DLT_SHM_ENABLE - case 's': - { + case 's': { strncpy(dltShmName, optarg, NAME_MAX); break; } #endif - case 'p': - { - daemon_local->flags.port = (unsigned int) atoi(optarg); + case 'p': { + daemon_local->flags.port = (unsigned int)atoi(optarg); if (daemon_local->flags.port == 0) { - fprintf (stderr, "Invalid port `%s' specified.\n", optarg); + fprintf(stderr, "Invalid port `%s' specified.\n", optarg); return -1; } break; } - case 'h': - { + case 'h': { usage(); return -2; /* return no error */ } - case '?': - { + case '?': { if ((optopt == 'c') || (optopt == 't') || (optopt == 'p') - #ifdef DLT_LOG_LEVEL_APP_CONFIG - || (optopt == 'a') - #endif +#ifdef DLT_LOG_LEVEL_APP_CONFIG + || (optopt == 'a') +#endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE || (optopt == 'l') #endif - ) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + ) + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", (uint32_t)optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", (uint32_t)optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - fprintf (stderr, "Invalid option, this should never occur!\n"); + default: { + fprintf(stderr, "Invalid option, this should never occur!\n"); return -1; } } - /* switch() */ + /* switch() */ #ifdef DLT_DAEMON_USE_FIFO_IPC int ret; @@ -399,15 +382,13 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) return -1; } - ret = snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX, - "%s/dltpipes", dltFifoBaseDir); + ret = snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX, "%s/dltpipes", dltFifoBaseDir); if (ret < 0 || ret >= DLT_PATH_MAX) { dlt_log(LOG_ERR, "Failed to construct userPipesDir path!\n"); return -1; } - ret = snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX, - "%s/dlt", dltFifoBaseDir); + ret = snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir); if (ret < 0 || ret >= DLT_PATH_MAX) { dlt_log(LOG_ERR, "Failed to construct daemonFifoName path!\n"); return -1; @@ -420,19 +401,19 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[]) return 0; -} /* option_handling() */ +} /* option_handling() */ /** * Option file parser */ -int option_file_parser(DltDaemonLocal *daemon_local) +int option_file_parser(DltDaemonLocal* daemon_local) { - FILE *pFile; + FILE* pFile; char line[value_length - 1]; char token[value_length]; char value[value_length]; - char *pch; - const char *filename; + char* pch; + const char* filename; ssize_t n; /* set default values for configuration */ @@ -446,18 +427,18 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->flags.loggingLevel = LOG_INFO; #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC - n = snprintf(daemon_local->flags.loggingFilename, - sizeof(daemon_local->flags.loggingFilename), - "%s/dlt.log", DLT_USER_IPC_PATH); + n = snprintf( + daemon_local->flags.loggingFilename, sizeof(daemon_local->flags.loggingFilename), "%s/dlt.log", + DLT_USER_IPC_PATH); #else /* DLT_DAEMON_USE_FIFO_IPC */ - n = snprintf(daemon_local->flags.loggingFilename, - sizeof(daemon_local->flags.loggingFilename), - "%s/dlt.log", dltFifoBaseDir); + n = snprintf( + daemon_local->flags.loggingFilename, sizeof(daemon_local->flags.loggingFilename), "%s/dlt.log", dltFifoBaseDir); #endif if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) { - dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n", - __func__, (long int)n, daemon_local->flags.loggingFilename); + dlt_vlog( + LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n", __func__, (long int)n, + daemon_local->flags.loggingFilename); } daemon_local->flags.enableLoggingFileLimit = false; daemon_local->flags.loggingFileSize = 250000; @@ -480,25 +461,20 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->flags.offlineLogstorageMaxCounterIdx = 0; daemon_local->flags.offlineLogstorageOptionalCounter = false; daemon_local->flags.offlineLogstorageCacheSize = 30000; /* 30MB */ - dlt_daemon_logstorage_set_logstorage_cache_size( - daemon_local->flags.offlineLogstorageCacheSize); - strncpy(daemon_local->flags.ctrlSockPath, - DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH, - sizeof(daemon_local->flags.ctrlSockPath)); + dlt_daemon_logstorage_set_logstorage_cache_size(daemon_local->flags.offlineLogstorageCacheSize); + strncpy( + daemon_local->flags.ctrlSockPath, DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH, sizeof(daemon_local->flags.ctrlSockPath)); #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC snprintf(daemon_local->flags.appSockPath, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH); if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX) - fprintf(stderr, "Provided path too long...trimming it to path[%s]\n", - daemon_local->flags.appSockPath); + fprintf(stderr, "Provided path too long...trimming it to path[%s]\n", daemon_local->flags.appSockPath); #else /* DLT_DAEMON_USE_FIFO_IPC */ memset(daemon_local->flags.daemonFifoGroup, 0, sizeof(daemon_local->flags.daemonFifoGroup)); #endif daemon_local->flags.gatewayMode = 0; - strncpy(daemon_local->flags.gatewayConfigFile, - DLT_GATEWAY_CONFIG_PATH, - DLT_DAEMON_FLAG_MAX); + strncpy(daemon_local->flags.gatewayConfigFile, DLT_GATEWAY_CONFIG_PATH, DLT_DAEMON_FLAG_MAX); daemon_local->flags.autoResponseGetLogInfoOption = 7; daemon_local->flags.contextLogLevel = DLT_LOG_INFO; daemon_local->flags.contextTraceStatus = DLT_TRACE_STATUS_OFF; @@ -518,13 +494,13 @@ int option_file_parser(DltDaemonLocal *daemon_local) filename = CONFIGURATION_FILES_DIR "/dlt.conf"; /*printf("Load configuration from file: %s\n",filename); */ - pFile = fopen (filename, "r"); + pFile = fopen(filename, "r"); if (pFile != NULL) { while (1) { /* fetch line from configuration file */ - if (fgets (line, value_length - 1, pFile) != NULL) { - pch = strtok (line, " =\r\n"); + if (fgets(line, value_length - 1, pFile) != NULL) { + pch = strtok(line, " =\r\n"); token[0] = 0; value[0] = 0; @@ -535,14 +511,13 @@ int option_file_parser(DltDaemonLocal *daemon_local) if (token[0] == 0) { strncpy(token, pch, sizeof(token) - 1); token[sizeof(token) - 1] = 0; - } - else { + } else { strncpy(value, pch, sizeof(value) - 1); value[sizeof(value) - 1] = 0; break; } - pch = strtok (NULL, " =\r\n"); + pch = strtok(NULL, " =\r\n"); } if (token[0] && value[0]) { @@ -550,349 +525,226 @@ int option_file_parser(DltDaemonLocal *daemon_local) if (strcmp(token, "Verbose") == 0) { daemon_local->flags.vflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "PrintASCII") == 0) - { + } else if (strcmp(token, "PrintASCII") == 0) { daemon_local->flags.aflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "PrintHex") == 0) - { + } else if (strcmp(token, "PrintHex") == 0) { daemon_local->flags.xflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "PrintHeadersOnly") == 0) - { + } else if (strcmp(token, "PrintHeadersOnly") == 0) { daemon_local->flags.sflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "SendSerialHeader") == 0) - { + } else if (strcmp(token, "SendSerialHeader") == 0) { daemon_local->flags.lflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "SendContextRegistration") == 0) - { + } else if (strcmp(token, "SendContextRegistration") == 0) { daemon_local->flags.rflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "SendContextRegistrationOption") == 0) - { + } else if (strcmp(token, "SendContextRegistrationOption") == 0) { daemon_local->flags.autoResponseGetLogInfoOption = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "SendMessageTime") == 0) - { + } else if (strcmp(token, "SendMessageTime") == 0) { daemon_local->flags.sendMessageTime = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "RS232SyncSerialHeader") == 0) - { + } else if (strcmp(token, "RS232SyncSerialHeader") == 0) { daemon_local->flags.mflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "TCPSyncSerialHeader") == 0) - { + } else if (strcmp(token, "TCPSyncSerialHeader") == 0) { daemon_local->flags.nflag = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "RS232DeviceName") == 0) - { + } else if (strcmp(token, "RS232DeviceName") == 0) { strncpy(daemon_local->flags.yvalue, value, NAME_MAX); daemon_local->flags.yvalue[NAME_MAX] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "RS232Baudrate") == 0) - { + } else if (strcmp(token, "RS232Baudrate") == 0) { strncpy(daemon_local->flags.bvalue, value, NAME_MAX); daemon_local->flags.bvalue[NAME_MAX] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "ECUId") == 0) - { + } else if (strcmp(token, "ECUId") == 0) { strncpy(daemon_local->flags.evalue, value, NAME_MAX); daemon_local->flags.evalue[NAME_MAX] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "PersistanceStoragePath") == 0) - { + } else if (strcmp(token, "PersistanceStoragePath") == 0) { strncpy(daemon_local->flags.ivalue, value, NAME_MAX); daemon_local->flags.ivalue[NAME_MAX] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "LoggingMode") == 0) - { + } else if (strcmp(token, "LoggingMode") == 0) { daemon_local->flags.loggingMode = (DltLoggingMode)atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "LoggingLevel") == 0) - { + } else if (strcmp(token, "LoggingLevel") == 0) { daemon_local->flags.loggingLevel = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "LoggingFilename") == 0) - { - strncpy(daemon_local->flags.loggingFilename, - value, - sizeof(daemon_local->flags.loggingFilename) - 1); + } else if (strcmp(token, "LoggingFilename") == 0) { + strncpy( + daemon_local->flags.loggingFilename, value, + sizeof(daemon_local->flags.loggingFilename) - 1); daemon_local->flags.loggingFilename[sizeof(daemon_local->flags.loggingFilename) - 1] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "EnableLoggingFileLimit") == 0) - { + } else if (strcmp(token, "EnableLoggingFileLimit") == 0) { daemon_local->flags.enableLoggingFileLimit = (bool)atoi(value); - } - else if (strcmp(token, "LoggingFileSize") == 0) - { + } else if (strcmp(token, "LoggingFileSize") == 0) { daemon_local->flags.loggingFileSize = atoi(value); - } - else if (strcmp(token, "LoggingFileMaxSize") == 0) - { + } else if (strcmp(token, "LoggingFileMaxSize") == 0) { daemon_local->flags.loggingFileMaxSize = atoi(value); - } - else if (strcmp(token, "TimeOutOnSend") == 0) - { + } else if (strcmp(token, "TimeOutOnSend") == 0) { daemon_local->timeoutOnSend = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "RingbufferMinSize") == 0) - { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->RingbufferMinSize)) < 0) { - fclose (pFile); + } else if (strcmp(token, "RingbufferMinSize") == 0) { + if (dlt_daemon_check_numeric_setting(token, value, &(daemon_local->RingbufferMinSize)) < 0) { + fclose(pFile); return -1; } - } - else if (strcmp(token, "RingbufferMaxSize") == 0) - { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->RingbufferMaxSize)) < 0) { - fclose (pFile); + } else if (strcmp(token, "RingbufferMaxSize") == 0) { + if (dlt_daemon_check_numeric_setting(token, value, &(daemon_local->RingbufferMaxSize)) < 0) { + fclose(pFile); return -1; } - } - else if (strcmp(token, "RingbufferStepSize") == 0) - { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->RingbufferStepSize)) < 0) { - fclose (pFile); + } else if (strcmp(token, "RingbufferStepSize") == 0) { + if (dlt_daemon_check_numeric_setting(token, value, &(daemon_local->RingbufferStepSize)) < 0) { + fclose(pFile); return -1; } - } - else if (strcmp(token, "SharedMemorySize") == 0) - { + } else if (strcmp(token, "SharedMemorySize") == 0) { daemon_local->flags.sharedMemorySize = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "OfflineTraceDirectory") == 0) - { - strncpy(daemon_local->flags.offlineTraceDirectory, value, - sizeof(daemon_local->flags.offlineTraceDirectory) - 1); - daemon_local->flags.offlineTraceDirectory[sizeof(daemon_local->flags.offlineTraceDirectory) - - 1] = 0; + } else if (strcmp(token, "OfflineTraceDirectory") == 0) { + strncpy( + daemon_local->flags.offlineTraceDirectory, value, + sizeof(daemon_local->flags.offlineTraceDirectory) - 1); + daemon_local->flags + .offlineTraceDirectory[sizeof(daemon_local->flags.offlineTraceDirectory) - 1] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "OfflineTraceFileSize") == 0) - { + } else if (strcmp(token, "OfflineTraceFileSize") == 0) { daemon_local->flags.offlineTraceFileSize = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "OfflineTraceMaxSize") == 0) - { + } else if (strcmp(token, "OfflineTraceMaxSize") == 0) { daemon_local->flags.offlineTraceMaxSize = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "OfflineTraceFileNameTimestampBased") == 0) - { + } else if (strcmp(token, "OfflineTraceFileNameTimestampBased") == 0) { daemon_local->flags.offlineTraceFilenameTimestampBased = (bool)atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "SendECUSoftwareVersion") == 0) - { + } else if (strcmp(token, "SendECUSoftwareVersion") == 0) { daemon_local->flags.sendECUSoftwareVersion = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "PathToECUSoftwareVersion") == 0) - { - strncpy(daemon_local->flags.pathToECUSoftwareVersion, value, - sizeof(daemon_local->flags.pathToECUSoftwareVersion) - 1); - daemon_local->flags.pathToECUSoftwareVersion[sizeof(daemon_local->flags.pathToECUSoftwareVersion) - - 1] = 0; + } else if (strcmp(token, "PathToECUSoftwareVersion") == 0) { + strncpy( + daemon_local->flags.pathToECUSoftwareVersion, value, + sizeof(daemon_local->flags.pathToECUSoftwareVersion) - 1); + daemon_local->flags + .pathToECUSoftwareVersion[sizeof(daemon_local->flags.pathToECUSoftwareVersion) - 1] = 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "ECUSoftwareVersionFileField") == 0) { - strncpy(daemon_local->flags.ecuSoftwareVersionFileField, value, - sizeof(daemon_local->flags.ecuSoftwareVersionFileField) - 1); - daemon_local->flags.ecuSoftwareVersionFileField[sizeof(daemon_local->flags.ecuSoftwareVersionFileField) - - 1] = 0; + } else if (strcmp(token, "ECUSoftwareVersionFileField") == 0) { + strncpy( + daemon_local->flags.ecuSoftwareVersionFileField, value, + sizeof(daemon_local->flags.ecuSoftwareVersionFileField) - 1); + daemon_local->flags + .ecuSoftwareVersionFileField[sizeof(daemon_local->flags.ecuSoftwareVersionFileField) - 1] = + 0; /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "SendTimezone") == 0) - { + } else if (strcmp(token, "SendTimezone") == 0) { daemon_local->flags.sendTimezone = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "OfflineLogstorageMaxDevices") == 0) - { + } else if (strcmp(token, "OfflineLogstorageMaxDevices") == 0) { daemon_local->flags.offlineLogstorageMaxDevices = (int)strtoul(value, NULL, 10); - } - else if (strcmp(token, "OfflineLogstorageDirPath") == 0) - { - strncpy(daemon_local->flags.offlineLogstorageDirPath, - value, - sizeof(daemon_local->flags.offlineLogstorageDirPath) - 1); - } - else if (strcmp(token, "OfflineLogstorageTimestamp") == 0) - { + } else if (strcmp(token, "OfflineLogstorageDirPath") == 0) { + strncpy( + daemon_local->flags.offlineLogstorageDirPath, value, + sizeof(daemon_local->flags.offlineLogstorageDirPath) - 1); + } else if (strcmp(token, "OfflineLogstorageTimestamp") == 0) { /* Check if set to 0, default otherwise */ if (atoi(value) == 0) daemon_local->flags.offlineLogstorageTimestamp = 0; - } - else if (strcmp(token, "OfflineLogstorageDelimiter") == 0) - { + } else if (strcmp(token, "OfflineLogstorageDelimiter") == 0) { /* Check if valid punctuation, default otherwise*/ if (ispunct((char)value[0])) daemon_local->flags.offlineLogstorageDelimiter = (char)value[0]; - } - else if (strcmp(token, "OfflineLogstorageMaxCounter") == 0) - { - daemon_local->flags.offlineLogstorageMaxCounter = (unsigned int) atoi(value); - daemon_local->flags.offlineLogstorageMaxCounterIdx = (unsigned int) strlen(value); + } else if (strcmp(token, "OfflineLogstorageMaxCounter") == 0) { + daemon_local->flags.offlineLogstorageMaxCounter = (unsigned int)atoi(value); + daemon_local->flags.offlineLogstorageMaxCounterIdx = (unsigned int)strlen(value); } else if (strcmp(token, "OfflineLogstorageOptionalIndex") == 0) { daemon_local->flags.offlineLogstorageOptionalCounter = atoi(value); - } - else if (strcmp(token, "OfflineLogstorageCacheSize") == 0) - { - daemon_local->flags.offlineLogstorageCacheSize = - (unsigned int)atoi(value); - dlt_daemon_logstorage_set_logstorage_cache_size( - daemon_local->flags.offlineLogstorageCacheSize); - } - else if (strcmp(token, "ControlSocketPath") == 0) - { - memset( - daemon_local->flags.ctrlSockPath, - 0, - DLT_DAEMON_FLAG_MAX); - strncpy( - daemon_local->flags.ctrlSockPath, - value, - DLT_DAEMON_FLAG_MAX - 1); - } - else if (strcmp(token, "GatewayMode") == 0) - { + } else if (strcmp(token, "OfflineLogstorageCacheSize") == 0) { + daemon_local->flags.offlineLogstorageCacheSize = (unsigned int)atoi(value); + dlt_daemon_logstorage_set_logstorage_cache_size(daemon_local->flags.offlineLogstorageCacheSize); + } else if (strcmp(token, "ControlSocketPath") == 0) { + memset(daemon_local->flags.ctrlSockPath, 0, DLT_DAEMON_FLAG_MAX); + strncpy(daemon_local->flags.ctrlSockPath, value, DLT_DAEMON_FLAG_MAX - 1); + } else if (strcmp(token, "GatewayMode") == 0) { daemon_local->flags.gatewayMode = atoi(value); /*printf("Option: %s=%s\n",token,value); */ - } - else if (strcmp(token, "GatewayConfigFile") == 0) - { - memset( - daemon_local->flags.gatewayConfigFile, - 0, - DLT_DAEMON_FLAG_MAX); - strncpy( - daemon_local->flags.gatewayConfigFile, - value, - DLT_DAEMON_FLAG_MAX - 1); - } - else if (strcmp(token, "ContextLogLevel") == 0) - { + } else if (strcmp(token, "GatewayConfigFile") == 0) { + memset(daemon_local->flags.gatewayConfigFile, 0, DLT_DAEMON_FLAG_MAX); + strncpy(daemon_local->flags.gatewayConfigFile, value, DLT_DAEMON_FLAG_MAX - 1); + } else if (strcmp(token, "ContextLogLevel") == 0) { int const intval = atoi(value); if ((intval >= DLT_LOG_OFF) && (intval <= DLT_LOG_VERBOSE)) { daemon_local->flags.contextLogLevel = intval; printf("Option: %s=%s\n", token, value); + } else { + fprintf( + stderr, "Invalid value for ContextLogLevel: %i. Must be in range [%i..%i]\n", intval, + DLT_LOG_OFF, DLT_LOG_VERBOSE); } - else { - fprintf(stderr, - "Invalid value for ContextLogLevel: %i. Must be in range [%i..%i]\n", - intval, - DLT_LOG_OFF, - DLT_LOG_VERBOSE); - } - } - else if (strcmp(token, "ContextTraceStatus") == 0) - { + } else if (strcmp(token, "ContextTraceStatus") == 0) { int const intval = atoi(value); if ((intval >= DLT_TRACE_STATUS_OFF) && (intval <= DLT_TRACE_STATUS_ON)) { daemon_local->flags.contextTraceStatus = intval; printf("Option: %s=%s\n", token, value); + } else { + fprintf( + stderr, "Invalid value for ContextTraceStatus: %i. Must be in range [%i..%i]\n", intval, + DLT_TRACE_STATUS_OFF, DLT_TRACE_STATUS_ON); } - else { - fprintf(stderr, - "Invalid value for ContextTraceStatus: %i. Must be in range [%i..%i]\n", - intval, - DLT_TRACE_STATUS_OFF, - DLT_TRACE_STATUS_ON); - } - } - else if (strcmp(token, "ForceContextLogLevelAndTraceStatus") == 0) - { + } else if (strcmp(token, "ForceContextLogLevelAndTraceStatus") == 0) { int const intval = atoi(value); if ((intval >= 0) && (intval <= 1)) { daemon_local->flags.enforceContextLLAndTS = intval; printf("Option: %s=%s\n", token, value); - } - else { - fprintf(stderr, - "Invalid value for ForceContextLogLevelAndTraceStatus: %i. Must be 0, 1\n", - intval); + } else { + fprintf( + stderr, "Invalid value for ForceContextLogLevelAndTraceStatus: %i. Must be 0, 1\n", + intval); } } - #ifdef DLT_DAEMON_USE_FIFO_IPC - else if (strcmp(token, "DaemonFIFOSize") == 0) - { - if (dlt_daemon_check_numeric_setting(token, - value, &(daemon_local->daemonFifoSize)) < 0) { - fclose (pFile); + else if (strcmp(token, "DaemonFIFOSize") == 0) { + if (dlt_daemon_check_numeric_setting(token, value, &(daemon_local->daemonFifoSize)) < 0) { + fclose(pFile); return -1; } #ifndef __linux__ - printf("Option DaemonFIFOSize is set but only supported on Linux. Ignored.\n"); + printf("Option DaemonFIFOSize is set but only supported on Linux. Ignored.\n"); #endif - } - else if (strcmp(token, "DaemonFifoGroup") == 0) - { + } else if (strcmp(token, "DaemonFifoGroup") == 0) { strncpy(daemon_local->flags.daemonFifoGroup, value, NAME_MAX); daemon_local->flags.daemonFifoGroup[NAME_MAX] = 0; } #endif #ifdef UDP_CONNECTION_SUPPORT - else if (strcmp(token, "UDPConnectionSetup") == 0) - { + else if (strcmp(token, "UDPConnectionSetup") == 0) { const long longval = strtol(value, NULL, 10); - if ((longval == MULTICAST_CONNECTION_DISABLED) - || (longval == MULTICAST_CONNECTION_ENABLED)) { + if ((longval == MULTICAST_CONNECTION_DISABLED) || (longval == MULTICAST_CONNECTION_ENABLED)) { daemon_local->UDPConnectionSetup = (int)longval; printf("Option: %s=%s\n", token, value); - } - else { + } else { daemon_local->UDPConnectionSetup = MULTICAST_CONNECTION_DISABLED; - fprintf(stderr, - "Invalid value for UDPConnectionSetup set to default %ld\n", - longval); + fprintf(stderr, "Invalid value for UDPConnectionSetup set to default %ld\n", longval); } - } - else if (strcmp(token, "UDPMulticastIPAddress") == 0) - { - strncpy(daemon_local->UDPMulticastIPAddress, value, - MULTICASTIP_MAX_SIZE - 1); - } - else if (strcmp(token, "UDPMulticastIPPort") == 0) - { + } else if (strcmp(token, "UDPMulticastIPAddress") == 0) { + strncpy(daemon_local->UDPMulticastIPAddress, value, MULTICASTIP_MAX_SIZE - 1); + } else if (strcmp(token, "UDPMulticastIPPort") == 0) { daemon_local->UDPMulticastIPPort = (int)strtol(value, NULL, 10); } #endif - else if (strcmp(token, "BindAddress") == 0) - { - DltBindAddress_t *newNode = NULL; - DltBindAddress_t *temp = NULL; + else if (strcmp(token, "BindAddress") == 0) { + DltBindAddress_t* newNode = NULL; + DltBindAddress_t* temp = NULL; - char *tok = strtok(value, ",;"); + char* tok = strtok(value, ",;"); if (tok != NULL) { daemon_local->flags.ipNodes = calloc(1, sizeof(DltBindAddress_t)); @@ -901,11 +753,9 @@ int option_file_parser(DltDaemonLocal *daemon_local) dlt_vlog(LOG_ERR, "Could not allocate for IP list\n"); fclose(pFile); return -1; - } - else { - strncpy(daemon_local->flags.ipNodes->ip, - tok, - sizeof(daemon_local->flags.ipNodes->ip) - 1); + } else { + strncpy( + daemon_local->flags.ipNodes->ip, tok, sizeof(daemon_local->flags.ipNodes->ip) - 1); daemon_local->flags.ipNodes->next = NULL; temp = daemon_local->flags.ipNodes; @@ -918,8 +768,7 @@ int option_file_parser(DltDaemonLocal *daemon_local) dlt_vlog(LOG_ERR, "Could not allocate for IP list\n"); fclose(pFile); return -1; - } - else { + } else { strncpy(newNode->ip, tok, sizeof(newNode->ip) - 1); } @@ -928,27 +777,22 @@ int option_file_parser(DltDaemonLocal *daemon_local) tok = strtok(NULL, ",;"); } } - } - else { + } else { dlt_vlog(LOG_WARNING, "BindAddress option is empty\n"); } - } - else if (strcmp(token, "InjectionMode") == 0) { + } else if (strcmp(token, "InjectionMode") == 0) { daemon_local->flags.injectionMode = atoi(value); - } - else { + } else { fprintf(stderr, "Unknown option: %s=%s\n", token, value); } } - } - else { + } else { break; } } - fclose (pFile); - } - else { + fclose(pFile); + } else { fprintf(stderr, "Cannot open configuration file: %s\n", filename); } @@ -960,27 +804,25 @@ int option_file_parser(DltDaemonLocal *daemon_local) * Load configuration file parser */ -static int compare_app_id_conf(const void *lhs, const void *rhs) +static int compare_app_id_conf(const void* lhs, const void* rhs) { - return strncmp(((DltDaemonContextLogSettings *)lhs)->apid, - ((DltDaemonContextLogSettings *)rhs)->apid, DLT_ID_SIZE); + return strncmp(((DltDaemonContextLogSettings*)lhs)->apid, ((DltDaemonContextLogSettings*)rhs)->apid, DLT_ID_SIZE); } -int app_id_default_log_level_config_parser(DltDaemon *daemon, - DltDaemonLocal *daemon_local) { - FILE *pFile; +int app_id_default_log_level_config_parser(DltDaemon* daemon, DltDaemonLocal* daemon_local) +{ + FILE* pFile; char line[value_length - 1]; char app_id_value[value_length]; char ctx_id_value[value_length]; DltLogLevelType log_level_value; - char *pch; - const char *filename; + char* pch; + const char* filename; /* open configuration file */ - filename = daemon_local->flags.avalue[0] - ? daemon_local->flags.avalue - : CONFIGURATION_FILES_DIR "/dlt-log-levels.conf"; + filename = + daemon_local->flags.avalue[0] ? daemon_local->flags.avalue : CONFIGURATION_FILES_DIR "/dlt-log-levels.conf"; pFile = fopen(filename, "r"); if (pFile == NULL) { @@ -996,28 +838,24 @@ int app_id_default_log_level_config_parser(DltDaemon *daemon, log_level_value = DLT_LOG_MAX; /* ignore comments and new lines*/ - if (strncmp(pch, "#", 1) == 0 || strncmp(pch, "\n", 1) == 0 - || strlen(pch) < 1) + if (strncmp(pch, "#", 1) == 0 || strncmp(pch, "\n", 1) == 0 || strlen(pch) < 1) continue; strncpy(app_id_value, pch, sizeof(app_id_value) - 1); app_id_value[sizeof(app_id_value) - 1] = 0; if (strlen(app_id_value) == 0 || strlen(app_id_value) > DLT_ID_SIZE) { if (app_id_value[strlen(app_id_value) - 1] == '\n') { - dlt_vlog(LOG_WARNING, "Missing log level for apid %s in log settings\n", - app_id_value); + dlt_vlog(LOG_WARNING, "Missing log level for apid %s in log settings\n", app_id_value); } else { - dlt_vlog(LOG_WARNING, - "Invalid apid for log settings settings: app id: %s\n", - app_id_value); + dlt_vlog(LOG_WARNING, "Invalid apid for log settings settings: app id: %s\n", app_id_value); } continue; } - char *pch_next1 = strtok(NULL, " \t"); - char *pch_next2 = strtok(NULL, " \t"); - char *log_level; + char* pch_next1 = strtok(NULL, " \t"); + char* pch_next2 = strtok(NULL, " \t"); + char* log_level; /* no context id given, log level is next token */ if (pch_next2 == NULL || pch_next2[0] == '#') { log_level = pch_next1; @@ -1028,10 +866,11 @@ int app_id_default_log_level_config_parser(DltDaemon *daemon, /* next token is token id */ strncpy(ctx_id_value, pch_next1, sizeof(ctx_id_value) - 1); if (strlen(ctx_id_value) == 0 || strlen(app_id_value) > DLT_ID_SIZE) { - dlt_vlog(LOG_WARNING, - "Invalid ctxid for log settings: app id: %s " - "(skipping line)\n", - app_id_value); + dlt_vlog( + LOG_WARNING, + "Invalid ctxid for log settings: app id: %s " + "(skipping line)\n", + app_id_value); continue; } @@ -1040,39 +879,34 @@ int app_id_default_log_level_config_parser(DltDaemon *daemon, errno = 0; log_level_value = strtol(log_level, NULL, 10); - if (errno != 0 || log_level_value >= DLT_LOG_MAX || - log_level_value <= DLT_LOG_DEFAULT) { - dlt_vlog(LOG_WARNING, - "Invalid log level (%i), app id %s, conversion error: %s\n", - log_level_value, app_id_value, strerror(errno)); + if (errno != 0 || log_level_value >= DLT_LOG_MAX || log_level_value <= DLT_LOG_DEFAULT) { + dlt_vlog( + LOG_WARNING, "Invalid log level (%i), app id %s, conversion error: %s\n", log_level_value, app_id_value, + strerror(errno)); continue; } - DltDaemonContextLogSettings *settings = - dlt_daemon_find_configured_app_id_ctx_id_settings( - daemon, app_id_value, NULL); + DltDaemonContextLogSettings* settings = + dlt_daemon_find_configured_app_id_ctx_id_settings(daemon, app_id_value, NULL); - if (settings != NULL && - strncmp(settings->ctid, ctx_id_value, DLT_ID_SIZE) == 0) { + if (settings != NULL && strncmp(settings->ctid, ctx_id_value, DLT_ID_SIZE) == 0) { if (strlen(ctx_id_value) > 0) { - dlt_vlog(LOG_WARNING, - "Appid %s with ctxid %s is already configured, skipping " - "duplicated entry\n", - app_id_value, ctx_id_value); + dlt_vlog( + LOG_WARNING, + "Appid %s with ctxid %s is already configured, skipping " + "duplicated entry\n", + app_id_value, ctx_id_value); } else { - dlt_vlog(LOG_WARNING, - "Appid %s is already configured, skipping duplicated entry\n", - app_id_value); + dlt_vlog(LOG_WARNING, "Appid %s is already configured, skipping duplicated entry\n", app_id_value); } continue; } /* allocate one more element in the trace load settings */ - DltDaemonContextLogSettings *tmp = - realloc(daemon->app_id_log_level_settings, - (++daemon->num_app_id_log_level_settings) * - sizeof(DltDaemonContextLogSettings)); + DltDaemonContextLogSettings* tmp = realloc( + daemon->app_id_log_level_settings, + (++daemon->num_app_id_log_level_settings) * sizeof(DltDaemonContextLogSettings)); if (tmp == NULL) { dlt_log(LOG_CRIT, "Failed to allocate memory for app load settings\n"); @@ -1082,8 +916,7 @@ int app_id_default_log_level_config_parser(DltDaemon *daemon, daemon->app_id_log_level_settings = tmp; /* update newly created entry */ - settings = &daemon->app_id_log_level_settings - [daemon->num_app_id_log_level_settings -1]; + settings = &daemon->app_id_log_level_settings[daemon->num_app_id_log_level_settings - 1]; memset(settings, 0, sizeof(DltDaemonContextLogSettings)); memcpy(settings->apid, app_id_value, DLT_ID_SIZE); @@ -1099,28 +932,27 @@ int app_id_default_log_level_config_parser(DltDaemon *daemon, /* log with or without context id */ if (strlen(ctid_buf) > 0) { dlt_vlog( - LOG_INFO, - "Configured trace limits for app id %s, context id %s, level %u\n", - apid_buf, ctid_buf, log_level_value); + LOG_INFO, "Configured trace limits for app id %s, context id %s, level %u\n", apid_buf, ctid_buf, + log_level_value); } else { - dlt_vlog(LOG_INFO, "Configured trace limits for app id %s, level %u\n", - apid_buf, log_level_value); + dlt_vlog(LOG_INFO, "Configured trace limits for app id %s, level %u\n", apid_buf, log_level_value); } } /* while */ fclose(pFile); /* list must be sorted to speed up dlt_daemon_find_configured_app_id_ctx_id_settings */ - qsort(daemon->app_id_log_level_settings, - daemon->num_app_id_log_level_settings, - sizeof(DltDaemonContextLogSettings), compare_app_id_conf); + qsort( + daemon->app_id_log_level_settings, daemon->num_app_id_log_level_settings, sizeof(DltDaemonContextLogSettings), + compare_app_id_conf); return 0; } #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE -static bool is_ascii_only(const char *str) { +static bool is_ascii_only(const char* str) +{ while (*str) { if ((unsigned char)*str > 127) { return false; @@ -1133,9 +965,9 @@ static bool is_ascii_only(const char *str) { /** * Load configuration file parser */ -int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_local) +int trace_load_config_file_parser(DltDaemon* daemon, DltDaemonLocal* daemon_local) { - FILE *pFile; + FILE* pFile; const int max_tokens = 4; const int min_tokens = 3; char tokens[max_tokens][value_length]; @@ -1148,8 +980,8 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca uint32_t soft_limit; uint32_t hard_limit; - char *pch; - const char *filename; + char* pch; + const char* filename; bool skipped; @@ -1165,14 +997,12 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca } /* open configuration file */ - filename = daemon_local->flags.lvalue[0] - ? daemon_local->flags.lvalue - : CONFIGURATION_FILES_DIR "/dlt-trace-load.conf"; + filename = + daemon_local->flags.lvalue[0] ? daemon_local->flags.lvalue : CONFIGURATION_FILES_DIR "/dlt-trace-load.conf"; - pFile = fopen (filename, "r"); + pFile = fopen(filename, "r"); if (pFile == NULL) { - dlt_vlog(LOG_WARNING, "Cannot open trace load configuration file: %s\n", - filename); + dlt_vlog(LOG_WARNING, "Cannot open trace load configuration file: %s\n", filename); return -errno; } @@ -1195,8 +1025,8 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca skipped = false; while (pch != NULL && i < max_tokens) { /* ignore comments, empty lines and new lines */ - if (strncmp(pch, "#", 1) == 0 || strncmp(pch, "\n", 1) == 0 || - strncmp(pch, "\r", 1) == 0 || strncmp(pch, " ", 1) == 0) { + if (strncmp(pch, "#", 1) == 0 || strncmp(pch, "\n", 1) == 0 || strncmp(pch, "\r", 1) == 0 + || strncmp(pch, " ", 1) == 0) { skipped = true; break; } @@ -1208,13 +1038,8 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca if (skipped && i < min_tokens) continue; - if (pch != NULL - && (pch[0] != '\n') - && (pch[0] != '\t') - && (pch[0] != ' ') - && (pch[0] != '#')) { - dlt_vlog(LOG_WARNING, - "Invalid trace load settings: too many tokens in line '%s'\n", line); + if (pch != NULL && (pch[0] != '\n') && (pch[0] != '\t') && (pch[0] != ' ') && (pch[0] != '#')) { + dlt_vlog(LOG_WARNING, "Invalid trace load settings: too many tokens in line '%s'\n", line); continue; } @@ -1223,87 +1048,75 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca int hard_limit_idx = has_ctx_id ? 3 : 2; strncpy(app_id_value, tokens[0], sizeof(app_id_value) - 1); - if ((strlen(app_id_value) == 0) - || (strlen(app_id_value) > DLT_ID_SIZE) - || (!is_ascii_only(app_id_value))) { - dlt_vlog(LOG_WARNING, - "Invalid apid for trace load settings: app id: '%s'\n", app_id_value); + if ((strlen(app_id_value) == 0) || (strlen(app_id_value) > DLT_ID_SIZE) || (!is_ascii_only(app_id_value))) { + dlt_vlog(LOG_WARNING, "Invalid apid for trace load settings: app id: '%s'\n", app_id_value); continue; } if (has_ctx_id) { strncpy(ctx_id_value, tokens[1], sizeof(ctx_id_value) - 1); - if ((strlen(ctx_id_value) == 0) - || (strlen(ctx_id_value) > DLT_ID_SIZE) - || (!is_ascii_only(ctx_id_value))) { - dlt_vlog(LOG_WARNING, - "Invalid ctid for trace load settings: context id: '%s'\n", ctx_id_value); + if ((strlen(ctx_id_value) == 0) || (strlen(ctx_id_value) > DLT_ID_SIZE) || (!is_ascii_only(ctx_id_value))) { + dlt_vlog(LOG_WARNING, "Invalid ctid for trace load settings: context id: '%s'\n", ctx_id_value); continue; } } if (strlen(tokens[soft_limit_idx]) == 0) { - dlt_vlog(LOG_WARNING, - "Invalid soft_limit for trace load settings: app id: '%.4s', '%s'\n", - app_id_value, tokens[soft_limit_idx]); + dlt_vlog( + LOG_WARNING, "Invalid soft_limit for trace load settings: app id: '%.4s', '%s'\n", app_id_value, + tokens[soft_limit_idx]); continue; } if (strlen(tokens[hard_limit_idx]) == 0) { - dlt_vlog(LOG_WARNING, - "Invalid hard_limit for trace load settings: app id: '%.4s', '%s'\n", - app_id_value, tokens[hard_limit_idx]); + dlt_vlog( + LOG_WARNING, "Invalid hard_limit for trace load settings: app id: '%.4s', '%s'\n", app_id_value, + tokens[hard_limit_idx]); continue; } - strncpy(soft_limit_value, tokens[soft_limit_idx], - sizeof(soft_limit_value) - 1); - strncpy(hard_limit_value, tokens[hard_limit_idx], - sizeof(hard_limit_value) - 1); + strncpy(soft_limit_value, tokens[soft_limit_idx], sizeof(soft_limit_value) - 1); + strncpy(hard_limit_value, tokens[hard_limit_idx], sizeof(hard_limit_value) - 1); errno = 0; - char *endptr; + char* endptr; endptr = NULL; soft_limit = strtoul(soft_limit_value, &endptr, 10); - if ((errno != 0) - || ((soft_limit == 0) && (soft_limit_value[0] != '0')) - || (soft_limit_value[0] == '-') + if ((errno != 0) || ((soft_limit == 0) && (soft_limit_value[0] != '0')) || (soft_limit_value[0] == '-') || ((*endptr != '\n') && (*endptr != '\0'))) { - dlt_vlog(LOG_WARNING, - "Invalid soft_limit for trace load settings: app id: '%.4s', soft_limit '%s'\n", - app_id_value, soft_limit_value); + dlt_vlog( + LOG_WARNING, "Invalid soft_limit for trace load settings: app id: '%.4s', soft_limit '%s'\n", + app_id_value, soft_limit_value); continue; } errno = 0; endptr = NULL; hard_limit = strtoul(hard_limit_value, &endptr, 10); - if ((errno != 0) - || ((hard_limit == 0) && (hard_limit_value[0] != '0')) - || (hard_limit_value[0] == '-') + if ((errno != 0) || ((hard_limit == 0) && (hard_limit_value[0] != '0')) || (hard_limit_value[0] == '-') || ((*endptr != '\n') && (*endptr != '\0'))) { - dlt_vlog(LOG_WARNING, - "Invalid hard_limit for trace load settings: app id: '%.4s', hard_limit '%s'\n", - app_id_value, hard_limit_value); + dlt_vlog( + LOG_WARNING, "Invalid hard_limit for trace load settings: app id: '%.4s', hard_limit '%s'\n", + app_id_value, hard_limit_value); continue; } if (soft_limit > hard_limit) { - dlt_vlog(LOG_WARNING, - "Invalid trace load settings: app id: '%.4s', soft limit %u is greater than hard limit %u\n", - app_id_value, soft_limit, hard_limit); + dlt_vlog( + LOG_WARNING, + "Invalid trace load settings: app id: '%.4s', soft limit %u is greater than hard limit %u\n", + app_id_value, soft_limit, hard_limit); continue; } - DltTraceLoadSettings *settings = NULL; + DltTraceLoadSettings* settings = NULL; int num_settings = 0; DltReturnValue find_trace_settings_return_value = dlt_daemon_find_preconfigured_trace_load_settings( - daemon, app_id_value, ctx_id_value, &settings, &num_settings, - 0); + daemon, app_id_value, ctx_id_value, &settings, &num_settings, 0); if (find_trace_settings_return_value != DLT_RETURN_OK || num_settings != 0) { - dlt_vlog(LOG_WARNING, - "App id '%.4s' is already configured, or an error occurred, skipping entry\n", - app_id_value); + dlt_vlog( + LOG_WARNING, "App id '%.4s' is already configured, or an error occurred, skipping entry\n", + app_id_value); if (settings != NULL) { free(settings); } @@ -1311,20 +1124,17 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca } /* allocate one more element in the trace load settings */ - DltTraceLoadSettings *tmp = - realloc(daemon->preconfigured_trace_load_settings, - (++daemon->preconfigured_trace_load_settings_count) * - sizeof(DltTraceLoadSettings)); + DltTraceLoadSettings* tmp = realloc( + daemon->preconfigured_trace_load_settings, + (++daemon->preconfigured_trace_load_settings_count) * sizeof(DltTraceLoadSettings)); if (tmp == NULL) { - dlt_log(LOG_CRIT, - "Failed to allocate memory for trace load settings\n"); + dlt_log(LOG_CRIT, "Failed to allocate memory for trace load settings\n"); return DLT_RETURN_ERROR; } daemon->preconfigured_trace_load_settings = tmp; - settings = &daemon->preconfigured_trace_load_settings - [daemon->preconfigured_trace_load_settings_count - 1]; + settings = &daemon->preconfigured_trace_load_settings[daemon->preconfigured_trace_load_settings_count - 1]; memset(settings, 0, sizeof(DltTraceLoadSettings)); settings->soft_limit = soft_limit; settings->hard_limit = hard_limit; @@ -1332,13 +1142,13 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca memcpy(settings->apid, app_id_value, DLT_ID_SIZE); if (has_ctx_id) { memcpy(settings->ctid, ctx_id_value, DLT_ID_SIZE); - dlt_vlog(LOG_INFO, - "Configured trace limits for app id '%.4s', ctx id '%.4s', soft limit: %u, hard_limit: %u\n", - app_id_value, ctx_id_value, soft_limit, hard_limit); + dlt_vlog( + LOG_INFO, "Configured trace limits for app id '%.4s', ctx id '%.4s', soft limit: %u, hard_limit: %u\n", + app_id_value, ctx_id_value, soft_limit, hard_limit); } else { - dlt_vlog(LOG_INFO, - "Configured trace limits for app id '%.4s', soft limit: %u, hard_limit: %u\n", - app_id_value, soft_limit, hard_limit); + dlt_vlog( + LOG_INFO, "Configured trace limits for app id '%.4s', soft limit: %u, hard_limit: %u\n", app_id_value, + soft_limit, hard_limit); } @@ -1347,19 +1157,19 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca fclose(pFile); // sort limits to improve search performance - qsort(daemon->preconfigured_trace_load_settings, daemon->preconfigured_trace_load_settings_count, - sizeof(DltTraceLoadSettings), - dlt_daemon_compare_trace_load_settings); + qsort( + daemon->preconfigured_trace_load_settings, daemon->preconfigured_trace_load_settings_count, + sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); return 0; } #endif -static int dlt_mkdir_recursive(const char *dir) +static int dlt_mkdir_recursive(const char* dir) { int ret = 0; char tmp[PATH_MAX + 1]; - char *p = NULL; - char *end = NULL; + char* p = NULL; + char* end = NULL; size_t len; strncpy(tmp, dir, PATH_MAX); @@ -1375,12 +1185,13 @@ static int dlt_mkdir_recursive(const char *dir) *p = 0; if (access(tmp, F_OK) != 0 && errno == ENOENT) { - ret = mkdir(tmp, - #ifdef DLT_DAEMON_USE_FIFO_IPC - S_IRWXU); - #else - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); - #endif + ret = mkdir( + tmp, +#ifdef DLT_DAEMON_USE_FIFO_IPC + S_IRWXU); +#else + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); +#endif } *p = '/'; @@ -1389,12 +1200,13 @@ static int dlt_mkdir_recursive(const char *dir) if ((ret == 0) || ((ret == -1) && (errno == EEXIST))) - ret = mkdir(tmp, - #ifdef DLT_DAEMON_USE_FIFO_IPC - S_IRWXU); - #else - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); - #endif + ret = mkdir( + tmp, +#ifdef DLT_DAEMON_USE_FIFO_IPC + S_IRWXU); +#else + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH /*S_IRWXU*/); +#endif if ((ret == -1) && (errno == EEXIST)) ret = 0; @@ -1403,7 +1215,7 @@ static int dlt_mkdir_recursive(const char *dir) } #ifdef DLT_DAEMON_USE_FIFO_IPC -static DltReturnValue dlt_daemon_create_pipes_dir(char *dir) +static DltReturnValue dlt_daemon_create_pipes_dir(char* dir) { int ret = DLT_RETURN_OK; @@ -1413,28 +1225,21 @@ static DltReturnValue dlt_daemon_create_pipes_dir(char *dir) } /* create dlt pipes directory */ - ret = mkdir(dir, - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX); + ret = mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX); if ((ret == -1) && (errno != EEXIST)) { - dlt_vlog(LOG_ERR, - "FIFO user dir %s cannot be created (%s)!\n", - dir, - strerror(errno)); + dlt_vlog(LOG_ERR, "FIFO user dir %s cannot be created (%s)!\n", dir, strerror(errno)); return DLT_RETURN_ERROR; } /* S_ISGID cannot be set by mkdir, let's reassign right bits */ - ret = chmod(dir, - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | - S_ISVTX); + ret = chmod( + dir, + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | S_ISVTX); if (ret == -1) { - dlt_vlog(LOG_ERR, - "FIFO user dir %s cannot be chmoded (%s)!\n", - dir, - strerror(errno)); + dlt_vlog(LOG_ERR, "FIFO user dir %s cannot be chmoded (%s)!\n", dir, strerror(errno)); return DLT_RETURN_ERROR; } @@ -1448,7 +1253,7 @@ static DltReturnValue dlt_daemon_create_pipes_dir(char *dir) /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { char version[DLT_DAEMON_TEXTBUFSIZE]; char local_str[DLT_DAEMON_TEXTBUFSIZE]; @@ -1462,7 +1267,7 @@ int main(int argc, char *argv[]) /* Command line option handling */ if ((back = option_handling(&daemon_local, argc, argv)) < 0) { if (back != -2) - fprintf (stderr, "option_handling() failed!\n"); + fprintf(stderr, "option_handling() failed!\n"); return -1; } @@ -1477,7 +1282,7 @@ int main(int argc, char *argv[]) /* Configuration file option handling */ if ((back = option_file_parser(&daemon_local)) < 0) { if (back != -2) - fprintf (stderr, "option_file_parser() failed!\n"); + fprintf(stderr, "option_file_parser() failed!\n"); return -1; } @@ -1485,26 +1290,26 @@ int main(int argc, char *argv[]) /* Initialize internal logging facility */ dlt_log_set_filename(daemon_local.flags.loggingFilename); dlt_log_set_level(daemon_local.flags.loggingLevel); - DltReturnValue log_init_result = - dlt_log_init_multiple_logfiles_support(daemon_local.flags.loggingMode, - daemon_local.flags.enableLoggingFileLimit, - daemon_local.flags.loggingFileSize, - daemon_local.flags.loggingFileMaxSize); + DltReturnValue log_init_result = dlt_log_init_multiple_logfiles_support( + daemon_local.flags.loggingMode, daemon_local.flags.enableLoggingFileLimit, daemon_local.flags.loggingFileSize, + daemon_local.flags.loggingFileMaxSize); if (log_init_result != DLT_RETURN_OK) { - fprintf(stderr, "Failed to init internal logging\n"); + fprintf(stderr, "Failed to init internal logging\n"); #ifdef WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK if (daemon_local.flags.loggingMode == DLT_LOG_TO_FILE) { - fprintf(stderr, "Falling back to syslog mode\n"); - - daemon_local.flags.loggingMode = DLT_LOG_TO_SYSLOG; - log_init_result = dlt_log_init(daemon_local.flags.loggingMode); - if (log_init_result != DLT_RETURN_OK) { - fprintf(stderr, "Failed to setup syslog logging, internal logs will " - "not be available\n"); - } - } + fprintf(stderr, "Falling back to syslog mode\n"); + + daemon_local.flags.loggingMode = DLT_LOG_TO_SYSLOG; + log_init_result = dlt_log_init(daemon_local.flags.loggingMode); + if (log_init_result != DLT_RETURN_OK) { + fprintf( + stderr, + "Failed to setup syslog logging, internal logs will " + "not be available\n"); + } + } #endif } @@ -1521,7 +1326,7 @@ int main(int argc, char *argv[]) PRINT_FUNCTION_VERBOSE(daemon_local.flags.vflag); /* Make sure the parent user directory is created */ - const char *dir_to_create; + const char* dir_to_create; #ifdef DLT_DAEMON_USE_FIFO_IPC dir_to_create = dltFifoBaseDir; #else @@ -1575,8 +1380,10 @@ int main(int argc, char *argv[]) /* Load control app id level configuration file without setting `back` to * prevent exit if file is missing */ if (app_id_default_log_level_config_parser(&daemon, &daemon_local) < 0) { - dlt_vlog(LOG_WARNING, "app_id_default_log_level_config_parser() failed, " - "no app specific log levels will be configured\n"); + dlt_vlog( + LOG_WARNING, + "app_id_default_log_level_config_parser() failed, " + "no app specific log levels will be configured\n"); } #endif @@ -1592,17 +1399,14 @@ int main(int argc, char *argv[]) if (daemon_local.flags.offlineLogstorageDirPath[0]) if (dlt_daemon_logstorage_setup_internal_storage( - &daemon, - &daemon_local, - daemon_local.flags.offlineLogstorageDirPath, - daemon_local.flags.vflag) == -1) - dlt_log(LOG_INFO, - "Setting up internal offline log storage failed!\n"); - - /* create fd for watchdog */ + &daemon, &daemon_local, daemon_local.flags.offlineLogstorageDirPath, daemon_local.flags.vflag) + == -1) + dlt_log(LOG_INFO, "Setting up internal offline log storage failed!\n"); + + /* create fd for watchdog */ #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE { - char *watchdogUSec = getenv("WATCHDOG_USEC"); + char* watchdogUSec = getenv("WATCHDOG_USEC"); // set a sensible default, in case the environment variable is not set unsigned int watchdogTimeoutSeconds = 30; @@ -1622,10 +1426,7 @@ int main(int argc, char *argv[]) daemon.watchdog_trigger_interval = watchdogTimeoutSeconds; daemon.watchdog_last_trigger_time = 0U; - create_timer_fd(&daemon_local, - watchdogTimeoutSeconds, - watchdogTimeoutSeconds, - DLT_TIMER_SYSTEMD); + create_timer_fd(&daemon_local, watchdogTimeoutSeconds, watchdogTimeoutSeconds, DLT_TIMER_SYSTEMD); } #endif @@ -1633,8 +1434,7 @@ int main(int argc, char *argv[]) create_timer_fd(&daemon_local, 1, 1, DLT_TIMER_PACKET); /* create fd for timer ecu version */ - if ((daemon_local.flags.sendECUSoftwareVersion > 0) || - (daemon_local.flags.sendTimezone > 0)) + if ((daemon_local.flags.sendECUSoftwareVersion > 0) || (daemon_local.flags.sendTimezone > 0)) create_timer_fd(&daemon_local, 60, 60, DLT_TIMER_ECU); /* initiate gateway */ @@ -1645,10 +1445,8 @@ int main(int argc, char *argv[]) } /* create gateway timer */ - create_timer_fd(&daemon_local, - daemon_local.pGateway.interval, - daemon_local.pGateway.interval, - DLT_TIMER_GATEWAY); + create_timer_fd( + &daemon_local, daemon_local.pGateway.interval, daemon_local.pGateway.interval, DLT_TIMER_GATEWAY); } /* For offline tracing we still can use the same states */ @@ -1659,37 +1457,29 @@ int main(int argc, char *argv[]) else dlt_daemon_change_state(&daemon, DLT_DAEMON_STATE_BUFFER); - dlt_daemon_init_user_information(&daemon, - &daemon_local.pGateway, - daemon_local.flags.gatewayMode, - daemon_local.flags.vflag); + dlt_daemon_init_user_information( + &daemon, &daemon_local.pGateway, daemon_local.flags.gatewayMode, daemon_local.flags.vflag); /* * Check for app and ctx runtime cfg. * These cfg must be loaded after ecuId and num_user_lists are available */ - if ((dlt_daemon_applications_load(&daemon, daemon.runtime_application_cfg, - daemon_local.flags.vflag) == 0) && - (dlt_daemon_contexts_load(&daemon, daemon.runtime_context_cfg, - daemon_local.flags.vflag) == 0)) + if ((dlt_daemon_applications_load(&daemon, daemon.runtime_application_cfg, daemon_local.flags.vflag) == 0) + && (dlt_daemon_contexts_load(&daemon, daemon.runtime_context_cfg, daemon_local.flags.vflag) == 0)) daemon.runtime_context_cfg_loaded = 1; - dlt_daemon_log_internal(&daemon, &daemon_local, - "Daemon launched. Starting to output traces...", - DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local.flags.vflag); + dlt_daemon_log_internal( + &daemon, &daemon_local, "Daemon launched. Starting to output traces...", DLT_LOG_INFO, DLT_DAEMON_APP_ID, + DLT_DAEMON_CTX_ID, daemon_local.flags.vflag); /* Even handling loop. */ while ((back >= 0) && (g_exit >= 0)) - back = dlt_daemon_handle_event(&daemon_local.pEvent, - &daemon, - &daemon_local); - - snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, "Exiting DLT daemon... [%d]", - g_signo); - dlt_daemon_log_internal(&daemon, &daemon_local, local_str, DLT_LOG_INFO, - DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local.flags.vflag); + back = dlt_daemon_handle_event(&daemon_local.pEvent, &daemon, &daemon_local); + + snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, "Exiting DLT daemon... [%d]", g_signo); + dlt_daemon_log_internal( + &daemon, &daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, + daemon_local.flags.vflag); dlt_vlog(LOG_NOTICE, "%s%s", local_str, "\n"); dlt_daemon_local_cleanup(&daemon, &daemon_local, daemon_local.flags.vflag); @@ -1726,7 +1516,7 @@ void dlt_trace_load_free(DltDaemon* daemon) #endif -int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_local_init_p1(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int ret = DLT_RETURN_OK; @@ -1741,13 +1531,10 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in if (ret == 0) { dlt_log(LOG_CRIT, "System not booted with systemd!\n"); - } - else if (ret < 0) - { + } else if (ret < 0) { dlt_log(LOG_CRIT, "sd_booted failed!\n"); return -1; - } - else { + } else { dlt_log(LOG_INFO, "System booted with systemd\n"); } @@ -1787,7 +1574,7 @@ int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, in return DLT_RETURN_OK; } -int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_local_init_p2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -1797,26 +1584,24 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in } /* Daemon data */ - if (dlt_daemon_init(daemon, daemon_local->RingbufferMinSize, daemon_local->RingbufferMaxSize, - daemon_local->RingbufferStepSize, daemon_local->flags.ivalue, - daemon_local->flags.contextLogLevel, - daemon_local->flags.contextTraceStatus, daemon_local->flags.enforceContextLLAndTS, - daemon_local->flags.vflag) == -1) { + if (dlt_daemon_init( + daemon, daemon_local->RingbufferMinSize, daemon_local->RingbufferMaxSize, daemon_local->RingbufferStepSize, + daemon_local->flags.ivalue, daemon_local->flags.contextLogLevel, daemon_local->flags.contextTraceStatus, + daemon_local->flags.enforceContextLLAndTS, daemon_local->flags.vflag) + == -1) { dlt_log(LOG_ERR, "Could not initialize daemon data\n"); return -1; } /* init offline trace */ - if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && - daemon_local->flags.offlineTraceDirectory[0]) { - if (multiple_files_buffer_init(&(daemon_local->offlineTrace), - daemon_local->flags.offlineTraceDirectory, - daemon_local->flags.offlineTraceFileSize, - daemon_local->flags.offlineTraceMaxSize, - daemon_local->flags.offlineTraceFilenameTimestampBased, - false, - DLT_OFFLINETRACE_FILENAME_BASE, - DLT_OFFLINETRACE_FILENAME_EXT) == -1) { + if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) + && daemon_local->flags.offlineTraceDirectory[0]) { + if (multiple_files_buffer_init( + &(daemon_local->offlineTrace), daemon_local->flags.offlineTraceDirectory, + daemon_local->flags.offlineTraceFileSize, daemon_local->flags.offlineTraceMaxSize, + daemon_local->flags.offlineTraceFilenameTimestampBased, false, DLT_OFFLINETRACE_FILENAME_BASE, + DLT_OFFLINETRACE_FILENAME_EXT) + == -1) { dlt_log(LOG_ERR, "Could not initialize offline trace\n"); return -1; } @@ -1836,13 +1621,12 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in } /* Set ECU id of daemon */ - if (daemon_local->flags.evalue[0]){ + if (daemon_local->flags.evalue[0]) { dlt_set_id(daemon->ecuid, daemon_local->flags.evalue); daemon->ecuid2len = (uint8_t)strlen(daemon_local->flags.evalue); dlt_set_id_v2(daemon->ecuid2, daemon_local->flags.evalue, daemon->ecuid2len); - } - else{ + } else { dlt_set_id(daemon->ecuid, DLT_DAEMON_ECU_ID); daemon->ecuid2len = (uint8_t)strlen(DLT_DAEMON_ECU_ID); dlt_set_id_v2(daemon->ecuid2, DLT_DAEMON_ECU_ID, daemon->ecuid2len); @@ -1854,13 +1638,14 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in #ifdef DLT_SHM_ENABLE /* init shared memory */ - if (dlt_shm_init_server(&(daemon_local->dlt_shm), daemon_local->flags.dltShmName, - daemon_local->flags.sharedMemorySize) == DLT_RETURN_ERROR) { + if (dlt_shm_init_server( + &(daemon_local->dlt_shm), daemon_local->flags.dltShmName, daemon_local->flags.sharedMemorySize) + == DLT_RETURN_ERROR) { dlt_log(LOG_ERR, "Could not initialize shared memory\n"); return -1; } - daemon_local->recv_buf_shm = (unsigned char *)calloc(1, DLT_SHM_RCV_BUFFER_SIZE); + daemon_local->recv_buf_shm = (unsigned char*)calloc(1, DLT_SHM_RCV_BUFFER_SIZE); if (NULL == daemon_local->recv_buf_shm) { dlt_log(LOG_ERR, "failed to allocated the buffer to receive shm data\n"); @@ -1896,7 +1681,7 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in return 0; } -static int dlt_daemon_init_serial(DltDaemonLocal *daemon_local) +static int dlt_daemon_init_serial(DltDaemonLocal* daemon_local) { /* create and open serial connection from/to client */ /* open serial connection */ @@ -1908,8 +1693,7 @@ static int dlt_daemon_init_serial(DltDaemonLocal *daemon_local) fd = open(daemon_local->flags.yvalue, O_RDWR); if (fd < 0) { - dlt_vlog(LOG_ERR, "Failed to open serial device %s\n", - daemon_local->flags.yvalue); + dlt_vlog(LOG_ERR, "Failed to open serial device %s\n", daemon_local->flags.yvalue); daemon_local->flags.yvalue[0] = 0; return -1; @@ -1923,38 +1707,31 @@ static int dlt_daemon_init_serial(DltDaemonLocal *daemon_local) daemon_local->baudrate = dlt_convert_serial_speed(speed); - if (dlt_setup_serial(fd, (speed_t) daemon_local->baudrate) < 0) { + if (dlt_setup_serial(fd, (speed_t)daemon_local->baudrate) < 0) { close(fd); daemon_local->flags.yvalue[0] = 0; - dlt_vlog(LOG_ERR, "Failed to configure serial device %s (%s) \n", - daemon_local->flags.yvalue, strerror(errno)); + dlt_vlog( + LOG_ERR, "Failed to configure serial device %s (%s) \n", daemon_local->flags.yvalue, strerror(errno)); return -1; } if (daemon_local->flags.vflag) dlt_log(LOG_DEBUG, "Serial init done\n"); - } - else { + } else { close(fd); - fprintf(stderr, - "Device is not a serial device, device = %s (%s) \n", - daemon_local->flags.yvalue, - strerror(errno)); + fprintf( + stderr, "Device is not a serial device, device = %s (%s) \n", daemon_local->flags.yvalue, strerror(errno)); daemon_local->flags.yvalue[0] = 0; return -1; } - return dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_CLIENT_MSG_SERIAL); + return dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_CLIENT_MSG_SERIAL); } #ifdef DLT_DAEMON_USE_FIFO_IPC -static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) +static int dlt_daemon_init_fifo(DltDaemonLocal* daemon_local) { int ret; int fd = -1; @@ -1966,48 +1743,41 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) umask(0); /* Try to delete existing pipe, ignore result of unlink */ - const char *tmpFifo = daemon_local->flags.daemonFifoName; + const char* tmpFifo = daemon_local->flags.daemonFifoName; unlink(tmpFifo); ret = mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IWGRP); if (ret == -1) { - dlt_vlog(LOG_WARNING, "FIFO user %s cannot be created (%s)!\n", - tmpFifo, strerror(errno)); + dlt_vlog(LOG_WARNING, "FIFO user %s cannot be created (%s)!\n", tmpFifo, strerror(errno)); return -1; } /* if */ /* Set group of daemon FIFO */ if (daemon_local->flags.daemonFifoGroup[0] != 0) { errno = 0; - struct group *group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup); + struct group* group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup); if (group_dlt) { ret = chown(tmpFifo, (uid_t)-1, group_dlt->gr_gid); if (ret == -1) - dlt_vlog(LOG_ERR, "FIFO user %s cannot be chowned to group %s (%s)\n", - tmpFifo, daemon_local->flags.daemonFifoGroup, - strerror(errno)); - } - else if ((errno == 0) || (errno == ENOENT) || (errno == EBADF) || (errno == EPERM)) - { - dlt_vlog(LOG_ERR, "Group name %s is not found (%s)\n", - daemon_local->flags.daemonFifoGroup, - strerror(errno)); - } - else { - dlt_vlog(LOG_ERR, "Failed to get group id of %s (%s)\n", - daemon_local->flags.daemonFifoGroup, - strerror(errno)); + dlt_vlog( + LOG_ERR, "FIFO user %s cannot be chowned to group %s (%s)\n", tmpFifo, + daemon_local->flags.daemonFifoGroup, strerror(errno)); + } else if ((errno == 0) || (errno == ENOENT) || (errno == EBADF) || (errno == EPERM)) { + dlt_vlog( + LOG_ERR, "Group name %s is not found (%s)\n", daemon_local->flags.daemonFifoGroup, strerror(errno)); + } else { + dlt_vlog( + LOG_ERR, "Failed to get group id of %s (%s)\n", daemon_local->flags.daemonFifoGroup, strerror(errno)); } } fd = open(tmpFifo, O_RDWR); if (fd == -1) { - dlt_vlog(LOG_WARNING, "FIFO user %s cannot be opened (%s)!\n", - tmpFifo, strerror(errno)); + dlt_vlog(LOG_WARNING, "FIFO user %s cannot be opened (%s)!\n", tmpFifo, strerror(errno)); return -1; } /* if */ @@ -2032,16 +1802,12 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local) * as soon as possible. This registration is automatically ignored * during next execution. */ - return dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_APP_MSG); + return dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_APP_MSG); } #endif #ifdef DLT_DAEMON_VSOCK_IPC_ENABLE -static int dlt_daemon_init_vsock(DltDaemonLocal *daemon_local) +static int dlt_daemon_init_vsock(DltDaemonLocal* daemon_local) { int fd; struct sockaddr_vm addr; @@ -2057,7 +1823,7 @@ static int dlt_daemon_init_vsock(DltDaemonLocal *daemon_local) addr.svm_port = DLT_VSOCK_PORT; addr.svm_cid = VMADDR_CID_ANY; - if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) != 0) { + if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) != 0) { dlt_vlog(LOG_ERR, "Failed to bind VSOCK socket: %s\n", strerror(errno)); close(fd); return -1; @@ -2069,16 +1835,12 @@ static int dlt_daemon_init_vsock(DltDaemonLocal *daemon_local) return -1; } - return dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_APP_CONNECT); + return dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_APP_CONNECT); } #endif #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC -static DltReturnValue dlt_daemon_init_app_socket(DltDaemonLocal *daemon_local) +static DltReturnValue dlt_daemon_init_app_socket(DltDaemonLocal* daemon_local) { /* socket access permission set to srw-rw-rw- (666) */ int mask = S_IXUSR | S_IXGRP | S_IXOTH; @@ -2100,28 +1862,17 @@ static DltReturnValue dlt_daemon_init_app_socket(DltDaemonLocal *daemon_local) * To avoid blocking users to launch dlt-daemon only through * init on android (e.g: by hand for debugging purpose), try to * create app socket by ourselves */ - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.appSockPath, - SOCK_STREAM, - mask); + ret = dlt_daemon_unix_socket_open(&fd, daemon_local->flags.appSockPath, SOCK_STREAM, mask); } #else - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.appSockPath, - SOCK_STREAM, - mask); + ret = dlt_daemon_unix_socket_open(&fd, daemon_local->flags.appSockPath, SOCK_STREAM, mask); #endif if (ret == DLT_RETURN_OK) { - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_APP_CONNECT)) { + if (dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_APP_CONNECT)) { dlt_log(LOG_CRIT, "Could not create connection for app socket.\n"); return DLT_RETURN_ERROR; } - } - else { + } else { dlt_log(LOG_CRIT, "Could not create and open app socket.\n"); return DLT_RETURN_ERROR; } @@ -2130,7 +1881,7 @@ static DltReturnValue dlt_daemon_init_app_socket(DltDaemonLocal *daemon_local) } #endif -static DltReturnValue dlt_daemon_initialize_control_socket(DltDaemonLocal *daemon_local) +static DltReturnValue dlt_daemon_initialize_control_socket(DltDaemonLocal* daemon_local) { /* socket access permission set to srw-rw---- (660) */ int mask = S_IXUSR | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; @@ -2152,23 +1903,14 @@ static DltReturnValue dlt_daemon_initialize_control_socket(DltDaemonLocal *daemo * To avoid blocking users to launch dlt-daemon only through * init on android (e.g by hand for debugging purpose), try to * create app socket by ourselves */ - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.ctrlSockPath, - SOCK_STREAM, - mask); + ret = dlt_daemon_unix_socket_open(&fd, daemon_local->flags.ctrlSockPath, SOCK_STREAM, mask); } #else - ret = dlt_daemon_unix_socket_open(&fd, - daemon_local->flags.ctrlSockPath, - SOCK_STREAM, - mask); + ret = dlt_daemon_unix_socket_open(&fd, daemon_local->flags.ctrlSockPath, SOCK_STREAM, mask); #endif if (ret == DLT_RETURN_OK) { - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_CONTROL_CONNECT) < DLT_RETURN_OK) { + if (dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_CONTROL_CONNECT) + < DLT_RETURN_OK) { dlt_log(LOG_ERR, "Could not initialize control socket.\n"); ret = DLT_RETURN_ERROR; } @@ -2177,9 +1919,7 @@ static DltReturnValue dlt_daemon_initialize_control_socket(DltDaemonLocal *daemo return ret; } -int dlt_daemon_local_connection_init(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +int dlt_daemon_local_connection_init(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { int fd = -1; @@ -2190,7 +1930,7 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon, return -1; } - DltBindAddress_t *head = daemon_local->flags.ipNodes; + DltBindAddress_t* head = daemon_local->flags.ipNodes; #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC /* create and open socket to receive incoming connections from user application */ @@ -2221,36 +1961,26 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon, if (head == NULL) { /* no IP set in BindAddress option, will use "0.0.0.0" as default */ if (dlt_daemon_socket_open(&fd, daemon_local->flags.port, "0.0.0.0") == DLT_RETURN_OK) { - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_CLIENT_CONNECT)) { + if (dlt_connection_create(daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_CLIENT_CONNECT)) { dlt_log(LOG_ERR, "Could not initialize main socket.\n"); return DLT_RETURN_ERROR; } - } - else { + } else { dlt_log(LOG_ERR, "Could not initialize main socket.\n"); return DLT_RETURN_ERROR; } - } - else { + } else { bool any_open = false; while (head != NULL) { /* open socket for each IP in the bindAddress list */ if (dlt_daemon_socket_open(&fd, daemon_local->flags.port, head->ip) == DLT_RETURN_OK) { - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - fd, - POLLIN, - DLT_CONNECTION_CLIENT_CONNECT)) { + if (dlt_connection_create( + daemon_local, &daemon_local->pEvent, fd, POLLIN, DLT_CONNECTION_CLIENT_CONNECT)) { dlt_vlog(LOG_ERR, "Could not create connection, for binding %s\n", head->ip); } else { any_open = true; } - } - else { + } else { dlt_vlog(LOG_ERR, "Could not open main socket, for binding %s\n", head->ip); } @@ -2269,8 +1999,7 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon, if (dlt_daemon_udp_connection_setup(daemon_local) < 0) { dlt_log(LOG_ERR, "UDP fd creation failed\n"); return DLT_RETURN_ERROR; - } - else { + } else { dlt_log(LOG_INFO, "UDP fd creation success\n"); } } @@ -2377,9 +2106,8 @@ static char* file_read_field(FILE* const file, const char* const fieldName) } /* check fieldName */ - if (strncmp(line, fieldName, fieldNameLen) == 0 && - (size_t)lineSize >= (fieldNameLen + 1) && - strchr(kDelimiters, line[fieldNameLen]) != NULL) { + if (strncmp(line, fieldName, fieldNameLen) == 0 && (size_t)lineSize >= (fieldNameLen + 1) + && strchr(kDelimiters, line[fieldNameLen]) != NULL) { /* trim fieldName */ line += fieldNameLen; @@ -2402,9 +2130,9 @@ static char* file_read_field(FILE* const file, const char* const fieldName) return result; } -int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_local_ecu_version_init(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { - FILE *f = NULL; + FILE* f = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2431,7 +2159,7 @@ int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_ return (daemon->ECUVersionString != NULL) ? 0 : -1; } -void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +void dlt_daemon_local_cleanup(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2459,8 +2187,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i #else /* DLT_DAEMON_USE_UNIX_SOCKET_IPC */ /* Try to delete existing pipe, ignore result of unlink() */ if (unlink(daemon_local->flags.appSockPath) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); } #endif @@ -2473,9 +2200,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i if (daemon_local->flags.offlineLogstorageMaxDevices > 0) { /* disconnect all logstorage devices */ - dlt_daemon_logstorage_cleanup(daemon, - daemon_local, - daemon_local->flags.vflag); + dlt_daemon_logstorage_cleanup(daemon, daemon_local, daemon_local->flags.vflag); free(daemon->storage_handle); } @@ -2484,8 +2209,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i free(daemon->ECUVersionString); if (unlink(daemon_local->flags.ctrlSockPath) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); } /* free IP list */ @@ -2498,13 +2222,12 @@ void dlt_daemon_exit_trigger() g_exit = -1; #ifdef DLT_DAEMON_USE_FIFO_IPC - char tmp[DLT_PATH_MAX] = { 0 }; + char tmp[DLT_PATH_MAX] = {0}; ssize_t n; n = snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir); if (n < 0 || (size_t)n > DLT_PATH_MAX) { - dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n", - __func__, (long int)n, tmp); + dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n", __func__, (long int)n, tmp); } (void)unlink(tmp); @@ -2513,7 +2236,6 @@ void dlt_daemon_exit_trigger() #ifdef __QNX__ dlt_daemon_cleanup_timers(); #endif - } void dlt_daemon_signal_handler(int sig) @@ -2521,22 +2243,19 @@ void dlt_daemon_signal_handler(int sig) g_signo = sig; switch (sig) { - case SIGHUP: - case SIGTERM: - case SIGINT: - case SIGQUIT: - { - /* finalize the server */ - dlt_vlog(LOG_NOTICE, "Exiting DLT daemon due to signal: %s\n", - strsignal(sig)); - dlt_daemon_exit_trigger(); - break; - } - default: - { - /* This case should never happen! */ - break; - } + case SIGHUP: + case SIGTERM: + case SIGINT: + case SIGQUIT: { + /* finalize the server */ + dlt_vlog(LOG_NOTICE, "Exiting DLT daemon due to signal: %s\n", strsignal(sig)); + dlt_daemon_exit_trigger(); + break; + } + default: { + /* This case should never happen! */ + break; + } } /* switch */ } /* dlt_daemon_signal_handler() */ @@ -2608,8 +2327,7 @@ void dlt_daemon_daemonize(int verbose) dlt_vlog(LOG_WARNING, "Failed to direct stderr to /dev/null. Error: %s\n", strerror(errno)); close(fd); - } - else { + } else { dlt_log(LOG_CRIT, "Error opening /dev/null, exiting DLT daemon\n"); exit(-1); /* fork error */ } @@ -2636,9 +2354,9 @@ void dlt_daemon_daemonize(int verbose) * to open the offline trace file. * This is a dlt-daemon only function. The libdlt has no equivalent function available. */ /* TODO: How to call when it doesn't has version info */ -int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, - char *str, DltLogLevelType level, - const char *app_id, const char *ctx_id, int verbose) +int dlt_daemon_log_internal( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* str, DltLogLevelType level, const char* app_id, + const char* ctx_id, int verbose) { static uint8_t uiMsgCount = 0; if (daemon->daemon_version == 2) { @@ -2660,23 +2378,23 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, msg.baseheadersizev2 = BASE_HEADER_V2_FIXED_SIZE; msg.baseheaderextrasizev2 = (int32_t)dlt_message_get_extraparameters_size_v2(msgcontent); /* Ecu Id, App Id, Ctx Id and Session Id*/ - msg.extendedheadersizev2 = (uint32_t)(1 + strlen(DLT_DAEMON_ECU_ID) + 1 + strlen(app_id) + 1 + strlen(ctx_id) + sizeof(uint32_t)); + msg.extendedheadersizev2 = + (uint32_t)(1 + strlen(DLT_DAEMON_ECU_ID) + 1 + strlen(app_id) + 1 + strlen(ctx_id) + sizeof(uint32_t)); - msg.headersizev2 = (int32_t) (msg.storageheadersizev2 + - msg.baseheadersizev2 + - msg.baseheaderextrasizev2 + - msg.extendedheadersizev2); + msg.headersizev2 = (int32_t)(msg.storageheadersizev2 + msg.baseheadersizev2 + msg.baseheaderextrasizev2 + + msg.extendedheadersizev2); msg.headerbufferv2 = (uint8_t*)malloc((size_t)msg.headersizev2); - if (dlt_set_storageheader_v2(&(msg.storageheaderv2), (uint8_t)strlen(DLT_DAEMON_ECU_ID), DLT_DAEMON_ECU_ID) != DLT_RETURN_OK) + if (dlt_set_storageheader_v2(&(msg.storageheaderv2), (uint8_t)strlen(DLT_DAEMON_ECU_ID), DLT_DAEMON_ECU_ID) + != DLT_RETURN_OK) return DLT_RETURN_ERROR; if (dlt_message_set_storageparameters_v2(&msg, 0) != DLT_RETURN_OK) return DLT_RETURN_ERROR; /* Set standardheader */ - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + msg.storageheadersizev2); + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + msg.storageheadersizev2); msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2; msg.baseheaderv2->htyp2 |= msgcontent; msg.baseheaderv2->htyp2 |= DLT_HTYP2_WEID; @@ -2686,53 +2404,53 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, msg.baseheaderv2->mcnt = uiMsgCount++; /* Fill base header conditional parameters */ - msg.headerextrav2.msin = (uint8_t)(DLT_MSIN_VERB | (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | - ((level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + msg.headerextrav2.msin = (uint8_t)(DLT_MSIN_VERB | (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) + | ((level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); msg.headerextrav2.noar = 1; /* number of arguments */ memset(msg.headerextrav2.seconds, 0, 5); msg.headerextrav2.nanoseconds = 0; -#if defined (__WIN32__) || defined(_MSC_VER) +#if defined(__WIN32__) || defined(_MSC_VER) time_t t = time(NULL); - if (t==-1){ + if (t == -1) { uint32_t tcnt = (uint32_t)(GetTickCount()); /* GetTickCount() in 10 ms resolution */ tcnt_seconds = tcnt / 100; - tcnt_ns = (tcnt - (tcnt*100)) * 10000; - msg.headerextrav2.seconds[0]=(tcnt_seconds >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(uint8_t)((tcnt_seconds >> 24) & 0xFF); - msg.headerextrav2.seconds[2]=(uint8_t)((tcnt_seconds >> 16) & 0xFF); - msg.headerextrav2.seconds[3]=(uint8_t)((tcnt_seconds >> 8) & 0xFF); - msg.headerextrav2.seconds[4]= (uint8_t)(tcnt_seconds & 0xFF); + tcnt_ns = (tcnt - (tcnt * 100)) * 10000; + msg.headerextrav2.seconds[0] = (tcnt_seconds >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (uint8_t)((tcnt_seconds >> 24) & 0xFF); + msg.headerextrav2.seconds[2] = (uint8_t)((tcnt_seconds >> 16) & 0xFF); + msg.headerextrav2.seconds[3] = (uint8_t)((tcnt_seconds >> 8) & 0xFF); + msg.headerextrav2.seconds[4] = (uint8_t)(tcnt_seconds & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { msg.headerextrav2.nanoseconds = tcnt_ns; } - }else{ - msg.headerextrav2.seconds[0]=(uint8_t)((t >> 32) & 0xFF); - msg.headerextrav2.seconds[1]=(uint8_t)((t >> 24) & 0xFF); - msg.headerextrav2.seconds[2]=(uint8_t)((t >> 16) & 0xFF); - msg.headerextrav2.seconds[3]=(uint8_t)((t >> 8) & 0xFF); - msg.headerextrav2.seconds[4]= (uint8_t)(t & 0xFF); + } else { + msg.headerextrav2.seconds[0] = (uint8_t)((t >> 32) & 0xFF); + msg.headerextrav2.seconds[1] = (uint8_t)((t >> 24) & 0xFF); + msg.headerextrav2.seconds[2] = (uint8_t)((t >> 16) & 0xFF); + msg.headerextrav2.seconds[3] = (uint8_t)((t >> 8) & 0xFF); + msg.headerextrav2.seconds[4] = (uint8_t)(t & 0xFF); msg.headerextrav2.nanoseconds |= 0x80000000; } #else struct timespec ts; - if(clock_gettime(CLOCK_REALTIME, &ts) == 0) { - msg.headerextrav2.seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - msg.headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - msg.headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - msg.headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - msg.headerextrav2.seconds[4]= (uint8_t)(ts.tv_sec & 0xFF); + if (clock_gettime(CLOCK_REALTIME, &ts) == 0) { + msg.headerextrav2.seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + msg.headerextrav2.seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + msg.headerextrav2.seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + msg.headerextrav2.seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + msg.headerextrav2.seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { - msg.headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } - }else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - msg.headerextrav2.seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - msg.headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - msg.headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - msg.headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - msg.headerextrav2.seconds[4]= (uint8_t)(ts.tv_sec & 0xFF); + } else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + msg.headerextrav2.seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + msg.headerextrav2.seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + msg.headerextrav2.seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + msg.headerextrav2.seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + msg.headerextrav2.seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { - msg.headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } msg.headerextrav2.nanoseconds |= 0x80000000; } @@ -2784,10 +2502,10 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, /* Set payload data... */ uiType = DLT_TYPE_INFO_STRG; - uiSize = (uint16_t) (strlen(str) + 1); - msg.datasize = (int32_t) (sizeof(uint32_t) + sizeof(uint16_t) + uiSize); + uiSize = (uint16_t)(strlen(str) + 1); + msg.datasize = (int32_t)(sizeof(uint32_t) + sizeof(uint16_t) + uiSize); - msg.databuffer = (uint8_t *)malloc((size_t) msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; if (msg.databuffer == 0) { @@ -2796,27 +2514,27 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, } msg.datasize = 0; - memcpy((uint8_t *)(msg.databuffer + msg.datasize), (uint8_t *)(&uiType), sizeof(uint32_t)); - msg.datasize += (int32_t) sizeof(uint32_t); - memcpy((uint8_t *)(msg.databuffer + msg.datasize), (uint8_t *)(&uiSize), sizeof(uint16_t)); - msg.datasize += (int32_t) sizeof(uint16_t); - memcpy((uint8_t *)(msg.databuffer + msg.datasize), str, uiSize); + memcpy((uint8_t*)(msg.databuffer + msg.datasize), (uint8_t*)(&uiType), sizeof(uint32_t)); + msg.datasize += (int32_t)sizeof(uint32_t); + memcpy((uint8_t*)(msg.databuffer + msg.datasize), (uint8_t*)(&uiSize), sizeof(uint16_t)); + msg.datasize += (int32_t)sizeof(uint16_t); + memcpy((uint8_t*)(msg.databuffer + msg.datasize), str, uiSize); msg.datasize += uiSize; /* Calc length */ - msg.baseheaderv2->len = DLT_HTOBE_16((uint16_t)(msg.headersizev2 - (int32_t)msg.storageheadersizev2 + msg.datasize)); + msg.baseheaderv2->len = + DLT_HTOBE_16((uint16_t)(msg.headersizev2 - (int32_t)msg.storageheadersizev2 + msg.datasize)); - dlt_daemon_client_send_v2(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, - msg.headerbufferv2, (int)msg.storageheadersizev2, - msg.headerbufferv2 + msg.storageheadersizev2, - (int) (msg.headersizev2 - (int32_t)msg.storageheadersizev2), - msg.databuffer, (int) msg.datasize, verbose); + dlt_daemon_client_send_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, msg.headerbufferv2, (int)msg.storageheadersizev2, + msg.headerbufferv2 + msg.storageheadersizev2, (int)(msg.headersizev2 - (int32_t)msg.storageheadersizev2), + msg.databuffer, (int)msg.datasize, verbose); dlt_message_free_v2(&msg, 0); } else if (daemon->daemon_version == 1) { - DltMessage msg = { 0 }; + DltMessage msg = {0}; - DltStandardHeaderExtra *pStandardExtra = NULL; + DltStandardHeaderExtra* pStandardExtra = NULL; uint32_t uiType; uint16_t uiSize; uint32_t uiExtraSize; @@ -2824,42 +2542,43 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, PRINT_FUNCTION_VERBOSE(verbose); /* Set storageheader */ - msg.storageheader = (DltStorageHeader *)(msg.headerbuffer); + msg.storageheader = (DltStorageHeader*)(msg.headerbuffer); dlt_set_storageheader(msg.storageheader, daemon->ecuid); /* Set standardheader */ - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); - msg.standardheader->htyp = DLT_HTYP_UEH | DLT_HTYP_WEID | DLT_HTYP_WSID | DLT_HTYP_WTMS | - DLT_HTYP_PROTOCOL_VERSION1; + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader->htyp = + DLT_HTYP_UEH | DLT_HTYP_WEID | DLT_HTYP_WSID | DLT_HTYP_WTMS | DLT_HTYP_PROTOCOL_VERSION1; msg.standardheader->mcnt = uiMsgCount++; - uiExtraSize = (uint32_t) (DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) + - (DLT_IS_HTYP_UEH(msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); - msg.headersize = (int32_t)((size_t)sizeof(DltStorageHeader) + (size_t)sizeof(DltStandardHeader) + (size_t)uiExtraSize); + uiExtraSize = (uint32_t)(DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) + + (DLT_IS_HTYP_UEH(msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); + msg.headersize = + (int32_t)((size_t)sizeof(DltStorageHeader) + (size_t)sizeof(DltStandardHeader) + (size_t)uiExtraSize); /* Set extraheader */ pStandardExtra = - (DltStandardHeaderExtra *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)); + (DltStandardHeaderExtra*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)); dlt_set_id(pStandardExtra->ecu, daemon->ecuid); pStandardExtra->tmsp = DLT_HTOBE_32(dlt_uptime()); pStandardExtra->seid = DLT_HTOBE_32((uint32_t)getpid()); /* Set extendedheader */ msg.extendedheader = - (DltExtendedHeader *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); - msg.extendedheader->msin = (uint8_t)(DLT_MSIN_VERB | (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | - ((level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.extendedheader->msin = (uint8_t)(DLT_MSIN_VERB | (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) + | ((level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); msg.extendedheader->noar = 1; dlt_set_id(msg.extendedheader->apid, app_id); dlt_set_id(msg.extendedheader->ctid, ctx_id); /* Set payload data... */ uiType = DLT_TYPE_INFO_STRG; - uiSize = (uint16_t) (strlen(str) + 1); + uiSize = (uint16_t)(strlen(str) + 1); msg.datasize = (int32_t)((size_t)sizeof(uint32_t) + (size_t)sizeof(uint16_t) + (size_t)uiSize); - msg.databuffer = (uint8_t *)malloc((size_t) msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = (int32_t)msg.datasize; if (msg.databuffer == 0) { @@ -2868,71 +2587,66 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, } msg.datasize = 0; - memcpy((uint8_t *)(msg.databuffer + msg.datasize), (uint8_t *)(&uiType), sizeof(uint32_t)); + memcpy((uint8_t*)(msg.databuffer + msg.datasize), (uint8_t*)(&uiType), sizeof(uint32_t)); msg.datasize += (int32_t)sizeof(uint32_t); - memcpy((uint8_t *)(msg.databuffer + msg.datasize), (uint8_t *)(&uiSize), sizeof(uint16_t)); + memcpy((uint8_t*)(msg.databuffer + msg.datasize), (uint8_t*)(&uiSize), sizeof(uint16_t)); msg.datasize += (int32_t)sizeof(uint16_t); - memcpy((uint8_t *)(msg.databuffer + msg.datasize), str, uiSize); + memcpy((uint8_t*)(msg.databuffer + msg.datasize), str, uiSize); msg.datasize += (int32_t)uiSize; /* Calc length */ - msg.standardheader->len = DLT_HTOBE_16((uint16_t)((size_t)msg.headersize - sizeof(DltStorageHeader) + (size_t)msg.datasize)); + msg.standardheader->len = + DLT_HTOBE_16((uint16_t)((size_t)msg.headersize - sizeof(DltStorageHeader) + (size_t)msg.datasize)); - dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, - msg.headerbuffer, sizeof(DltStorageHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (int)(msg.headersize - (int32_t)sizeof(DltStorageHeader)), - msg.databuffer, (int)msg.datasize, verbose); + dlt_daemon_client_send( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, msg.headerbuffer, sizeof(DltStorageHeader), + msg.headerbuffer + sizeof(DltStorageHeader), (int)(msg.headersize - (int32_t)sizeof(DltStorageHeader)), + msg.databuffer, (int)msg.datasize, verbose); free(msg.databuffer); - }else { + } else { return -1; } return 0; } -int dlt_daemon_check_numeric_setting(char *token, - char *value, - unsigned long *data) +int dlt_daemon_check_numeric_setting(char* token, char* value, unsigned long* data) { char value_check[value_length]; value_check[0] = 0; sscanf(value, "%lu%s", data, value_check); if (value_check[0] || !isdigit(value[0])) { - fprintf(stderr, "Invalid input [%s] detected in option %s\n", - value, - token); + fprintf(stderr, "Invalid input [%s] detected in option %s\n", value, token); return -1; } return 0; } -int dlt_daemon_process_client_connect(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_client_connect( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { socklen_t cli_size; struct sockaddr_un cli; int in_sock = -1; - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_log(LOG_ERR, - "Invalid function parameters used for function " - "dlt_daemon_process_client_connect()\n"); + dlt_log( + LOG_ERR, + "Invalid function parameters used for function " + "dlt_daemon_process_client_connect()\n"); return -1; } /* event from TCP server socket, new connection */ cli_size = sizeof(cli); - if ((in_sock = accept(receiver->fd, (struct sockaddr *)&cli, &cli_size)) < 0) { - if (errno == ECONNABORTED) // Caused by nmap -v -p 3490 -Pn + if ((in_sock = accept(receiver->fd, (struct sockaddr*)&cli, &cli_size)) < 0) { + if (errno == ECONNABORTED) // Caused by nmap -v -p 3490 -Pn return 0; dlt_vlog(LOG_ERR, "accept() for socket %d failed: %s\n", receiver->fd, strerror(errno)); return -1; @@ -2940,7 +2654,7 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, if (daemon->daemon_version == 2) { /* check if file file descriptor was already used, and make it invalid if it - * is reused. */ + * is reused. */ /* This prevents sending messages to wrong file descriptor */ dlt_daemon_applications_invalidate_fd_v2(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd_v2(daemon, daemon->ecuid, in_sock, verbose); @@ -2950,53 +2664,38 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, timeout_send.tv_sec = daemon_local->timeoutOnSend; timeout_send.tv_usec = 0; - if (setsockopt (in_sock, - SOL_SOCKET, - SO_SNDTIMEO, - (char *)&timeout_send, - sizeof(timeout_send)) < 0) + if (setsockopt(in_sock, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout_send, sizeof(timeout_send)) < 0) dlt_log(LOG_WARNING, "setsockopt failed\n"); - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - in_sock, - POLLIN, - DLT_CONNECTION_CLIENT_MSG_TCP)) { + if (dlt_connection_create( + daemon_local, &daemon_local->pEvent, in_sock, POLLIN, DLT_CONNECTION_CLIENT_MSG_TCP)) { dlt_log(LOG_ERR, "Failed to register new client. \n"); close(in_sock); return -1; } /* send connection info about connected */ - dlt_daemon_control_message_connection_info_v2(in_sock, - daemon, - daemon_local, - DLT_CONNECTION_STATUS_CONNECTED, - "", - verbose); + dlt_daemon_control_message_connection_info_v2( + in_sock, daemon, daemon_local, DLT_CONNECTION_STATUS_CONNECTED, "", verbose); /* send ecu version string */ if (daemon_local->flags.sendECUSoftwareVersion > 0) { if (daemon_local->flags.sendECUSoftwareVersion > 0) - dlt_daemon_control_get_software_version_v2(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); + dlt_daemon_control_get_software_version_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); if (daemon_local->flags.sendTimezone > 0) - dlt_daemon_control_message_timezone_v2(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); + dlt_daemon_control_message_timezone_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); } - snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "New client connection #%d established, Total Clients : %d", - in_sock, daemon_local->client_connections); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "New client connection #%d established, Total Clients : %d", in_sock, + daemon_local->client_connections); - dlt_daemon_log_internal(daemon, daemon_local, local_str, DLT_LOG_INFO, - DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local->flags.vflag); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, + daemon_local->flags.vflag); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); if (daemon_local->client_connections == 1) { @@ -3015,14 +2714,14 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, daemon->connectionState = 1; dlt_daemon_user_send_all_log_state_v2(daemon, verbose); - #ifdef DLT_TRACE_LOAD_CTRL_ENABLE +#ifdef DLT_TRACE_LOAD_CTRL_ENABLE /* Reset number of received bytes from FIFO */ daemon->bytes_recv = 0; - #endif +#endif } } else if (daemon->daemon_version == 1) { /* check if file file descriptor was already used, and make it invalid if it - * is reused. */ + * is reused. */ /* This prevents sending messages to wrong file descriptor */ dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); @@ -3032,53 +2731,38 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, timeout_send.tv_sec = daemon_local->timeoutOnSend; timeout_send.tv_usec = 0; - if (setsockopt (in_sock, - SOL_SOCKET, - SO_SNDTIMEO, - (char *)&timeout_send, - sizeof(timeout_send)) < 0) + if (setsockopt(in_sock, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout_send, sizeof(timeout_send)) < 0) dlt_log(LOG_WARNING, "setsockopt failed\n"); - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - in_sock, - POLLIN, - DLT_CONNECTION_CLIENT_MSG_TCP)) { + if (dlt_connection_create( + daemon_local, &daemon_local->pEvent, in_sock, POLLIN, DLT_CONNECTION_CLIENT_MSG_TCP)) { dlt_log(LOG_ERR, "Failed to register new client. \n"); close(in_sock); return -1; } /* send connection info about connected */ - dlt_daemon_control_message_connection_info(in_sock, - daemon, - daemon_local, - DLT_CONNECTION_STATUS_CONNECTED, - "", - verbose); + dlt_daemon_control_message_connection_info( + in_sock, daemon, daemon_local, DLT_CONNECTION_STATUS_CONNECTED, "", verbose); /* send ecu version string */ if (daemon_local->flags.sendECUSoftwareVersion > 0) { if (daemon_local->flags.sendECUSoftwareVersion > 0) - dlt_daemon_control_get_software_version(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); + dlt_daemon_control_get_software_version( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); if (daemon_local->flags.sendTimezone > 0) - dlt_daemon_control_message_timezone(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); + dlt_daemon_control_message_timezone( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); } - snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "New client connection #%d established, Total Clients : %d", - in_sock, daemon_local->client_connections); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "New client connection #%d established, Total Clients : %d", in_sock, + daemon_local->client_connections); - dlt_daemon_log_internal(daemon, daemon_local, local_str, DLT_LOG_INFO, - DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local->flags.vflag); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, + daemon_local->flags.vflag); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); if (daemon_local->client_connections == 1) { @@ -3103,7 +2787,7 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, daemon->bytes_recv = 0; #endif } - }else { + } else { return -1; } return 0; @@ -3117,11 +2801,11 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, * @param secure_msg The secure message to populate (output) * @return 0 on success, -1 on validation failure */ -static int dlt_daemon_create_secure_message(DltMessage *tainted_msg, DltMessage *secure_msg) +static int dlt_daemon_create_secure_message(DltMessage* tainted_msg, DltMessage* secure_msg) { uint32_t service_id; - DltServiceOfflineLogstorage *tainted_req; - DltServiceOfflineLogstorage *secure_req; + DltServiceOfflineLogstorage* tainted_req; + DltServiceOfflineLogstorage* secure_req; char secure_mount_point[DLT_MOUNT_PATH_MAX]; size_t i; @@ -3145,13 +2829,12 @@ static int dlt_daemon_create_secure_message(DltMessage *tainted_msg, DltMessage } /* Set up header pointers */ - secure_msg->storageheader = (DltStorageHeader *)(secure_msg->headerbuffer); - secure_msg->standardheader = (DltStandardHeader *)(secure_msg->headerbuffer + sizeof(DltStorageHeader)); + secure_msg->storageheader = (DltStorageHeader*)(secure_msg->headerbuffer); + secure_msg->standardheader = (DltStandardHeader*)(secure_msg->headerbuffer + sizeof(DltStorageHeader)); if (DLT_IS_HTYP_UEH(secure_msg->standardheader->htyp)) { - secure_msg->extendedheader = (DltExtendedHeader *)(secure_msg->headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(secure_msg->standardheader->htyp)); + secure_msg->extendedheader = + (DltExtendedHeader*)(secure_msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(secure_msg->standardheader->htyp)); } /* Point to the same databuffer initially */ @@ -3162,13 +2845,12 @@ static int dlt_daemon_create_secure_message(DltMessage *tainted_msg, DltMessage return 0; /* Get service ID */ - service_id = DLT_ENDIAN_GET_32(tainted_msg->standardheader->htyp, - *((uint32_t *)(tainted_msg->databuffer))); + service_id = DLT_ENDIAN_GET_32(tainted_msg->standardheader->htyp, *((uint32_t*)(tainted_msg->databuffer))); /* Sanitize logstorage messages with path validation */ if (service_id == DLT_SERVICE_ID_OFFLINE_LOGSTORAGE) { /* Cast to logstorage request structure */ - tainted_req = (DltServiceOfflineLogstorage *)(tainted_msg->databuffer); + tainted_req = (DltServiceOfflineLogstorage*)(tainted_msg->databuffer); if (tainted_req == NULL) return -1; @@ -3194,20 +2876,19 @@ static int dlt_daemon_create_secure_message(DltMessage *tainted_msg, DltMessage } /* Now sanitize the databuffer */ - secure_req = (DltServiceOfflineLogstorage *)(secure_msg->databuffer); + secure_req = (DltServiceOfflineLogstorage*)(secure_msg->databuffer); /* Explicitly sanitize: copy path to secure local buffer using allow list */ memset(secure_mount_point, 0, sizeof(secure_mount_point)); for (i = 0; i < DLT_MOUNT_PATH_MAX - 1 && tainted_req->mount_point[i] != '\0'; i++) { char c = tainted_req->mount_point[i]; /* Apply allow list - only safe characters allowed */ - if ((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - c == '/' || c == '-' || c == '_' || c == '.') { + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '/' || c == '-' + || c == '_' || c == '.') { secure_mount_point[i] = c; } else { - dlt_vlog(LOG_WARNING, "Rejected logstorage message with invalid character in path at position %zu\n", i); + dlt_vlog( + LOG_WARNING, "Rejected logstorage message with invalid character in path at position %zu\n", i); return -1; } } @@ -3234,10 +2915,8 @@ static int dlt_daemon_create_secure_message(DltMessage *tainted_msg, DltMessage return 0; } -int dlt_daemon_process_client_messages(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_client_messages( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { int bytes_to_be_removed = 0; int must_close_socket = -1; @@ -3245,83 +2924,66 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_log(LOG_ERR, - "Invalid function parameters used for function " - "dlt_daemon_process_client_messages()\n"); + dlt_log( + LOG_ERR, + "Invalid function parameters used for function " + "dlt_daemon_process_client_messages()\n"); return -1; } must_close_socket = dlt_receiver_receive(receiver); if (must_close_socket < 0) { - dlt_daemon_close_socket(receiver->fd, - daemon, - daemon_local, - verbose); + dlt_daemon_close_socket(receiver->fd, daemon, daemon_local, verbose); return -1; } - if(daemon->daemon_version == DLTProtocolV2) { + if (daemon->daemon_version == DLTProtocolV2) { /* Process all received messages */ - while (dlt_message_read_v2(&(daemon_local->msgv2), - (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, - daemon_local->flags.nflag, - daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { - + while (dlt_message_read_v2( + &(daemon_local->msgv2), (uint8_t*)receiver->buf, (unsigned int)receiver->bytesRcvd, + daemon_local->flags.nflag, daemon_local->flags.vflag) + == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ - if ((0 < receiver->fd) && - DLT_MSG_IS_CONTROL_REQUEST_V2(&(daemon_local->msgv2))) - dlt_daemon_client_process_control_v2(receiver->fd, - daemon, - daemon_local, - &(daemon_local->msgv2), - daemon_local->flags.vflag); - bytes_to_be_removed = (int) (daemon_local->msgv2.headersizev2 + - daemon_local->msgv2.datasize - (int32_t)daemon_local->msgv2.storageheadersizev2); + if ((0 < receiver->fd) && DLT_MSG_IS_CONTROL_REQUEST_V2(&(daemon_local->msgv2))) + dlt_daemon_client_process_control_v2( + receiver->fd, daemon, daemon_local, &(daemon_local->msgv2), daemon_local->flags.vflag); + bytes_to_be_removed = (int)(daemon_local->msgv2.headersizev2 + daemon_local->msgv2.datasize + - (int32_t)daemon_local->msgv2.storageheadersizev2); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += (int)sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1) { - dlt_log(LOG_WARNING, - "Can't remove bytes from receiver for sockets\n"); + dlt_log(LOG_WARNING, "Can't remove bytes from receiver for sockets\n"); return -1; } } /* while */ } else if (daemon->daemon_version == DLTProtocolV1) { /* Process all received messages */ - while (dlt_message_read(&(daemon_local->msg), - (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, - daemon_local->flags.nflag, - daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { - + while (dlt_message_read( + &(daemon_local->msg), (uint8_t*)receiver->buf, (unsigned int)receiver->bytesRcvd, + daemon_local->flags.nflag, daemon_local->flags.vflag) + == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ - if ((0 < receiver->fd) && - DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg))) - dlt_daemon_client_process_control(receiver->fd, - daemon, - daemon_local, - &(daemon_local->msg), - daemon_local->flags.vflag); - - bytes_to_be_removed = (int)((size_t)daemon_local->msg.headersize + - (size_t)daemon_local->msg.datasize - - (size_t)sizeof(DltStorageHeader)); + if ((0 < receiver->fd) && DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg))) + dlt_daemon_client_process_control( + receiver->fd, daemon, daemon_local, &(daemon_local->msg), daemon_local->flags.vflag); + + bytes_to_be_removed = (int)((size_t)daemon_local->msg.headersize + (size_t)daemon_local->msg.datasize + - (size_t)sizeof(DltStorageHeader)); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += (int)sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1) { - dlt_log(LOG_WARNING, - "Can't remove bytes from receiver for sockets\n"); + dlt_log(LOG_WARNING, "Can't remove bytes from receiver for sockets\n"); return -1; } } /* while */ @@ -3331,53 +2993,47 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, } if (dlt_receiver_move_to_begin(receiver) == -1) { - dlt_log(LOG_WARNING, - "Can't move bytes to beginning of receiver buffer for sockets\n"); + dlt_log(LOG_WARNING, "Can't move bytes to beginning of receiver buffer for sockets\n"); return -1; } if (must_close_socket == 0) /* FIXME: Why the hell do we need to close the socket - * on control message reception ?? - */ - dlt_daemon_close_socket(receiver->fd, - daemon, - daemon_local, - verbose); + * on control message reception ?? + */ + dlt_daemon_close_socket(receiver->fd, daemon, daemon_local, verbose); return 0; } -int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_client_messages_serial( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { int bytes_to_be_removed = 0; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_log(LOG_ERR, - "Invalid function parameters used for function " - "dlt_daemon_process_client_messages_serial()\n"); + dlt_log( + LOG_ERR, + "Invalid function parameters used for function " + "dlt_daemon_process_client_messages_serial()\n"); return -1; } if (dlt_receiver_receive(receiver) <= 0) { - dlt_log(LOG_WARNING, - "dlt_receiver_receive_fd() for messages from serial interface " - "failed!\n"); + dlt_log( + LOG_WARNING, + "dlt_receiver_receive_fd() for messages from serial interface " + "failed!\n"); return -1; } /* Process all received messages */ - while (dlt_message_read(&(daemon_local->msg), - (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, - daemon_local->flags.mflag, - daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { - + while (dlt_message_read( + &(daemon_local->msg), (uint8_t*)receiver->buf, (unsigned int)receiver->bytesRcvd, + daemon_local->flags.mflag, daemon_local->flags.vflag) + == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ if (DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg))) { DltMessage secure_msg = {0}; @@ -3385,38 +3041,34 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, if (dlt_daemon_create_secure_message(&(daemon_local->msg), &secure_msg) < 0) continue; - if (dlt_daemon_client_process_control(receiver->fd, - daemon, - daemon_local, - &(daemon_local->msg), - daemon_local->flags.vflag) + if (dlt_daemon_client_process_control( + receiver->fd, daemon, daemon_local, &(daemon_local->msg), daemon_local->flags.vflag) == -1) { dlt_log(LOG_WARNING, "Can't process control messages\n"); return -1; } } - bytes_to_be_removed = (int)((size_t)daemon_local->msg.headersize + - (size_t)daemon_local->msg.datasize - - sizeof(DltStorageHeader)); + bytes_to_be_removed = + (int)((size_t)daemon_local->msg.headersize + (size_t)daemon_local->msg.datasize - sizeof(DltStorageHeader)); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += (int)sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1) { - dlt_log(LOG_WARNING, - "Can't remove bytes from receiver for serial connection\n"); + dlt_log(LOG_WARNING, "Can't remove bytes from receiver for serial connection\n"); return -1; } } /* while */ if (dlt_receiver_move_to_begin(receiver) == -1) { - dlt_log(LOG_WARNING, - "Can't move bytes to beginning of receiver buffer for serial " - "connection\n"); + dlt_log( + LOG_WARNING, + "Can't move bytes to beginning of receiver buffer for serial " + "connection\n"); return -1; } @@ -3424,10 +3076,7 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, } int dlt_daemon_process_control_connect( - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { socklen_t ctrl_size; struct sockaddr_un ctrl; @@ -3436,16 +3085,17 @@ int dlt_daemon_process_control_connect( PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_log(LOG_ERR, - "Invalid function parameters used for function " - "dlt_daemon_process_control_connect()\n"); + dlt_log( + LOG_ERR, + "Invalid function parameters used for function " + "dlt_daemon_process_control_connect()\n"); return -1; } /* event from UNIX server socket, new connection */ ctrl_size = sizeof(ctrl); - if ((in_sock = accept(receiver->fd, (struct sockaddr *)&ctrl, &ctrl_size)) < 0) { + if ((in_sock = accept(receiver->fd, (struct sockaddr*)&ctrl, &ctrl_size)) < 0) { dlt_vlog(LOG_ERR, "accept() on UNIX control socket %d failed: %s\n", receiver->fd, strerror(errno)); return -1; } @@ -3456,20 +3106,16 @@ int dlt_daemon_process_control_connect( if (daemon->daemon_version == 2) { dlt_daemon_applications_invalidate_fd_v2(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd_v2(daemon, daemon->ecuid, in_sock, verbose); - }else if (daemon->daemon_version == 1) { + } else if (daemon->daemon_version == 1) { dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); - }else { + } else { return -1; } dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - in_sock, - POLLIN, - DLT_CONNECTION_CONTROL_MSG)) { + if (dlt_connection_create(daemon_local, &daemon_local->pEvent, in_sock, POLLIN, DLT_CONNECTION_CONTROL_MSG)) { dlt_log(LOG_ERR, "Failed to register new client. \n"); /* TODO: Perform clean-up */ return -1; @@ -3482,20 +3128,14 @@ int dlt_daemon_process_control_connect( } #if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE -int dlt_daemon_process_app_connect( - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_app_connect(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { int in_sock = -1; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_vlog(LOG_ERR, - "%s: Invalid parameters\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -3511,11 +3151,7 @@ int dlt_daemon_process_app_connect( dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose); - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - in_sock, - POLLIN, - DLT_CONNECTION_APP_MSG)) { + if (dlt_connection_create(daemon_local, &daemon_local->pEvent, in_sock, POLLIN, DLT_CONNECTION_APP_MSG)) { dlt_log(LOG_ERR, "Failed to register new application. \n"); close(in_sock); return -1; @@ -3529,104 +3165,81 @@ int dlt_daemon_process_app_connect( #endif int dlt_daemon_process_control_messages( - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { int bytes_to_be_removed = 0; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_log(LOG_ERR, - "Invalid function parameters used for function " - "dlt_daemon_process_control_messages()\n"); + dlt_log( + LOG_ERR, + "Invalid function parameters used for function " + "dlt_daemon_process_control_messages()\n"); return -1; } if (dlt_receiver_receive(receiver) <= 0) { - dlt_daemon_close_socket(receiver->fd, - daemon, - daemon_local, - verbose); + dlt_daemon_close_socket(receiver->fd, daemon, daemon_local, verbose); return -1; } - if(daemon->daemon_version == DLTProtocolV2) { + if (daemon->daemon_version == DLTProtocolV2) { /* Process all received messages */ - while (dlt_message_read_v2(&(daemon_local->msgv2), - (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, - daemon_local->flags.nflag, - daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { - + while (dlt_message_read_v2( + &(daemon_local->msgv2), (uint8_t*)receiver->buf, (unsigned int)receiver->bytesRcvd, + daemon_local->flags.nflag, daemon_local->flags.vflag) + == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ - if ((0 < receiver->fd) && - DLT_MSG_IS_CONTROL_REQUEST_V2(&(daemon_local->msgv2))) - dlt_daemon_client_process_control_v2(receiver->fd, - daemon, - daemon_local, - &(daemon_local->msgv2), - daemon_local->flags.vflag); - bytes_to_be_removed = (int) (daemon_local->msgv2.headersizev2 - + daemon_local->msgv2.datasize - - (int32_t)daemon_local->msgv2.storageheadersizev2); + if ((0 < receiver->fd) && DLT_MSG_IS_CONTROL_REQUEST_V2(&(daemon_local->msgv2))) + dlt_daemon_client_process_control_v2( + receiver->fd, daemon, daemon_local, &(daemon_local->msgv2), daemon_local->flags.vflag); + bytes_to_be_removed = (int)(daemon_local->msgv2.headersizev2 + daemon_local->msgv2.datasize + - (int32_t)daemon_local->msgv2.storageheadersizev2); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += (int)sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1) { - dlt_log(LOG_WARNING, - "Can't remove bytes from receiver for sockets\n"); + dlt_log(LOG_WARNING, "Can't remove bytes from receiver for sockets\n"); return -1; } } /* while */ - } - else if (daemon->daemon_version == DLTProtocolV1) { + } else if (daemon->daemon_version == DLTProtocolV1) { /* Process all received messages */ while (dlt_message_read( - &(daemon_local->msg), - (uint8_t *)receiver->buf, - (unsigned int) receiver->bytesRcvd, - daemon_local->flags.nflag, - daemon_local->flags.vflag) == DLT_MESSAGE_ERROR_OK) { - + &(daemon_local->msg), (uint8_t*)receiver->buf, (unsigned int)receiver->bytesRcvd, + daemon_local->flags.nflag, daemon_local->flags.vflag) + == DLT_MESSAGE_ERROR_OK) { /* Check for control message */ - if ((receiver->fd > 0) && - DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg))) { + if ((receiver->fd > 0) && DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg))) { DltMessage secure_msg = {0}; /* Create sanitized message to break taint chain */ if (dlt_daemon_create_secure_message(&(daemon_local->msg), &secure_msg) < 0) continue; - if (dlt_daemon_client_process_control(receiver->fd, - daemon, - daemon_local, - &secure_msg, - daemon_local->flags.vflag) + if (dlt_daemon_client_process_control( + receiver->fd, daemon, daemon_local, &secure_msg, daemon_local->flags.vflag) == -1) { dlt_log(LOG_WARNING, "Can't process control messages\n"); return -1; } } - bytes_to_be_removed = (int)((size_t)daemon_local->msg.headersize + - (size_t)daemon_local->msg.datasize - - sizeof(DltStorageHeader)); + bytes_to_be_removed = (int)((size_t)daemon_local->msg.headersize + (size_t)daemon_local->msg.datasize + - sizeof(DltStorageHeader)); if (daemon_local->msg.found_serialheader) - bytes_to_be_removed += (int) sizeof(dltSerialHeader); + bytes_to_be_removed += (int)sizeof(dltSerialHeader); if (daemon_local->msg.resync_offset) bytes_to_be_removed += daemon_local->msg.resync_offset; if (dlt_receiver_remove(receiver, bytes_to_be_removed) == -1) { - dlt_log(LOG_WARNING, - "Can't remove bytes from receiver for sockets\n"); + dlt_log(LOG_WARNING, "Can't remove bytes from receiver for sockets\n"); return -1; } } /* while */ @@ -3643,24 +3256,20 @@ int dlt_daemon_process_control_messages( return 0; } -static int dlt_daemon_process_user_message_not_sup(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +static int dlt_daemon_process_user_message_not_sup( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { - DltUserHeader *userheader = (DltUserHeader *)(receiver->buf); + DltUserHeader* userheader = (DltUserHeader*)(receiver->buf); (void)daemon; (void)daemon_local; PRINT_FUNCTION_VERBOSE(verbose); - dlt_vlog(LOG_ERR, "Invalid user message type received: %u!\n", - userheader->message); + dlt_vlog(LOG_ERR, "Invalid user message type received: %u!\n", userheader->message); /* remove user header */ if (dlt_receiver_remove(receiver, sizeof(DltUserHeader)) == -1) - dlt_log(LOG_WARNING, - "Can't remove bytes from receiver for user messages\n"); + dlt_log(LOG_WARNING, "Can't remove bytes from receiver for user messages\n"); return -1; } @@ -3681,41 +3290,34 @@ static dlt_daemon_process_user_message_func process_user_func[DLT_USER_MESSAGE_N dlt_daemon_process_user_message_not_sup, dlt_daemon_process_user_message_marker, dlt_daemon_process_user_message_not_sup, - dlt_daemon_process_user_message_not_sup -}; + dlt_daemon_process_user_message_not_sup}; -int dlt_daemon_process_user_messages(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_user_messages( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { int offset = 0; int run_loop = 1; - int32_t min_size = (int32_t) sizeof(DltUserHeader); - DltUserHeader *userheader; + int32_t min_size = (int32_t)sizeof(DltUserHeader); + DltUserHeader* userheader; int recv; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { - dlt_log(LOG_ERR, - "Invalid function parameters used for function " - "dlt_daemon_process_user_messages()\n"); + dlt_log( + LOG_ERR, + "Invalid function parameters used for function " + "dlt_daemon_process_user_messages()\n"); return -1; } recv = dlt_receiver_receive(receiver); if (recv <= 0 && receiver->type == DLT_RECEIVE_SOCKET) { - dlt_daemon_close_socket(receiver->fd, - daemon, - daemon_local, - verbose); + dlt_daemon_close_socket(receiver->fd, daemon, daemon_local, verbose); return 0; - } - else if (recv < 0) { - dlt_log(LOG_WARNING, - "dlt_receiver_receive_fd() for user messages failed!\n"); + } else if (recv < 0) { + dlt_log(LOG_WARNING, "dlt_receiver_receive_fd() for user messages failed!\n"); return -1; } @@ -3723,34 +3325,32 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, if (daemon->daemon_version == DLTProtocolV2) { #ifdef DLT_TRACE_LOAD_CTRL_ENABLE /* Count up number of received bytes from FIFO */ - if (receiver->bytesRcvd > receiver->lastBytesRcvd) - { + if (receiver->bytesRcvd > receiver->lastBytesRcvd) { daemon->bytes_recv += receiver->bytesRcvd - receiver->lastBytesRcvd; } #endif /* look through buffer as long as data is in there */ while ((receiver->bytesRcvd >= min_size) && run_loop) { - #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE +#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE /* this loop may be running long, so we have to exit it at some point to be able to - * to process other events, like feeding the watchdog - */ - bool watchdog_triggered= dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); + * to process other events, like feeding the watchdog + */ + bool watchdog_triggered = dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); if (watchdog_triggered) { dlt_vlog(LOG_WARNING, "%s yields due to watchdog.\n", __func__); - run_loop = 0; // exit loop in next iteration + run_loop = 0; // exit loop in next iteration } - #endif +#endif dlt_daemon_process_user_message_func func = NULL; offset = 0; - userheader = (DltUserHeader *)(receiver->buf + offset); + userheader = (DltUserHeader*)(receiver->buf + offset); - while (!dlt_user_check_userheader(userheader) && - (offset + min_size <= receiver->bytesRcvd)) { + while (!dlt_user_check_userheader(userheader) && (offset + min_size <= receiver->bytesRcvd)) { /* resync if necessary */ offset++; - userheader = (DltUserHeader *)(receiver->buf + offset); + userheader = (DltUserHeader*)(receiver->buf + offset); } /* Check for user header pattern */ @@ -3760,8 +3360,7 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, /* Set new start offset */ if (offset > 0) { if (dlt_receiver_remove(receiver, offset) == -1) { - dlt_log(LOG_WARNING, - "Can't remove offset from receiver\n"); + dlt_log(LOG_WARNING, "Can't remove offset from receiver\n"); return -1; } } @@ -3770,25 +3369,22 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, else func = process_user_func[userheader->message]; - if (func(daemon, - daemon_local, - receiver, - daemon_local->flags.vflag) == -1) + if (func(daemon, daemon_local, receiver, daemon_local->flags.vflag) == -1) run_loop = 0; } /* keep not read data in buffer */ if (dlt_receiver_move_to_begin(receiver) == -1) { - dlt_log(LOG_WARNING, - "Can't move bytes to beginning of receiver buffer for user " - "messages\n"); + dlt_log( + LOG_WARNING, + "Can't move bytes to beginning of receiver buffer for user " + "messages\n"); return -1; } } else if (daemon->daemon_version == DLTProtocolV1) { #ifdef DLT_TRACE_LOAD_CTRL_ENABLE /* Count up number of received bytes from FIFO */ - if (receiver->bytesRcvd > receiver->lastBytesRcvd) - { + if (receiver->bytesRcvd > receiver->lastBytesRcvd) { daemon->bytes_recv += receiver->bytesRcvd - receiver->lastBytesRcvd; } #endif @@ -3797,24 +3393,23 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, while ((receiver->bytesRcvd >= min_size) && run_loop) { #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE /* this loop may be running long, so we have to exit it at some point to be able to - * to process other events, like feeding the watchdog - */ - bool watchdog_triggered= dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); + * to process other events, like feeding the watchdog + */ + bool watchdog_triggered = dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); if (watchdog_triggered) { dlt_vlog(LOG_WARNING, "%s yields due to watchdog.\n", __func__); - run_loop = 0; // exit loop in next iteration + run_loop = 0; // exit loop in next iteration } #endif dlt_daemon_process_user_message_func func = NULL; offset = 0; - userheader = (DltUserHeader *)(receiver->buf + offset); + userheader = (DltUserHeader*)(receiver->buf + offset); - while (!dlt_user_check_userheader(userheader) && - (offset + min_size <= receiver->bytesRcvd)) { + while (!dlt_user_check_userheader(userheader) && (offset + min_size <= receiver->bytesRcvd)) { /* resync if necessary */ offset++; - userheader = (DltUserHeader *)(receiver->buf + offset); + userheader = (DltUserHeader*)(receiver->buf + offset); } /* Check for user header pattern */ @@ -3824,8 +3419,7 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, /* Set new start offset */ if (offset > 0) { if (dlt_receiver_remove(receiver, offset) == -1) { - dlt_log(LOG_WARNING, - "Can't remove offset from receiver\n"); + dlt_log(LOG_WARNING, "Can't remove offset from receiver\n"); return -1; } } @@ -3835,18 +3429,16 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, else func = process_user_func[userheader->message]; - if (func(daemon, - daemon_local, - receiver, - daemon_local->flags.vflag) == -1) + if (func(daemon, daemon_local, receiver, daemon_local->flags.vflag) == -1) run_loop = 0; } /* keep not read data in buffer */ if (dlt_receiver_move_to_begin(receiver) == -1) { - dlt_log(LOG_WARNING, - "Can't move bytes to beginning of receiver buffer for user " - "messages\n"); + dlt_log( + LOG_WARNING, + "Can't move bytes to beginning of receiver buffer for user " + "messages\n"); return -1; } } else { @@ -3857,10 +3449,8 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, return 0; } -int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_overflow( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { uint32_t len = sizeof(DltUserControlMsgBufferOverflow); DltUserControlMsgBufferOverflow userpayload; @@ -3868,26 +3458,18 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } - if (dlt_receiver_check_and_get(rec, - &userpayload, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, &userpayload, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return -1; /* Store in daemon, that a message buffer overflow has occured */ /* look if TCP connection to client is available or it least message can be put into buffer */ - if (dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - userpayload.overflow_counter, - userpayload.apid, - verbose)) + if (dlt_daemon_control_message_buffer_overflow( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, userpayload.overflow_counter, userpayload.apid, verbose)) /* there was an error when storing message */ /* add the counter of lost messages to the daemon counter */ daemon->overflow_counter += userpayload.overflow_counter; @@ -3895,7 +3477,7 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, return 0; } -int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_send_message_overflow(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { int ret; PRINT_FUNCTION_VERBOSE(verbose); @@ -3906,16 +3488,14 @@ int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_l } /* Store in daemon, that a message buffer overflow has occured */ - if ((ret = - dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, - daemon->overflow_counter, - "", verbose))) + if ((ret = dlt_daemon_control_message_buffer_overflow( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon->overflow_counter, "", verbose))) return ret; return DLT_DAEMON_ERROR_OK; } -int dlt_daemon_send_message_overflow_v2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_send_message_overflow_v2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { int ret; PRINT_FUNCTION_VERBOSE(verbose); @@ -3926,54 +3506,48 @@ int dlt_daemon_send_message_overflow_v2(DltDaemon *daemon, DltDaemonLocal *daemo } /* Store in daemon, that a message buffer overflow has occured */ - if ((ret = - dlt_daemon_control_message_buffer_overflow_v2(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, - daemon->overflow_counter, - NULL, verbose))) + if ((ret = dlt_daemon_control_message_buffer_overflow_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon->overflow_counter, NULL, verbose))) return ret; return DLT_DAEMON_ERROR_OK; } -int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_register_application( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { uint32_t to_remove = 0; - DltDaemonApplication *application = NULL; - DltDaemonApplication *old_application = NULL; + DltDaemonApplication* application = NULL; + DltDaemonApplication* old_application = NULL; pid_t old_pid = 0; - char description[DLT_DAEMON_DESCSIZE + 1] = { '\0' }; - char *origin; + char description[DLT_DAEMON_DESCSIZE + 1] = {'\0'}; + char* origin; int fd = -1; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } - if(daemon->daemon_version == DLTProtocolV2) { + if (daemon->daemon_version == DLTProtocolV2) { uint32_t len = sizeof(DltUserControlMsgRegisterApplicationV2); DltUserControlMsgRegisterApplicationV2 usercontext; memset(&usercontext, 0, sizeof(DltUserControlMsgRegisterApplicationV2)); usercontext.apid = NULL; int usercontextSize; - uint8_t *buffer; + uint8_t* buffer; int offset = 0; - usercontext.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer - usercontextSize = (int) (sizeof(uint8_t) + usercontext.apidlen + sizeof(pid_t) + sizeof(uint32_t)); + usercontext.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer + usercontextSize = (int)(sizeof(uint8_t) + usercontext.apidlen + sizeof(pid_t) + sizeof(uint32_t)); buffer = (uint8_t*)calloc((size_t)usercontextSize, 1); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } @@ -3983,17 +3557,13 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, int temp = 0; /* We shall not remove data before checking that everything is there. */ - temp = dlt_receiver_check_and_get(rec, - buffer, - (unsigned int)usercontextSize, - DLT_RCV_SKIP_HEADER); + temp = dlt_receiver_check_and_get(rec, buffer, (unsigned int)usercontextSize, DLT_RCV_SKIP_HEADER); if (temp < 0) { /* Not enough bytes received */ return -1; - } - else { - to_remove = (uint32_t) temp; + } else { + to_remove = (uint32_t)temp; } offset = 0; @@ -4023,25 +3593,28 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, dlt_log(LOG_ERR, "Unable to get application description\n"); /* in case description was not readable, set dummy description */ memcpy(description, "Unknown", sizeof("Unknown")); - /* unknown len of original description, set to 0 to not remove in next step. Because message buffer is re-adjusted the corrupted description is ignored. */ + /* unknown len of original description, set to 0 to not remove in next step. Because message buffer is + * re-adjusted the corrupted description is ignored. */ len = 0; } /* adjust to_remove */ - to_remove += (uint32_t) sizeof(DltUserHeader) + len; + to_remove += (uint32_t)sizeof(DltUserHeader) + len; /* point to begin of message */ rec->buf = origin; - //TBD: Need init_v2 ? + // TBD: Need init_v2 ? /* We can now remove data. */ - if (dlt_receiver_remove(rec, (int) to_remove) != DLT_RETURN_OK) { + if (dlt_receiver_remove(rec, (int)to_remove) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return -1; } - dlt_daemon_application_find_v2(daemon, usercontext.apidlen, usercontext.apid, daemon->ecuid2len, daemon->ecuid2, verbose, &old_application); + dlt_daemon_application_find_v2( + daemon, usercontext.apidlen, usercontext.apid, daemon->ecuid2len, daemon->ecuid2, verbose, + &old_application); if (old_application != NULL) old_pid = old_application->pid; @@ -4049,49 +3622,37 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, if (rec->type == DLT_RECEIVE_SOCKET) fd = rec->fd; /* For sockets, an app specific fd has already been created with accept(). */ - application = dlt_daemon_application_add_v2(daemon, - usercontext.apidlen, - usercontext.apid, - usercontext.pid, - description, - fd, - daemon->ecuid2len, - daemon->ecuid2, - verbose); + application = dlt_daemon_application_add_v2( + daemon, usercontext.apidlen, usercontext.apid, usercontext.pid, description, fd, daemon->ecuid2len, + daemon->ecuid2, verbose); /* send log state to new application */ dlt_daemon_user_send_log_state_v2(daemon, application, verbose); if (application == NULL) { - dlt_vlog(LOG_WARNING, "Can't add ApplicationID '%s' for PID %d\n", - usercontext.apid, usercontext.pid); + dlt_vlog(LOG_WARNING, "Can't add ApplicationID '%s' for PID %d\n", usercontext.apid, usercontext.pid); return -1; - } - else if (old_pid != application->pid) - { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; + } else if (old_pid != application->pid) { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "ApplicationID '%s' registered for PID %d, Description=%s", - application->apid2, - application->pid, - application->application_description); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "ApplicationID '%s' registered for PID %d, Description=%s", + application->apid2, application->pid, application->application_description); - dlt_daemon_log_internal(daemon, daemon_local, local_str, DLT_LOG_INFO, - DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local->flags.vflag); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, + daemon_local->flags.vflag); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } #ifdef DLT_TRACE_LOAD_CTRL_ENABLE if (dlt_daemon_user_send_trace_load_config(daemon, application, verbose) != DLT_RETURN_OK) - dlt_vlog(LOG_WARNING, "Cannot send trace config to Apid: %.4s, PID: %d\n", - application->apid, application->pid); + dlt_vlog( + LOG_WARNING, "Cannot send trace config to Apid: %.4s, PID: %d\n", application->apid, application->pid); #endif free(buffer); - } else if(daemon->daemon_version == DLTProtocolV1) { + } else if (daemon->daemon_version == DLTProtocolV1) { DltUserControlMsgRegisterApplication userapp; uint32_t len = sizeof(DltUserControlMsgRegisterApplication); memset(&userapp, 0, sizeof(DltUserControlMsgRegisterApplication)); @@ -4101,16 +3662,13 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, int temp = 0; /* We shall not remove data before checking that everything is there. */ - temp = dlt_receiver_check_and_get(rec, - &userapp, - len, - DLT_RCV_SKIP_HEADER); + temp = dlt_receiver_check_and_get(rec, &userapp, len, DLT_RCV_SKIP_HEADER); if (temp < 0) /* Not enough bytes received */ return -1; else { - to_remove = (uint32_t) temp; + to_remove = (uint32_t)temp; } len = userapp.description_length; @@ -4129,18 +3687,18 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, memcpy(description, "Unknown", sizeof("Unknown")); /* unknown len of original description, set to 0 to not remove in next - * step. Because message buffer is re-adjusted the corrupted description - * is ignored. */ + * step. Because message buffer is re-adjusted the corrupted description + * is ignored. */ len = 0; } /* adjust to_remove */ - to_remove += (uint32_t) sizeof(DltUserHeader) + len; + to_remove += (uint32_t)sizeof(DltUserHeader) + len; /* point to begin of message */ rec->buf = origin; /* We can now remove data. */ - if (dlt_receiver_remove(rec, (int) to_remove) != DLT_RETURN_OK) { + if (dlt_receiver_remove(rec, (int)to_remove) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return -1; } @@ -4153,42 +3711,31 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, if (rec->type == DLT_RECEIVE_SOCKET) fd = rec->fd; /* For sockets, an app specific fd has already been created with accept(). */ - application = dlt_daemon_application_add(daemon, - userapp.apid, - userapp.pid, - description, - fd, - daemon->ecuid, - verbose); + application = + dlt_daemon_application_add(daemon, userapp.apid, userapp.pid, description, fd, daemon->ecuid, verbose); /* send log state to new application */ dlt_daemon_user_send_log_state(daemon, application, verbose); if (application == NULL) { - dlt_vlog(LOG_WARNING, "Can't add ApplicationID '%.4s' for PID %d\n", - userapp.apid, userapp.pid); + dlt_vlog(LOG_WARNING, "Can't add ApplicationID '%.4s' for PID %d\n", userapp.apid, userapp.pid); return -1; - } - else if (old_pid != application->pid) - { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; - - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "ApplicationID '%.4s' registered for PID %d, Description=%s", - application->apid, - application->pid, - application->application_description); - dlt_daemon_log_internal(daemon, daemon_local, local_str, DLT_LOG_INFO, - DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local->flags.vflag); + } else if (old_pid != application->pid) { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; + + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "ApplicationID '%.4s' registered for PID %d, Description=%s", + application->apid, application->pid, application->application_description); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, + daemon_local->flags.vflag); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - if (dlt_daemon_user_send_trace_load_config(daemon, application, verbose) != DLT_RETURN_OK) - dlt_vlog(LOG_WARNING, "Cannot send trace config to Apid: %.4s, PID: %d\n", - application->apid, application->pid); + if (dlt_daemon_user_send_trace_load_config(daemon, application, verbose) != DLT_RETURN_OK) + dlt_vlog( + LOG_WARNING, "Cannot send trace config to Apid: %.4s, PID: %d\n", application->apid, application->pid); #endif } else { dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__); @@ -4197,24 +3744,21 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, return 0; } -int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_register_context( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { uint32_t to_remove = 0; uint32_t len = (uint32_t)(sizeof(DltUserControlMsgRegisterContext)); DltUserControlMsgRegisterContext userctxt; - char description[DLT_DAEMON_DESCSIZE + 1] = { '\0' }; - DltDaemonApplication *application = NULL; - DltDaemonContext *context = NULL; - char *origin; + char description[DLT_DAEMON_DESCSIZE + 1] = {'\0'}; + DltDaemonApplication* application = NULL; + DltDaemonContext* context = NULL; + char* origin; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } @@ -4225,23 +3769,23 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, usercontext.apid = NULL; usercontext.ctid = NULL; int usercontextSize; - uint8_t *buffer; + uint8_t* buffer; DltMessageV2 msg; int offset = 0; PRINT_FUNCTION_VERBOSE(verbose); - usercontext.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer - usercontext.ctidlen = (uint8_t)rec->buf[9 + usercontext.apidlen]; // TBD: write function to get ctidlen from received buffer + usercontext.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer + usercontext.ctidlen = + (uint8_t)rec->buf[9 + usercontext.apidlen]; // TBD: write function to get ctidlen from received buffer - usercontextSize = (int)(sizeof(uint8_t) + usercontext.apidlen + - sizeof(uint8_t) + usercontext.ctidlen + 10 + sizeof(pid_t)); + usercontextSize = + (int)(sizeof(uint8_t) + usercontext.apidlen + sizeof(uint8_t) + usercontext.ctidlen + 10 + sizeof(pid_t)); len = (uint32_t)usercontextSize; buffer = (uint8_t*)malloc((size_t)usercontextSize); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); free(buffer); return -1; } @@ -4251,34 +3795,31 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, /* Adding temp variable to check the return value */ int temp = 0; - temp = dlt_receiver_check_and_get(rec, - buffer, - (unsigned int)len, - DLT_RCV_SKIP_HEADER); + temp = dlt_receiver_check_and_get(rec, buffer, (unsigned int)len, DLT_RCV_SKIP_HEADER); if (temp < 0) { /* Not enough bytes received */ free(buffer); return -1; } else { - to_remove = (uint32_t) temp; + to_remove = (uint32_t)temp; } memcpy(&(usercontext.apidlen), buffer, 1); offset = 1; - usercontext.apid = (char *)malloc((size_t)usercontext.apidlen + 1); + usercontext.apid = (char*)malloc((size_t)usercontext.apidlen + 1); if (usercontext.apid == NULL) { dlt_log(LOG_ERR, "Memory allocation failed for usercontext.apid\n"); free(buffer); return -1; } memcpy(usercontext.apid, (buffer + offset), usercontext.apidlen); - memset((usercontext.apid + usercontext.apidlen), '\0', 1); // Null-terminate string + memset((usercontext.apid + usercontext.apidlen), '\0', 1); // Null-terminate string offset += usercontext.apidlen; memcpy(&(usercontext.ctidlen), (buffer + offset), 1); offset += 1; - usercontext.ctid = (char *)malloc((size_t)usercontext.ctidlen + 1); + usercontext.ctid = (char*)malloc((size_t)usercontext.ctidlen + 1); if (usercontext.ctid == NULL) { dlt_log(LOG_ERR, "Memory allocation failed for usercontext.ctid\n"); free(usercontext.apid); @@ -4286,7 +3827,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, return -1; } memcpy(usercontext.ctid, (buffer + offset), usercontext.ctidlen); - memset((usercontext.ctid + usercontext.ctidlen), '\0', 1); // Null-terminate string + memset((usercontext.ctid + usercontext.ctidlen), '\0', 1); // Null-terminate string offset += usercontext.ctidlen; memcpy(&(usercontext.log_level_pos), (buffer + offset), sizeof(int32_t)); offset += (int)sizeof(int32_t); @@ -4314,18 +3855,18 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, memcpy(description, "Unknown", sizeof("Unknown")); /* unknown len of original description, set to 0 to not remove in next - * step. Because message buffer is re-adjusted the corrupted description - * is ignored. */ + * step. Because message buffer is re-adjusted the corrupted description + * is ignored. */ len = 0; } /* adjust to_remove */ - to_remove += (uint32_t) sizeof(DltUserHeader) + len; + to_remove += (uint32_t)sizeof(DltUserHeader) + len; /* point to begin of message */ rec->buf = origin; /* We can now remove data. */ - if (dlt_receiver_remove(rec, (int) to_remove) != DLT_RETURN_OK) { + if (dlt_receiver_remove(rec, (int)to_remove) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); free(usercontext.apid); free(usercontext.ctid); @@ -4333,20 +3874,13 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, return -1; } - dlt_daemon_application_find_v2(daemon, - usercontext.apidlen, - usercontext.apid, - daemon->ecuid2len, - daemon->ecuid2, - verbose, - &application); + dlt_daemon_application_find_v2( + daemon, usercontext.apidlen, usercontext.apid, daemon->ecuid2len, daemon->ecuid2, verbose, &application); if (application == NULL) { - dlt_vlog(LOG_WARNING, - "ApID '%s' not found for new ContextID '%s' in %s\n", - usercontext.apid, - usercontext.ctid, - __func__); + dlt_vlog( + LOG_WARNING, "ApID '%s' not found for new ContextID '%s' in %s\n", usercontext.apid, usercontext.ctid, + __func__); free(usercontext.apid); free(usercontext.ctid); @@ -4359,8 +3893,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, usercontext.log_level = DLT_LOG_DEFAULT; } else { /* Plausibility check */ - if ((usercontext.log_level < DLT_LOG_DEFAULT) || - (usercontext.log_level > DLT_LOG_VERBOSE)) { + if ((usercontext.log_level < DLT_LOG_DEFAULT) || (usercontext.log_level > DLT_LOG_VERBOSE)) { free(usercontext.apid); free(usercontext.ctid); free(buffer); @@ -4373,8 +3906,8 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, usercontext.trace_status = DLT_TRACE_STATUS_DEFAULT; } else { /* Plausibility check */ - if ((usercontext.trace_status < DLT_TRACE_STATUS_DEFAULT) || - (usercontext.trace_status > DLT_TRACE_STATUS_ON)) { + if ((usercontext.trace_status < DLT_TRACE_STATUS_DEFAULT) + || (usercontext.trace_status > DLT_TRACE_STATUS_ON)) { free(usercontext.apid); free(usercontext.ctid); free(buffer); @@ -4382,55 +3915,37 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, } } - context = dlt_daemon_context_add_v2(daemon, - usercontext.apidlen, - usercontext.apid, - usercontext.ctidlen, - usercontext.ctid, - usercontext.log_level, - usercontext.trace_status, - usercontext.log_level_pos, - application->user_handle, - description, - daemon->ecuid2len, - daemon->ecuid2, - verbose); + context = dlt_daemon_context_add_v2( + daemon, usercontext.apidlen, usercontext.apid, usercontext.ctidlen, usercontext.ctid, usercontext.log_level, + usercontext.trace_status, usercontext.log_level_pos, application->user_handle, description, + daemon->ecuid2len, daemon->ecuid2, verbose); if (context == NULL) { - dlt_vlog(LOG_WARNING, - "Can't add ContextID '%s' for ApID '%s'\n in %s", - usercontext.ctid, usercontext.apid, __func__); + dlt_vlog( + LOG_WARNING, "Can't add ContextID '%s' for ApID '%s'\n in %s", usercontext.ctid, usercontext.apid, + __func__); free(usercontext.apid); free(usercontext.ctid); free(buffer); return -1; - } - else { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; + } else { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "ContextID '%s' registered for ApID '%s', Description=%s", - context->ctid2, - context->apid2, - context->context_description); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "ContextID '%s' registered for ApID '%s', Description=%s", + context->ctid2, context->apid2, context->context_description); if (verbose) - dlt_daemon_log_internal(daemon, daemon_local, local_str, - DLT_LOG_INFO, DLT_DAEMON_APP_ID, - DLT_DAEMON_CTX_ID, verbose); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, verbose); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } if (daemon_local->flags.offlineLogstorageMaxDevices) { - //TBD: update for DLT V2 + // TBD: update for DLT V2 /* Store log level set for offline logstorage into context structure*/ - context->storage_log_level = - (int8_t) dlt_daemon_logstorage_get_loglevel(daemon, - (int8_t) daemon_local->flags.offlineLogstorageMaxDevices, - usercontext.apid, - usercontext.ctid); - } - else + context->storage_log_level = (int8_t)dlt_daemon_logstorage_get_loglevel( + daemon, (int8_t)daemon_local->flags.offlineLogstorageMaxDevices, usercontext.apid, usercontext.ctid); + } else context->storage_log_level = DLT_LOG_DEFAULT; /* Create automatic get log info response for registered context */ @@ -4441,10 +3956,8 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, return -1; } - msg.datasize = (int)(sizeof(uint32_t) + sizeof(uint8_t) + - sizeof(uint8_t) + usercontext.apidlen + - sizeof(uint8_t) + usercontext.ctidlen + - DLT_ID_SIZE); + msg.datasize = (int)(sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint8_t) + usercontext.apidlen + + sizeof(uint8_t) + usercontext.ctidlen + DLT_ID_SIZE); if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); @@ -4452,7 +3965,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } @@ -4468,7 +3981,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, char com_buf[DLT_ID_SIZE]; req_local.service_id = DLT_SERVICE_ID_GET_LOG_INFO; - req_local.options = (uint8_t) daemon_local->flags.autoResponseGetLogInfoOption; + req_local.options = (uint8_t)daemon_local->flags.autoResponseGetLogInfoOption; req_local.apidlen = usercontext.apidlen; req_local.ctidlen = usercontext.ctidlen; /* fill id buffers */ @@ -4502,10 +4015,9 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, if ((usercontext.log_level == DLT_LOG_DEFAULT) || (usercontext.trace_status == DLT_TRACE_STATUS_DEFAULT)) { /* This call also replaces the default values with the values defined for default */ if (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == -1) { - dlt_vlog(LOG_WARNING, "Can't send current log level as response to %s for (%s;%s)\n", - __func__, - context->apid, - context->ctid); + dlt_vlog( + LOG_WARNING, "Can't send current log level as response to %s for (%s;%s)\n", __func__, + context->apid, context->ctid); free(usercontext.apid); free(usercontext.ctid); free(buffer); @@ -4518,23 +4030,20 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, free(buffer); } else if (daemon->daemon_version == DLTProtocolV1) { DltMessage msg; - DltServiceGetLogInfoRequest *req = NULL; + DltServiceGetLogInfoRequest* req = NULL; memset(&userctxt, 0, sizeof(DltUserControlMsgRegisterContext)); origin = rec->buf; /* Adding temp variable to check the return value */ int temp = 0; - temp = dlt_receiver_check_and_get(rec, - &userctxt, - len, - DLT_RCV_SKIP_HEADER); + temp = dlt_receiver_check_and_get(rec, &userctxt, len, DLT_RCV_SKIP_HEADER); if (temp < 0) /* Not enough bytes received */ return -1; else { - to_remove = (uint32_t) temp; + to_remove = (uint32_t)temp; } len = userctxt.description_length; @@ -4553,33 +4062,28 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, memcpy(description, "Unknown", sizeof("Unknown")); /* unknown len of original description, set to 0 to not remove in next - * step. Because message buffer is re-adjusted the corrupted description - * is ignored. */ + * step. Because message buffer is re-adjusted the corrupted description + * is ignored. */ len = 0; } /* adjust to_remove */ - to_remove += (uint32_t) sizeof(DltUserHeader) + len; + to_remove += (uint32_t)sizeof(DltUserHeader) + len; /* point to begin of message */ rec->buf = origin; /* We can now remove data. */ - if (dlt_receiver_remove(rec, (int) to_remove) != DLT_RETURN_OK) { + if (dlt_receiver_remove(rec, (int)to_remove) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); return -1; } - application = dlt_daemon_application_find(daemon, - userctxt.apid, - daemon->ecuid, - verbose); + application = dlt_daemon_application_find(daemon, userctxt.apid, daemon->ecuid, verbose); if (application == 0) { - dlt_vlog(LOG_WARNING, - "ApID '%.4s' not found for new ContextID '%.4s' in %s\n", - userctxt.apid, - userctxt.ctid, - __func__); + dlt_vlog( + LOG_WARNING, "ApID '%.4s' not found for new ContextID '%.4s' in %s\n", userctxt.apid, userctxt.ctid, + __func__); return 0; } @@ -4589,8 +4093,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, userctxt.log_level = DLT_LOG_DEFAULT; } else { /* Plausibility check */ - if ((userctxt.log_level < DLT_LOG_DEFAULT) || - (userctxt.log_level > DLT_LOG_VERBOSE)) { + if ((userctxt.log_level < DLT_LOG_DEFAULT) || (userctxt.log_level > DLT_LOG_VERBOSE)) { return -1; } } @@ -4600,54 +4103,38 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, userctxt.trace_status = DLT_TRACE_STATUS_DEFAULT; } else { /* Plausibility check */ - if ((userctxt.trace_status < DLT_TRACE_STATUS_DEFAULT) || - (userctxt.trace_status > DLT_TRACE_STATUS_ON)) { + if ((userctxt.trace_status < DLT_TRACE_STATUS_DEFAULT) || (userctxt.trace_status > DLT_TRACE_STATUS_ON)) { return -1; } } - context = dlt_daemon_context_add(daemon, - userctxt.apid, - userctxt.ctid, - userctxt.log_level, - userctxt.trace_status, - userctxt.log_level_pos, - application->user_handle, - description, - daemon->ecuid, - verbose); + context = dlt_daemon_context_add( + daemon, userctxt.apid, userctxt.ctid, userctxt.log_level, userctxt.trace_status, userctxt.log_level_pos, + application->user_handle, description, daemon->ecuid, verbose); if (context == 0) { - dlt_vlog(LOG_WARNING, - "Can't add ContextID '%.4s' for ApID '%.4s'\n in %s", - userctxt.ctid, userctxt.apid, __func__); + dlt_vlog( + LOG_WARNING, "Can't add ContextID '%.4s' for ApID '%.4s'\n in %s", userctxt.ctid, userctxt.apid, + __func__); return -1; - } - else { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; + } else { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "ContextID '%.4s' registered for ApID '%.4s', Description=%s", - context->ctid, - context->apid, - context->context_description); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "ContextID '%.4s' registered for ApID '%.4s', Description=%s", + context->ctid, context->apid, context->context_description); if (verbose) - dlt_daemon_log_internal(daemon, daemon_local, local_str, - DLT_LOG_INFO, DLT_DAEMON_APP_ID, - DLT_DAEMON_CTX_ID, verbose); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, verbose); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } if (daemon_local->flags.offlineLogstorageMaxDevices) /* Store log level set for offline logstorage into context structure*/ - context->storage_log_level = - (int8_t) dlt_daemon_logstorage_get_loglevel(daemon, - (int8_t) daemon_local->flags.offlineLogstorageMaxDevices, - userctxt.apid, - userctxt.ctid); + context->storage_log_level = (int8_t)dlt_daemon_logstorage_get_loglevel( + daemon, (int8_t)daemon_local->flags.offlineLogstorageMaxDevices, userctxt.apid, userctxt.ctid); else context->storage_log_level = DLT_LOG_DEFAULT; @@ -4667,7 +4154,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } @@ -4676,10 +4163,10 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, return -1; } - req = (DltServiceGetLogInfoRequest *)msg.databuffer; + req = (DltServiceGetLogInfoRequest*)msg.databuffer; req->service_id = DLT_SERVICE_ID_GET_LOG_INFO; - req->options = (uint8_t) daemon_local->flags.autoResponseGetLogInfoOption; + req->options = (uint8_t)daemon_local->flags.autoResponseGetLogInfoOption; dlt_set_id(req->apid, userctxt.apid); dlt_set_id(req->ctid, userctxt.ctid); dlt_set_id(req->com, "remo"); @@ -4693,10 +4180,9 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, if ((userctxt.log_level == DLT_LOG_DEFAULT) || (userctxt.trace_status == DLT_TRACE_STATUS_DEFAULT)) { /* This call also replaces the default values with the values defined for default */ if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) { - dlt_vlog(LOG_WARNING, "Can't send current log level as response to %s for (%.4s;%.4s)\n", - __func__, - context->apid, - context->ctid); + dlt_vlog( + LOG_WARNING, "Can't send current log level as response to %s for (%.4s;%.4s)\n", __func__, + context->apid, context->ctid); return -1; } } @@ -4709,22 +4195,18 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, return 0; } -int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_unregister_application( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { - DltDaemonApplication *application = NULL; - DltDaemonContext *context; + DltDaemonApplication* application = NULL; + DltDaemonContext* context; int i, offset_base; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, - "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } @@ -4732,8 +4214,8 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, uint32_t len = sizeof(DltUserControlMsgUnregisterApplicationV2); DltUserControlMsgUnregisterApplicationV2 userapp; int userappSize; - uint8_t *buffer; - userapp.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer + uint8_t* buffer; + userapp.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer userapp.apid = NULL; userappSize = (int)sizeof(uint8_t) + userapp.apidlen + (int)sizeof(pid_t); len = (uint32_t)userappSize; @@ -4741,17 +4223,14 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, int offset = 0; - if (dlt_receiver_check_and_get(rec, - buffer, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, buffer, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return -1; memcpy(&(userapp.apidlen), buffer, 1); offset = 1; char apid_buf[DLT_V2_ID_SIZE]; - dlt_set_id_v2(apid_buf, (const char *)(buffer + offset), userapp.apidlen); + dlt_set_id_v2(apid_buf, (const char*)(buffer + offset), userapp.apidlen); userapp.apid = apid_buf; offset += userapp.apidlen; memcpy(&(userapp.pid), (buffer + offset), sizeof(pid_t)); @@ -4762,15 +4241,10 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, if (user_list->num_applications > 0) { /* Delete this application and all corresponding contexts - * for this application from internal table. - */ - dlt_daemon_application_find_v2(daemon, - userapp.apidlen, - userapp.apid, - daemon->ecuid2len, - daemon->ecuid2, - verbose, - &application); + * for this application from internal table. + */ + dlt_daemon_application_find_v2( + daemon, userapp.apidlen, userapp.apid, daemon->ecuid2len, daemon->ecuid2, verbose, &application); if (application != NULL) { /* Calculate start offset within contexts[] */ offset_base = 0; @@ -4780,41 +4254,25 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, context = &(user_list->contexts[offset_base + i]); if (context) { /* Delete context */ - if (dlt_daemon_context_del_v2(daemon, - context, - daemon->ecuid2len, - daemon->ecuid2, - verbose) == -1) { - dlt_vlog(LOG_WARNING, - "Can't delete CtID '%s' for ApID '%s' in %s\n", - context->ctid, - context->apid, - __func__); + if (dlt_daemon_context_del_v2(daemon, context, daemon->ecuid2len, daemon->ecuid2, verbose) + == -1) { + dlt_vlog( + LOG_WARNING, "Can't delete CtID '%s' for ApID '%s' in %s\n", context->ctid, + context->apid, __func__); return -1; } } } /* Delete this application entry from internal table*/ - if (dlt_daemon_application_del_v2(daemon, - application, - daemon->ecuid2len, - daemon->ecuid2, - verbose) == -1) { - dlt_vlog(LOG_WARNING, - "Can't delete ApID '%s' in %s\n", - application->apid, - __func__); + if (dlt_daemon_application_del_v2(daemon, application, daemon->ecuid2len, daemon->ecuid2, verbose) + == -1) { + dlt_vlog(LOG_WARNING, "Can't delete ApID '%s' in %s\n", application->apid, __func__); return -1; - } - else { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "Unregistered ApID '%s'", - userapp.apid); - dlt_daemon_log_internal(daemon, daemon_local, local_str, - DLT_LOG_INFO, DLT_DAEMON_APP_ID, - DLT_DAEMON_CTX_ID, verbose); + } else { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; + snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, "Unregistered ApID '%s'", userapp.apid); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, verbose); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } } @@ -4822,10 +4280,7 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, } else if (daemon->daemon_version == DLTProtocolV1) { uint32_t len = sizeof(DltUserControlMsgUnregisterApplication); DltUserControlMsgUnregisterApplication userapp; - if (dlt_receiver_check_and_get(rec, - &userapp, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, &userapp, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return -1; @@ -4836,12 +4291,9 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, if (user_list->num_applications > 0) { /* Delete this application and all corresponding contexts - * for this application from internal table. - */ - application = dlt_daemon_application_find(daemon, - userapp.apid, - daemon->ecuid, - verbose); + * for this application from internal table. + */ + application = dlt_daemon_application_find(daemon, userapp.apid, daemon->ecuid, verbose); if (application) { /* Calculate start offset within contexts[] */ @@ -4855,41 +4307,25 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, if (context) { /* Delete context */ - if (dlt_daemon_context_del(daemon, - context, - daemon->ecuid, - verbose) == -1) { - dlt_vlog(LOG_WARNING, - "Can't delete CtID '%.4s' for ApID '%.4s' in %s\n", - context->ctid, - context->apid, - __func__); + if (dlt_daemon_context_del(daemon, context, daemon->ecuid, verbose) == -1) { + dlt_vlog( + LOG_WARNING, "Can't delete CtID '%.4s' for ApID '%.4s' in %s\n", context->ctid, + context->apid, __func__); return -1; } } } /* Delete this application entry from internal table*/ - if (dlt_daemon_application_del(daemon, - application, - daemon->ecuid, - verbose) == -1) { - dlt_vlog(LOG_WARNING, - "Can't delete ApID '%.4s' in %s\n", - application->apid, - __func__); + if (dlt_daemon_application_del(daemon, application, daemon->ecuid, verbose) == -1) { + dlt_vlog(LOG_WARNING, "Can't delete ApID '%.4s' in %s\n", application->apid, __func__); return -1; - } - else { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; - - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "Unregistered ApID '%.4s'", - userapp.apid); - dlt_daemon_log_internal(daemon, daemon_local, local_str, - DLT_LOG_INFO, DLT_DAEMON_APP_ID, - DLT_DAEMON_CTX_ID, verbose); + } else { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; + + snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, "Unregistered ApID '%.4s'", userapp.apid); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, verbose); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } } @@ -4902,20 +4338,16 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, return 0; } -int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_unregister_context( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { DltUserControlMsgUnregisterContext userctxt; - DltDaemonContext *context; + DltDaemonContext* context; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, - "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } @@ -4924,74 +4356,62 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, uint32_t len = sizeof(DltUserControlMsgUnregisterContextV2); DltUserControlMsgUnregisterContextV2 usercontext; int usercontextSize; - uint8_t *buffer; + uint8_t* buffer; usercontext.apid = NULL; usercontext.ctid = NULL; - usercontext.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer - usercontext.ctidlen = (uint8_t)rec->buf[9 + usercontext.apidlen]; // TBD: write function to get ctidlen from received buffer - usercontextSize = (int)(sizeof(uint8_t) + usercontext.apidlen + - sizeof(uint8_t) + usercontext.ctidlen + sizeof(pid_t)); + usercontext.apidlen = (uint8_t)rec->buf[8]; // TBD: write function to get apidlen from received buffer + usercontext.ctidlen = + (uint8_t)rec->buf[9 + usercontext.apidlen]; // TBD: write function to get ctidlen from received buffer + usercontextSize = + (int)(sizeof(uint8_t) + usercontext.apidlen + sizeof(uint8_t) + usercontext.ctidlen + sizeof(pid_t)); len = (uint32_t)usercontextSize; buffer = (uint8_t*)malloc((size_t)usercontextSize); int offset = 0; - if (dlt_receiver_check_and_get(rec, - buffer, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0){ + if (dlt_receiver_check_and_get(rec, buffer, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) { /* Not enough bytes received */ return -1; } memcpy(&(usercontext.apidlen), buffer, 1); offset = 1; - dlt_set_id_v2(usercontext.apid, (const char *)(buffer + offset), usercontext.apidlen); + dlt_set_id_v2(usercontext.apid, (const char*)(buffer + offset), usercontext.apidlen); offset += usercontext.apidlen; memcpy(&(usercontext.ctidlen), (buffer + offset), 1); offset += 1; - dlt_set_id_v2(usercontext.ctid, (const char *)(buffer + offset), usercontext.ctidlen); + dlt_set_id_v2(usercontext.ctid, (const char*)(buffer + offset), usercontext.ctidlen); offset += usercontext.ctidlen; memcpy(&(usercontext.pid), (buffer + offset), sizeof(pid_t)); offset += (int)sizeof(pid_t); - context = dlt_daemon_context_find_v2(daemon, - usercontext.apidlen, - usercontext.apid, - usercontext.ctidlen, - usercontext.ctid, - daemon->ecuid2len, - daemon->ecuid2, - verbose); + context = dlt_daemon_context_find_v2( + daemon, usercontext.apidlen, usercontext.apid, usercontext.ctidlen, usercontext.ctid, daemon->ecuid2len, + daemon->ecuid2, verbose); /* In case the daemon is loaded with predefined contexts and its context - * unregisters, the context information will not be deleted from daemon's - * table until its parent application is unregistered. - */ + * unregisters, the context information will not be deleted from daemon's + * table until its parent application is unregistered. + */ if (context && (context->predefined == false)) { /* Delete this connection entry from internal table*/ if (dlt_daemon_context_del_v2(daemon, context, daemon->ecuid2len, daemon->ecuid2, verbose) == -1) { - dlt_vlog(LOG_WARNING, - "Can't delete CtID '%s' for ApID '%s' in %s\n", - usercontext.ctid ? usercontext.ctid : "", - usercontext.apid ? usercontext.apid : "", - __func__); + dlt_vlog( + LOG_WARNING, "Can't delete CtID '%s' for ApID '%s' in %s\n", + usercontext.ctid ? usercontext.ctid : "", usercontext.apid ? usercontext.apid : "", + __func__); return -1; - } - else { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; - - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "Unregistered CtID '%s' for ApID '%s'", - usercontext.ctid ? usercontext.ctid : "", - usercontext.apid ? usercontext.apid : ""); - - if (verbose){ - dlt_daemon_log_internal(daemon, daemon_local, local_str, - DLT_LOG_INFO, DLT_DAEMON_APP_ID, - DLT_DAEMON_CTX_ID, verbose); + } else { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; + + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "Unregistered CtID '%s' for ApID '%s'", + usercontext.ctid ? usercontext.ctid : "", usercontext.apid ? usercontext.apid : ""); + + if (verbose) { + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, verbose); } dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); @@ -5000,58 +4420,38 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, /* Create automatic unregister context response for unregistered context */ if (daemon_local->flags.rflag) - dlt_daemon_control_message_unregister_context_v2(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - usercontext.apidlen, - usercontext.apid, - usercontext.ctidlen, - usercontext.ctid, - "remo", - verbose); - } - else if (daemon->daemon_version == DLTProtocolV1) { + dlt_daemon_control_message_unregister_context_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, usercontext.apidlen, usercontext.apid, + usercontext.ctidlen, usercontext.ctid, "remo", verbose); + } else if (daemon->daemon_version == DLTProtocolV1) { uint32_t len = sizeof(DltUserControlMsgUnregisterContext); - if (dlt_receiver_check_and_get(rec, - &userctxt, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, &userctxt, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return -1; - context = dlt_daemon_context_find(daemon, - userctxt.apid, - userctxt.ctid, - daemon->ecuid, - verbose); + context = dlt_daemon_context_find(daemon, userctxt.apid, userctxt.ctid, daemon->ecuid, verbose); /* In case the daemon is loaded with predefined contexts and its context - * unregisters, the context information will not be deleted from daemon's - * table until its parent application is unregistered. - */ + * unregisters, the context information will not be deleted from daemon's + * table until its parent application is unregistered. + */ if (context && (context->predefined == false)) { /* Delete this connection entry from internal table*/ if (dlt_daemon_context_del(daemon, context, daemon->ecuid, verbose) == -1) { - dlt_vlog(LOG_WARNING, - "Can't delete CtID '%.4s' for ApID '%.4s' in %s\n", - userctxt.ctid, - userctxt.apid, - __func__); + dlt_vlog( + LOG_WARNING, "Can't delete CtID '%.4s' for ApID '%.4s' in %s\n", userctxt.ctid, userctxt.apid, + __func__); return -1; - } - else { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; + } else { + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; - snprintf(local_str, - DLT_DAEMON_TEXTBUFSIZE, - "Unregistered CtID '%.4s' for ApID '%.4s'", - userctxt.ctid, - userctxt.apid); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "Unregistered CtID '%.4s' for ApID '%.4s'", userctxt.ctid, + userctxt.apid); if (verbose) - dlt_daemon_log_internal(daemon, daemon_local, local_str, - DLT_LOG_INFO, DLT_DAEMON_APP_ID, - DLT_DAEMON_CTX_ID, verbose); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, verbose); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); } @@ -5059,13 +4459,8 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, /* Create automatic unregister context response for unregistered context */ if (daemon_local->flags.rflag) - dlt_daemon_control_message_unregister_context(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - userctxt.apid, - userctxt.ctid, - "remo", - verbose); + dlt_daemon_control_message_unregister_context( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, userctxt.apid, userctxt.ctid, "remo", verbose); } else { dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__); return -1; @@ -5073,10 +4468,7 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, return 0; } -int dlt_daemon_process_user_message_log(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_log(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { int ret = 0; int size = 0; @@ -5110,15 +4502,12 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, } #endif /* get log message from SHM then store into receiver buffer */ - size = dlt_shm_pull(&(daemon_local->dlt_shm), - daemon_local->recv_buf_shm, - DLT_SHM_RCV_BUFFER_SIZE); + size = dlt_shm_pull(&(daemon_local->dlt_shm), daemon_local->recv_buf_shm, DLT_SHM_RCV_BUFFER_SIZE); if (size <= 0) break; - ret = dlt_message_read(&(daemon_local->msg), - daemon_local->recv_buf_shm, size, 0, verbose); + ret = dlt_message_read(&(daemon_local->msg), daemon_local->recv_buf_shm, size, 0, verbose); if (DLT_MESSAGE_ERROR_OK != ret) { dlt_shm_remove(&(daemon_local->dlt_shm)); @@ -5127,15 +4516,16 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, } #if defined(DLT_LOG_LEVEL_APP_CONFIG) || defined(DLT_TRACE_LOAD_CTRL_ENABLE) - DltDaemonApplication *app = dlt_daemon_application_find( - daemon, daemon_local->msg.extendedheader->apid, daemon->ecuid, verbose); + DltDaemonApplication* app = + dlt_daemon_application_find(daemon, daemon_local->msg.extendedheader->apid, daemon->ecuid, verbose); #endif /* discard non-allowed levels if enforcement is on */ keep_message = enforce_context_ll_and_ts_keep_message( daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - , app + , + app #endif ); @@ -5145,7 +4535,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, #endif if (keep_message) - dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose); + dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose); if (DLT_DAEMON_ERROR_OK != ret) dlt_log(LOG_ERR, "failed to send message to client.\n"); @@ -5153,111 +4543,104 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, #else /* DLT_SHM_ENABLE */ if (daemon->daemon_version == DLTProtocolV2) { - ret = dlt_message_read_v2(&(daemon_local->msgv2), - (unsigned char *)rec->buf + sizeof(DltUserHeader), - (unsigned int) ((unsigned int) rec->bytesRcvd - sizeof(DltUserHeader)), - 0, - verbose); + ret = dlt_message_read_v2( + &(daemon_local->msgv2), (unsigned char*)rec->buf + sizeof(DltUserHeader), + (unsigned int)((unsigned int)rec->bytesRcvd - sizeof(DltUserHeader)), 0, verbose); if (ret != DLT_MESSAGE_ERROR_OK) { if (ret != DLT_MESSAGE_ERROR_SIZE) /* This is a normal usecase: The daemon reads the data in 10kb chunks. - * Thus the last trace in this chunk is probably not complete and will be completed - * with the next chunk read. This happens always when the FIFO is filled with more than 10kb before - * the daemon is able to read from the FIFO. - * Thus the loglevel of this message is set to DEBUG. - * A cleaner solution would be to check more in detail whether the message is not complete (normal usecase) - * or the headers are corrupted (error case). */ + * Thus the last trace in this chunk is probably not complete and will be completed + * with the next chunk read. This happens always when the FIFO is filled with more than 10kb before + * the daemon is able to read from the FIFO. + * Thus the loglevel of this message is set to DEBUG. + * A cleaner solution would be to check more in detail whether the message is not complete (normal + * usecase) or the headers are corrupted (error case). */ dlt_log(LOG_DEBUG, "Can't read messages from receiver\n"); return DLT_DAEMON_ERROR_UNKNOWN; } #if defined(DLT_LOG_LEVEL_APP_CONFIG) || defined(DLT_TRACE_LOAD_CTRL_ENABLE) - DltDaemonApplication *app = (DltDaemonApplication *)malloc(sizeof(DltDaemonApplication)); + DltDaemonApplication* app = (DltDaemonApplication*)malloc(sizeof(DltDaemonApplication)); dlt_daemon_application_find_v2( - daemon, daemon_local->msgv2.extendedheaderv2->apidlen, - daemon_local->msgv2.extendedheaderv2->apid, daemon->ecuid2len, daemon->ecuid2, verbose, &app); + daemon, daemon_local->msgv2.extendedheaderv2->apidlen, daemon_local->msgv2.extendedheaderv2->apid, + daemon->ecuid2len, daemon->ecuid2, verbose, &app); #endif /* discard non-allowed levels if enforcement is on */ keep_message = enforce_context_ll_and_ts_keep_message_v2( daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - , app + , + app #endif ); // check trace_load #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - keep_message &= - trace_load_keep_message_v2(app, size, daemon, daemon_local, verbose); + keep_message &= trace_load_keep_message_v2(app, size, daemon, daemon_local, verbose); #endif - if (keep_message){ + if (keep_message) { dlt_daemon_client_send_message_to_all_client_v2(daemon, daemon_local, verbose); } /* keep not read data in buffer */ - size = (int) (daemon_local->msgv2.headersizev2 + - daemon_local->msgv2.datasize + - (int32_t)sizeof(DltUserHeader) - - (int32_t) daemon_local->msgv2.storageheadersizev2); + size = (int)(daemon_local->msgv2.headersizev2 + daemon_local->msgv2.datasize + (int32_t)sizeof(DltUserHeader) + - (int32_t)daemon_local->msgv2.storageheadersizev2); if (daemon_local->msgv2.found_serialheader) - size += (int) sizeof(dltSerialHeader); + size += (int)sizeof(dltSerialHeader); if (dlt_receiver_remove(rec, size) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "failed to remove bytes from receiver.\n"); return DLT_DAEMON_ERROR_UNKNOWN; } } else if (daemon->daemon_version == DLTProtocolV1) { - ret = dlt_message_read(&(daemon_local->msg), - (unsigned char *)rec->buf + sizeof(DltUserHeader), - (unsigned int) ((unsigned int) rec->bytesRcvd - sizeof(DltUserHeader)), - 0, - verbose); + ret = dlt_message_read( + &(daemon_local->msg), (unsigned char*)rec->buf + sizeof(DltUserHeader), + (unsigned int)((unsigned int)rec->bytesRcvd - sizeof(DltUserHeader)), 0, verbose); if (ret != DLT_MESSAGE_ERROR_OK) { if (ret != DLT_MESSAGE_ERROR_SIZE) /* This is a normal usecase: The daemon reads the data in 10kb chunks. - * Thus the last trace in this chunk is probably not complete and will be completed - * with the next chunk read. This happens always when the FIFO is filled with more than 10kb before - * the daemon is able to read from the FIFO. - * Thus the loglevel of this message is set to DEBUG. - * A cleaner solution would be to check more in detail whether the message is not complete (normal usecase) - * or the headers are corrupted (error case). */ + * Thus the last trace in this chunk is probably not complete and will be completed + * with the next chunk read. This happens always when the FIFO is filled with more than 10kb before + * the daemon is able to read from the FIFO. + * Thus the loglevel of this message is set to DEBUG. + * A cleaner solution would be to check more in detail whether the message is not complete (normal + * usecase) or the headers are corrupted (error case). */ dlt_log(LOG_DEBUG, "Can't read messages from receiver\n"); return DLT_DAEMON_ERROR_UNKNOWN; } #if defined(DLT_LOG_LEVEL_APP_CONFIG) || defined(DLT_TRACE_LOAD_CTRL_ENABLE) - DltDaemonApplication *app = dlt_daemon_application_find( - daemon, daemon_local->msg.extendedheader->apid, daemon->ecuid, verbose); + DltDaemonApplication* app = + dlt_daemon_application_find(daemon, daemon_local->msg.extendedheader->apid, daemon->ecuid, verbose); #endif /* discard non-allowed levels if enforcement is on */ keep_message = enforce_context_ll_and_ts_keep_message( daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - , app + , + app #endif ); // check trace_load #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - keep_message &= - trace_load_keep_message(app, size, daemon, daemon_local, verbose); + keep_message &= trace_load_keep_message(app, size, daemon, daemon_local, verbose); #endif - if (keep_message){ + if (keep_message) { dlt_daemon_client_send_message_to_all_client(daemon, daemon_local, verbose); } /* keep not read data in buffer */ - size = (int) ((size_t)daemon_local->msg.headersize + - (size_t)daemon_local->msg.datasize - sizeof(DltStorageHeader) + - sizeof(DltUserHeader)); + size = (int)((size_t)daemon_local->msg.headersize + (size_t)daemon_local->msg.datasize + - sizeof(DltStorageHeader) + sizeof(DltUserHeader)); if (daemon_local->msg.found_serialheader) - size += (int) sizeof(dltSerialHeader); + size += (int)sizeof(dltSerialHeader); if (dlt_receiver_remove(rec, size) != DLT_RETURN_OK) { dlt_log(LOG_WARNING, "failed to remove bytes from receiver.\n"); @@ -5272,14 +4655,15 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, return DLT_DAEMON_ERROR_OK; } -bool enforce_context_ll_and_ts_keep_message(DltDaemonLocal *daemon_local +bool enforce_context_ll_and_ts_keep_message( + DltDaemonLocal* daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - , DltDaemonApplication *app + , + DltDaemonApplication* app #endif ) { - if (!daemon_local->flags.enforceContextLLAndTS || - !daemon_local->msg.extendedheader) { + if (!daemon_local->flags.enforceContextLLAndTS || !daemon_local->msg.extendedheader) { return true; } @@ -5292,7 +4676,7 @@ bool enforce_context_ll_and_ts_keep_message(DltDaemonLocal *daemon_local const int mtin = DLT_GET_MSIN_MTIN(daemon_local->msg.extendedheader->msin); #ifdef DLT_LOG_LEVEL_APP_CONFIG if (app->num_context_log_level_settings > 0) { - DltDaemonContextLogSettings *log_settings = + DltDaemonContextLogSettings* log_settings = dlt_daemon_find_app_log_level_config(app, daemon_local->msg.extendedheader->ctid); if (log_settings != NULL) { @@ -5303,9 +4687,11 @@ bool enforce_context_ll_and_ts_keep_message(DltDaemonLocal *daemon_local return mtin <= daemon_local->flags.contextLogLevel; } -bool enforce_context_ll_and_ts_keep_message_v2(DltDaemonLocal *daemon_local +bool enforce_context_ll_and_ts_keep_message_v2( + DltDaemonLocal* daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - , DltDaemonApplication *app + , + DltDaemonApplication* app #endif ) { @@ -5323,7 +4709,7 @@ bool enforce_context_ll_and_ts_keep_message_v2(DltDaemonLocal *daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG if (app->num_context_log_level_settings > 0) { /* TODO: Call dlt_daemon_find_app_log_level_config_v2 for DLTv2 */ - DltDaemonContextLogSettings *log_settings = + DltDaemonContextLogSettings* log_settings = dlt_daemon_find_app_log_level_config(app, daemon_local->msgv2.extendedheaderv2->ctid); if (log_settings != NULL) { @@ -5336,10 +4722,8 @@ bool enforce_context_ll_and_ts_keep_message_v2(DltDaemonLocal *daemon_local #ifdef DLT_TRACE_LOAD_CTRL_ENABLE -bool trace_load_keep_message(DltDaemonApplication *app, - const int size, DltDaemon *const daemon, - DltDaemonLocal *const daemon_local, - int verbose) +bool trace_load_keep_message( + DltDaemonApplication* app, const int size, DltDaemon* const daemon, DltDaemonLocal* const daemon_local, int verbose) { bool keep_message = true; if (app == NULL || !daemon_local->msg.extendedheader) { @@ -5356,63 +4740,47 @@ bool trace_load_keep_message(DltDaemonApplication *app, app->apid, }; - DltDaemonContext *context = dlt_daemon_context_find( - daemon, - app->apid, - msg->extendedheader->ctid, - daemon->ecuid, - verbose); + DltDaemonContext* context = + dlt_daemon_context_find(daemon, app->apid, msg->extendedheader->ctid, daemon->ecuid, verbose); if (context == NULL) { context = dlt_daemon_context_add( - daemon, - app->apid, - msg->extendedheader->ctid, - daemon->default_log_level, - daemon->default_trace_status, - 0, - app->user_handle, - "", - daemon->ecuid, - verbose); + daemon, app->apid, msg->extendedheader->ctid, daemon->default_log_level, daemon->default_trace_status, 0, + app->user_handle, "", daemon->ecuid, verbose); if (context == NULL) { - dlt_vlog(LOG_WARNING, - "Can't add ContextID '%.4s' for ApID '%.4s' in %s\n", - msg->extendedheader->ctid, app->apid, __func__); + dlt_vlog( + LOG_WARNING, "Can't add ContextID '%.4s' for ApID '%.4s' in %s\n", msg->extendedheader->ctid, app->apid, + __func__); return false; } } pthread_rwlock_wrlock(&trace_load_rw_lock); keep_message = dlt_check_trace_load( - context->trace_load_settings, mtin, msg->headerextra.tmsp, size, - dlt_daemon_output_internal_msg, (void *)(¶ms)); + context->trace_load_settings, mtin, msg->headerextra.tmsp, size, dlt_daemon_output_internal_msg, + (void*)(¶ms)); pthread_rwlock_unlock(&trace_load_rw_lock); return keep_message; } #endif -int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_set_app_ll_ts( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { uint32_t len = sizeof(DltUserControlMsgAppLogLevelTraceStatus); DltUserControlMsgAppLogLevelTraceStatus userctxt; - DltDaemonApplication *application; - DltDaemonContext *context; + DltDaemonApplication* application; + DltDaemonContext* context; int i, offset_base; int8_t old_log_level, old_trace_status; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, - "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return DLT_RETURN_ERROR; } @@ -5423,19 +4791,13 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, memset(&userctxt, 0, len); - if (dlt_receiver_check_and_get(rec, - &userctxt, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, &userctxt, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return DLT_RETURN_ERROR; if (user_list->num_applications > 0) { /* Get all contexts with application id matching the received application id */ - application = dlt_daemon_application_find(daemon, - userctxt.apid, - daemon->ecuid, - verbose); + application = dlt_daemon_application_find(daemon, userctxt.apid, daemon->ecuid, verbose); if (application) { /* Calculate start offset within contexts[] */ @@ -5449,16 +4811,14 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, if (context) { old_log_level = context->log_level; - context->log_level = (int8_t) userctxt.log_level; /* No endianess conversion necessary*/ + context->log_level = (int8_t)userctxt.log_level; /* No endianess conversion necessary*/ old_trace_status = context->trace_status; - context->trace_status = (int8_t) userctxt.trace_status; /* No endianess conversion necessary */ + context->trace_status = (int8_t)userctxt.trace_status; /* No endianess conversion necessary */ /* The following function sends also the trace status */ - if ((context->user_handle >= DLT_FD_MINIMUM) && - (dlt_daemon_user_send_log_level(daemon, - context, - verbose) != 0)) { + if ((context->user_handle >= DLT_FD_MINIMUM) + && (dlt_daemon_user_send_log_level(daemon, context, verbose) != 0)) { context->log_level = old_log_level; context->trace_status = old_trace_status; } @@ -5470,10 +4830,8 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, return DLT_RETURN_OK; } -int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_log_mode( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { DltUserControlMsgLogMode userctxt; uint32_t len = sizeof(DltUserControlMsgLogMode); @@ -5487,10 +4845,7 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, memset(&userctxt, 0, len); - if (dlt_receiver_check_and_get(rec, - &userctxt, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, &userctxt, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return -1; @@ -5503,27 +4858,21 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, return 0; } -int dlt_daemon_process_user_message_marker(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose) +int dlt_daemon_process_user_message_marker( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose) { uint32_t len = sizeof(DltUserControlMsgLogMode); DltUserControlMsgLogMode userctxt; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (rec == NULL)) { - dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", - __func__); + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return -1; } memset(&userctxt, 0, len); - if (dlt_receiver_check_and_get(rec, - &userctxt, - len, - DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) + if (dlt_receiver_check_and_get(rec, &userctxt, len, DLT_RCV_SKIP_HEADER | DLT_RCV_REMOVE) < 0) /* Not enough bytes received */ return -1; @@ -5533,7 +4882,7 @@ int dlt_daemon_process_user_message_marker(DltDaemon *daemon, return 0; } -int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_send_ringbuffer_to_client(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { int ret; static uint8_t data[DLT_DAEMON_RCVBUFSIZE]; @@ -5556,9 +4905,8 @@ int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daem dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); #endif - if ((ret = - dlt_daemon_client_send(DLT_DAEMON_SEND_FORCE, daemon, daemon_local, 0, 0, data, length, 0, 0, - verbose))) + if ((ret = dlt_daemon_client_send( + DLT_DAEMON_SEND_FORCE, daemon, daemon_local, 0, 0, data, length, 0, 0, verbose))) return ret; dlt_buffer_remove(&(daemon->client_ringbuffer)); @@ -5575,7 +4923,7 @@ int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daem return DLT_DAEMON_ERROR_OK; } -int dlt_daemon_send_ringbuffer_to_client_v2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_send_ringbuffer_to_client_v2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { int ret; static uint8_t data[DLT_DAEMON_RCVBUFSIZE]; @@ -5598,9 +4946,8 @@ int dlt_daemon_send_ringbuffer_to_client_v2(DltDaemon *daemon, DltDaemonLocal *d dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); #endif - if ((ret = - dlt_daemon_client_send_v2(DLT_DAEMON_SEND_FORCE, daemon, daemon_local, 0, 0, data, length, 0, 0, - verbose))) + if ((ret = dlt_daemon_client_send_v2( + DLT_DAEMON_SEND_FORCE, daemon, daemon_local, 0, 0, data, length, 0, 0, verbose))) return ret; dlt_buffer_remove(&(daemon->client_ringbuffer)); @@ -5618,56 +4965,59 @@ int dlt_daemon_send_ringbuffer_to_client_v2(DltDaemon *daemon, DltDaemonLocal *d } #ifdef __QNX__ -static void *timer_thread(void *data) +static void* timer_thread(void* data) { int pexit = 0; unsigned int sleep_ret = 0; - DltDaemonPeriodicData* timer_thread_data = (DltDaemonPeriodicData*) data; + DltDaemonPeriodicData* timer_thread_data = (DltDaemonPeriodicData*)data; /* Timer will start in starts_in sec*/ if ((sleep_ret = sleep(timer_thread_data->starts_in))) { - dlt_vlog(LOG_NOTICE, "Sleep remains [%u] for starting!" - "Stop thread of timer [%d]\n", - sleep_ret, timer_thread_data->timer_id); - close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); - return NULL; + dlt_vlog( + LOG_NOTICE, + "Sleep remains [%u] for starting!" + "Stop thread of timer [%d]\n", + sleep_ret, timer_thread_data->timer_id); + close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); + return NULL; } while (1) { - if ((dlt_timer_pipes[timer_thread_data->timer_id][1] > 0) && - (0 > write(dlt_timer_pipes[timer_thread_data->timer_id][1], "1", 1))) { - dlt_vlog(LOG_ERR, "Failed to send notification for timer [%s]!\n", - dlt_timer_names[timer_thread_data->timer_id]); + if ((dlt_timer_pipes[timer_thread_data->timer_id][1] > 0) + && (0 > write(dlt_timer_pipes[timer_thread_data->timer_id][1], "1", 1))) { + dlt_vlog( + LOG_ERR, "Failed to send notification for timer [%s]!\n", dlt_timer_names[timer_thread_data->timer_id]); pexit = 1; } if (pexit || g_exit) { - dlt_vlog(LOG_NOTICE, "Received signal!" - "Stop thread of timer [%d]\n", - timer_thread_data->timer_id); + dlt_vlog( + LOG_NOTICE, + "Received signal!" + "Stop thread of timer [%d]\n", + timer_thread_data->timer_id); close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); return NULL; } if ((sleep_ret = sleep(timer_thread_data->period_sec))) { - dlt_vlog(LOG_NOTICE, "Sleep remains [%u] for interval!" - "Stop thread of timer [%d]\n", - sleep_ret, timer_thread_data->timer_id); - close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); - return NULL; + dlt_vlog( + LOG_NOTICE, + "Sleep remains [%u] for interval!" + "Stop thread of timer [%d]\n", + sleep_ret, timer_thread_data->timer_id); + close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]); + return NULL; } } } #endif -int create_timer_fd(DltDaemonLocal *daemon_local, - unsigned int period_sec, - unsigned int starts_in, - DltTimers timer_id) +int create_timer_fd(DltDaemonLocal* daemon_local, unsigned int period_sec, unsigned int starts_in, DltTimers timer_id) { int local_fd = DLT_FD_INIT; - char *timer_name = NULL; + char* timer_name = NULL; if (timer_id >= DLT_TIMER_UNKNOWN) { dlt_log(DLT_LOG_ERROR, "Unknown timer."); @@ -5685,24 +5035,21 @@ int create_timer_fd(DltDaemonLocal *daemon_local, /* timer not activated via the service file */ dlt_vlog(LOG_INFO, "<%s> not set: period=0\n", timer_name); local_fd = DLT_FD_INIT; - } - else { + } else { #ifdef linux struct itimerspec l_timer_spec; local_fd = timerfd_create(CLOCK_MONOTONIC, 0); if (local_fd < 0) - dlt_vlog(LOG_WARNING, "<%s> timerfd_create failed: %s\n", - timer_name, strerror(errno)); + dlt_vlog(LOG_WARNING, "<%s> timerfd_create failed: %s\n", timer_name, strerror(errno)); - l_timer_spec.it_interval.tv_sec = (long int) period_sec; - l_timer_spec.it_interval.tv_nsec = (long int) 0; - l_timer_spec.it_value.tv_sec = (long int) starts_in; - l_timer_spec.it_value.tv_nsec = (long int) 0; + l_timer_spec.it_interval.tv_sec = (long int)period_sec; + l_timer_spec.it_interval.tv_nsec = (long int)0; + l_timer_spec.it_value.tv_sec = (long int)starts_in; + l_timer_spec.it_value.tv_nsec = (long int)0; if (timerfd_settime(local_fd, 0, &l_timer_spec, NULL) < 0) { - dlt_vlog(LOG_WARNING, "<%s> timerfd_settime failed: %s\n", - timer_name, strerror(errno)); + dlt_vlog(LOG_WARNING, "<%s> timerfd_settime failed: %s\n", timer_name, strerror(errno)); local_fd = DLT_FD_INIT; } #elif defined(__QNX__) @@ -5710,16 +5057,14 @@ int create_timer_fd(DltDaemonLocal *daemon_local, * Since timerfd is not valid in QNX, new threads are introduced * to manage timers and communicate with main thread when timer expires. */ - if(0 != pipe(dlt_timer_pipes[timer_id])) { - dlt_vlog(LOG_ERR, "Failed to create pipe for timer [%s]", - dlt_timer_names[timer_id]); + if (0 != pipe(dlt_timer_pipes[timer_id])) { + dlt_vlog(LOG_ERR, "Failed to create pipe for timer [%s]", dlt_timer_names[timer_id]); return -1; } if (NULL == timer_data[timer_id]) { timer_data[timer_id] = calloc(1, sizeof(DltDaemonPeriodicData)); if (NULL == timer_data[timer_id]) { - dlt_vlog(LOG_ERR, "Failed to allocate memory for timer_data [%s]!\n", - dlt_timer_names[timer_id]); + dlt_vlog(LOG_ERR, "Failed to allocate memory for timer_data [%s]!\n", dlt_timer_names[timer_id]); close_pipes(dlt_timer_pipes[timer_id]); return -1; } @@ -5730,10 +5075,8 @@ int create_timer_fd(DltDaemonLocal *daemon_local, timer_data[timer_id]->starts_in = starts_in; timer_data[timer_id]->wakeups_missed = 0; - if (0 != pthread_create(&timer_threads[timer_id], NULL, - &timer_thread, (void*)timer_data[timer_id])) { - dlt_vlog(LOG_ERR, "Failed to create new thread for timer [%s]!\n", - dlt_timer_names[timer_id]); + if (0 != pthread_create(&timer_threads[timer_id], NULL, &timer_thread, (void*)timer_data[timer_id])) { + dlt_vlog(LOG_ERR, "Failed to create new thread for timer [%s]!\n", dlt_timer_names[timer_id]); /* Clean up timer before returning */ close_pipes(dlt_timer_pipes[timer_id]); free(timer_data[timer_id]); @@ -5745,17 +5088,13 @@ int create_timer_fd(DltDaemonLocal *daemon_local, #endif } - return dlt_connection_create(daemon_local, - &daemon_local->pEvent, - local_fd, - POLLIN, - dlt_timer_conn_types[timer_id]); + return dlt_connection_create(daemon_local, &daemon_local->pEvent, local_fd, POLLIN, dlt_timer_conn_types[timer_id]); } /* Close connection function */ -int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_close_socket(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { - char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' }; + char local_str[DLT_DAEMON_TEXTBUFSIZE] = {'\0'}; PRINT_FUNCTION_VERBOSE(verbose); @@ -5765,9 +5104,7 @@ int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_ } /* Closure is done while unregistering has for any connection */ - dlt_event_handler_unregister_connection(&daemon_local->pEvent, - daemon_local, - sock); + dlt_event_handler_unregister_connection(&daemon_local->pEvent, daemon_local, sock); if (daemon_local->client_connections == 0) { /* send new log state to all applications */ @@ -5790,31 +5127,21 @@ int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_ } if (daemon->daemon_version == DLTProtocolV2) { - dlt_daemon_control_message_connection_info_v2(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - DLT_CONNECTION_STATUS_DISCONNECTED, - "", - verbose); + dlt_daemon_control_message_connection_info_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, DLT_CONNECTION_STATUS_DISCONNECTED, "", verbose); } else if (daemon->daemon_version == DLTProtocolV1) { - dlt_daemon_control_message_connection_info(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - DLT_CONNECTION_STATUS_DISCONNECTED, - "", - verbose); + dlt_daemon_control_message_connection_info( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, DLT_CONNECTION_STATUS_DISCONNECTED, "", verbose); } else { dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__); return -1; } - snprintf(local_str, DLT_DAEMON_TEXTBUFSIZE, - "Client connection #%d closed. Total Clients : %d", - sock, - daemon_local->client_connections); - dlt_daemon_log_internal(daemon, daemon_local, local_str, DLT_LOG_INFO, - DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, - daemon_local->flags.vflag); + snprintf( + local_str, DLT_DAEMON_TEXTBUFSIZE, "Client connection #%d closed. Total Clients : %d", sock, + daemon_local->client_connections); + dlt_daemon_log_internal( + daemon, daemon_local, local_str, DLT_LOG_INFO, DLT_DAEMON_APP_ID, DLT_DAEMON_CTX_ID, daemon_local->flags.vflag); dlt_vlog(LOG_DEBUG, "%s%s", local_str, "\n"); return 0; @@ -5823,11 +5150,12 @@ int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE static DltReturnValue dlt_daemon_output_internal_msg( - const DltLogLevelType loglevel, const char *const text, void* const params) { + const DltLogLevelType loglevel, const char* const text, void* const params) +{ struct DltTraceLoadLogParams* log_params = (struct DltTraceLoadLogParams*)params; return dlt_daemon_log_internal( - log_params->daemon, log_params->daemon_local, (char *)text, loglevel, - log_params->app_id, DLT_TRACE_LOAD_CONTEXT_ID, log_params->verbose); + log_params->daemon, log_params->daemon_local, (char*)text, loglevel, log_params->app_id, + DLT_TRACE_LOAD_CONTEXT_ID, log_params->verbose); } #endif diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index c1e62fbfb..8f9162137 100644 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -87,134 +87,144 @@ /** * The flags of a dlt daemon. */ -typedef struct -{ - int aflag; /**< (Boolean) Print DLT messages; payload as ASCII */ - int sflag; /**< (Boolean) Print DLT messages; payload as hex */ - int xflag; /**< (Boolean) Print DLT messages; only headers */ - int vflag; /**< (Boolean) Verbose mode */ - int dflag; /**< (Boolean) Daemonize */ - int lflag; /**< (Boolean) Send DLT messages with serial header */ - int rflag; /**< (Boolean) Send automatic get log info response during context registration */ - int mflag; /**< (Boolean) Sync to serial header on serial connection */ - int nflag; /**< (Boolean) Sync to serial header on all TCP connections */ - char evalue[NAME_MAX + 1]; /**< (String: ECU ID) Set ECU ID (Default: ECU1) */ - char bvalue[NAME_MAX + 1]; /**< (String: Baudrate) Serial device baudrate (Default: 115200) */ - char yvalue[NAME_MAX + 1]; /**< (String: Devicename) Additional support for serial device */ - char ivalue[NAME_MAX + 1]; /**< (String: Directory) Directory where to store the persistant configuration (Default: /tmp) */ - char cvalue[NAME_MAX + 1]; /**< (String: Directory) Filename of DLT configuration file (Default: /etc/dlt.conf) */ +typedef struct { + int aflag; /**< (Boolean) Print DLT messages; payload as ASCII */ + int sflag; /**< (Boolean) Print DLT messages; payload as hex */ + int xflag; /**< (Boolean) Print DLT messages; only headers */ + int vflag; /**< (Boolean) Verbose mode */ + int dflag; /**< (Boolean) Daemonize */ + int lflag; /**< (Boolean) Send DLT messages with serial header */ + int rflag; /**< (Boolean) Send automatic get log info response during context registration */ + int mflag; /**< (Boolean) Sync to serial header on serial connection */ + int nflag; /**< (Boolean) Sync to serial header on all TCP connections */ + char evalue[NAME_MAX + 1]; /**< (String: ECU ID) Set ECU ID (Default: ECU1) */ + char bvalue[NAME_MAX + 1]; /**< (String: Baudrate) Serial device baudrate (Default: 115200) */ + char yvalue[NAME_MAX + 1]; /**< (String: Devicename) Additional support for serial device */ + char ivalue[NAME_MAX + 1]; /**< (String: Directory) Directory where to store the persistant configuration (Default: + /tmp) */ + char cvalue[NAME_MAX + 1]; /**< (String: Directory) Filename of DLT configuration file (Default: /etc/dlt.conf) */ #ifdef DLT_LOG_LEVEL_APP_CONFIG - char avalue[NAME_MAX + 1]; /**< (String: Directory) Filename of the app id default level config (Default: /etc/dlt-log-levels.conf) */ + char avalue[NAME_MAX + 1]; /**< (String: Directory) Filename of the app id default level config (Default: + /etc/dlt-log-levels.conf) */ #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - char lvalue[NAME_MAX + 1]; /**< (String: Directory) Filename of DLT trace limit file (Default: /etc/dlt-trace_load.conf) */ + char lvalue[NAME_MAX + 1]; /**< (String: Directory) Filename of DLT trace limit file (Default: + /etc/dlt-trace_load.conf) */ #endif - int sharedMemorySize; /**< (int) Size of shared memory (Default: 100000) */ - int sendMessageTime; /**< (Boolean) Send periodic Message Time if client is connected (Default: 0) */ - char offlineTraceDirectory[DLT_DAEMON_FLAG_MAX]; /**< (String: Directory) Store DLT messages to local directory (Default: /etc/dlt.conf) */ - int offlineTraceFileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */ - int offlineTraceMaxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */ - bool offlineTraceFilenameTimestampBased; /**< (Boolean) timestamp based or index based (Default: true=Timestamp based) */ - DltLoggingMode loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */ - int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */ - char loggingFilename[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */ - bool enableLoggingFileLimit; /**< (Boolean) Indicate whether size of logging file(s) is limited (Default: false) */ - int loggingFileSize; /**< (int) Maximum size in bytes of one logging file (Default: 250000) */ - int loggingFileMaxSize; /**< (int) Maximum size in bytes of all logging files (Default: 1000000) */ - int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */ - char pathToECUSoftwareVersion[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The file from which to read the ECU version from. */ - char ecuSoftwareVersionFileField[DLT_DAEMON_FLAG_MAX]; /**< Reads a specific VALUE from a FIELD=VALUE ECU version file. */ - int sendTimezone; /**< (Boolean) Send Timezone perdiodically */ - int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */ - char offlineLogstorageDirPath[DLT_MOUNT_PATH_MAX]; /**< (String: Directory) DIR path to store offline logs */ - int offlineLogstorageTimestamp; /**< (int) Append timestamp in offline logstorage filename */ - char offlineLogstorageDelimiter; /**< (char) Append delimeter character in offline logstorage filename */ - unsigned int offlineLogstorageMaxCounter; /**< (int) Maximum offline logstorage file counter index until wraparound */ - unsigned int offlineLogstorageMaxCounterIdx; /**< (int) String len of offlineLogstorageMaxCounter */ - unsigned int offlineLogstorageCacheSize; /**< (int) Max cache size offline logstorage cache */ - int offlineLogstorageOptionalCounter; /**< (Boolean) Do not append index to filename if NOFiles=1 */ + int sharedMemorySize; /**< (int) Size of shared memory (Default: 100000) */ + int sendMessageTime; /**< (Boolean) Send periodic Message Time if client is connected (Default: 0) */ + char offlineTraceDirectory[DLT_DAEMON_FLAG_MAX]; /**< (String: Directory) Store DLT messages to local directory + (Default: /etc/dlt.conf) */ + int offlineTraceFileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */ + int offlineTraceMaxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */ + bool offlineTraceFilenameTimestampBased; /**< (Boolean) timestamp based or index based (Default: true=Timestamp + based) */ + DltLoggingMode loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */ + int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */ + char loggingFilename[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The logging filename if internal logging mode is + log to file (Default: /tmp/log) */ + bool enableLoggingFileLimit; /**< (Boolean) Indicate whether size of logging file(s) is limited (Default: false) */ + int loggingFileSize; /**< (int) Maximum size in bytes of one logging file (Default: 250000) */ + int loggingFileMaxSize; /**< (int) Maximum size in bytes of all logging files (Default: 1000000) */ + int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */ + char pathToECUSoftwareVersion[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The file from which to read the ECU + version from. */ + char ecuSoftwareVersionFileField[DLT_DAEMON_FLAG_MAX]; /**< Reads a specific VALUE from a FIELD=VALUE ECU version + file. */ + int sendTimezone; /**< (Boolean) Send Timezone perdiodically */ + int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */ + char offlineLogstorageDirPath[DLT_MOUNT_PATH_MAX]; /**< (String: Directory) DIR path to store offline logs */ + int offlineLogstorageTimestamp; /**< (int) Append timestamp in offline logstorage filename */ + char offlineLogstorageDelimiter; /**< (char) Append delimeter character in offline logstorage filename */ + unsigned int + offlineLogstorageMaxCounter; /**< (int) Maximum offline logstorage file counter index until wraparound */ + unsigned int offlineLogstorageMaxCounterIdx; /**< (int) String len of offlineLogstorageMaxCounter */ + unsigned int offlineLogstorageCacheSize; /**< (int) Max cache size offline logstorage cache */ + int offlineLogstorageOptionalCounter; /**< (Boolean) Do not append index to filename if NOFiles=1 */ #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC - char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */ -#else /* DLT_DAEMON_USE_FIFO_IPC */ - char userPipesDir[DLT_PATH_MAX]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */ - char daemonFifoName[DLT_PATH_MAX]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */ - char daemonFifoGroup[DLT_PATH_MAX]; /**< (String: Group name) Owner group of local fifo (Default: Primary Group) */ + char appSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to User socket */ +#else /* DLT_DAEMON_USE_FIFO_IPC */ + char + userPipesDir[DLT_PATH_MAX]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */ + char daemonFifoName[DLT_PATH_MAX]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */ + char daemonFifoGroup[DLT_PATH_MAX]; /**< (String: Group name) Owner group of local fifo (Default: Primary Group) */ #endif #ifdef DLT_SHM_ENABLE - char dltShmName[NAME_MAX + 1]; /**< Shared memory name */ + char dltShmName[NAME_MAX + 1]; /**< Shared memory name */ #endif - unsigned int port; /**< port number */ - char ctrlSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to Control socket */ - int gatewayMode; /**< (Boolean) Gateway Mode */ - char gatewayConfigFile[DLT_DAEMON_FLAG_MAX]; /**< Gateway config file path */ - int autoResponseGetLogInfoOption; /**< (int) The Option of automatic get log info response during context registration. (Default: 7) */ - int contextLogLevel; /**< (int) log level sent to context if registered with default log-level or if enforced */ - int contextTraceStatus; /**< (int) trace status sent to context if registered with default trace status or if enforced */ - int enforceContextLLAndTS; /**< (Boolean) Enforce log-level, trace-status not to exceed contextLogLevel, contextTraceStatus */ - DltBindAddress_t* ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */ - int injectionMode; /**< (Boolean) Injection mode */ - int protocolVersion; /**< (int) Protocol version selected by user (1 or 2, 0=default) */ + unsigned int port; /**< port number */ + char ctrlSockPath[DLT_DAEMON_FLAG_MAX]; /**< Path to Control socket */ + int gatewayMode; /**< (Boolean) Gateway Mode */ + char gatewayConfigFile[DLT_DAEMON_FLAG_MAX]; /**< Gateway config file path */ + int autoResponseGetLogInfoOption; /**< (int) The Option of automatic get log info response during context + registration. (Default: 7) */ + int contextLogLevel; /**< (int) log level sent to context if registered with default log-level or if enforced */ + int contextTraceStatus; /**< (int) trace status sent to context if registered with default trace status or if + enforced */ + int enforceContextLLAndTS; /**< (Boolean) Enforce log-level, trace-status not to exceed contextLogLevel, + contextTraceStatus */ + DltBindAddress_t* + ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */ + int injectionMode; /**< (Boolean) Injection mode */ + int protocolVersion; /**< (int) Protocol version selected by user (1 or 2, 0=default) */ } DltDaemonFlags; /** * The global parameters of a dlt daemon. */ -typedef struct -{ - DltDaemonFlags flags; /**< flags of the daemon */ - DltFile file; /**< struct for file access */ - DltEventHandler pEvent; /**< struct for message producer event handling */ - DltGateway pGateway; /**< struct for passive node connection handling */ - DltMessage msg; /**< one dlt message */ - DltMessageV2 msgv2; /**< one dlt v2 message */ - int client_connections; /**< counter for nr. of client connections */ - int client_connection_version; /**< Connected client version */ - size_t baudrate; /**< Baudrate of serial connection */ +typedef struct { + DltDaemonFlags flags; /**< flags of the daemon */ + DltFile file; /**< struct for file access */ + DltEventHandler pEvent; /**< struct for message producer event handling */ + DltGateway pGateway; /**< struct for passive node connection handling */ + DltMessage msg; /**< one dlt message */ + DltMessageV2 msgv2; /**< one dlt v2 message */ + int client_connections; /**< counter for nr. of client connections */ + int client_connection_version; /**< Connected client version */ + size_t baudrate; /**< Baudrate of serial connection */ #ifdef DLT_SHM_ENABLE - DltShm dlt_shm; /**< Shared memory handling */ - unsigned char *recv_buf_shm; /**< buffer for receive message from shm */ + DltShm dlt_shm; /**< Shared memory handling */ + unsigned char* recv_buf_shm; /**< buffer for receive message from shm */ #endif - MultipleFilesRingBuffer offlineTrace; /**< Offline trace handling */ - MultipleFilesRingBuffer dltLogging; /**< Dlt logging handling */ + MultipleFilesRingBuffer offlineTrace; /**< Offline trace handling */ + MultipleFilesRingBuffer dltLogging; /**< Dlt logging handling */ int timeoutOnSend; unsigned long RingbufferMinSize; unsigned long RingbufferMaxSize; unsigned long RingbufferStepSize; unsigned long daemonFifoSize; #ifdef UDP_CONNECTION_SUPPORT - int UDPConnectionSetup; /* enable/disable the UDP connection */ - char UDPMulticastIPAddress[MULTICASTIP_MAX_SIZE]; /* multicast ip addres */ - int UDPMulticastIPPort; /* multicast port */ + int UDPConnectionSetup; /* enable/disable the UDP connection */ + char UDPMulticastIPAddress[MULTICASTIP_MAX_SIZE]; /* multicast ip addres */ + int UDPMulticastIPPort; /* multicast port */ #endif } DltDaemonLocal; -typedef struct -{ +typedef struct { unsigned long long wakeups_missed; unsigned int period_sec; unsigned int starts_in; int timer_id; } DltDaemonPeriodicData; -typedef struct -{ - DltDaemon *daemon; - DltDaemonLocal *daemon_local; +typedef struct { + DltDaemon* daemon; + DltDaemonLocal* daemon_local; } DltDaemonTimingPacketThreadData; typedef DltDaemonTimingPacketThreadData DltDaemonECUVersionThreadData; -#define DLT_DAEMON_ERROR_OK 0 -#define DLT_DAEMON_ERROR_UNKNOWN -1 -#define DLT_DAEMON_ERROR_BUFFER_FULL -2 -#define DLT_DAEMON_ERROR_SEND_FAILED -3 -#define DLT_DAEMON_ERROR_WRITE_FAILED -4 +#define DLT_DAEMON_ERROR_OK 0 +#define DLT_DAEMON_ERROR_UNKNOWN -1 +#define DLT_DAEMON_ERROR_BUFFER_FULL -2 +#define DLT_DAEMON_ERROR_SEND_FAILED -3 +#define DLT_DAEMON_ERROR_WRITE_FAILED -4 /* Function prototypes */ -void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_local_connection_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_local_cleanup(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_local_init_p1(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_local_init_p2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_local_connection_init(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_local_ecu_version_init(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); void dlt_daemon_daemonize(int verbose); void dlt_daemon_exit_trigger(); @@ -223,94 +233,80 @@ void dlt_daemon_signal_handler(int sig); void dlt_daemon_cleanup_timers(); void close_pipes(int fds[2]); #endif -int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); -int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *revc, int verbose); -int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *recv, - int verbose); -int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); -int dlt_daemon_process_one_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); -int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); -ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); +int dlt_daemon_process_client_connect(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); +int dlt_daemon_process_client_messages(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* revc, int verbose); +int dlt_daemon_process_client_messages_serial( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); +int dlt_daemon_process_user_messages(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); +int dlt_daemon_process_one_s_timer(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); +int dlt_daemon_process_sixty_s_timer(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); +ssize_t dlt_daemon_process_systemd_timer( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); -int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); +int dlt_daemon_process_control_connect(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); #if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE -int dlt_daemon_process_app_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); +int dlt_daemon_process_app_connect(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); #endif -int dlt_daemon_process_control_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, - int verbose); +int dlt_daemon_process_control_messages( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); -typedef int (*dlt_daemon_process_user_message_func)(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, - int verbose); +typedef int (*dlt_daemon_process_user_message_func)( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); -int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); -int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_send_message_overflow_v2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); -int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); -int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); -int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); -int dlt_daemon_process_user_message_log(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); +int dlt_daemon_process_user_message_overflow( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); +int dlt_daemon_send_message_overflow(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_send_message_overflow_v2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_process_user_message_register_application( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); +int dlt_daemon_process_user_message_unregister_application( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); +int dlt_daemon_process_user_message_register_context( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); +int dlt_daemon_process_user_message_unregister_context( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); +int dlt_daemon_process_user_message_log(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); -bool enforce_context_ll_and_ts_keep_message(DltDaemonLocal *daemon_local +bool enforce_context_ll_and_ts_keep_message( + DltDaemonLocal* daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - ,DltDaemonApplication *app + , + DltDaemonApplication* app #endif - ); +); -bool enforce_context_ll_and_ts_keep_message_v2(DltDaemonLocal *daemon_local +bool enforce_context_ll_and_ts_keep_message_v2( + DltDaemonLocal* daemon_local #ifdef DLT_LOG_LEVEL_APP_CONFIG - ,DltDaemonApplication *app + , + DltDaemonApplication* app #endif - ); +); -int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); -int dlt_daemon_process_user_message_marker(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); +int dlt_daemon_process_user_message_set_app_ll_ts( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); +int dlt_daemon_process_user_message_marker( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); -int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -int dlt_daemon_send_ringbuffer_to_client_v2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -void dlt_daemon_timingpacket_thread(void *ptr); -void dlt_daemon_ecu_version_thread(void *ptr); +int dlt_daemon_send_ringbuffer_to_client(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +int dlt_daemon_send_ringbuffer_to_client_v2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); +void dlt_daemon_timingpacket_thread(void* ptr); +void dlt_daemon_ecu_version_thread(void* ptr); #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) -void dlt_daemon_systemd_watchdog_thread(void *ptr); +void dlt_daemon_systemd_watchdog_thread(void* ptr); #endif -int create_timer_fd(DltDaemonLocal *daemon_local, unsigned int period_sec, unsigned int starts_in, DltTimers timer); +int create_timer_fd(DltDaemonLocal* daemon_local, unsigned int period_sec, unsigned int starts_in, DltTimers timer); -int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +int dlt_daemon_close_socket(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); #ifdef DLT_TRACE_LOAD_CTRL_ENABLE bool trace_load_keep_message( - DltDaemonApplication *app, int size, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); + DltDaemonApplication* app, int size, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); // Functions that are only exposed for testing and should not be public // for normal builds #ifdef DLT_UNIT_TESTS -int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_local); +int trace_load_config_file_parser(DltDaemon* daemon, DltDaemonLocal* daemon_local); #endif #endif diff --git a/src/daemon/dlt-daemon_cfg.h b/src/daemon/dlt-daemon_cfg.h index d041a19c0..c612fa23b 100644 --- a/src/daemon/dlt-daemon_cfg.h +++ b/src/daemon/dlt-daemon_cfg.h @@ -77,31 +77,31 @@ #define DLT_DAEMON_ECU_VERSION_THREAD_STACKSIZE 100000 /* Size of receive buffer for shm connection (from user application) */ -#define DLT_SHM_RCV_BUFFER_SIZE 10000 +#define DLT_SHM_RCV_BUFFER_SIZE 10000 /* Size of receive buffer for fifo connection (from user application) */ -#define DLT_DAEMON_RCVBUFSIZE 10024 +#define DLT_DAEMON_RCVBUFSIZE 10024 /* Size of receive buffer for socket connection (from dlt client) */ -#define DLT_DAEMON_RCVBUFSIZESOCK 10024 +#define DLT_DAEMON_RCVBUFSIZESOCK 10024 /* Size of receive buffer for serial connection (from dlt client) */ #define DLT_DAEMON_RCVBUFSIZESERIAL 10024 /* Size of buffer for text output */ -#define DLT_DAEMON_TEXTSIZE 10024 +#define DLT_DAEMON_TEXTSIZE 10024 /* Size of buffer */ -#define DLT_DAEMON_TEXTBUFSIZE 512 +#define DLT_DAEMON_TEXTBUFSIZE 512 /* Maximum length of a description */ -#define DLT_DAEMON_DESCSIZE 256 +#define DLT_DAEMON_DESCSIZE 256 /* Umask of daemon, creates files with permission 750 */ -#define DLT_DAEMON_UMASK 027 +#define DLT_DAEMON_UMASK 027 /* Default ECU ID, used in storage header and transmitted to client*/ #define DLT_DAEMON_ECU_ID "ECU1" /* Default ECU ID Length, used in extended header and transmitted to client*/ -#define DLT_DAEMON_ECU_ID_LEN 4 +#define DLT_DAEMON_ECU_ID_LEN 4 /* Default baudrate for serial interface */ #define DLT_DAEMON_SERIAL_DEFAULT_BAUDRATE 115200 diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index ed36b87a5..5e7ac3016 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -40,15 +40,15 @@ #include #ifdef linux -# include +#include #endif #include #if defined(linux) && defined(__NR_statx) -# include +#include #endif #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE -# include +#include #endif #include "dlt_types.h" @@ -67,7 +67,7 @@ #include "dlt_daemon_offline_logstorage.h" #include "dlt_gateway.h" #ifdef UDP_CONNECTION_SUPPORT -# include "dlt_daemon_udp_socket.h" +#include "dlt_daemon_udp_socket.h" #endif /** Inline function to calculate/set the requested log level or traces status @@ -100,20 +100,14 @@ static inline int8_t getStatus(uint8_t request_log, int context_log) * * @return The amount of data transferred. */ -static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - void *data1, - int size1, - void *data2, - int size2, - int verbose) +static int dlt_daemon_client_send_all_multiple( + DltDaemon* daemon, DltDaemonLocal* daemon_local, void* data1, int size1, void* data2, int size2, int verbose) { int sent = 0; nfds_t i = 0; int ret = 0; - DltConnection *temp = NULL; - int type_mask = - (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL); + DltConnection* temp = NULL; + int type_mask = (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL); PRINT_FUNCTION_VERBOSE(verbose); @@ -122,37 +116,26 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon, return 0; } - for (i = 0; i < daemon_local->pEvent.nfds; i++) - { + for (i = 0; i < daemon_local->pEvent.nfds; i++) { #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE bool watchdog_triggered = dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon); if (watchdog_triggered) { - dlt_vlog(LOG_WARNING, "%s notified watchdog, processed %lu/%lu fds already.\n", - __func__, i, daemon_local->pEvent.nfds); + dlt_vlog( + LOG_WARNING, "%s notified watchdog, processed %lu/%lu fds already.\n", __func__, i, + daemon_local->pEvent.nfds); } #endif - temp = dlt_event_handler_find_connection(&(daemon_local->pEvent), - daemon_local->pEvent.pfd[i].fd); + temp = dlt_event_handler_find_connection(&(daemon_local->pEvent), daemon_local->pEvent.pfd[i].fd); - if ((temp == NULL) || (temp->receiver == NULL) || - !((1 << temp->type) & type_mask)) { + if ((temp == NULL) || (temp->receiver == NULL) || !((1 << temp->type) & type_mask)) { dlt_log(LOG_DEBUG, "The connection not found or the connection type not TCP/Serial.\n"); continue; } - ret = dlt_connection_send_multiple(temp, - data1, - size1, - data2, - size2, - daemon->sendserialheader); - - if ((ret != DLT_DAEMON_ERROR_OK) && - (DLT_CONNECTION_CLIENT_MSG_TCP == temp->type)) { - dlt_daemon_close_socket(temp->receiver->fd, - daemon, - daemon_local, - verbose); + ret = dlt_connection_send_multiple(temp, data1, size1, data2, size2, daemon->sendserialheader); + + if ((ret != DLT_DAEMON_ERROR_OK) && (DLT_CONNECTION_CLIENT_MSG_TCP == temp->type)) { + dlt_daemon_close_socket(temp->receiver->fd, daemon, daemon_local, verbose); } if (ret != DLT_DAEMON_ERROR_OK) @@ -165,8 +148,7 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon, } /* for */ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - if (sent) - { + if (sent) { const uint32_t serial_header = daemon->sendserialheader ? sizeof(dltSerialHeader) : 0; daemon->bytes_sent += size1 + size2 + serial_header; } @@ -176,16 +158,9 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon, } /* TODO: Extract the storage header v2 from buffer */ -int dlt_daemon_client_send(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - void *storage_header, - int storage_header_size, - void *data1, - int size1, - void *data2, - int size2, - int verbose) +int dlt_daemon_client_send( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, void* storage_header, int storage_header_size, + void* data1, int size1, void* data2, int size2, int verbose) { int sent, ret; int ret_logstorage = 0; @@ -199,16 +174,12 @@ int dlt_daemon_client_send(int sock, if ((sock != DLT_DAEMON_SEND_TO_ALL) && (sock != DLT_DAEMON_SEND_FORCE)) { /* Send message to specific socket */ if (isatty(sock)) { - if ((ret = - dlt_daemon_serial_send(sock, data1, size1, data2, size2, - (char)daemon->sendserialheader))) { + if ((ret = dlt_daemon_serial_send(sock, data1, size1, data2, size2, (char)daemon->sendserialheader))) { dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__); return ret; } } else { - if ((ret = - dlt_daemon_socket_send(sock, data1, size1, data2, size2, - (char)daemon->sendserialheader))) { + if ((ret = dlt_daemon_socket_send(sock, data1, size1, data2, size2, (char)daemon->sendserialheader))) { dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__); return ret; } @@ -224,8 +195,8 @@ int dlt_daemon_client_send(int sock, if ((sock != DLT_DAEMON_SEND_FORCE) && (daemon->state != DLT_DAEMON_STATE_SEND_BUFFER)) { if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) { - if (dlt_offline_trace_write(&(daemon_local->offlineTrace), storage_header, storage_header_size, data1, - size1, data2, size2)) { + if (dlt_offline_trace_write( + &(daemon_local->offlineTrace), storage_header, storage_header_size, data1, size1, data2, size2)) { static int error_dlt_offline_trace_write_failed = 0; if (!error_dlt_offline_trace_write_failed) { @@ -241,14 +212,8 @@ int dlt_daemon_client_send(int sock, * this need to be checked because the function is dlt_daemon_client_send is called by * newly introduced dlt_daemon_log_internal */ if (daemon_local->flags.offlineLogstorageMaxDevices > 0) - ret_logstorage = dlt_daemon_logstorage_write(daemon, - &daemon_local->flags, - storage_header, - storage_header_size, - data1, - size1, - data2, - size2); + ret_logstorage = dlt_daemon_logstorage_write( + daemon, &daemon_local->flags, storage_header, storage_header_size, data1, size1, data2, size2); } /* send messages to daemon socket */ @@ -257,11 +222,7 @@ int dlt_daemon_client_send(int sock, if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) { /* Forward message to network client if network routing is not disabled */ if (ret_logstorage != 1) { - dlt_daemon_udp_dltmsg_multicast(data1, - size1, - data2, - size2, - verbose); + dlt_daemon_udp_dltmsg_multicast(data1, size1, data2, size2, verbose); } } @@ -270,13 +231,7 @@ int dlt_daemon_client_send(int sock, if ((sock == DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) { /* Forward message to network client if network routing is not disabled */ if (ret_logstorage != 1) { - sent = dlt_daemon_client_send_all_multiple(daemon, - daemon_local, - data1, - size1, - data2, - size2, - verbose); + sent = dlt_daemon_client_send_all_multiple(daemon, daemon_local, data1, size1, data2, size2, verbose); if ((sock == DLT_DAEMON_SEND_FORCE) && !sent) { return DLT_DAEMON_ERROR_SEND_FAILED; @@ -286,12 +241,13 @@ int dlt_daemon_client_send(int sock, } /* Message was not sent to client, so store it in client ringbuffer */ - if ((sock != DLT_DAEMON_SEND_FORCE) && - ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) || - (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) { + if ((sock != DLT_DAEMON_SEND_FORCE) + && ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) + || (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) { if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) { /* Store message in history buffer */ - ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, (unsigned int)size1, data2, (unsigned int)size2, 0U, 0U); + ret = dlt_buffer_push3( + &(daemon->client_ringbuffer), data1, (unsigned int)size1, data2, (unsigned int)size2, 0U, 0U); if (ret < DLT_RETURN_OK) { dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL); } @@ -304,19 +260,15 @@ int dlt_daemon_client_send(int sock, return DLT_DAEMON_ERROR_BUFFER_FULL; } } else { - if ((daemon->overflow_counter > 0) && - (daemon_local->client_connections > 0)) { + if ((daemon->overflow_counter > 0) && (daemon_local->client_connections > 0)) { sent_message_overflow_cnt++; if (sent_message_overflow_cnt >= 2) { sent_message_overflow_cnt--; - } - else { - if (dlt_daemon_send_message_overflow(daemon, daemon_local, - verbose) == DLT_DAEMON_ERROR_OK) { - dlt_vlog(LOG_WARNING, - "%s: %u messages discarded! Now able to send messages to the client.\n", - __func__, - daemon->overflow_counter); + } else { + if (dlt_daemon_send_message_overflow(daemon, daemon_local, verbose) == DLT_DAEMON_ERROR_OK) { + dlt_vlog( + LOG_WARNING, "%s: %u messages discarded! Now able to send messages to the client.\n", __func__, + daemon->overflow_counter); daemon->overflow_counter = 0; sent_message_overflow_cnt--; } @@ -325,19 +277,11 @@ int dlt_daemon_client_send(int sock, } return DLT_DAEMON_ERROR_OK; - } -int dlt_daemon_client_send_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - void *storage_header, - int storage_header_size, - void *data1, - int size1, - void *data2, - int size2, - int verbose) +int dlt_daemon_client_send_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, void* storage_header, int storage_header_size, + void* data1, int size1, void* data2, int size2, int verbose) { int sent, ret; int ret_logstorage = 0; @@ -351,16 +295,12 @@ int dlt_daemon_client_send_v2(int sock, if ((sock != DLT_DAEMON_SEND_TO_ALL) && (sock != DLT_DAEMON_SEND_FORCE)) { /* Send message to specific socket */ if (isatty(sock)) { - if ((ret = - dlt_daemon_serial_send(sock, data1, size1, data2, size2, - (char)daemon->sendserialheader))) { + if ((ret = dlt_daemon_serial_send(sock, data1, size1, data2, size2, (char)daemon->sendserialheader))) { dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__); return ret; } } else { - if ((ret = - dlt_daemon_socket_send(sock, data1, size1, data2, size2, - (char)daemon->sendserialheader))) { + if ((ret = dlt_daemon_socket_send(sock, data1, size1, data2, size2, (char)daemon->sendserialheader))) { dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__); return ret; } @@ -377,8 +317,8 @@ int dlt_daemon_client_send_v2(int sock, if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) { /* To update for v2*/ - if (dlt_offline_trace_write(&(daemon_local->offlineTrace), storage_header, storage_header_size, data1, - size1, data2, size2)) { + if (dlt_offline_trace_write( + &(daemon_local->offlineTrace), storage_header, storage_header_size, data1, size1, data2, size2)) { static int error_dlt_offline_trace_write_failed = 0; if (!error_dlt_offline_trace_write_failed) { @@ -395,14 +335,8 @@ int dlt_daemon_client_send_v2(int sock, * newly introduced dlt_daemon_log_internal */ /* To Update to dlt_daemon_logstorage_write_v2*/ if (daemon_local->flags.offlineLogstorageMaxDevices > 0) - ret_logstorage = dlt_daemon_logstorage_write(daemon, - &daemon_local->flags, - storage_header, - storage_header_size, - data1, - size1, - data2, - size2); + ret_logstorage = dlt_daemon_logstorage_write( + daemon, &daemon_local->flags, storage_header, storage_header_size, data1, size1, data2, size2); } /* send messages to daemon socket */ @@ -411,11 +345,7 @@ int dlt_daemon_client_send_v2(int sock, if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) { /* Forward message to network client if network routing is not disabled */ if (ret_logstorage != 1) { - dlt_daemon_udp_dltmsg_multicast(data1, - size1, - data2, - size2, - verbose); + dlt_daemon_udp_dltmsg_multicast(data1, size1, data2, size2, verbose); } } @@ -424,13 +354,7 @@ int dlt_daemon_client_send_v2(int sock, if ((sock == DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) { /* Forward message to network client if network routing is not disabled */ if (ret_logstorage != 1) { - sent = dlt_daemon_client_send_all_multiple(daemon, - daemon_local, - data1, - size1, - data2, - size2, - verbose); + sent = dlt_daemon_client_send_all_multiple(daemon, daemon_local, data1, size1, data2, size2, verbose); if ((sock == DLT_DAEMON_SEND_FORCE) && !sent) { return DLT_DAEMON_ERROR_SEND_FAILED; @@ -440,12 +364,13 @@ int dlt_daemon_client_send_v2(int sock, } /* Message was not sent to client, so store it in client ringbuffer */ - if ((sock != DLT_DAEMON_SEND_FORCE) && - ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) || - (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) { + if ((sock != DLT_DAEMON_SEND_FORCE) + && ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) + || (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) { if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) { /* Store message in history buffer */ - ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, (unsigned int)size1, data2, (unsigned int)size2, 0, 0); + ret = dlt_buffer_push3( + &(daemon->client_ringbuffer), data1, (unsigned int)size1, data2, (unsigned int)size2, 0, 0); if (ret < DLT_RETURN_OK) { dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL); } @@ -458,19 +383,15 @@ int dlt_daemon_client_send_v2(int sock, return DLT_DAEMON_ERROR_BUFFER_FULL; } } else { - if ((daemon->overflow_counter > 0) && - (daemon_local->client_connections > 0)) { + if ((daemon->overflow_counter > 0) && (daemon_local->client_connections > 0)) { sent_message_overflow_cnt++; if (sent_message_overflow_cnt >= 2) { sent_message_overflow_cnt--; - } - else { - if (dlt_daemon_send_message_overflow_v2(daemon, daemon_local, - verbose) == DLT_DAEMON_ERROR_OK) { - dlt_vlog(LOG_WARNING, - "%s: %u messages discarded! Now able to send messages to the client.\n", - __func__, - daemon->overflow_counter); + } else { + if (dlt_daemon_send_message_overflow_v2(daemon, daemon_local, verbose) == DLT_DAEMON_ERROR_OK) { + dlt_vlog( + LOG_WARNING, "%s: %u messages discarded! Now able to send messages to the client.\n", __func__, + daemon->overflow_counter); daemon->overflow_counter = 0; sent_message_overflow_cnt--; } @@ -479,15 +400,12 @@ int dlt_daemon_client_send_v2(int sock, } return DLT_DAEMON_ERROR_OK; - } -int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +int dlt_daemon_client_send_message_to_all_client(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { static char text[DLT_DAEMON_TEXTSIZE]; - char * ecu_ptr = NULL; + char* ecu_ptr = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -497,22 +415,19 @@ int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, } /* set overwrite ecu id */ - if ((daemon_local->flags.evalue[0]) && - (strncmp(daemon_local->msg.headerextra.ecu, - DLT_DAEMON_ECU_ID, DLT_ID_SIZE) == 0)) { + if ((daemon_local->flags.evalue[0]) + && (strncmp(daemon_local->msg.headerextra.ecu, DLT_DAEMON_ECU_ID, DLT_ID_SIZE) == 0)) { /* Set header extra parameters */ dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid); /*msg.headerextra.seid = 0; */ if (dlt_message_set_extraparameters(&(daemon_local->msg), 0)) { - dlt_vlog(LOG_WARNING, - "%s: failed to set message extra parameters.\n", __func__); + dlt_vlog(LOG_WARNING, "%s: failed to set message extra parameters.\n", __func__); return DLT_DAEMON_ERROR_UNKNOWN; } /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ - daemon_local->msg.headerextra.tmsp = - DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); } /* prepare storage header */ @@ -523,48 +438,39 @@ int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, } if (dlt_set_storageheader(daemon_local->msg.storageheader, ecu_ptr)) { - dlt_vlog(LOG_WARNING, - "%s: failed to set storage header with header type: 0x%x\n", - __func__, daemon_local->msg.standardheader->htyp); + dlt_vlog( + LOG_WARNING, "%s: failed to set storage header with header type: 0x%x\n", __func__, + daemon_local->msg.standardheader->htyp); return DLT_DAEMON_ERROR_UNKNOWN; } /* if no filter set or filter is matching display message */ if (daemon_local->flags.xflag) { - if (DLT_RETURN_OK != - dlt_message_print_hex(&(daemon_local->msg), text, - DLT_DAEMON_TEXTSIZE, verbose)) + if (DLT_RETURN_OK != dlt_message_print_hex(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose)) dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n"); } else if (daemon_local->flags.aflag) { - if (DLT_RETURN_OK != - dlt_message_print_ascii(&(daemon_local->msg), text, - DLT_DAEMON_TEXTSIZE, verbose)) + if (DLT_RETURN_OK != dlt_message_print_ascii(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose)) dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n"); } else if (daemon_local->flags.sflag) { - if (DLT_RETURN_OK != - dlt_message_print_header(&(daemon_local->msg), text, - DLT_DAEMON_TEXTSIZE, verbose)) + if (DLT_RETURN_OK != dlt_message_print_header(&(daemon_local->msg), text, DLT_DAEMON_TEXTSIZE, verbose)) dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n"); } /* send message to client or write to log file */ - return dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, - daemon_local->msg.headerbuffer, sizeof(DltStorageHeader), - daemon_local->msg.headerbuffer + sizeof(DltStorageHeader), - (int)(daemon_local->msg.headersize - (int32_t)sizeof(DltStorageHeader)), - daemon_local->msg.databuffer, (int)daemon_local->msg.datasize, verbose); - + return dlt_daemon_client_send( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->msg.headerbuffer, sizeof(DltStorageHeader), + daemon_local->msg.headerbuffer + sizeof(DltStorageHeader), + (int)(daemon_local->msg.headersize - (int32_t)sizeof(DltStorageHeader)), daemon_local->msg.databuffer, + (int)daemon_local->msg.datasize, verbose); } -int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { static char text[DLT_DAEMON_TEXTSIZE]; - char * ecu_ptr = NULL; + char* ecu_ptr = NULL; uint8_t ecu_len = 0; uint32_t temp_extended_size = 0; - uint8_t *temp_buffer = (uint8_t *)malloc((size_t)daemon_local->msgv2.headersizev2); + uint8_t* temp_buffer = (uint8_t*)malloc((size_t)daemon_local->msgv2.headersizev2); if (temp_buffer == NULL) { return DLT_RETURN_ERROR; } @@ -580,9 +486,11 @@ int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, temp_extended_size = daemon_local->msgv2.extendedheadersizev2; /* set overwrite ecu id */ - if ((daemon_local->flags.evalue[0]) && - (strncmp(daemon_local->msgv2.extendedheaderv2.ecid, - DLT_DAEMON_ECU_ID, daemon_local->msgv2.extendedheaderv2.ecidlen) == 0)) { + if ((daemon_local->flags.evalue[0]) + && (strncmp( + daemon_local->msgv2.extendedheaderv2.ecid, DLT_DAEMON_ECU_ID, + daemon_local->msgv2.extendedheaderv2.ecidlen) + == 0)) { daemon_local->msgv2.extendedheaderv2.ecidlen = daemon->ecuid2len; dlt_set_id_v2(daemon_local->msgv2.extendedheaderv2.ecid, daemon->ecuid2, daemon->ecuid2len); @@ -607,17 +515,18 @@ int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, daemon_local->msgv2.storageheadersizev2 = (uint32_t)(STORAGE_HEADER_V2_FIXED_SIZE + ecu_len); if (dlt_set_storageheader_v2(&(daemon_local->msgv2.storageheaderv2), ecu_len, ecu_ptr)) { - dlt_vlog(LOG_WARNING, - "%s: failed to set storage header with header type: 0x%x\n", - __func__, daemon_local->msg.standardheader->htyp); + dlt_vlog( + LOG_WARNING, "%s: failed to set storage header with header type: 0x%x\n", __func__, + daemon_local->msg.standardheader->htyp); return DLT_DAEMON_ERROR_UNKNOWN; } - daemon_local->msgv2.headersizev2 = (int32_t)((uint32_t)daemon_local->msgv2.headersizev2 - temp_extended_size + - daemon_local->msgv2.extendedheadersizev2 + daemon_local->msgv2.storageheadersizev2); + daemon_local->msgv2.headersizev2 = + (int32_t)((uint32_t)daemon_local->msgv2.headersizev2 - temp_extended_size + + daemon_local->msgv2.extendedheadersizev2 + daemon_local->msgv2.storageheadersizev2); /* allocate new header buffer, copy cached header parts into it, then replace the old buffer */ - uint8_t *new_headerbufferv2 = (uint8_t *)malloc((size_t)daemon_local->msgv2.headersizev2); + uint8_t* new_headerbufferv2 = (uint8_t*)malloc((size_t)daemon_local->msgv2.headersizev2); if (new_headerbufferv2 == NULL) { free(temp_buffer); return DLT_RETURN_ERROR; @@ -630,16 +539,16 @@ int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, } /* Copy base header + base header extra from temp buffer (skip old storage header) */ - memcpy(new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2, - temp_buffer + old_storage_size, - (daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2)); + memcpy( + new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2, temp_buffer + old_storage_size, + (daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2)); /* Copy extended header from temp buffer */ - uint32_t old_extended_offset = old_storage_size + daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2; - uint32_t new_extended_offset = daemon_local->msgv2.storageheadersizev2 + daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2; - memcpy(new_headerbufferv2 + new_extended_offset, - temp_buffer + old_extended_offset, - temp_extended_size); + uint32_t old_extended_offset = + old_storage_size + daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2; + uint32_t new_extended_offset = daemon_local->msgv2.storageheadersizev2 + daemon_local->msgv2.baseheadersizev2 + + daemon_local->msgv2.baseheaderextrasizev2; + memcpy(new_headerbufferv2 + new_extended_offset, temp_buffer + old_extended_offset, temp_extended_size); free(temp_buffer); @@ -648,57 +557,45 @@ int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, daemon_local->msgv2.headerbufferv2 = new_headerbufferv2; /* Update baseheaderv2 pointer to point into the new buffer */ - daemon_local->msgv2.baseheaderv2 = (DltBaseHeaderV2 *)(new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2); + daemon_local->msgv2.baseheaderv2 = (DltBaseHeaderV2*)(new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2); /* Re-parse extended parameters from the new buffer to update pointers */ DltHtyp2ContentType msgcontent = daemon_local->msgv2.baseheaderv2->htyp2 & MSGCONTENT_MASK; - if (dlt_message_get_extendedparameters_from_recievedbuffer_v2(&(daemon_local->msgv2), - new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2, - msgcontent) != DLT_RETURN_OK) { - dlt_vlog(LOG_WARNING, - "%s: failed to get message extended parameters.\n", __func__); + if (dlt_message_get_extendedparameters_from_recievedbuffer_v2( + &(daemon_local->msgv2), new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2, msgcontent) + != DLT_RETURN_OK) { + dlt_vlog(LOG_WARNING, "%s: failed to get message extended parameters.\n", __func__); return DLT_DAEMON_ERROR_UNKNOWN; } if (dlt_message_set_extendedparameters_v2(&(daemon_local->msgv2))) { - dlt_vlog(LOG_WARNING, - "%s: failed to set message extended parameters.\n", __func__); + dlt_vlog(LOG_WARNING, "%s: failed to set message extended parameters.\n", __func__); return DLT_DAEMON_ERROR_UNKNOWN; } /* if no filter set or filter is matching display message */ if (daemon_local->flags.xflag) { - if (DLT_RETURN_OK != - dlt_message_print_hex_v2(&(daemon_local->msgv2), text, - DLT_DAEMON_TEXTSIZE, verbose)) + if (DLT_RETURN_OK != dlt_message_print_hex_v2(&(daemon_local->msgv2), text, DLT_DAEMON_TEXTSIZE, verbose)) dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n"); } else if (daemon_local->flags.aflag) { - if (DLT_RETURN_OK != - dlt_message_print_ascii_v2(&(daemon_local->msgv2), text, - DLT_DAEMON_TEXTSIZE, verbose)) + if (DLT_RETURN_OK != dlt_message_print_ascii_v2(&(daemon_local->msgv2), text, DLT_DAEMON_TEXTSIZE, verbose)) dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n"); } else if (daemon_local->flags.sflag) { - if (DLT_RETURN_OK != - dlt_message_print_header_v2(&(daemon_local->msgv2), text, - DLT_DAEMON_TEXTSIZE, verbose)) + if (DLT_RETURN_OK != dlt_message_print_header_v2(&(daemon_local->msgv2), text, DLT_DAEMON_TEXTSIZE, verbose)) dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n"); } /* send message to client or write to log file */ - return dlt_daemon_client_send_v2(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, - daemon_local->msgv2.headerbufferv2, (int)daemon_local->msgv2.storageheadersizev2, - daemon_local->msgv2.headerbufferv2 + daemon_local->msgv2.storageheadersizev2, - (int)(daemon_local->msgv2.headersizev2 - (int32_t)daemon_local->msgv2.storageheadersizev2), - daemon_local->msgv2.databuffer, (int) daemon_local->msgv2.datasize, verbose); + return dlt_daemon_client_send_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->msgv2.headerbufferv2, + (int)daemon_local->msgv2.storageheadersizev2, + daemon_local->msgv2.headerbufferv2 + daemon_local->msgv2.storageheadersizev2, + (int)(daemon_local->msgv2.headersizev2 - (int32_t)daemon_local->msgv2.storageheadersizev2), + daemon_local->msgv2.databuffer, (int)daemon_local->msgv2.datasize, verbose); } -int dlt_daemon_client_send_control_message(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - char *apid, - char *ctid, - int verbose) +int dlt_daemon_client_send_control_message( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, char* apid, char* ctid, int verbose) { int ret; int32_t len; @@ -709,13 +606,13 @@ int dlt_daemon_client_send_control_message(int sock, return DLT_DAEMON_ERROR_UNKNOWN; /* prepare storage header */ - msg->storageheader = (DltStorageHeader *)msg->headerbuffer; + msg->storageheader = (DltStorageHeader*)msg->headerbuffer; if (dlt_set_storageheader(msg->storageheader, daemon->ecuid) == DLT_RETURN_ERROR) return DLT_DAEMON_ERROR_UNKNOWN; /* prepare standard header */ - msg->standardheader = (DltStandardHeader *)(msg->headerbuffer + sizeof(DltStorageHeader)); + msg->standardheader = (DltStandardHeader*)(msg->headerbuffer + sizeof(DltStorageHeader)); msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; #if (BYTE_ORDER == BIG_ENDIAN) @@ -734,32 +631,28 @@ int dlt_daemon_client_send_control_message(int sock, dlt_message_set_extraparameters(msg, verbose); /* prepare extended header */ - msg->extendedheader = - (DltExtendedHeader *)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + msg->extendedheader = (DltExtendedHeader*)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); msg->extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE; msg->extendedheader->noar = 1; /* number of arguments */ if (strcmp(apid, "") == 0) - dlt_set_id(msg->extendedheader->apid, DLT_DAEMON_CTRL_APID); /* application id */ + dlt_set_id(msg->extendedheader->apid, DLT_DAEMON_CTRL_APID); /* application id */ else dlt_set_id(msg->extendedheader->apid, apid); if (strcmp(ctid, "") == 0) - dlt_set_id(msg->extendedheader->ctid, DLT_DAEMON_CTRL_CTID); /* context id */ + dlt_set_id(msg->extendedheader->ctid, DLT_DAEMON_CTRL_CTID); /* context id */ else dlt_set_id(msg->extendedheader->ctid, ctid); /* prepare length information */ - msg->headersize = (int32_t)((size_t)sizeof(DltStorageHeader) - + (size_t)sizeof(DltStandardHeader) - + (size_t)sizeof(DltExtendedHeader) - + (size_t)DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + msg->headersize = (int32_t)((size_t)sizeof(DltStorageHeader) + (size_t)sizeof(DltStandardHeader) + + (size_t)sizeof(DltExtendedHeader) + + (size_t)DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); - len = (int32_t)((size_t)msg->headersize - - (size_t)sizeof(DltStorageHeader) - + (size_t)msg->datasize); + len = (int32_t)((size_t)msg->headersize - (size_t)sizeof(DltStorageHeader) + (size_t)msg->datasize); if (len > UINT16_MAX) { dlt_log(LOG_WARNING, "Huge control message discarded!\n"); @@ -768,11 +661,10 @@ int dlt_daemon_client_send_control_message(int sock, msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len)); - if ((ret = - dlt_daemon_client_send(sock, daemon, daemon_local, msg->headerbuffer, sizeof(DltStorageHeader), - msg->headerbuffer + sizeof(DltStorageHeader), - (int)(msg->headersize - (int32_t)sizeof(DltStorageHeader)), - msg->databuffer, (int)msg->datasize, verbose))) { + if ((ret = dlt_daemon_client_send( + sock, daemon, daemon_local, msg->headerbuffer, sizeof(DltStorageHeader), + msg->headerbuffer + sizeof(DltStorageHeader), (int)(msg->headersize - (int32_t)sizeof(DltStorageHeader)), + msg->databuffer, (int)msg->datasize, verbose))) { dlt_log(LOG_DEBUG, "dlt_daemon_control_send_control_message: DLT message send to all failed!.\n"); return ret; } @@ -780,13 +672,8 @@ int dlt_daemon_client_send_control_message(int sock, return DLT_DAEMON_ERROR_OK; } -int dlt_daemon_client_send_control_message_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - char *apid, - char *ctid, - int verbose) +int dlt_daemon_client_send_control_message_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, char* apid, char* ctid, int verbose) { int ret; int32_t len; @@ -820,8 +707,8 @@ int dlt_daemon_client_send_control_message_v2(int sock, msg->baseheaderextrasizev2 = (int32_t)dlt_message_get_extraparameters_size_v2(DLT_CONTROL_MSG); msg->extendedheadersizev2 = (uint32_t)((daemon->ecuid2len) + 1 + appidlen + 1 + ctxidlen + 1); - msg->headersizev2 = (int32_t)(msg->storageheadersizev2 + msg->baseheadersizev2 + - msg->baseheaderextrasizev2 + msg->extendedheadersizev2); + msg->headersizev2 = (int32_t)(msg->storageheadersizev2 + msg->baseheadersizev2 + msg->baseheaderextrasizev2 + + msg->extendedheadersizev2); if (msg->headerbufferv2 != NULL) { free(msg->headerbufferv2); @@ -838,7 +725,7 @@ int dlt_daemon_client_send_control_message_v2(int sock, } /* prepare base header */ - msg->baseheaderv2 = (DltBaseHeaderV2 *)(msg->headerbufferv2 + msg->storageheadersizev2); + msg->baseheaderv2 = (DltBaseHeaderV2*)(msg->headerbufferv2 + msg->storageheadersizev2); msg->baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2; msg->baseheaderv2->htyp2 |= DLT_CONTROL_MSG; @@ -851,47 +738,47 @@ int dlt_daemon_client_send_control_message_v2(int sock, msg->headerextrav2.noar = 1; /* number of arguments */ memset(msg->headerextrav2.seconds, 0, 5); msg->headerextrav2.nanoseconds = 0; -#if defined (__WIN32__) || defined(_MSC_VER) +#if defined(__WIN32__) || defined(_MSC_VER) time_t t = time(NULL); - if (t==-1) { + if (t == -1) { uint32_t tcnt = (uint32_t)(GetTickCount()); /* GetTickCount() in 10 ms resolution */ tcnt_seconds = tcnt / 100; - tcnt_ns = (tcnt - (tcnt*100)) * 10000; - msg->headerextrav2.seconds[0]=(tcnt_seconds >> 32) & 0xFF; - msg->headerextrav2.seconds[1]=(tcnt_seconds >> 24) & 0xFF; - msg->headerextrav2.seconds[2]=(tcnt_seconds >> 16) & 0xFF; - msg->headerextrav2.seconds[3]=(tcnt_seconds >> 8) & 0xFF; - msg->headerextrav2.seconds[4]= tcnt_seconds & 0xFF; + tcnt_ns = (tcnt - (tcnt * 100)) * 10000; + msg->headerextrav2.seconds[0] = (tcnt_seconds >> 32) & 0xFF; + msg->headerextrav2.seconds[1] = (tcnt_seconds >> 24) & 0xFF; + msg->headerextrav2.seconds[2] = (tcnt_seconds >> 16) & 0xFF; + msg->headerextrav2.seconds[3] = (tcnt_seconds >> 8) & 0xFF; + msg->headerextrav2.seconds[4] = tcnt_seconds & 0xFF; if (ts.tv_nsec < 0x3B9ACA00) { msg->headerextrav2.nanoseconds = tcnt_ns; } } else { - msg->headerextrav2.seconds[0]=(t >> 32) & 0xFF; - msg->headerextrav2.seconds[1]=(t >> 24) & 0xFF; - msg->headerextrav2.seconds[2]=(t >> 16) & 0xFF; - msg->headerextrav2.seconds[3]=(t >> 8) & 0xFF; - msg->headerextrav2.seconds[4]= t & 0xFF; + msg->headerextrav2.seconds[0] = (t >> 32) & 0xFF; + msg->headerextrav2.seconds[1] = (t >> 24) & 0xFF; + msg->headerextrav2.seconds[2] = (t >> 16) & 0xFF; + msg->headerextrav2.seconds[3] = (t >> 8) & 0xFF; + msg->headerextrav2.seconds[4] = t & 0xFF; msg->headerextrav2.nanoseconds |= 0x80000000; } #else struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) == 0) { - msg->headerextrav2.seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - msg->headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - msg->headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - msg->headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - msg->headerextrav2.seconds[4]= (uint8_t)(ts.tv_sec & 0xFF); + msg->headerextrav2.seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + msg->headerextrav2.seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + msg->headerextrav2.seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + msg->headerextrav2.seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + msg->headerextrav2.seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { - msg->headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg->headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } } else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - msg->headerextrav2.seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - msg->headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - msg->headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - msg->headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - msg->headerextrav2.seconds[4]= (uint8_t)(ts.tv_sec & 0xFF); + msg->headerextrav2.seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + msg->headerextrav2.seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + msg->headerextrav2.seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + msg->headerextrav2.seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + msg->headerextrav2.seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { - msg->headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg->headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } msg->headerextrav2.nanoseconds |= 0x80000000; } @@ -945,23 +832,21 @@ int dlt_daemon_client_send_control_message_v2(int sock, return DLT_RETURN_ERROR; } - len = (int32_t) (msg->headersizev2 - (int32_t)msg->storageheadersizev2 + msg->datasize); + len = (int32_t)(msg->headersizev2 - (int32_t)msg->storageheadersizev2 + msg->datasize); if (len > UINT16_MAX) { - dlt_vlog(LOG_ERR, - "%s: Critical: Huge injection message discarded!\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Critical: Huge injection message discarded!\n", __func__); dlt_message_free_v2(msg, 0); return DLT_RETURN_ERROR; } msg->baseheaderv2->len = DLT_HTOBE_16((uint16_t)len); - if ((ret = - dlt_daemon_client_send_v2(sock, daemon, daemon_local, msg->headerbufferv2, (int)msg->storageheadersizev2, - msg->headerbufferv2 + (int)msg->storageheadersizev2, - (int) (msg->headersizev2 - (int32_t)msg->storageheadersizev2), - msg->databuffer, (int) msg->datasize, verbose))) { + if ((ret = dlt_daemon_client_send_v2( + sock, daemon, daemon_local, msg->headerbufferv2, (int)msg->storageheadersizev2, + msg->headerbufferv2 + (int)msg->storageheadersizev2, + (int)(msg->headersizev2 - (int32_t)msg->storageheadersizev2), msg->databuffer, (int)msg->datasize, + verbose))) { dlt_log(LOG_DEBUG, "dlt_daemon_control_send_control_message: DLT message send to all failed!.\n"); return ret; } @@ -969,11 +854,8 @@ int dlt_daemon_client_send_control_message_v2(int sock, return DLT_DAEMON_ERROR_OK; } -int dlt_daemon_client_process_control(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +int dlt_daemon_client_process_control( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { uint32_t id, id_tmp = 0; DltStandardHeaderExtra extra; @@ -992,239 +874,153 @@ int dlt_daemon_client_process_control(int sock, /* check if the message needs to be forwarded */ if (daemon_local->flags.gatewayMode == 1) { if (strncmp(daemon_local->flags.evalue, extra.ecu, DLT_ID_SIZE) != 0) - return dlt_gateway_forward_control_message(&daemon_local->pGateway, - daemon_local, - msg, - extra.ecu, - verbose); + return dlt_gateway_forward_control_message(&daemon_local->pGateway, daemon_local, msg, extra.ecu, verbose); } - id_tmp = *((uint32_t *)(msg->databuffer)); + id_tmp = *((uint32_t*)(msg->databuffer)); id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_CALLSW_CINJECTION)) { /* Control message handling */ switch (id) { - case DLT_SERVICE_ID_SET_LOG_LEVEL: - { + case DLT_SERVICE_ID_SET_LOG_LEVEL: { dlt_daemon_control_set_log_level(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_SET_TRACE_STATUS: - { + case DLT_SERVICE_ID_SET_TRACE_STATUS: { dlt_daemon_control_set_trace_status(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_LOG_INFO: - { + case DLT_SERVICE_ID_GET_LOG_INFO: { dlt_daemon_control_get_log_info(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL: - { + case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL: { dlt_daemon_control_get_default_log_level(sock, daemon, daemon_local, verbose); break; } - case DLT_SERVICE_ID_STORE_CONFIG: - { + case DLT_SERVICE_ID_STORE_CONFIG: { if (dlt_daemon_applications_save(daemon, daemon->runtime_application_cfg, verbose) == 0) { if (dlt_daemon_contexts_save(daemon, daemon->runtime_context_cfg, verbose) == 0) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, - verbose); - } - else { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); + } else { /* Delete saved files */ - dlt_daemon_control_reset_to_factory_default(daemon, - daemon->runtime_application_cfg, - daemon->runtime_context_cfg, - daemon_local->flags.contextLogLevel, - daemon_local->flags.contextTraceStatus, - daemon_local->flags.enforceContextLLAndTS, - verbose); - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_reset_to_factory_default( + daemon, daemon->runtime_application_cfg, daemon->runtime_context_cfg, + daemon_local->flags.contextLogLevel, daemon_local->flags.contextTraceStatus, + daemon_local->flags.enforceContextLLAndTS, verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } - } - else { - dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, - verbose); + } else { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } break; } - case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT: - { - dlt_daemon_control_reset_to_factory_default(daemon, - daemon->runtime_application_cfg, - daemon->runtime_context_cfg, - daemon_local->flags.contextLogLevel, - daemon_local->flags.contextTraceStatus, - daemon_local->flags.enforceContextLLAndTS, - verbose); + case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT: { + dlt_daemon_control_reset_to_factory_default( + daemon, daemon->runtime_application_cfg, daemon->runtime_context_cfg, + daemon_local->flags.contextLogLevel, daemon_local->flags.contextTraceStatus, + daemon_local->flags.enforceContextLLAndTS, verbose); dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); break; } - case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_VERBOSE_MODE: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_VERBOSE_MODE: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_MESSAGE_FILTERING: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_MESSAGE_FILTERING: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_TIMING_PACKETS: - { + case DLT_SERVICE_ID_SET_TIMING_PACKETS: { dlt_daemon_control_set_timing_packets(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_LOCAL_TIME: - { + case DLT_SERVICE_ID_GET_LOCAL_TIME: { /* Send response with valid timestamp (TMSP) field */ dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); break; } - case DLT_SERVICE_ID_USE_ECU_ID: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_ECU_ID: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_USE_SESSION_ID: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_SESSION_ID: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_USE_TIMESTAMP: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_TIMESTAMP: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_USE_EXTENDED_HEADER: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_EXTENDED_HEADER: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL: - { + case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL: { dlt_daemon_control_set_default_log_level(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS: - { + case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS: { dlt_daemon_control_set_default_trace_status(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: - { + case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: { dlt_daemon_control_get_software_version(sock, daemon, daemon_local, verbose); break; } - case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW: - { - dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon_local, daemon->overflow_counter, "", - verbose); + case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW: { + dlt_daemon_control_message_buffer_overflow( + sock, daemon, daemon_local, daemon->overflow_counter, "", verbose); break; } - case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE: - { + case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE: { dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT: - { - dlt_daemon_control_passive_node_connect(sock, - daemon, - daemon_local, - msg, - verbose); + case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT: { + dlt_daemon_control_passive_node_connect(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS: - { - dlt_daemon_control_passive_node_connect_status(sock, - daemon, - daemon_local, - verbose); + case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS: { + dlt_daemon_control_passive_node_connect_status(sock, daemon, daemon_local, verbose); break; } - case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL: - { + case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL: { dlt_daemon_control_set_all_log_level(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS: - { + case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS: { dlt_daemon_control_set_all_trace_status(sock, daemon, daemon_local, msg, verbose); break; } - default: - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + default: { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } } - } - else { + } else { /* Injection handling */ dlt_daemon_control_callsw_cinjection(sock, daemon, daemon_local, msg, verbose); } @@ -1232,11 +1028,8 @@ int dlt_daemon_client_process_control(int sock, return 0; } -int dlt_daemon_client_process_control_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +int dlt_daemon_client_process_control_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { uint32_t id, id_tmp = 0; DltExtendedHeaderV2 extended; @@ -1254,240 +1047,154 @@ int dlt_daemon_client_process_control_v2(int sock, /* check if the message needs to be forwarded */ if (daemon_local->flags.gatewayMode == 1) { if (strncmp(daemon_local->flags.evalue, extended.ecid, extended.ecidlen) != 0) - return dlt_gateway_forward_control_message_v2(&daemon_local->pGateway, - daemon_local, - msg, - extended.ecidlen, - extended.ecid, - verbose); + return dlt_gateway_forward_control_message_v2( + &daemon_local->pGateway, daemon_local, msg, extended.ecidlen, extended.ecid, verbose); } - id_tmp = *((uint32_t *)(msg->databuffer)); + id_tmp = *((uint32_t*)(msg->databuffer)); id = DLT_LETOH_32(id_tmp); if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_CALLSW_CINJECTION)) { /* Control message handling */ switch (id) { - case DLT_SERVICE_ID_SET_LOG_LEVEL: - { + case DLT_SERVICE_ID_SET_LOG_LEVEL: { dlt_daemon_control_set_log_level_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_SET_TRACE_STATUS: - { + case DLT_SERVICE_ID_SET_TRACE_STATUS: { dlt_daemon_control_set_trace_status_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_LOG_INFO: - { + case DLT_SERVICE_ID_GET_LOG_INFO: { dlt_daemon_control_get_log_info_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL: - { + case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL: { dlt_daemon_control_get_default_log_level_v2(sock, daemon, daemon_local, verbose); break; } - case DLT_SERVICE_ID_STORE_CONFIG: - { + case DLT_SERVICE_ID_STORE_CONFIG: { if (dlt_daemon_applications_save_v2(daemon, daemon->runtime_application_cfg, verbose) == 0) { if (dlt_daemon_contexts_save_v2(daemon, daemon->runtime_context_cfg, verbose) == 0) { - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, - verbose); - } - else { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); + } else { /* Delete saved files */ - dlt_daemon_control_reset_to_factory_default_v2(daemon, - daemon->runtime_application_cfg, - daemon->runtime_context_cfg, - daemon_local->flags.contextLogLevel, - daemon_local->flags.contextTraceStatus, - daemon_local->flags.enforceContextLLAndTS, - verbose); - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_reset_to_factory_default_v2( + daemon, daemon->runtime_application_cfg, daemon->runtime_context_cfg, + daemon_local->flags.contextLogLevel, daemon_local->flags.contextTraceStatus, + daemon_local->flags.enforceContextLLAndTS, verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } - } - else { - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, - verbose); + } else { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } break; } - case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT: - { - dlt_daemon_control_reset_to_factory_default_v2(daemon, - daemon->runtime_application_cfg, - daemon->runtime_context_cfg, - daemon_local->flags.contextLogLevel, - daemon_local->flags.contextTraceStatus, - daemon_local->flags.enforceContextLLAndTS, - verbose); + case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT: { + dlt_daemon_control_reset_to_factory_default_v2( + daemon, daemon->runtime_application_cfg, daemon->runtime_context_cfg, + daemon_local->flags.contextLogLevel, daemon_local->flags.contextTraceStatus, + daemon_local->flags.enforceContextLLAndTS, verbose); dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); break; } - case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_VERBOSE_MODE: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_VERBOSE_MODE: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_MESSAGE_FILTERING: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_SET_MESSAGE_FILTERING: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_TIMING_PACKETS: - { + case DLT_SERVICE_ID_SET_TIMING_PACKETS: { dlt_daemon_control_set_timing_packets_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_LOCAL_TIME: - { + case DLT_SERVICE_ID_GET_LOCAL_TIME: { /* Send response with valid timestamp (TMSP) field */ dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); break; } - case DLT_SERVICE_ID_USE_ECU_ID: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_ECU_ID: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_USE_SESSION_ID: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_SESSION_ID: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_USE_TIMESTAMP: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_TIMESTAMP: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_USE_EXTENDED_HEADER: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + case DLT_SERVICE_ID_USE_EXTENDED_HEADER: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } - case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL: - { + case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL: { dlt_daemon_control_set_default_log_level_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS: - { + case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS: { dlt_daemon_control_set_default_trace_status_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: - { + case DLT_SERVICE_ID_GET_SOFTWARE_VERSION: { dlt_daemon_control_get_software_version_v2(sock, daemon, daemon_local, verbose); break; } - case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW: - { - dlt_daemon_control_message_buffer_overflow_v2(sock, daemon, daemon_local, daemon->overflow_counter, "", - verbose); + case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW: { + dlt_daemon_control_message_buffer_overflow_v2( + sock, daemon, daemon_local, daemon->overflow_counter, "", verbose); break; } - case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE: - { + case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE: { dlt_daemon_control_service_logstorage_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT: - { - dlt_daemon_control_passive_node_connect_v2(sock, - daemon, - daemon_local, - msg, - verbose); + case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT: { + dlt_daemon_control_passive_node_connect_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS: - { - dlt_daemon_control_passive_node_connect_status_v2(sock, - daemon, - daemon_local, - verbose); + case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS: { + dlt_daemon_control_passive_node_connect_status_v2(sock, daemon, daemon_local, verbose); break; } - case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL: - { + case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL: { dlt_daemon_control_set_all_log_level_v2(sock, daemon, daemon_local, msg, verbose); break; } - case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS: - { + case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS: { dlt_daemon_control_set_all_trace_status_v2(sock, daemon, daemon_local, msg, verbose); break; } - default: - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + default: { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); break; } } - } - else { + } else { /* Injection handling */ dlt_daemon_control_callsw_cinjection_v2(sock, daemon, daemon_local, msg, verbose); } @@ -1495,11 +1202,11 @@ int dlt_daemon_client_process_control_v2(int sock, return 0; } -void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +void dlt_daemon_control_get_software_version(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessage msg; uint32_t len; - DltServiceGetSoftwareVersionResponse *resp; + DltServiceGetSoftwareVersionResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -1508,20 +1215,17 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDae /* initialise new message */ if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_SOFTWARE_VERSION, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } /* prepare payload of data */ - len = (uint32_t) strlen(daemon->ECUVersionString); + len = (uint32_t)strlen(daemon->ECUVersionString); /* msg.datasize = sizeof(serviceID) + sizeof(status) + sizeof(length) + len */ - msg.datasize = (int32_t)((size_t)sizeof(uint32_t) + (size_t)sizeof(uint8_t) + (size_t)sizeof(uint32_t) + (size_t)len); + msg.datasize = + (int32_t)((size_t)sizeof(uint32_t) + (size_t)sizeof(uint8_t) + (size_t)sizeof(uint32_t) + (size_t)len); if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); @@ -1529,21 +1233,17 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDae } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_SOFTWARE_VERSION, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } - resp = (DltServiceGetSoftwareVersionResponse *)msg.databuffer; + resp = (DltServiceGetSoftwareVersionResponse*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; resp->status = DLT_SERVICE_RESPONSE_OK; resp->length = len; @@ -1556,11 +1256,11 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDae dlt_message_free(&msg, 0); } -void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessageV2 msg; uint32_t len; - DltServiceGetSoftwareVersionResponse *resp; + DltServiceGetSoftwareVersionResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -1569,20 +1269,16 @@ void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, Dlt /* initialise new message */ if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_SOFTWARE_VERSION, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } /* prepare payload of data */ - len = (uint32_t) strlen(daemon->ECUVersionString); + len = (uint32_t)strlen(daemon->ECUVersionString); /* msg.datasize = sizeof(serviceID) + sizeof(status) + sizeof(length) + len */ - msg.datasize = (int32_t) (sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t) + len); + msg.datasize = (int32_t)(sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t) + len); if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); @@ -1590,21 +1286,17 @@ void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, Dlt } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_SOFTWARE_VERSION, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } - resp = (DltServiceGetSoftwareVersionResponse *)msg.databuffer; + resp = (DltServiceGetSoftwareVersionResponse*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; resp->status = DLT_SERVICE_RESPONSE_OK; resp->length = len; @@ -1617,10 +1309,10 @@ void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, Dlt dlt_message_free_v2(&msg, 0); } -void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +void dlt_daemon_control_get_default_log_level(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessage msg; - DltServiceGetDefaultLogLevelResponse *resp; + DltServiceGetDefaultLogLevelResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -1629,12 +1321,8 @@ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDa /* initialise new message */ if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -1646,24 +1334,20 @@ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDa } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } - resp = (DltServiceGetDefaultLogLevelResponse *)msg.databuffer; + resp = (DltServiceGetDefaultLogLevelResponse*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; resp->status = DLT_SERVICE_RESPONSE_OK; - resp->log_level = (uint8_t) daemon->default_log_level; + resp->log_level = (uint8_t)daemon->default_log_level; /* send message */ dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -1672,10 +1356,10 @@ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDa dlt_message_free(&msg, 0); } -void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessageV2 msg; - DltServiceGetDefaultLogLevelResponse *resp; + DltServiceGetDefaultLogLevelResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -1684,12 +1368,8 @@ void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, Dl /* initialise new message */ if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -1701,24 +1381,20 @@ void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, Dl } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } - resp = (DltServiceGetDefaultLogLevelResponse *)msg.databuffer; + resp = (DltServiceGetDefaultLogLevelResponse*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; resp->status = DLT_SERVICE_RESPONSE_OK; - resp->log_level = (uint8_t) daemon->default_log_level; + resp->log_level = (uint8_t)daemon->default_log_level; /* send message */ dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -1727,16 +1403,13 @@ void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, Dl dlt_message_free_v2(&msg, 0); } -void dlt_daemon_control_get_log_info(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_get_log_info( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { - DltServiceGetLogInfoRequest *req; + DltServiceGetLogInfoRequest* req; DltMessage resp; - DltDaemonContext *context = 0; - DltDaemonApplication *application = 0; + DltDaemonContext* context = 0; + DltDaemonApplication* application = 0; int num_applications = 0, num_contexts = 0; uint16_t count_app_ids = 0, count_con_ids = 0; @@ -1747,7 +1420,7 @@ void dlt_daemon_control_get_log_info(int sock, int32_t i, j; size_t offset = 0; - char *apid = 0; + char* apid = 0; int8_t ll, ts; uint16_t len; int8_t value; @@ -1756,7 +1429,7 @@ void dlt_daemon_control_get_log_info(int sock, uint32_t sid; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1772,58 +1445,40 @@ void dlt_daemon_control_get_log_info(int sock, return; /* prepare pointer to message request */ - req = (DltServiceGetLogInfoRequest *)(msg->databuffer); + req = (DltServiceGetLogInfoRequest*)(msg->databuffer); /* initialise new message */ if (dlt_message_init(&resp, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_LOG_INFO, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } /* check request */ if ((req->options < 3) || (req->options > 7)) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_LOG_INFO, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } if (req->apid[0] != '\0') { - application = dlt_daemon_application_find(daemon, - req->apid, - daemon->ecuid, - verbose); + application = dlt_daemon_application_find(daemon, req->apid, daemon->ecuid, verbose); if (application) { num_applications = 1; if (req->ctid[0] != '\0') { - context = dlt_daemon_context_find(daemon, - req->apid, - req->ctid, - daemon->ecuid, - verbose); + context = dlt_daemon_context_find(daemon, req->apid, req->ctid, daemon->ecuid, verbose); num_contexts = ((context) ? 1 : 0); - } - else { + } else { num_contexts = application->num_contexts; } - } - else { + } else { num_applications = 0; num_contexts = 0; } - } - else { + } else { /* Request all applications and contexts */ num_applications = user_list->num_applications; num_contexts = user_list->num_contexts; @@ -1844,8 +1499,8 @@ void dlt_daemon_control_get_log_info(int sock, if ((req->options == 5) || (req->options == 6) || (req->options == 7)) sizecont += sizeof(int8_t); /* trace status */ - resp.datasize += (int32_t)(((size_t) num_applications * (sizeof(uint32_t) + sizeof(uint16_t))) + - ((size_t) num_contexts * sizecont)); + resp.datasize += (int32_t)(((size_t)num_applications * (sizeof(uint32_t) + sizeof(uint16_t))) + + ((size_t)num_contexts * sizecont)); resp.datasize += (int32_t)sizeof(uint16_t); @@ -1861,29 +1516,27 @@ void dlt_daemon_control_get_log_info(int sock, if (context->context_description != 0) resp.datasize += (int32_t)strlen(context->context_description); } - } - else - /* One application, all contexts */ - if ((user_list->applications) && (application)) { - /* Calculate start offset within contexts[] */ - offset_base = 0; - - for (i = 0; i < (application - (user_list->applications)); i++) - offset_base += user_list->applications[i].num_contexts; + } else + /* One application, all contexts */ + if ((user_list->applications) && (application)) { + /* Calculate start offset within contexts[] */ + offset_base = 0; - /* Iterate over all contexts belonging to this application */ - for (j = 0; j < application->num_contexts; j++) { + for (i = 0; i < (application - (user_list->applications)); i++) + offset_base += user_list->applications[i].num_contexts; - context = &(user_list->contexts[offset_base + j]); + /* Iterate over all contexts belonging to this application */ + for (j = 0; j < application->num_contexts; j++) { + context = &(user_list->contexts[offset_base + j]); - if (context) { - resp.datasize += (int32_t)sizeof(uint16_t); + if (context) { + resp.datasize += (int32_t)sizeof(uint16_t); - if (context->context_description != 0) - resp.datasize += (int32_t)strlen(context->context_description); + if (context->context_description != 0) + resp.datasize += (int32_t)strlen(context->context_description); + } } } - } /* Space for application description */ if (application) { @@ -1892,15 +1545,13 @@ void dlt_daemon_control_get_log_info(int sock, if (application->application_description != 0) resp.datasize += (int32_t)strlen(application->application_description); } - } - else { + } else { /* All applications, all contexts */ for (i = 0; i < user_list->num_contexts; i++) { resp.datasize += (int32_t)sizeof(uint16_t); if (user_list->contexts[i].context_description != 0) - resp.datasize += - (int32_t)strlen(user_list->contexts[i].context_description); + resp.datasize += (int32_t)strlen(user_list->contexts[i].context_description); } for (i = 0; i < user_list->num_applications; i++) { @@ -1913,21 +1564,15 @@ void dlt_daemon_control_get_log_info(int sock, } if (verbose) - dlt_vlog(LOG_DEBUG, - "Allocate %u bytes for response msg databuffer\n", - resp.datasize); + dlt_vlog(LOG_DEBUG, "Allocate %u bytes for response msg databuffer\n", resp.datasize); /* Allocate buffer for response message */ - resp.databuffer = (uint8_t *)malloc((size_t)resp.datasize); + resp.databuffer = (uint8_t*)malloc((size_t)resp.datasize); resp.databuffersize = resp.datasize; if (resp.databuffer == 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_LOG_INFO, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -1939,12 +1584,13 @@ void dlt_daemon_control_get_log_info(int sock, memcpy(resp.databuffer, &sid, sizeof(uint32_t)); offset += sizeof(uint32_t); - value = (int8_t) (((num_applications != 0) && (num_contexts != 0)) ? req->options : 8); /* 8 = no matching context found */ + value = (int8_t)(((num_applications != 0) && (num_contexts != 0)) ? req->options : + 8); /* 8 = no matching context found */ memcpy(resp.databuffer + offset, &value, sizeof(int8_t)); offset += sizeof(int8_t); - count_app_ids = (uint16_t) num_applications; + count_app_ids = (uint16_t)num_applications; if (count_app_ids != 0) { memcpy(resp.databuffer + offset, &count_app_ids, sizeof(uint16_t)); @@ -1957,8 +1603,7 @@ void dlt_daemon_control_get_log_info(int sock, for (i = 0; i < count_app_ids; i++) { if (req->apid[0] != '\0') { apid = req->apid; - } - else { + } else { if (user_list->applications) apid = user_list->applications[i].apid; else @@ -1966,10 +1611,7 @@ void dlt_daemon_control_get_log_info(int sock, apid = 0; } - application = dlt_daemon_application_find(daemon, - apid, - daemon->ecuid, - verbose); + application = dlt_daemon_application_find(daemon, apid, daemon->ecuid, verbose); if ((user_list->applications) && (application)) { /* Calculate start offset within contexts[] */ @@ -1978,7 +1620,7 @@ void dlt_daemon_control_get_log_info(int sock, for (j = 0; j < (application - (user_list->applications)); j++) offset_base += user_list->applications[j].num_contexts; - dlt_set_id((char *)(resp.databuffer + offset), apid); + dlt_set_id((char*)(resp.databuffer + offset), apid); offset += sizeof(ID4); #if (DLT_DEBUG_GETLOGINFO == 1) @@ -1987,9 +1629,9 @@ void dlt_daemon_control_get_log_info(int sock, #endif if (req->apid[0] != '\0') - count_con_ids = (uint16_t) num_contexts; + count_con_ids = (uint16_t)num_contexts; else - count_con_ids = (uint16_t) application->num_contexts; + count_con_ids = (uint16_t)application->num_contexts; memcpy(resp.databuffer + offset, &count_con_ids, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -2003,18 +1645,16 @@ void dlt_daemon_control_get_log_info(int sock, dlt_vlog(LOG_DEBUG, "j: %d \n", j); #endif - if (!((count_con_ids == 1) && (req->apid[0] != '\0') && - (req->ctid[0] != '\0'))) + if (!((count_con_ids == 1) && (req->apid[0] != '\0') && (req->ctid[0] != '\0'))) context = &(user_list->contexts[offset_base + j]); /* else: context was already searched and found * (one application (found) with one context (found))*/ - if ((context) && - ((req->ctid[0] == '\0') || ((req->ctid[0] != '\0') && - (memcmp(context->ctid, req->ctid, DLT_ID_SIZE) == 0))) - ) { - dlt_set_id((char *)(resp.databuffer + offset), context->ctid); + if ((context) + && ((req->ctid[0] == '\0') + || ((req->ctid[0] != '\0') && (memcmp(context->ctid, req->ctid, DLT_ID_SIZE) == 0)))) { + dlt_set_id((char*)(resp.databuffer + offset), context->ctid); offset += sizeof(ID4); #if (DLT_DEBUG_GETLOGINFO == 1) @@ -2039,14 +1679,14 @@ void dlt_daemon_control_get_log_info(int sock, /* Mode 7 */ if (req->options == 7) { if (context->context_description) { - len = (uint16_t) strlen(context->context_description); + len = (uint16_t)strlen(context->context_description); memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); - memcpy(resp.databuffer + offset, context->context_description, - strlen(context->context_description)); + memcpy( + resp.databuffer + offset, context->context_description, + strlen(context->context_description)); offset += strlen(context->context_description); - } - else { + } else { len = 0; memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -2054,8 +1694,7 @@ void dlt_daemon_control_get_log_info(int sock, } #if (DLT_DEBUG_GETLOGINFO == 1) - dlt_vlog(LOG_DEBUG, "ll=%d ts=%d \n", (int32_t)ll, - (int32_t)ts); + dlt_vlog(LOG_DEBUG, "ll=%d ts=%d \n", (int32_t)ll, (int32_t)ts); #endif } @@ -2067,14 +1706,14 @@ void dlt_daemon_control_get_log_info(int sock, /* Mode 7 */ if (req->options == 7) { if (application->application_description) { - len = (uint16_t) strlen(application->application_description); + len = (uint16_t)strlen(application->application_description); memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); - memcpy(resp.databuffer + offset, application->application_description, - strlen(application->application_description)); + memcpy( + resp.databuffer + offset, application->application_description, + strlen(application->application_description)); offset += strlen(application->application_description); - } - else { + } else { len = 0; memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -2086,7 +1725,7 @@ void dlt_daemon_control_get_log_info(int sock, } /* if (count_app_ids!=0) */ - dlt_set_id((char *)(resp.databuffer + offset), DLT_DAEMON_REMO_STRING); + dlt_set_id((char*)(resp.databuffer + offset), DLT_DAEMON_REMO_STRING); /* send message */ dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &resp, "", "", verbose); @@ -2095,16 +1734,13 @@ void dlt_daemon_control_get_log_info(int sock, dlt_message_free(&resp, 0); } -void dlt_daemon_control_get_log_info_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_get_log_info_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { - DltServiceGetLogInfoRequestV2 *req; + DltServiceGetLogInfoRequestV2* req; DltMessageV2 resp; - DltDaemonContext *context = NULL; - DltDaemonApplication *application = NULL; + DltDaemonContext* context = NULL; + DltDaemonApplication* application = NULL; int num_applications = 0, num_contexts = 0; uint16_t count_app_ids = 0, count_con_ids = 0; @@ -2114,7 +1750,7 @@ void dlt_daemon_control_get_log_info_v2(int sock, #endif size_t offset = 0; uint8_t apidlen = 0; - char *apid = 0; + char* apid = 0; int8_t ll, ts; uint16_t len; int8_t value; @@ -2123,7 +1759,7 @@ void dlt_daemon_control_get_log_info_v2(int sock, uint32_t sid; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2138,7 +1774,7 @@ void dlt_daemon_control_get_log_info_v2(int sock, if (user_list == NULL) return; - req = (DltServiceGetLogInfoRequestV2 *)calloc(1, sizeof(DltServiceGetLogInfoRequestV2)); + req = (DltServiceGetLogInfoRequestV2*)calloc(1, sizeof(DltServiceGetLogInfoRequestV2)); if (req == NULL) return; @@ -2151,70 +1787,48 @@ void dlt_daemon_control_get_log_info_v2(int sock, db_offset = db_offset + (int)sizeof(uint8_t); memcpy(&(req->apidlen), msg->databuffer + db_offset, sizeof(uint8_t)); db_offset = db_offset + (int)sizeof(uint8_t); - dlt_set_id_v2(req->apid, (const char *)(msg->databuffer + db_offset), req->apidlen); + dlt_set_id_v2(req->apid, (const char*)(msg->databuffer + db_offset), req->apidlen); db_offset = db_offset + (int)req->apidlen; - memcpy(&(req->ctidlen), (const char *)(msg->databuffer + db_offset), sizeof(uint8_t)); + memcpy(&(req->ctidlen), (const char*)(msg->databuffer + db_offset), sizeof(uint8_t)); db_offset = db_offset + (int)sizeof(uint8_t); - dlt_set_id_v2(req->ctid, (const char *)(msg->databuffer + db_offset), req->ctidlen); + dlt_set_id_v2(req->ctid, (const char*)(msg->databuffer + db_offset), req->ctidlen); db_offset = db_offset + (int)req->ctidlen; - memcpy((req->com), (const char *)(msg->databuffer + db_offset), DLT_ID_SIZE); + memcpy((req->com), (const char*)(msg->databuffer + db_offset), DLT_ID_SIZE); /* initialise new message */ if (dlt_message_init_v2(&resp, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_LOG_INFO, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } /* check request */ if ((req->options < 3) || (req->options > 7)) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_LOG_INFO, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } if (req->apidlen != 0) { - - dlt_daemon_application_find_v2(daemon, - req->apidlen, - req->apid, - daemon->ecuid2len, - daemon->ecuid2, - verbose, - &application); + dlt_daemon_application_find_v2( + daemon, req->apidlen, req->apid, daemon->ecuid2len, daemon->ecuid2, verbose, &application); if (application) { num_applications = 1; if (req->ctidlen != 0) { - context = dlt_daemon_context_find_v2(daemon, - req->apidlen, - req->apid, - req->ctidlen, - req->ctid, - daemon->ecuid2len, - daemon->ecuid2, - verbose); + context = dlt_daemon_context_find_v2( + daemon, req->apidlen, req->apid, req->ctidlen, req->ctid, daemon->ecuid2len, daemon->ecuid2, + verbose); num_contexts = ((context) ? 1 : 0); - } - else { + } else { num_contexts = application->num_contexts; } - } - else { + } else { num_applications = 0; num_contexts = 0; } - } - else { + } else { /* Request all applications and contexts */ num_applications = user_list->num_applications; num_contexts = user_list->num_contexts; @@ -2234,19 +1848,23 @@ void dlt_daemon_control_get_log_info_v2(int sock, if ((req->options == 5) || (req->options == 6) || (req->options == 7)) sizecont += sizeof(int8_t); /* trace status */ - if ((num_applications == user_list->num_applications) && (num_contexts == user_list->num_contexts)){ - for(int i = 0; iapplications[i].apid2len /* app_id */ + sizeof(uint16_t) /* count_con_ids */)); + if ((num_applications == user_list->num_applications) && (num_contexts == user_list->num_contexts)) { + for (int i = 0; i < num_applications; i++) { + resp.datasize += (int32_t)(( + sizeof(uint8_t) /* app_id length */ + user_list->applications[i].apid2len /* app_id */ + + sizeof(uint16_t) /* count_con_ids */)); } - for(int j = 0; jcontexts[j].ctid2len); + for (int j = 0; j < num_contexts; j++) { + resp.datasize += (int32_t)(sizecont + user_list->contexts[j].ctid2len); } - }else if (num_applications == 1) { - resp.datasize += (int32_t) ((sizeof(uint8_t) /* app_id length */ + application->apid2len /* app_id */ + sizeof(uint16_t) /* count_con_ids */)); + } else if (num_applications == 1) { + resp.datasize += (int32_t)(( + sizeof(uint8_t) /* app_id length */ + application->apid2len /* app_id */ + + sizeof(uint16_t) /* count_con_ids */)); /* 1 application and 1 context*/ if (num_contexts == 1) { - resp.datasize += (int32_t) (sizecont + context->ctid2len); - }else if (num_contexts == application->num_contexts) { + resp.datasize += (int32_t)(sizecont + context->ctid2len); + } else if (num_contexts == application->num_contexts) { if ((user_list->applications) && (application)) { /* Calculate start offset within contexts[] */ offset_base = 0; @@ -2259,13 +1877,13 @@ void dlt_daemon_control_get_log_info_v2(int sock, context = &(user_list->contexts[offset_base + j]); if (context) { - resp.datasize += (int32_t) (sizecont + context->ctid2len); + resp.datasize += (int32_t)(sizecont + context->ctid2len); } } } } } - resp.datasize += (int32_t) sizeof(uint16_t) /* count_app_ids */; + resp.datasize += (int32_t)sizeof(uint16_t) /* count_app_ids */; /* Add additional size for response of Mode 7 */ if (req->options == 7) { @@ -2273,76 +1891,69 @@ void dlt_daemon_control_get_log_info_v2(int sock, if (req->ctidlen != 0) { /* One application, one context */ if (context) { - resp.datasize += (int32_t) sizeof(uint16_t) /* len_context_description */; + resp.datasize += (int32_t)sizeof(uint16_t) /* len_context_description */; if (context->context_description != 0) - resp.datasize += (int32_t) strlen(context->context_description); /* context_description */ + resp.datasize += (int32_t)strlen(context->context_description); /* context_description */ } - } - else - /* One application, all contexts */ - if ((user_list->applications) && (application)) { - /* Calculate start offset within contexts[] */ - offset_base = 0; + } else + /* One application, all contexts */ + if ((user_list->applications) && (application)) { + /* Calculate start offset within contexts[] */ + offset_base = 0; - for (int i = 0; i < (application - (user_list->applications)); i++) - offset_base += user_list->applications[i].num_contexts; + for (int i = 0; i < (application - (user_list->applications)); i++) + offset_base += user_list->applications[i].num_contexts; - /* Iterate over all contexts belonging to this application */ - for (int j = 0; j < application->num_contexts; j++) { - context = &(user_list->contexts[offset_base + j]); + /* Iterate over all contexts belonging to this application */ + for (int j = 0; j < application->num_contexts; j++) { + context = &(user_list->contexts[offset_base + j]); - if (context) { - resp.datasize += (int32_t) sizeof(uint16_t) /* len_context_description */; + if (context) { + resp.datasize += (int32_t)sizeof(uint16_t) /* len_context_description */; - if (context->context_description != 0) - resp.datasize += (int32_t) strlen(context->context_description); /* context_description */ + if (context->context_description != 0) + resp.datasize += + (int32_t)strlen(context->context_description); /* context_description */ + } } } - } /* Space for application description */ if (application) { - resp.datasize += (int32_t) sizeof(uint16_t) /* len_app_description */; + resp.datasize += (int32_t)sizeof(uint16_t) /* len_app_description */; if (application->application_description != 0) - resp.datasize += (int32_t) strlen(application->application_description); /* app_description */ + resp.datasize += (int32_t)strlen(application->application_description); /* app_description */ } - } - else { + } else { /* All applications, all contexts */ for (int i = 0; i < user_list->num_contexts; i++) { - resp.datasize += (int32_t) sizeof(uint16_t) /* len_context_description */; + resp.datasize += (int32_t)sizeof(uint16_t) /* len_context_description */; if (user_list->contexts[i].context_description != 0) - resp.datasize += - (int32_t) strlen(user_list->contexts[i].context_description); + resp.datasize += (int32_t)strlen(user_list->contexts[i].context_description); } for (int i = 0; i < user_list->num_applications; i++) { - resp.datasize += (int32_t) sizeof(uint16_t) /* len_app_description */; + resp.datasize += (int32_t)sizeof(uint16_t) /* len_app_description */; if (user_list->applications[i].application_description != 0) - resp.datasize += (int32_t) strlen(user_list->applications[i].application_description); /* app_description */ + resp.datasize += + (int32_t)strlen(user_list->applications[i].application_description); /* app_description */ } } } if (verbose) - dlt_vlog(LOG_DEBUG, - "Allocate %u bytes for response msg databuffer\n", - resp.datasize); + dlt_vlog(LOG_DEBUG, "Allocate %u bytes for response msg databuffer\n", resp.datasize); /* Allocate buffer for response message */ - resp.databuffer = (uint8_t *)malloc((size_t)resp.datasize); + resp.databuffer = (uint8_t*)malloc((size_t)resp.datasize); resp.datasize = resp.datasize; if (resp.databuffer == 0) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_GET_LOG_INFO, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -2354,12 +1965,13 @@ void dlt_daemon_control_get_log_info_v2(int sock, memcpy(resp.databuffer, &sid, sizeof(uint32_t)); offset += sizeof(uint32_t); - value = (int8_t) (((num_applications != 0) && (num_contexts != 0)) ? req->options : 8); /* 8 = no matching context found */ + value = (int8_t)(((num_applications != 0) && (num_contexts != 0)) ? req->options : + 8); /* 8 = no matching context found */ memcpy(resp.databuffer + offset, &value, sizeof(int8_t)); offset += sizeof(int8_t); - count_app_ids = (uint16_t) num_applications; + count_app_ids = (uint16_t)num_applications; if (count_app_ids != 0) { memcpy(resp.databuffer + offset, &count_app_ids, sizeof(uint16_t)); @@ -2373,26 +1985,19 @@ void dlt_daemon_control_get_log_info_v2(int sock, if (req->apidlen != 0) { apid = req->apid; apidlen = req->apidlen; - } - else { - if (user_list->applications){ + } else { + if (user_list->applications) { apid = user_list->applications[i].apid2; apidlen = user_list->applications[i].apid2len; - } - else { + } else { /* This should never occur! */ apid = NULL; apidlen = 0; } } - dlt_daemon_application_find_v2(daemon, - apidlen, - apid, - daemon->ecuid2len, - daemon->ecuid2, - verbose, - &application); + dlt_daemon_application_find_v2( + daemon, apidlen, apid, daemon->ecuid2len, daemon->ecuid2, verbose, &application); if ((user_list->applications) && (application)) { /* Calculate start offset within contexts[] */ @@ -2415,9 +2020,9 @@ void dlt_daemon_control_get_log_info_v2(int sock, dlt_vlog(LOG_DEBUG, "apid: %s\n", buf); #endif if (req->apidlen != 0) - count_con_ids = (uint16_t) num_contexts; + count_con_ids = (uint16_t)num_contexts; else - count_con_ids = (uint16_t) application->num_contexts; + count_con_ids = (uint16_t)application->num_contexts; memcpy(resp.databuffer + offset, &count_con_ids, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -2431,25 +2036,23 @@ void dlt_daemon_control_get_log_info_v2(int sock, dlt_vlog(LOG_DEBUG, "j: %d \n", j); #endif - if (!((count_con_ids == 1) && (req->apidlen != 0) && - (req->ctidlen != 0))) + if (!((count_con_ids == 1) && (req->apidlen != 0) && (req->ctidlen != 0))) context = &(user_list->contexts[offset_base + j]); /* else: context was already searched and found * (one application (found) with one context (found))*/ - if ((context) && - ((req->ctidlen == 0) || ((req->ctidlen != 0) && - (memcmp(context->ctid2, req->ctid, req->ctidlen) == 0))) - ) { - memcpy(resp.databuffer + offset, &(context->ctid2len), 1); - offset += 1; - memcpy(resp.databuffer + offset, context->ctid2, context->ctid2len); - offset += context->ctid2len; + if ((context) + && ((req->ctidlen == 0) + || ((req->ctidlen != 0) && (memcmp(context->ctid2, req->ctid, req->ctidlen) == 0)))) { + memcpy(resp.databuffer + offset, &(context->ctid2len), 1); + offset += 1; + memcpy(resp.databuffer + offset, context->ctid2, context->ctid2len); + offset += context->ctid2len; #if (DLT_DEBUG_GETLOGINFO == 1) // dlt_print_id_v2(buf, context->ctid, context->ctid2len); - //TBD: Enable below check for NULL + // TBD: Enable below check for NULL /* if ((buf == NULL) || (context->ctid == NULL) || (context->ctid2len == 0)) { dlt_vlog(LOG_ERR, "Failed to memcpy ctid\n"); @@ -2477,14 +2080,14 @@ void dlt_daemon_control_get_log_info_v2(int sock, /* Mode 7 */ if (req->options == 7) { if (context->context_description) { - len = (uint16_t) strlen(context->context_description); + len = (uint16_t)strlen(context->context_description); memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); - memcpy(resp.databuffer + offset, context->context_description, - strlen(context->context_description)); + memcpy( + resp.databuffer + offset, context->context_description, + strlen(context->context_description)); offset += strlen(context->context_description); - } - else { + } else { len = 0; memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -2492,8 +2095,7 @@ void dlt_daemon_control_get_log_info_v2(int sock, } #if (DLT_DEBUG_GETLOGINFO == 1) - dlt_vlog(LOG_DEBUG, "ll=%d ts=%d \n", (int32_t)ll, - (int32_t)ts); + dlt_vlog(LOG_DEBUG, "ll=%d ts=%d \n", (int32_t)ll, (int32_t)ts); #endif } @@ -2505,14 +2107,14 @@ void dlt_daemon_control_get_log_info_v2(int sock, /* Mode 7 */ if (req->options == 7) { if (application->application_description) { - len = (uint16_t) strlen(application->application_description); + len = (uint16_t)strlen(application->application_description); memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); - memcpy(resp.databuffer + offset, application->application_description, - strlen(application->application_description)); + memcpy( + resp.databuffer + offset, application->application_description, + strlen(application->application_description)); offset += strlen(application->application_description); - } - else { + } else { len = 0; memcpy(resp.databuffer + offset, &len, sizeof(uint16_t)); offset += sizeof(uint16_t); @@ -2524,7 +2126,7 @@ void dlt_daemon_control_get_log_info_v2(int sock, } /* if (count_app_ids!=0) */ - dlt_set_id((char *)(resp.databuffer + offset), DLT_DAEMON_REMO_STRING); + dlt_set_id((char*)(resp.databuffer + offset), DLT_DAEMON_REMO_STRING); /* send message */ dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &resp, "", "", verbose); @@ -2535,16 +2137,12 @@ void dlt_daemon_control_get_log_info_v2(int sock, dlt_message_free_v2(&resp, 0); } -int dlt_daemon_control_message_buffer_overflow(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - unsigned int overflow_counter, - char *apid, - int verbose) +int dlt_daemon_control_message_buffer_overflow( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, unsigned int overflow_counter, char* apid, int verbose) { int ret; DltMessage msg; - DltServiceMessageBufferOverflowResponse *resp; + DltServiceMessageBufferOverflowResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2553,12 +2151,8 @@ int dlt_daemon_control_message_buffer_overflow(int sock, /* initialise new message */ if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); return DLT_DAEMON_ERROR_UNKNOWN; } @@ -2571,14 +2165,14 @@ int dlt_daemon_control_message_buffer_overflow(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return DLT_DAEMON_ERROR_UNKNOWN; - resp = (DltServiceMessageBufferOverflowResponse *)msg.databuffer; + resp = (DltServiceMessageBufferOverflowResponse*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW; resp->status = DLT_SERVICE_RESPONSE_OK; resp->overflow = DLT_MESSAGE_BUFFER_OVERFLOW; @@ -2596,16 +2190,12 @@ int dlt_daemon_control_message_buffer_overflow(int sock, return DLT_DAEMON_ERROR_OK; } -int dlt_daemon_control_message_buffer_overflow_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - unsigned int overflow_counter, - char *apid, - int verbose) +int dlt_daemon_control_message_buffer_overflow_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, unsigned int overflow_counter, char* apid, int verbose) { int ret; DltMessageV2 msg; - DltServiceMessageBufferOverflowResponse *resp; + DltServiceMessageBufferOverflowResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2614,12 +2204,8 @@ int dlt_daemon_control_message_buffer_overflow_v2(int sock, /* initialise new message */ if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); return DLT_DAEMON_ERROR_UNKNOWN; } @@ -2632,14 +2218,14 @@ int dlt_daemon_control_message_buffer_overflow_v2(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return DLT_DAEMON_ERROR_UNKNOWN; - resp = (DltServiceMessageBufferOverflowResponse *)msg.databuffer; + resp = (DltServiceMessageBufferOverflowResponse*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW; resp->status = DLT_SERVICE_RESPONSE_OK; resp->overflow = DLT_MESSAGE_BUFFER_OVERFLOW; @@ -2657,15 +2243,11 @@ int dlt_daemon_control_message_buffer_overflow_v2(int sock, return DLT_DAEMON_ERROR_OK; } -void dlt_daemon_control_service_response(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint32_t service_id, - int8_t status, - int verbose) +void dlt_daemon_control_service_response( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint32_t service_id, int8_t status, int verbose) { DltMessage msg; - DltServiceResponse *resp; + DltServiceResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2685,16 +2267,16 @@ void dlt_daemon_control_service_response(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return; - resp = (DltServiceResponse *)msg.databuffer; + resp = (DltServiceResponse*)msg.databuffer; resp->service_id = service_id; - resp->status = (uint8_t) status; + resp->status = (uint8_t)status; /* send message */ dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -2703,15 +2285,11 @@ void dlt_daemon_control_service_response(int sock, dlt_message_free(&msg, 0); } -void dlt_daemon_control_service_response_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint32_t service_id, - int8_t status, - int verbose) +void dlt_daemon_control_service_response_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint32_t service_id, int8_t status, int verbose) { DltMessageV2 msg; - DltServiceResponse *resp; + DltServiceResponse* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2731,16 +2309,16 @@ void dlt_daemon_control_service_response_v2(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return; - resp = (DltServiceResponse *)msg.databuffer; + resp = (DltServiceResponse*)msg.databuffer; resp->service_id = service_id; - resp->status = (uint8_t) status; + resp->status = (uint8_t)status; /* send message */ dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose); @@ -2749,16 +2327,11 @@ void dlt_daemon_control_service_response_v2(int sock, dlt_message_free_v2(&msg, 0); } -int dlt_daemon_control_message_unregister_context(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *comid, - int verbose) +int dlt_daemon_control_message_unregister_context( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, char* apid, char* ctid, char* comid, int verbose) { DltMessage msg; - DltServiceUnregisterContext *resp; + DltServiceUnregisterContext* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2778,14 +2351,14 @@ int dlt_daemon_control_message_unregister_context(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return -1; - resp = (DltServiceUnregisterContext *)msg.databuffer; + resp = (DltServiceUnregisterContext*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_UNREGISTER_CONTEXT; resp->status = DLT_SERVICE_RESPONSE_OK; dlt_set_id(resp->apid, apid); @@ -2804,15 +2377,9 @@ int dlt_daemon_control_message_unregister_context(int sock, return 0; } -int dlt_daemon_control_message_unregister_context_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint8_t apidlen, - char *apid, - uint8_t ctidlen, - char *ctid, - char *comid, - int verbose) +int dlt_daemon_control_message_unregister_context_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint8_t apidlen, char* apid, uint8_t ctidlen, char* ctid, + char* comid, int verbose) { DltMessageV2 msg; DltServiceUnregisterContextV2 resp; @@ -2831,7 +2398,8 @@ int dlt_daemon_control_message_unregister_context_v2(int sock, return -1; /* prepare payload of data */ - contextSize = (uint8_t)(sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint8_t) + apidlen + sizeof(uint8_t) + ctidlen + DLT_ID_SIZE); + contextSize = (uint8_t)(sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint8_t) + apidlen + sizeof(uint8_t) + ctidlen + + DLT_ID_SIZE); msg.datasize = contextSize; @@ -2841,7 +2409,7 @@ int dlt_daemon_control_message_unregister_context_v2(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } @@ -2880,15 +2448,11 @@ int dlt_daemon_control_message_unregister_context_v2(int sock, return 0; } -int dlt_daemon_control_message_connection_info(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint8_t state, - char *comid, - int verbose) +int dlt_daemon_control_message_connection_info( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint8_t state, char* comid, int verbose) { DltMessage msg; - DltServiceConnectionInfo *resp; + DltServiceConnectionInfo* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2908,14 +2472,14 @@ int dlt_daemon_control_message_connection_info(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return -1; - resp = (DltServiceConnectionInfo *)msg.databuffer; + resp = (DltServiceConnectionInfo*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_CONNECTION_INFO; resp->status = DLT_SERVICE_RESPONSE_OK; resp->state = state; @@ -2933,15 +2497,11 @@ int dlt_daemon_control_message_connection_info(int sock, return 0; } -int dlt_daemon_control_message_connection_info_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint8_t state, - char *comid, - int verbose) +int dlt_daemon_control_message_connection_info_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint8_t state, char* comid, int verbose) { DltMessageV2 msg; - DltServiceConnectionInfo *resp; + DltServiceConnectionInfo* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -2961,14 +2521,14 @@ int dlt_daemon_control_message_connection_info_v2(int sock, } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return -1; - resp = (DltServiceConnectionInfo *)msg.databuffer; + resp = (DltServiceConnectionInfo*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_CONNECTION_INFO; resp->status = DLT_SERVICE_RESPONSE_OK; resp->state = state; @@ -2986,10 +2546,10 @@ int dlt_daemon_control_message_connection_info_v2(int sock, return 0; } -int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_control_message_timezone(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessage msg; - DltServiceTimezone *resp; + DltServiceTimezone* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -3009,14 +2569,14 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return -1; - resp = (DltServiceTimezone *)msg.databuffer; + resp = (DltServiceTimezone*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_TIMEZONE; resp->status = DLT_SERVICE_RESPONSE_OK; @@ -3048,10 +2608,10 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo return 0; } -int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessageV2 msg; - DltServiceTimezone *resp; + DltServiceTimezone* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -3071,14 +2631,14 @@ int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon *daemon, DltDaemo } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return -1; - resp = (DltServiceTimezone *)msg.databuffer; + resp = (DltServiceTimezone*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_TIMEZONE; resp->status = DLT_SERVICE_RESPONSE_OK; @@ -3103,10 +2663,10 @@ int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon *daemon, DltDaemo return 0; } -int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +int dlt_daemon_control_message_marker(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessage msg; - DltServiceMarker *resp; + DltServiceMarker* resp; PRINT_FUNCTION_VERBOSE(verbose); @@ -3126,14 +2686,14 @@ int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLoca } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } if (msg.databuffer == 0) return -1; - resp = (DltServiceMarker *)msg.databuffer; + resp = (DltServiceMarker*)msg.databuffer; resp->service_id = DLT_SERVICE_ID_MARKER; resp->status = DLT_SERVICE_RESPONSE_OK; @@ -3149,16 +2709,13 @@ int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLoca return 0; } -void dlt_daemon_control_callsw_cinjection(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_callsw_cinjection( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { char apid[DLT_ID_SIZE], ctid[DLT_ID_SIZE]; uint32_t id = 0, id_tmp = 0; - uint8_t *ptr; - DltDaemonContext *context; + uint8_t* ptr; + DltDaemonContext* context; uint32_t data_length_inject = 0; uint32_t data_length_inject_tmp = 0; @@ -3166,14 +2723,14 @@ void dlt_daemon_control_callsw_cinjection(int sock, DltUserHeader userheader; DltUserControlMsgInjection usercontext; - uint8_t *userbuffer; + uint8_t* userbuffer; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - datalength = (int32_t) msg->datasize; + datalength = (int32_t)msg->datasize; ptr = msg->databuffer; DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); /* Get service id */ @@ -3199,19 +2756,14 @@ void dlt_daemon_control_callsw_cinjection(int sock, if (DLT_IS_HTYP_UEH(msg->standardheader->htyp)) { dlt_set_id(apid, msg->extendedheader->apid); dlt_set_id(ctid, msg->extendedheader->ctid); - } - else { + } else { /* No extended header, and therefore no apid and ctid available */ dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } /* At this point, apid and ctid is available */ - context = dlt_daemon_context_find(daemon, - apid, - ctid, - daemon->ecuid, - verbose); + context = dlt_daemon_context_find(daemon, apid, ctid, daemon->ecuid, verbose); if (context == 0) { /* dlt_log(LOG_INFO,"No context found!\n"); */ @@ -3227,7 +2779,7 @@ void dlt_daemon_control_callsw_cinjection(int sock, usercontext.log_level_pos = context->log_level_pos; - if (data_length_inject > (uint32_t) msg->databuffersize) { + if (data_length_inject > (uint32_t)msg->databuffersize) { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -3239,16 +2791,15 @@ void dlt_daemon_control_callsw_cinjection(int sock, return; } - usercontext.data_length_inject = (uint32_t) data_length_inject; + usercontext.data_length_inject = (uint32_t)data_length_inject; usercontext.service_id = id; - memcpy(userbuffer, ptr, (size_t) data_length_inject); /* Copy received injection to send buffer */ + memcpy(userbuffer, ptr, (size_t)data_length_inject); /* Copy received injection to send buffer */ /* write to FIFO */ - DltReturnValue ret = - dlt_user_log_out3_with_timeout(context->user_handle, &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgInjection), - userbuffer, (size_t) data_length_inject); + DltReturnValue ret = dlt_user_log_out3_with_timeout( + context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgInjection), userbuffer, (size_t)data_length_inject); if (ret < DLT_RETURN_OK) { if (ret == DLT_RETURN_PIPE_ERROR) { @@ -3258,34 +2809,29 @@ void dlt_daemon_control_callsw_cinjection(int sock, } dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); } free(userbuffer); userbuffer = 0; - } - else { + } else { /* Invalid ID */ - dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); } } -void dlt_daemon_control_callsw_cinjection_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_callsw_cinjection_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { uint8_t apidlen = 0, ctidlen = 0; - char *apid = NULL; - char *ctid = NULL; + char* apid = NULL; + char* ctid = NULL; uint32_t id = 0, id_tmp = 0; - uint8_t *ptr; - DltDaemonContext *context; + uint8_t* ptr; + DltDaemonContext* context; uint32_t data_length_inject = 0; uint32_t data_length_inject_tmp = 0; @@ -3293,24 +2839,25 @@ void dlt_daemon_control_callsw_cinjection_v2(int sock, DltUserHeader userheader; DltUserControlMsgInjection usercontext; - uint8_t *userbuffer; + uint8_t* userbuffer; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - datalength = (int32_t) msg->datasize; + datalength = (int32_t)msg->datasize; ptr = msg->databuffer; DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); /* Get service id */ // id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); - //TBD: Review endianness for V2, id extraction + // TBD: Review endianness for V2, id extraction id = DLT_ENDIAN_GET_32(msg->baseheaderv2->htyp2, id_tmp); /* injectionMode is disabled */ if (daemon_local->flags.injectionMode == 0) { - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_PERM_DENIED, verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_PERM_DENIED, verbose); return; } @@ -3325,29 +2872,22 @@ void dlt_daemon_control_callsw_cinjection_v2(int sock, /* Get context handle for apid, ctid (and seid) */ /* Warning: seid is ignored in this implementation! */ - //TBD: Review EH(htyp2) vs UEH(htyp) + // TBD: Review EH(htyp2) vs UEH(htyp) if (DLT_IS_HTYP2_EH(msg->baseheaderv2->htyp2)) { - //TBD: Check if apidlen and ctidlen are fetched properly in runtime + // TBD: Check if apidlen and ctidlen are fetched properly in runtime apidlen = msg->extendedheaderv2.apidlen; dlt_set_id_v2(apid, msg->extendedheaderv2.apid, msg->extendedheaderv2.apidlen); ctidlen = msg->extendedheaderv2.ctidlen; dlt_set_id_v2(ctid, msg->extendedheaderv2.ctid, msg->extendedheaderv2.ctidlen); - } - else { + } else { /* No extended header, and therefore no apid and ctid available */ dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } /* At this point, apid and ctid is available */ - context = dlt_daemon_context_find_v2(daemon, - apidlen, - apid, - ctidlen, - ctid, - daemon->ecuid2len, - daemon->ecuid2, - verbose); + context = dlt_daemon_context_find_v2( + daemon, apidlen, apid, ctidlen, ctid, daemon->ecuid2len, daemon->ecuid2, verbose); if (context == 0) { /* dlt_log(LOG_INFO,"No context found!\n"); */ @@ -3363,7 +2903,7 @@ void dlt_daemon_control_callsw_cinjection_v2(int sock, usercontext.log_level_pos = context->log_level_pos; - if (data_length_inject > (uint32_t) msg->databuffersize) { + if (data_length_inject > (uint32_t)msg->databuffersize) { dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } @@ -3375,16 +2915,15 @@ void dlt_daemon_control_callsw_cinjection_v2(int sock, return; } - usercontext.data_length_inject = (uint32_t) data_length_inject; + usercontext.data_length_inject = (uint32_t)data_length_inject; usercontext.service_id = id; - memcpy(userbuffer, ptr, (size_t) data_length_inject); /* Copy received injection to send buffer */ + memcpy(userbuffer, ptr, (size_t)data_length_inject); /* Copy received injection to send buffer */ /* write to FIFO */ - DltReturnValue ret = - dlt_user_log_out3_with_timeout(context->user_handle, &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgInjection), - userbuffer, (size_t) data_length_inject); + DltReturnValue ret = dlt_user_log_out3_with_timeout( + context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgInjection), userbuffer, (size_t)data_length_inject); if (ret < DLT_RETURN_OK) { if (ret == DLT_RETURN_PIPE_ERROR) { @@ -3394,28 +2933,22 @@ void dlt_daemon_control_callsw_cinjection_v2(int sock, } dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); - } - else { + } else { dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); } free(userbuffer); userbuffer = 0; - } - else { + } else { /* Invalid ID */ - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose); } } -void dlt_daemon_send_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - int8_t loglevel, - int verbose) +void dlt_daemon_send_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, int8_t loglevel, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3425,23 +2958,18 @@ void dlt_daemon_send_log_level(int sock, old_log_level = context->log_level; context->log_level = loglevel; /* No endianess conversion necessary*/ - if ((context->user_handle >= DLT_FD_MINIMUM) && - (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + if ((context->user_handle >= DLT_FD_MINIMUM) && (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) { + dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_OK, verbose); + } else { dlt_log(LOG_ERR, "Log level could not be sent!\n"); context->log_level = old_log_level; - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_send_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - int8_t loglevel, - int verbose) +void dlt_daemon_send_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, int8_t loglevel, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3451,33 +2979,29 @@ void dlt_daemon_send_log_level_v2(int sock, old_log_level = context->log_level; context->log_level = loglevel; /* No endianess conversion necessary*/ - if ((context->user_handle >= DLT_FD_MINIMUM) && - (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == 0)) { - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + if ((context->user_handle >= DLT_FD_MINIMUM) + && (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == 0)) { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_OK, verbose); + } else { dlt_log(LOG_ERR, "Log level could not be sent!\n"); context->log_level = old_log_level; - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_find_multiple_context_and_send_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int8_t app_flag, - char *str, - int8_t len, - int8_t loglevel, - int verbose) +void dlt_daemon_find_multiple_context_and_send_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int8_t app_flag, char* str, int8_t len, int8_t loglevel, + int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int count = 0; - DltDaemonContext *context = NULL; - char src_str[DLT_ID_SIZE + 1] = { 0 }; + DltDaemonContext* context = NULL; + char src_str[DLT_ID_SIZE + 1] = {0}; int ret = 0; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; if (daemon == 0) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -3510,22 +3034,17 @@ void dlt_daemon_find_multiple_context_and_send_log_level(int sock, } } -void dlt_daemon_find_multiple_context_and_send_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int8_t app_flag, - char *str, - int8_t len, - int8_t loglevel, - int verbose) +void dlt_daemon_find_multiple_context_and_send_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int8_t app_flag, char* str, int8_t len, int8_t loglevel, + int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int count = 0; - DltDaemonContext *context = NULL; + DltDaemonContext* context = NULL; char src_str[DLT_V2_ID_SIZE] = {0}; int ret = 0; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; if (daemon == 0) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -3559,18 +3078,15 @@ void dlt_daemon_find_multiple_context_and_send_log_level_v2(int sock, } -void dlt_daemon_control_set_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - char apid[DLT_ID_SIZE + 1] = { 0 }; - char ctid[DLT_ID_SIZE + 1] = { 0 }; - DltServiceSetLogLevel *req = NULL; - DltDaemonContext *context = NULL; + char apid[DLT_ID_SIZE + 1] = {0}; + char ctid[DLT_ID_SIZE + 1] = {0}; + DltServiceSetLogLevel* req = NULL; + DltDaemonContext* context = NULL; int8_t apid_length = 0; int8_t ctid_length = 0; @@ -3580,94 +3096,56 @@ void dlt_daemon_control_set_log_level(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0) return; - req = (DltServiceSetLogLevel *)(msg->databuffer); + req = (DltServiceSetLogLevel*)(msg->databuffer); if (daemon_local->flags.enforceContextLLAndTS) - req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextLogLevel); + req->log_level = (uint8_t)getStatus(req->log_level, daemon_local->flags.contextLogLevel); dlt_set_id(apid, req->apid); dlt_set_id(ctid, req->ctid); - apid_length = (int8_t) strlen(apid); - ctid_length = (int8_t) strlen(ctid); - - if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/ - dlt_daemon_find_multiple_context_and_send_log_level(sock, - daemon, - daemon_local, - 1, - apid, - (int8_t) (apid_length - 1), - (int8_t) req->log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and apid is null*/ + apid_length = (int8_t)strlen(apid); + ctid_length = (int8_t)strlen(ctid); + + if ((apid_length != 0) && (apid[apid_length - 1] == '*') + && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/ + dlt_daemon_find_multiple_context_and_send_log_level( + sock, daemon, daemon_local, 1, apid, (int8_t)(apid_length - 1), (int8_t)req->log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in + it and apid is null*/ { - dlt_daemon_find_multiple_context_and_send_log_level(sock, - daemon, - daemon_local, - 0, - ctid, - (int8_t) (ctid_length - 1), - (int8_t) req->log_level, - verbose); - } - else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/ + dlt_daemon_find_multiple_context_and_send_log_level( + sock, daemon, daemon_local, 0, ctid, (int8_t)(ctid_length - 1), (int8_t)req->log_level, verbose); + } else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/ { - dlt_daemon_find_multiple_context_and_send_log_level(sock, - daemon, - daemon_local, - 1, - apid, - DLT_ID_SIZE, - (int8_t) req->log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/ + dlt_daemon_find_multiple_context_and_send_log_level( + sock, daemon, daemon_local, 1, apid, DLT_ID_SIZE, (int8_t)req->log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/ { - dlt_daemon_find_multiple_context_and_send_log_level(sock, - daemon, - daemon_local, - 0, - ctid, - DLT_ID_SIZE, - (int8_t) req->log_level, - verbose); - } - else { - context = dlt_daemon_context_find(daemon, - apid, - ctid, - daemon->ecuid, - verbose); + dlt_daemon_find_multiple_context_and_send_log_level( + sock, daemon, daemon_local, 0, ctid, DLT_ID_SIZE, (int8_t)req->log_level, verbose); + } else { + context = dlt_daemon_context_find(daemon, apid, ctid, daemon->ecuid, verbose); /* Set log level */ if (context != 0) { - dlt_daemon_send_log_level(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose); - } - else { - dlt_vlog(LOG_ERR, "Could not set log level: %d. Context [%.4s:%.4s] not found:", req->log_level, apid, - ctid); - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_SET_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_send_log_level(sock, daemon, daemon_local, context, (int8_t)req->log_level, verbose); + } else { + dlt_vlog( + LOG_ERR, "Could not set log level: %d. Context [%.4s:%.4s] not found:", req->log_level, apid, ctid); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_SET_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); } } } -void dlt_daemon_control_set_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - char *apid =NULL; - char *ctid =NULL; + char* apid = NULL; + char* ctid = NULL; DltServiceSetLogLevelV2 req = {0}; - DltDaemonContext *context = NULL; + DltDaemonContext* context = NULL; int8_t apid_length = 0; int8_t ctid_length = 0; int offset = 0; @@ -3682,101 +3160,61 @@ void dlt_daemon_control_set_log_level_v2(int sock, offset = offset + (int)sizeof(uint32_t); memcpy(&(req.apidlen), msg->databuffer + offset, sizeof(uint8_t)); offset = offset + (int)sizeof(uint8_t); - dlt_set_id_v2(req.apid, (const char *)(msg->databuffer + offset), req.apidlen); + dlt_set_id_v2(req.apid, (const char*)(msg->databuffer + offset), req.apidlen); offset = offset + req.apidlen; memcpy(&(req.ctidlen), msg->databuffer + offset, sizeof(uint8_t)); offset = offset + (int)sizeof(uint8_t); - dlt_set_id_v2(req.ctid, (const char *)(msg->databuffer + offset), req.ctidlen); + dlt_set_id_v2(req.ctid, (const char*)(msg->databuffer + offset), req.ctidlen); offset = offset + req.ctidlen; memcpy(&(req.log_level), msg->databuffer + offset, sizeof(uint8_t)); offset = offset + (int)sizeof(uint8_t); memcpy(&(req.com), msg->databuffer + offset, DLT_ID_SIZE); if (daemon_local->flags.enforceContextLLAndTS) - req.log_level = (uint8_t) getStatus(req.log_level, daemon_local->flags.contextLogLevel); + req.log_level = (uint8_t)getStatus(req.log_level, daemon_local->flags.contextLogLevel); - apid_length = (int8_t) req.apidlen; + apid_length = (int8_t)req.apidlen; dlt_set_id_v2(apid, req.apid, req.apidlen); - ctid_length = (int8_t) req.ctidlen; + ctid_length = (int8_t)req.ctidlen; dlt_set_id_v2(ctid, req.ctid, req.ctidlen); - if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid == NULL)) { /*apid provided having '*' in it and ctid is null*/ - dlt_daemon_find_multiple_context_and_send_log_level_v2(sock, - daemon, - daemon_local, - 1, - apid, - (int8_t) (apid_length - 1), - (int8_t) req.log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid == NULL)) /*ctid provided is having '*' in it and apid is null*/ + if ((apid_length != 0) && (apid[apid_length - 1] == '*') + && (ctid == NULL)) { /*apid provided having '*' in it and ctid is null*/ + dlt_daemon_find_multiple_context_and_send_log_level_v2( + sock, daemon, daemon_local, 1, apid, (int8_t)(apid_length - 1), (int8_t)req.log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid == NULL)) /*ctid provided is having '*' in + it and apid is null*/ { - dlt_daemon_find_multiple_context_and_send_log_level_v2(sock, - daemon, - daemon_local, - 0, - ctid, - (int8_t) (ctid_length - 1), - (int8_t) req.log_level, - verbose); - } - else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid == NULL)) /*only app id case*/ + dlt_daemon_find_multiple_context_and_send_log_level_v2( + sock, daemon, daemon_local, 0, ctid, (int8_t)(ctid_length - 1), (int8_t)req.log_level, verbose); + } else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid == NULL)) /*only app id case*/ { - dlt_daemon_find_multiple_context_and_send_log_level_v2(sock, - daemon, - daemon_local, - 1, - apid, - apid_length, - (int8_t) req.log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid == NULL)) /*only context id case*/ + dlt_daemon_find_multiple_context_and_send_log_level_v2( + sock, daemon, daemon_local, 1, apid, apid_length, (int8_t)req.log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid == NULL)) /*only context id case*/ { - dlt_daemon_find_multiple_context_and_send_log_level_v2(sock, - daemon, - daemon_local, - 0, - ctid, - ctid_length, - (int8_t) req.log_level, - verbose); - } - else { - context = dlt_daemon_context_find_v2(daemon, - (uint8_t)apid_length, - apid, - (uint8_t)ctid_length, - ctid, - daemon->ecuid2len, - daemon->ecuid2, - verbose); + dlt_daemon_find_multiple_context_and_send_log_level_v2( + sock, daemon, daemon_local, 0, ctid, ctid_length, (int8_t)req.log_level, verbose); + } else { + context = dlt_daemon_context_find_v2( + daemon, (uint8_t)apid_length, apid, (uint8_t)ctid_length, ctid, daemon->ecuid2len, daemon->ecuid2, verbose); /* Set log level */ if (context != 0) { - dlt_daemon_send_log_level_v2(sock, daemon, daemon_local, context, (int8_t) req.log_level, verbose); - } - else { - dlt_vlog(LOG_ERR, "Could not set log level: %d. Context [%s:%s] not found:", req.log_level, - apid ? apid : "", - ctid ? ctid : ""); - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_SET_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_send_log_level_v2(sock, daemon, daemon_local, context, (int8_t)req.log_level, verbose); + } else { + dlt_vlog( + LOG_ERR, "Could not set log level: %d. Context [%s:%s] not found:", req.log_level, + apid ? apid : "", ctid ? ctid : ""); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_SET_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); } } } -void dlt_daemon_send_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - int8_t tracestatus, - int verbose) +void dlt_daemon_send_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, int8_t tracestatus, + int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3786,23 +3224,19 @@ void dlt_daemon_send_trace_status(int sock, old_trace_status = context->trace_status; context->trace_status = tracestatus; /* No endianess conversion necessary*/ - if ((context->user_handle >= DLT_FD_MINIMUM) && - (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) { - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + if ((context->user_handle >= DLT_FD_MINIMUM) && (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) { + dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_OK, verbose); + } else { dlt_log(LOG_ERR, "Trace status could not be sent!\n"); context->trace_status = old_trace_status; - dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_send_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - int8_t tracestatus, - int verbose) +void dlt_daemon_send_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, int8_t tracestatus, + int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3812,33 +3246,29 @@ void dlt_daemon_send_trace_status_v2(int sock, old_trace_status = context->trace_status; context->trace_status = tracestatus; /* No endianess conversion necessary*/ - if ((context->user_handle >= DLT_FD_MINIMUM) && - (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == 0)) { - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + if ((context->user_handle >= DLT_FD_MINIMUM) + && (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == 0)) { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_OK, verbose); + } else { dlt_log(LOG_ERR, "Trace status could not be sent!\n"); context->trace_status = old_trace_status; - dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, (uint32_t)id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_find_multiple_context_and_send_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int8_t app_flag, - char *str, - int8_t len, - int8_t tracestatus, - int verbose) +void dlt_daemon_find_multiple_context_and_send_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int8_t app_flag, char* str, int8_t len, + int8_t tracestatus, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int count = 0; - DltDaemonContext *context = NULL; - char src_str[DLT_ID_SIZE + 1] = { 0 }; + DltDaemonContext* context = NULL; + char src_str[DLT_ID_SIZE + 1] = {0}; int ret = 0; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; if (daemon == 0) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -3871,22 +3301,17 @@ void dlt_daemon_find_multiple_context_and_send_trace_status(int sock, } } -void dlt_daemon_find_multiple_context_and_send_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int8_t app_flag, - char *str, - int8_t len, - int8_t tracestatus, - int verbose) +void dlt_daemon_find_multiple_context_and_send_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int8_t app_flag, char* str, int8_t len, + int8_t tracestatus, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int count = 0; - DltDaemonContext *context = NULL; - char src_str[DLT_V2_ID_SIZE] = { 0 }; + DltDaemonContext* context = NULL; + char src_str[DLT_V2_ID_SIZE] = {0}; int ret = 0; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; if (daemon == 0) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -3919,18 +3344,15 @@ void dlt_daemon_find_multiple_context_and_send_trace_status_v2(int sock, } } -void dlt_daemon_control_set_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - char apid[DLT_ID_SIZE + 1] = { 0 }; - char ctid[DLT_ID_SIZE + 1] = { 0 }; - DltServiceSetLogLevel *req = NULL; - DltDaemonContext *context = NULL; + char apid[DLT_ID_SIZE + 1] = {0}; + char ctid[DLT_ID_SIZE + 1] = {0}; + DltServiceSetLogLevel* req = NULL; + DltDaemonContext* context = NULL; int8_t apid_length = 0; int8_t ctid_length = 0; @@ -3940,192 +3362,120 @@ void dlt_daemon_control_set_trace_status(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0) return; - req = (DltServiceSetLogLevel *)(msg->databuffer); + req = (DltServiceSetLogLevel*)(msg->databuffer); if (daemon_local->flags.enforceContextLLAndTS) - req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextTraceStatus); + req->log_level = (uint8_t)getStatus(req->log_level, daemon_local->flags.contextTraceStatus); dlt_set_id(apid, req->apid); dlt_set_id(ctid, req->ctid); - apid_length = (int8_t) strlen(apid); - ctid_length = (int8_t) strlen(ctid); + apid_length = (int8_t)strlen(apid); + ctid_length = (int8_t)strlen(ctid); - if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/ - dlt_daemon_find_multiple_context_and_send_trace_status(sock, - daemon, - daemon_local, - 1, - apid, - (int8_t) (apid_length - 1), - (int8_t) req->log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and apid is null*/ + if ((apid_length != 0) && (apid[apid_length - 1] == '*') + && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/ + dlt_daemon_find_multiple_context_and_send_trace_status( + sock, daemon, daemon_local, 1, apid, (int8_t)(apid_length - 1), (int8_t)req->log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in + it and apid is null*/ { - dlt_daemon_find_multiple_context_and_send_trace_status(sock, - daemon, - daemon_local, - 0, - ctid, - (int8_t) (ctid_length - 1), - (int8_t) req->log_level, - verbose); - } - else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/ + dlt_daemon_find_multiple_context_and_send_trace_status( + sock, daemon, daemon_local, 0, ctid, (int8_t)(ctid_length - 1), (int8_t)req->log_level, verbose); + } else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/ { - dlt_daemon_find_multiple_context_and_send_trace_status(sock, - daemon, - daemon_local, - 1, - apid, - DLT_ID_SIZE, - (int8_t) req->log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/ + dlt_daemon_find_multiple_context_and_send_trace_status( + sock, daemon, daemon_local, 1, apid, DLT_ID_SIZE, (int8_t)req->log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/ { - dlt_daemon_find_multiple_context_and_send_trace_status(sock, - daemon, - daemon_local, - 0, - ctid, - DLT_ID_SIZE, - (int8_t) req->log_level, - verbose); - } - else { + dlt_daemon_find_multiple_context_and_send_trace_status( + sock, daemon, daemon_local, 0, ctid, DLT_ID_SIZE, (int8_t)req->log_level, verbose); + } else { context = dlt_daemon_context_find(daemon, apid, ctid, daemon->ecuid, verbose); /* Set trace status */ if (context != 0) { - dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose); - } - else { - dlt_vlog(LOG_ERR, - "Could not set trace status: %d. Context [%.4s:%.4s] not found:", - req->log_level, - apid, - ctid); - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_SET_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, (int8_t)req->log_level, verbose); + } else { + dlt_vlog( + LOG_ERR, "Could not set trace status: %d. Context [%.4s:%.4s] not found:", req->log_level, apid, ctid); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_SET_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); } } } -void dlt_daemon_control_set_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - char *apid = NULL; - char *ctid = NULL; - DltServiceSetLogLevelV2 *req = NULL; - DltDaemonContext *context = NULL; + char* apid = NULL; + char* ctid = NULL; + DltServiceSetLogLevelV2* req = NULL; + DltDaemonContext* context = NULL; int8_t apid_length = 0; int8_t ctid_length = 0; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; - //TBD: Review sizeof(DltServiceSetLogLevelV2)) or fixed size + // TBD: Review sizeof(DltServiceSetLogLevelV2)) or fixed size if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevelV2)) < 0) return; - req = (DltServiceSetLogLevelV2 *)(msg->databuffer); + req = (DltServiceSetLogLevelV2*)(msg->databuffer); if (daemon_local->flags.enforceContextLLAndTS) - req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextTraceStatus); + req->log_level = (uint8_t)getStatus(req->log_level, daemon_local->flags.contextTraceStatus); - apid_length = (int8_t) req->apidlen; + apid_length = (int8_t)req->apidlen; dlt_set_id_v2(apid, req->apid, req->apidlen); - ctid_length = (int8_t) req->ctidlen; + ctid_length = (int8_t)req->ctidlen; dlt_set_id_v2(ctid, req->ctid, req->ctidlen); - //TBD: Review apid[apid_length - 1] == '*' - if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid == NULL)) { /*apid provided having '*' in it and ctid is null*/ - dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock, - daemon, - daemon_local, - 1, - apid, - (int8_t) (apid_length - 1), - (int8_t) req->log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid == NULL)) /*ctid provided is having '*' in it and apid is null*/ + // TBD: Review apid[apid_length - 1] == '*' + if ((apid_length != 0) && (apid[apid_length - 1] == '*') + && (ctid == NULL)) { /*apid provided having '*' in it and ctid is null*/ + dlt_daemon_find_multiple_context_and_send_trace_status_v2( + sock, daemon, daemon_local, 1, apid, (int8_t)(apid_length - 1), (int8_t)req->log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid == NULL)) /*ctid provided is having '*' in + it and apid is null*/ { - dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock, - daemon, - daemon_local, - 0, - ctid, - (int8_t) (ctid_length - 1), - (int8_t) req->log_level, - verbose); - } - else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid == NULL)) /*only app id case*/ + dlt_daemon_find_multiple_context_and_send_trace_status_v2( + sock, daemon, daemon_local, 0, ctid, (int8_t)(ctid_length - 1), (int8_t)req->log_level, verbose); + } else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid == NULL)) /*only app id case*/ { - dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock, - daemon, - daemon_local, - 1, - apid, - apid_length, - (int8_t) req->log_level, - verbose); - } - else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid == NULL)) /*only context id case*/ + dlt_daemon_find_multiple_context_and_send_trace_status_v2( + sock, daemon, daemon_local, 1, apid, apid_length, (int8_t)req->log_level, verbose); + } else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid == NULL)) /*only context id case*/ { - dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock, - daemon, - daemon_local, - 0, - ctid, - ctid_length, - (int8_t) req->log_level, - verbose); - } - else { - context = dlt_daemon_context_find_v2(daemon, (uint8_t)apid_length, apid, (uint8_t)ctid_length, ctid, daemon->ecuid2len, daemon->ecuid2, verbose); + dlt_daemon_find_multiple_context_and_send_trace_status_v2( + sock, daemon, daemon_local, 0, ctid, ctid_length, (int8_t)req->log_level, verbose); + } else { + context = dlt_daemon_context_find_v2( + daemon, (uint8_t)apid_length, apid, (uint8_t)ctid_length, ctid, daemon->ecuid2len, daemon->ecuid2, verbose); /* Set trace status */ if (context != 0) { - dlt_daemon_send_trace_status_v2(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose); - } - else { - dlt_vlog(LOG_ERR, - "Could not set trace status: %d. Context [%.4s:%.4s] not found:", - req->log_level, - apid ? apid : "", - ctid ? ctid : ""); - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_SET_LOG_LEVEL, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_send_trace_status_v2(sock, daemon, daemon_local, context, (int8_t)req->log_level, verbose); + } else { + dlt_vlog( + LOG_ERR, "Could not set trace status: %d. Context [%.4s:%.4s] not found:", req->log_level, + apid ? apid : "", ctid ? ctid : ""); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_SET_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose); } } } -void dlt_daemon_control_set_default_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_default_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) @@ -4134,7 +3484,7 @@ void dlt_daemon_control_set_default_log_level(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ if (/*(req->log_level>=0) &&*/ @@ -4142,27 +3492,23 @@ void dlt_daemon_control_set_default_log_level(int sock, if (daemon_local->flags.enforceContextLLAndTS) daemon->default_log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel); else - daemon->default_log_level = (int8_t) req->log_level; /* No endianess conversion necessary */ + daemon->default_log_level = (int8_t)req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the default log level */ dlt_daemon_user_send_default_update(daemon, verbose); dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_default_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_default_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) @@ -4171,7 +3517,7 @@ void dlt_daemon_control_set_default_log_level_v2(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ if (/*(req->log_level>=0) &&*/ @@ -4179,27 +3525,23 @@ void dlt_daemon_control_set_default_log_level_v2(int sock, if (daemon_local->flags.enforceContextLLAndTS) daemon->default_log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel); else - daemon->default_log_level = (int8_t) req->log_level; /* No endianess conversion necessary */ + daemon->default_log_level = (int8_t)req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the default log level */ dlt_daemon_user_send_default_update(daemon, verbose); dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_all_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_all_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetDefaultLogLevel *req = NULL; + DltServiceSetDefaultLogLevel* req = NULL; uint32_t id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL; int8_t loglevel = 0; @@ -4211,36 +3553,29 @@ void dlt_daemon_control_set_all_log_level(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ if ((req != NULL) && ((req->log_level <= DLT_LOG_VERBOSE) || (req->log_level == (uint8_t)DLT_LOG_DEFAULT))) { - loglevel = (int8_t) req->log_level; + loglevel = (int8_t)req->log_level; /* Send Update to all contexts using the new log level */ dlt_daemon_user_send_all_log_level_update( - daemon, - daemon_local->flags.enforceContextLLAndTS, - (int8_t)daemon_local->flags.contextLogLevel, - loglevel, + daemon, daemon_local->flags.enforceContextLLAndTS, (int8_t)daemon_local->flags.contextLogLevel, loglevel, verbose); dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_all_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_all_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetDefaultLogLevel *req = NULL; + DltServiceSetDefaultLogLevel* req = NULL; uint32_t id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL; int8_t loglevel = 0; @@ -4252,37 +3587,30 @@ void dlt_daemon_control_set_all_log_level_v2(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ if ((req != NULL) && ((req->log_level <= DLT_LOG_VERBOSE) || (req->log_level == (uint8_t)DLT_LOG_DEFAULT))) { - loglevel = (int8_t) req->log_level; + loglevel = (int8_t)req->log_level; /* Send Update to all contexts using the new log level */ dlt_daemon_user_send_all_log_level_update_v2( - daemon, - daemon_local->flags.enforceContextLLAndTS, - (int8_t)daemon_local->flags.contextLogLevel, - loglevel, + daemon, daemon_local->flags.enforceContextLLAndTS, (int8_t)daemon_local->flags.contextLogLevel, loglevel, verbose); dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_default_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_default_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); /* Payload of request message */ - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) @@ -4291,36 +3619,31 @@ void dlt_daemon_control_set_default_trace_status(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ - if ((req->log_level == DLT_TRACE_STATUS_OFF) || - (req->log_level == DLT_TRACE_STATUS_ON)) { + if ((req->log_level == DLT_TRACE_STATUS_OFF) || (req->log_level == DLT_TRACE_STATUS_ON)) { if (daemon_local->flags.enforceContextLLAndTS) daemon->default_trace_status = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); else - daemon->default_trace_status = (int8_t) req->log_level; /* No endianess conversion necessary*/ + daemon->default_trace_status = (int8_t)req->log_level; /* No endianess conversion necessary*/ /* Send Update to all contexts using the default trace status */ dlt_daemon_user_send_default_update(daemon, verbose); dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_default_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_default_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); /* Payload of request message */ - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) @@ -4329,35 +3652,30 @@ void dlt_daemon_control_set_default_trace_status_v2(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ - if ((req->log_level == DLT_TRACE_STATUS_OFF) || - (req->log_level == DLT_TRACE_STATUS_ON)) { + if ((req->log_level == DLT_TRACE_STATUS_OFF) || (req->log_level == DLT_TRACE_STATUS_ON)) { if (daemon_local->flags.enforceContextLLAndTS) daemon->default_trace_status = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); else - daemon->default_trace_status = (int8_t) req->log_level; /* No endianess conversion necessary*/ + daemon->default_trace_status = (int8_t)req->log_level; /* No endianess conversion necessary*/ /* Send Update to all contexts using the default trace status */ dlt_daemon_user_send_default_update_v2(daemon, verbose); dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_all_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_all_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetDefaultLogLevel *req = NULL; + DltServiceSetDefaultLogLevel* req = NULL; uint32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS; int8_t tracestatus = 0; @@ -4369,35 +3687,31 @@ void dlt_daemon_control_set_all_trace_status(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ - if ((req != NULL) && - ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT))) { + if ((req != NULL) + && ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT))) { if (daemon_local->flags.enforceContextLLAndTS) tracestatus = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); else - tracestatus = (int8_t) req->log_level; /* No endianess conversion necessary */ + tracestatus = (int8_t)req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the new log level */ dlt_daemon_user_send_all_trace_status_update(daemon, tracestatus, verbose); dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_all_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_all_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetDefaultLogLevel *req = NULL; + DltServiceSetDefaultLogLevel* req = NULL; uint32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS; int8_t tracestatus = 0; @@ -4409,35 +3723,31 @@ void dlt_daemon_control_set_all_trace_status_v2(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0) return; - req = (DltServiceSetDefaultLogLevel *)(msg->databuffer); + req = (DltServiceSetDefaultLogLevel*)(msg->databuffer); /* No endianess conversion necessary */ - if ((req != NULL) && - ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT))) { + if ((req != NULL) + && ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT))) { if (daemon_local->flags.enforceContextLLAndTS) tracestatus = getStatus(req->log_level, daemon_local->flags.contextTraceStatus); else - tracestatus = (int8_t) req->log_level; /* No endianess conversion necessary */ + tracestatus = (int8_t)req->log_level; /* No endianess conversion necessary */ /* Send Update to all contexts using the new log level */ dlt_daemon_user_send_all_trace_status_update_v2(daemon, tracestatus, verbose); dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_timing_packets(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_set_timing_packets( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */ + DltServiceSetVerboseMode* req; /* request uses same struct as set verbose mode */ uint32_t id = DLT_SERVICE_ID_SET_TIMING_PACKETS; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) @@ -4446,27 +3756,23 @@ void dlt_daemon_control_set_timing_packets(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetVerboseMode)) < 0) return; - req = (DltServiceSetVerboseMode *)(msg->databuffer); + req = (DltServiceSetVerboseMode*)(msg->databuffer); if ((req->new_status == 0) || (req->new_status == 1)) { daemon->timingpackets = req->new_status; dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_set_timing_packets_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_set_timing_packets_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */ + DltServiceSetVerboseMode* req; /* request uses same struct as set verbose mode */ uint32_t id = DLT_SERVICE_ID_SET_TIMING_PACKETS; if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) @@ -4475,19 +3781,18 @@ void dlt_daemon_control_set_timing_packets_v2(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetVerboseMode)) < 0) return; - req = (DltServiceSetVerboseMode *)(msg->databuffer); + req = (DltServiceSetVerboseMode*)(msg->databuffer); if ((req->new_status == 0) || (req->new_status == 1)) { daemon->timingpackets = req->new_status; dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); - } - else { + } else { dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +void dlt_daemon_control_message_time(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessage msg; int32_t len; @@ -4504,11 +3809,11 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal /* send message */ /* prepare storage header */ - msg.storageheader = (DltStorageHeader *)msg.headerbuffer; + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; dlt_set_storageheader(msg.storageheader, daemon->ecuid); /* prepare standard header */ - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; #if (BYTE_ORDER == BIG_ENDIAN) @@ -4524,18 +3829,18 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal dlt_message_set_extraparameters(&msg, verbose); /* prepare extended header */ - msg.extendedheader = - (DltExtendedHeader *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); msg.extendedheader->msin = DLT_MSIN_CONTROL_TIME; - msg.extendedheader->noar = 0; /* number of arguments */ - dlt_set_id(msg.extendedheader->apid, ""); /* application id */ - dlt_set_id(msg.extendedheader->ctid, ""); /* context id */ + msg.extendedheader->noar = 0; /* number of arguments */ + dlt_set_id(msg.extendedheader->apid, ""); /* application id */ + dlt_set_id(msg.extendedheader->ctid, ""); /* context id */ /* prepare length information */ - msg.headersize = (int32_t)((size_t)sizeof(DltStorageHeader) + (size_t)sizeof(DltStandardHeader) + (size_t)sizeof(DltExtendedHeader) + - (size_t)DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.headersize = (int32_t)((size_t)sizeof(DltStorageHeader) + (size_t)sizeof(DltStandardHeader) + + (size_t)sizeof(DltExtendedHeader) + + (size_t)DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); len = (int32_t)((size_t)msg.headersize - (size_t)sizeof(DltStorageHeader) + (size_t)msg.datasize); @@ -4551,20 +3856,16 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal msg.standardheader->len = DLT_HTOBE_16(((uint16_t)len)); /* Send message, ignore return value */ - dlt_daemon_client_send(sock, daemon, daemon_local, msg.headerbuffer, - sizeof(DltStorageHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (int) msg.headersize - (int) sizeof(DltStorageHeader), - msg.databuffer, (int) msg.datasize, verbose); + dlt_daemon_client_send( + sock, daemon, daemon_local, msg.headerbuffer, sizeof(DltStorageHeader), + msg.headerbuffer + sizeof(DltStorageHeader), (int)msg.headersize - (int)sizeof(DltStorageHeader), + msg.databuffer, (int)msg.datasize, verbose); /* free message */ dlt_message_free(&msg, 0); } -int dlt_daemon_process_one_s_timer(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_one_s_timer(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { uint64_t expir = 0; ssize_t res = 0; @@ -4579,37 +3880,26 @@ int dlt_daemon_process_one_s_timer(DltDaemon *daemon, res = read(receiver->fd, &expir, sizeof(expir)); if (res < 0) { - dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__, strerror(errno)); /* Activity received on timer_wd, but unable to read the fd: * let's go on sending notification */ } - if ((daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) || - (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL)) { - if (dlt_daemon_send_ringbuffer_to_client(daemon, - daemon_local, - daemon_local->flags.vflag)) - dlt_log(LOG_DEBUG, - "Can't send contents of ring buffer to clients\n"); + if ((daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) || (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL)) { + if (dlt_daemon_send_ringbuffer_to_client(daemon, daemon_local, daemon_local->flags.vflag)) + dlt_log(LOG_DEBUG, "Can't send contents of ring buffer to clients\n"); } - if ((daemon->timingpackets) && - (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) - dlt_daemon_control_message_time(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); + if ((daemon->timingpackets) && (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) + dlt_daemon_control_message_time(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); dlt_log(LOG_DEBUG, "Timer timingpacket\n"); return 0; } -int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_daemon_process_sixty_s_timer( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { uint64_t expir = 0; ssize_t res = 0; @@ -4624,24 +3914,19 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, res = read(receiver->fd, &expir, sizeof(expir)); if (res < 0) { - dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__, strerror(errno)); /* Activity received on timer_wd, but unable to read the fd: * let's go on sending notification */ } - if (daemon_local->flags.sendECUSoftwareVersion > 0){ + if (daemon_local->flags.sendECUSoftwareVersion > 0) { if (daemon->daemon_version == DLTProtocolV2) { - dlt_daemon_control_get_software_version_v2(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); - }else if (daemon->daemon_version == DLTProtocolV1) { - dlt_daemon_control_get_software_version(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); - }else { + dlt_daemon_control_get_software_version_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); + } else if (daemon->daemon_version == DLTProtocolV1) { + dlt_daemon_control_get_software_version( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); + } else { dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__); return -1; } @@ -4653,20 +3938,16 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, struct tm lt; /*Added memset to avoid compiler warning for near initialization */ - memset((void *)<, 0, sizeof(lt)); + memset((void*)<, 0, sizeof(lt)); tzset(); localtime_r(&t, <); if (daemon->daemon_version == DLTProtocolV2) { - dlt_daemon_control_message_timezone_v2(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); - }else if (daemon->daemon_version == DLTProtocolV1) { - dlt_daemon_control_message_timezone(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - daemon_local->flags.vflag); - }else { + dlt_daemon_control_message_timezone_v2( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); + } else if (daemon->daemon_version == DLTProtocolV1) { + dlt_daemon_control_message_timezone( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, daemon_local->flags.vflag); + } else { dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__); return -1; } @@ -4678,10 +3959,8 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, } #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE -ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +ssize_t dlt_daemon_process_systemd_timer( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { uint64_t expir = 0; ssize_t res = -1; @@ -4703,8 +3982,8 @@ ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, #ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE if (!daemon->received_message_since_last_watchdog_interval) { - dlt_log(LOG_WARNING, "No new messages received since last watchdog timer run\n"); - return 0; + dlt_log(LOG_WARNING, "No new messages received since last watchdog timer run\n"); + return 0; } daemon->received_message_since_last_watchdog_interval = 0; #endif @@ -4716,10 +3995,8 @@ ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, return 0; } #else -ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +ssize_t dlt_daemon_process_systemd_timer( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { (void)daemon; (void)daemon_local; @@ -4732,16 +4009,13 @@ ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, } #endif -void dlt_daemon_control_service_logstorage(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_service_logstorage( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { - DltServiceOfflineLogstorage *req = NULL; + DltServiceOfflineLogstorage* req = NULL; int ret = 0; unsigned int connection_type = 0; - DltLogStorage *device = NULL; + DltLogStorage* device = NULL; int device_index = -1; uint32_t i = 0; @@ -4756,98 +4030,73 @@ void dlt_daemon_control_service_logstorage(int sock, PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL)) { - dlt_vlog(LOG_ERR, - "%s: Invalid function parameters\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Invalid function parameters\n", __func__); return; } if ((daemon_local->flags.offlineLogstorageMaxDevices <= 0) || (msg->databuffer == NULL)) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - - dlt_log(LOG_INFO, - "Logstorage functionality not enabled or MAX device set is 0\n"); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + + dlt_log(LOG_INFO, "Logstorage functionality not enabled or MAX device set is 0\n"); return; } if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceOfflineLogstorage)) < 0) return; - req = (DltServiceOfflineLogstorage *)(msg->databuffer); + req = (DltServiceOfflineLogstorage*)(msg->databuffer); - if(req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { + if (req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { req_st_status = stat(req->mount_point, &req_mpoint_st); tmp_errno = errno; if (req_st_status < 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - - dlt_vlog(LOG_WARNING, - "%s: Failed to stat requested mount point [%s] with error [%s]\n", - __func__, req->mount_point, strerror(tmp_errno)); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + + dlt_vlog( + LOG_WARNING, "%s: Failed to stat requested mount point [%s] with error [%s]\n", __func__, + req->mount_point, strerror(tmp_errno)); return; } } - for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) { + for (i = 0; i < (uint32_t)daemon_local->flags.offlineLogstorageMaxDevices; i++) { connection_type = daemon->storage_handle[i].connection_type; memset(&daemon_mpoint_st, 0, sizeof(struct stat)); if (strlen(daemon->storage_handle[i].device_mount_point) > 1) { - daemon_st_status = stat(daemon->storage_handle[i].device_mount_point, - &daemon_mpoint_st); + daemon_st_status = stat(daemon->storage_handle[i].device_mount_point, &daemon_mpoint_st); tmp_errno = errno; if (daemon_st_status < 0) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - dlt_vlog(LOG_WARNING, - "%s: Failed to stat daemon mount point [%s] with error [%s]\n", - __func__, daemon->storage_handle[i].device_mount_point, - strerror(tmp_errno)); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_vlog( + LOG_WARNING, "%s: Failed to stat daemon mount point [%s] with error [%s]\n", __func__, + daemon->storage_handle[i].device_mount_point, strerror(tmp_errno)); return; } /* Check if the requested device path is already used as log storage device */ - if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev && - req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) { - device_index = (int) i; + if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev && req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) { + device_index = (int)i; break; } } /* Get first available device index here */ - if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && - (device_index == -1)) - device_index = (int) i; + if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && (device_index == -1)) + device_index = (int)i; } /* It might be possible to sync all caches of all devices */ - if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) && - (strlen(req->mount_point) == 0)) { + if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) && (strlen(req->mount_point) == 0)) { /* It is expected to receive an empty mount point to sync all Logstorage * devices in this case. */ - } - else if (device_index == -1) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + } else if (device_index == -1) { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); dlt_log(LOG_WARNING, "MAX devices already in use \n"); return; } @@ -4859,126 +4108,75 @@ void dlt_daemon_control_service_logstorage(int sock, ret = dlt_logstorage_device_connected(device, req->mount_point); if (ret == 1) { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_WARNING, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_WARNING, verbose); return; - } - else if (ret != 0) - { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + } else if (ret != 0) { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); /* Update maintain logstorage loglevel if necessary */ - if (daemon->storage_handle[device_index].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) - { + if (daemon->storage_handle[device_index].maintain_logstorage_loglevel + != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) { daemon->maintain_logstorage_loglevel = daemon->storage_handle[device_index].maintain_logstorage_loglevel; } /* Check if log level of running application needs an update */ - dlt_daemon_logstorage_update_application_loglevel(daemon, - daemon_local, - device_index, - verbose); + dlt_daemon_logstorage_update_application_loglevel(daemon, daemon_local, device_index, verbose); } /* Check for device disconnection request from log storage ctrl app */ - else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED) - { + else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED) { /* Check if log level of running application needs to be reset */ dlt_daemon_logstorage_reset_application_loglevel( - daemon, - daemon_local, - device_index, - (int) daemon_local->flags.offlineLogstorageMaxDevices, - verbose); + daemon, daemon_local, device_index, (int)daemon_local->flags.offlineLogstorageMaxDevices, verbose); - dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]), - DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); + dlt_logstorage_device_disconnected( + &(daemon->storage_handle[device_index]), DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); } /* Check for cache synchronization request from log storage ctrl app */ - else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) - { + else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { ret = 0; if (device_index == -1) { /* sync all Logstorage devices */ - for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) - if (daemon->storage_handle[i].connection_type == - DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + for (i = 0; i < (uint32_t)daemon_local->flags.offlineLogstorageMaxDevices; i++) + if (daemon->storage_handle[i].connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ret = dlt_daemon_logstorage_sync_cache( - daemon, - daemon_local, - daemon->storage_handle[i].device_mount_point, - verbose); - } - else { + daemon, daemon_local, daemon->storage_handle[i].device_mount_point, verbose); + } else { /* trigger logstorage to sync caches */ - ret = dlt_daemon_logstorage_sync_cache(daemon, - daemon_local, - req->mount_point, - verbose); + ret = dlt_daemon_logstorage_sync_cache(daemon, daemon_local, req->mount_point, verbose); } if (ret == 0) - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); else - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - } - else { - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + } else { + dlt_daemon_control_service_response( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_service_logstorage_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_service_logstorage_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { - DltServiceOfflineLogstorage *req = NULL; + DltServiceOfflineLogstorage* req = NULL; int ret = 0; unsigned int connection_type = 0; - DltLogStorage *device = NULL; + DltLogStorage* device = NULL; int device_index = -1; uint32_t i = 0; @@ -4993,98 +4191,73 @@ void dlt_daemon_control_service_logstorage_v2(int sock, PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL)) { - dlt_vlog(LOG_ERR, - "%s: Invalid function parameters\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Invalid function parameters\n", __func__); return; } if ((daemon_local->flags.offlineLogstorageMaxDevices <= 0) || (msg->databuffer == NULL)) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - - dlt_log(LOG_INFO, - "Logstorage functionality not enabled or MAX device set is 0\n"); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + + dlt_log(LOG_INFO, "Logstorage functionality not enabled or MAX device set is 0\n"); return; } if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceOfflineLogstorage)) < 0) return; - req = (DltServiceOfflineLogstorage *)(msg->databuffer); + req = (DltServiceOfflineLogstorage*)(msg->databuffer); - if(req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { + if (req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { req_st_status = stat(req->mount_point, &req_mpoint_st); tmp_errno = errno; if (req_st_status < 0) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - - dlt_vlog(LOG_WARNING, - "%s: Failed to stat requested mount point [%s] with error [%s]\n", - __func__, req->mount_point, strerror(tmp_errno)); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + + dlt_vlog( + LOG_WARNING, "%s: Failed to stat requested mount point [%s] with error [%s]\n", __func__, + req->mount_point, strerror(tmp_errno)); return; } } - for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) { + for (i = 0; i < (uint32_t)daemon_local->flags.offlineLogstorageMaxDevices; i++) { connection_type = daemon->storage_handle[i].connection_type; memset(&daemon_mpoint_st, 0, sizeof(struct stat)); if (strlen(daemon->storage_handle[i].device_mount_point) > 1) { - daemon_st_status = stat(daemon->storage_handle[i].device_mount_point, - &daemon_mpoint_st); + daemon_st_status = stat(daemon->storage_handle[i].device_mount_point, &daemon_mpoint_st); tmp_errno = errno; if (daemon_st_status < 0) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - dlt_vlog(LOG_WARNING, - "%s: Failed to stat daemon mount point [%s] with error [%s]\n", - __func__, daemon->storage_handle[i].device_mount_point, - strerror(tmp_errno)); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + dlt_vlog( + LOG_WARNING, "%s: Failed to stat daemon mount point [%s] with error [%s]\n", __func__, + daemon->storage_handle[i].device_mount_point, strerror(tmp_errno)); return; } /* Check if the requested device path is already used as log storage device */ - if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev && - req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) { - device_index = (int) i; + if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev && req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) { + device_index = (int)i; break; } } /* Get first available device index here */ - if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && - (device_index == -1)) - device_index = (int) i; + if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) && (device_index == -1)) + device_index = (int)i; } /* It might be possible to sync all caches of all devices */ - if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) && - (strlen(req->mount_point) == 0)) { + if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) && (strlen(req->mount_point) == 0)) { /* It is expected to receive an empty mount point to sync all Logstorage * devices in this case. */ - } - else if (device_index == -1) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + } else if (device_index == -1) { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); dlt_log(LOG_WARNING, "MAX devices already in use \n"); return; } @@ -5096,143 +4269,88 @@ void dlt_daemon_control_service_logstorage_v2(int sock, ret = dlt_logstorage_device_connected(device, req->mount_point); if (ret == 1) { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_WARNING, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_WARNING, verbose); return; - } - else if (ret != 0) - { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + } else if (ret != 0) { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); return; } - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); /* Update maintain logstorage loglevel if necessary */ - if (daemon->storage_handle[device_index].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) - { + if (daemon->storage_handle[device_index].maintain_logstorage_loglevel + != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) { daemon->maintain_logstorage_loglevel = daemon->storage_handle[device_index].maintain_logstorage_loglevel; } /* Check if log level of running application needs an update */ - dlt_daemon_logstorage_update_application_loglevel_v2(daemon, - daemon_local, - device_index, - verbose); + dlt_daemon_logstorage_update_application_loglevel_v2(daemon, daemon_local, device_index, verbose); } /* Check for device disconnection request from log storage ctrl app */ - else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED) - { + else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED) { /* Check if log level of running application needs to be reset */ dlt_daemon_logstorage_reset_application_loglevel( - daemon, - daemon_local, - device_index, - (int) daemon_local->flags.offlineLogstorageMaxDevices, - verbose); + daemon, daemon_local, device_index, (int)daemon_local->flags.offlineLogstorageMaxDevices, verbose); - dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]), - DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); + dlt_logstorage_device_disconnected( + &(daemon->storage_handle[device_index]), DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); } /* Check for cache synchronization request from log storage ctrl app */ - else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) - { + else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) { ret = 0; if (device_index == -1) { /* sync all Logstorage devices */ - for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) - if (daemon->storage_handle[i].connection_type == - DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + for (i = 0; i < (uint32_t)daemon_local->flags.offlineLogstorageMaxDevices; i++) + if (daemon->storage_handle[i].connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ret = dlt_daemon_logstorage_sync_cache( - daemon, - daemon_local, - daemon->storage_handle[i].device_mount_point, - verbose); - } - else { + daemon, daemon_local, daemon->storage_handle[i].device_mount_point, verbose); + } else { /* trigger logstorage to sync caches */ - ret = dlt_daemon_logstorage_sync_cache(daemon, - daemon_local, - req->mount_point, - verbose); + ret = dlt_daemon_logstorage_sync_cache(daemon, daemon_local, req->mount_point, verbose); } if (ret == 0) - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); else - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); - } - else { - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); + } else { + dlt_daemon_control_service_response_v2( + sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); } } -void dlt_daemon_control_passive_node_connect(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose) +void dlt_daemon_control_passive_node_connect( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - DltServicePassiveNodeConnect *req; + DltServicePassiveNodeConnect* req; uint32_t id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT; - if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || - (msg->databuffer == NULL)) + if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; /* return error, if gateway mode not enabled*/ if (daemon_local->flags.gatewayMode == 0) { - dlt_log(LOG_WARNING, - "Received passive node connection status request, " - "but GatewayMode is disabled\n"); + dlt_log( + LOG_WARNING, + "Received passive node connection status request, " + "but GatewayMode is disabled\n"); dlt_daemon_control_service_response( - sock, - daemon, - daemon_local, - DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, - DLT_SERVICE_RESPONSE_ERROR, + sock, daemon, daemon_local, DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, DLT_SERVICE_RESPONSE_ERROR, verbose); return; @@ -5241,56 +4359,37 @@ void dlt_daemon_control_passive_node_connect(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServicePassiveNodeConnect)) < 0) return; - req = (DltServicePassiveNodeConnect *)msg->databuffer; - - if (dlt_gateway_process_on_demand_request(&daemon_local->pGateway, - daemon_local, - req->node_id, - (int) req->connection_status, - verbose) < 0) - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + req = (DltServicePassiveNodeConnect*)msg->databuffer; + + if (dlt_gateway_process_on_demand_request( + &daemon_local->pGateway, daemon_local, req->node_id, (int)req->connection_status, verbose) + < 0) + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); else - dlt_daemon_control_service_response(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); } -void dlt_daemon_control_passive_node_connect_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose) +void dlt_daemon_control_passive_node_connect_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - //TBD: Review node_id member of DltServicePassiveNodeConnect - DltServicePassiveNodeConnect *req; + // TBD: Review node_id member of DltServicePassiveNodeConnect + DltServicePassiveNodeConnect* req; uint32_t id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT; - if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || - (msg->databuffer == NULL)) + if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; /* return error, if gateway mode not enabled*/ if (daemon_local->flags.gatewayMode == 0) { - dlt_log(LOG_WARNING, - "Received passive node connection status request, " - "but GatewayMode is disabled\n"); + dlt_log( + LOG_WARNING, + "Received passive node connection status request, " + "but GatewayMode is disabled\n"); dlt_daemon_control_service_response_v2( - sock, - daemon, - daemon_local, - DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, - DLT_SERVICE_RESPONSE_ERROR, + sock, daemon, daemon_local, DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, DLT_SERVICE_RESPONSE_ERROR, verbose); return; @@ -5299,36 +4398,22 @@ void dlt_daemon_control_passive_node_connect_v2(int sock, if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServicePassiveNodeConnect)) < 0) return; - req = (DltServicePassiveNodeConnect *)msg->databuffer; - - if (dlt_gateway_process_on_demand_request(&daemon_local->pGateway, - daemon_local, - req->node_id, - (int) req->connection_status, - verbose) < 0) - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_ERROR, - verbose); + req = (DltServicePassiveNodeConnect*)msg->databuffer; + + if (dlt_gateway_process_on_demand_request( + &daemon_local->pGateway, daemon_local, req->node_id, (int)req->connection_status, verbose) + < 0) + dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose); else - dlt_daemon_control_service_response_v2(sock, - daemon, - daemon_local, - id, - DLT_SERVICE_RESPONSE_OK, - verbose); + dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose); } -void dlt_daemon_control_passive_node_connect_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +void dlt_daemon_control_passive_node_connect_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessageV2 msg; - DltServicePassiveNodeConnectionInfo *resp; - DltGatewayConnection *con = NULL; + DltServicePassiveNodeConnectionInfo* resp; + DltGatewayConnection* con = NULL; unsigned int i = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -5341,16 +4426,13 @@ void dlt_daemon_control_passive_node_connect_status_v2(int sock, /* return error, if gateway mode not enabled*/ if (daemon_local->flags.gatewayMode == 0) { - dlt_log(LOG_WARNING, - "Received passive node connection status request, " - "but GatewayMode is disabled\n"); + dlt_log( + LOG_WARNING, + "Received passive node connection status request, " + "but GatewayMode is disabled\n"); dlt_daemon_control_service_response_v2( - sock, - daemon, - daemon_local, - DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, - DLT_SERVICE_RESPONSE_ERROR, + sock, daemon, daemon_local, DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, DLT_SERVICE_RESPONSE_ERROR, verbose); return; @@ -5363,7 +4445,7 @@ void dlt_daemon_control_passive_node_connect_status_v2(int sock, msg.databuffer = NULL; if (msg.databuffer == NULL) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); if (msg.databuffer == NULL) { dlt_log(LOG_CRIT, "Cannot allocate memory for message response\n"); @@ -5373,45 +4455,36 @@ void dlt_daemon_control_passive_node_connect_status_v2(int sock, msg.databuffersize = msg.datasize; } - resp = (DltServicePassiveNodeConnectionInfo *)msg.databuffer; + resp = (DltServicePassiveNodeConnectionInfo*)msg.databuffer; memset(resp, 0, (size_t)msg.datasize); resp->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS; resp->status = DLT_SERVICE_RESPONSE_OK; - resp->num_connections = (uint32_t) daemon_local->pGateway.num_connections; + resp->num_connections = (uint32_t)daemon_local->pGateway.num_connections; for (i = 0; i < resp->num_connections; i++) { if ((i * DLT_ID_SIZE) > DLT_ENTRY_MAX) { - dlt_log(LOG_ERR, - "Maximal message size reached. Skip further information\n"); + dlt_log(LOG_ERR, "Maximal message size reached. Skip further information\n"); break; } con = &daemon_local->pGateway.connections[i]; resp->connection_status[i] = con->status; - //TBD: Review node_id[i * con->ecuid2len] + // TBD: Review node_id[i * con->ecuid2len] memcpy(&resp->node_id[i * con->ecuid2len], con->ecuid2, con->ecuid2len); } - dlt_daemon_client_send_control_message_v2(sock, - daemon, - daemon_local, - &msg, - "", - "", - verbose); + dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose); /* free message */ dlt_message_free_v2(&msg, verbose); } -void dlt_daemon_control_passive_node_connect_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +void dlt_daemon_control_passive_node_connect_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { DltMessage msg; - DltServicePassiveNodeConnectionInfo *resp; - DltGatewayConnection *con = NULL; + DltServicePassiveNodeConnectionInfo* resp; + DltGatewayConnection* con = NULL; unsigned int i = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -5424,16 +4497,13 @@ void dlt_daemon_control_passive_node_connect_status(int sock, /* return error, if gateway mode not enabled*/ if (daemon_local->flags.gatewayMode == 0) { - dlt_log(LOG_WARNING, - "Received passive node connection status request, " - "but GatewayMode is disabled\n"); + dlt_log( + LOG_WARNING, + "Received passive node connection status request, " + "but GatewayMode is disabled\n"); dlt_daemon_control_service_response( - sock, - daemon, - daemon_local, - DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, - DLT_SERVICE_RESPONSE_ERROR, + sock, daemon, daemon_local, DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS, DLT_SERVICE_RESPONSE_ERROR, verbose); return; @@ -5446,7 +4516,7 @@ void dlt_daemon_control_passive_node_connect_status(int sock, msg.databuffer = NULL; if (msg.databuffer == NULL) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); if (msg.databuffer == NULL) { dlt_log(LOG_CRIT, "Cannot allocate memory for message response\n"); @@ -5456,16 +4526,15 @@ void dlt_daemon_control_passive_node_connect_status(int sock, msg.databuffersize = msg.datasize; } - resp = (DltServicePassiveNodeConnectionInfo *)msg.databuffer; + resp = (DltServicePassiveNodeConnectionInfo*)msg.databuffer; memset(resp, 0, (size_t)msg.datasize); resp->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS; resp->status = DLT_SERVICE_RESPONSE_OK; - resp->num_connections = (uint32_t) daemon_local->pGateway.num_connections; + resp->num_connections = (uint32_t)daemon_local->pGateway.num_connections; for (i = 0; i < resp->num_connections; i++) { if ((i * DLT_ID_SIZE) > DLT_ENTRY_MAX) { - dlt_log(LOG_ERR, - "Maximal message size reached. Skip further information\n"); + dlt_log(LOG_ERR, "Maximal message size reached. Skip further information\n"); break; } @@ -5475,13 +4544,7 @@ void dlt_daemon_control_passive_node_connect_status(int sock, memcpy(&resp->node_id[i * DLT_ID_SIZE], con->ecuid, DLT_ID_SIZE); } - dlt_daemon_client_send_control_message(sock, - daemon, - daemon_local, - &msg, - "", - "", - verbose); + dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose); /* free message */ dlt_message_free(&msg, verbose); } diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h index 9a5fa547e..fafc68ea2 100644 --- a/src/daemon/dlt_daemon_client.h +++ b/src/daemon/dlt_daemon_client.h @@ -80,16 +80,9 @@ * @param verbose if set to true verbose information is printed out. * @return unequal 0 if there is an error or buffer is full */ -int dlt_daemon_client_send(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - void *storage_header, - int storage_header_size, - void *data1, - int size1, - void *data2, - int size2, - int verbose); +int dlt_daemon_client_send( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, void* storage_header, int storage_header_size, + void* data1, int size1, void* data2, int size2, int verbose); /** * Send out message to client or store message in offline trace. @@ -105,16 +98,9 @@ int dlt_daemon_client_send(int sock, * @param verbose if set to true verbose information is printed out. * @return unequal 0 if there is an error or buffer is full */ -int dlt_daemon_client_send_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - void *storage_header, - int storage_header_size, - void *data1, - int size1, - void *data2, - int size2, - int verbose); +int dlt_daemon_client_send_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, void* storage_header, int storage_header_size, + void* data1, int size1, void* data2, int size2, int verbose); /** * Send out message to all client or store message in offline trace. @@ -123,9 +109,7 @@ int dlt_daemon_client_send_v2(int sock, * @param verbose if set to true verbose information is printed out. * @return 0 if success, less than 0 if there is an error or buffer is full */ -int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose); +int dlt_daemon_client_send_message_to_all_client(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Send out message to all client or store message in offline trace. @@ -134,9 +118,7 @@ int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return 0 if success, less than 0 if there is an error or buffer is full */ -int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose); +int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Send out response message to dlt client @@ -149,13 +131,8 @@ int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return -1 if there is an error or buffer is full */ -int dlt_daemon_client_send_control_message(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - char *apid, - char *ctid, - int verbose); +int dlt_daemon_client_send_control_message( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, char* apid, char* ctid, int verbose); /** * Send out response message to dlt client for DLT V2 @@ -168,13 +145,8 @@ int dlt_daemon_client_send_control_message(int sock, * @param verbose if set to true verbose information is printed out. * @return -1 if there is an error or buffer is full */ -int dlt_daemon_client_send_control_message_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - char *apid, - char *ctid, - int verbose); +int dlt_daemon_client_send_control_message_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, char* apid, char* ctid, int verbose); /** * Process and generate response to received get log info control message * @param sock connection handle used for sending response @@ -183,11 +155,8 @@ int dlt_daemon_client_send_control_message_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_log_info(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_get_log_info( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received get log info control message @@ -198,11 +167,8 @@ void dlt_daemon_control_get_log_info(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_log_info_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_get_log_info_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received get software version control message * @param sock connection handle used for sending response @@ -210,7 +176,7 @@ void dlt_daemon_control_get_log_info_v2(int sock, * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_control_get_software_version(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process and generate response to received get software version control message @@ -219,7 +185,7 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDae * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_control_get_software_version(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process and generate response to received get software version control message for DLT V2 @@ -228,7 +194,7 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDae * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process and generate response to received get default log level control message @@ -237,7 +203,7 @@ void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, Dlt * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_control_get_default_log_level(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process and generate response to received get default log level control message @@ -247,7 +213,8 @@ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDa * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_control_get_default_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process and generate response to message buffer overflow control message @@ -259,12 +226,8 @@ void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, Dl * @param verbose if set to true verbose information is printed out. * @return -1 if there is an error or buffer overflow, else 0 */ -int dlt_daemon_control_message_buffer_overflow(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - unsigned int overflow_counter, - char *apid, - int verbose); +int dlt_daemon_control_message_buffer_overflow( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, unsigned int overflow_counter, char* apid, int verbose); /** * Process and generate response to message buffer overflow control message @@ -276,12 +239,8 @@ int dlt_daemon_control_message_buffer_overflow(int sock, * @param verbose if set to true verbose information is printed out. * @return -1 if there is an error or buffer overflow, else 0 */ -int dlt_daemon_control_message_buffer_overflow_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - unsigned int overflow_counter, - char *apid, - int verbose); +int dlt_daemon_control_message_buffer_overflow_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, unsigned int overflow_counter, char* apid, int verbose); /** * Generate response to control message from dlt client @@ -292,12 +251,8 @@ int dlt_daemon_control_message_buffer_overflow_v2(int sock, * @param status status of response (e.g. ok, not supported, error) * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_service_response(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint32_t service_id, - int8_t status, - int verbose); +void dlt_daemon_control_service_response( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint32_t service_id, int8_t status, int verbose); /** * Generate response to control message from dlt client for DLT V2 @@ -308,12 +263,8 @@ void dlt_daemon_control_service_response(int sock, * @param status status of response (e.g. ok, not supported, error) * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_service_response_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint32_t service_id, - int8_t status, - int verbose); +void dlt_daemon_control_service_response_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint32_t service_id, int8_t status, int verbose); /** * Send control message unregister context (add on to AUTOSAR standard) * @param sock connection handle used for sending response @@ -324,13 +275,8 @@ void dlt_daemon_control_service_response_v2(int sock, * @param comid Communication id where apid is unregistered * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_unregister_context(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *comid, - int verbose); +int dlt_daemon_control_message_unregister_context( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, char* apid, char* ctid, char* comid, int verbose); /** * Send control message unregister context (add on to AUTOSAR standard) @@ -342,15 +288,9 @@ int dlt_daemon_control_message_unregister_context(int sock, * @param comid Communication id where apid is unregistered * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_unregister_context_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint8_t apidlen, - char *apid, - uint8_t ctidlen, - char *ctid, - char *comid, - int verbose); +int dlt_daemon_control_message_unregister_context_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint8_t apidlen, char* apid, uint8_t ctidlen, char* ctid, + char* comid, int verbose); /** * Send control message connection info (add on to AUTOSAR standard) @@ -361,12 +301,8 @@ int dlt_daemon_control_message_unregister_context_v2(int sock, * @param comid Communication id where connection state changed * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_connection_info(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint8_t state, - char *comid, - int verbose); +int dlt_daemon_control_message_connection_info( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint8_t state, char* comid, int verbose); /** * Send control message connection info (add on to AUTOSAR standard) for DLT V2 @@ -377,12 +313,8 @@ int dlt_daemon_control_message_connection_info(int sock, * @param comid Communication id where connection state changed * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_connection_info_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - uint8_t state, - char *comid, - int verbose); +int dlt_daemon_control_message_connection_info_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, uint8_t state, char* comid, int verbose); /** * Send control message timezone (add on to AUTOSAR standard) @@ -391,7 +323,7 @@ int dlt_daemon_control_message_connection_info_v2(int sock, * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +int dlt_daemon_control_message_timezone(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Send control message timezone (add on to AUTOSAR standard) for DLT V2 @@ -400,7 +332,7 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Send control message marker (add on to AUTOSAR standard) @@ -409,7 +341,7 @@ int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon *daemon, DltDaemo * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +int dlt_daemon_control_message_marker(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process received control message from dlt client * @param sock connection handle used for sending response @@ -418,11 +350,8 @@ int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLoca * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_client_process_control(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +int dlt_daemon_client_process_control( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process received control message from dlt client @@ -432,11 +361,8 @@ int dlt_daemon_client_process_control(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -int dlt_daemon_client_process_control_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +int dlt_daemon_client_process_control_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received sw injection control message @@ -446,11 +372,8 @@ int dlt_daemon_client_process_control_v2(int sock, * @param msg pointer to received sw injection control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_callsw_cinjection(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_callsw_cinjection( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received sw injection control message @@ -461,11 +384,8 @@ void dlt_daemon_control_callsw_cinjection(int sock, * @param msg pointer to received sw injection control message DLT version 2 * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_callsw_cinjection_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_callsw_cinjection_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received set log level control message @@ -475,11 +395,8 @@ void dlt_daemon_control_callsw_cinjection_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received set log level control message @@ -490,11 +407,8 @@ void dlt_daemon_control_set_log_level(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received set trace status control message @@ -504,11 +418,8 @@ void dlt_daemon_control_set_log_level_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received set trace status control message @@ -518,11 +429,8 @@ void dlt_daemon_control_set_trace_status(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received set default log level control message @@ -532,11 +440,8 @@ void dlt_daemon_control_set_trace_status_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_default_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_default_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received set default log level control message @@ -547,11 +452,8 @@ void dlt_daemon_control_set_default_log_level(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_default_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_default_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received set all log level control message @@ -561,11 +463,8 @@ void dlt_daemon_control_set_default_log_level_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_all_log_level(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_all_log_level( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received set all log level control message @@ -576,11 +475,8 @@ void dlt_daemon_control_set_all_log_level(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_all_log_level_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_all_log_level_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received set default trace status control message @@ -590,11 +486,8 @@ void dlt_daemon_control_set_all_log_level_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_default_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_default_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received set default trace status control message @@ -605,11 +498,8 @@ void dlt_daemon_control_set_default_trace_status(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_default_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_default_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received set all trace status control message @@ -619,11 +509,8 @@ void dlt_daemon_control_set_default_trace_status_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_all_trace_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_all_trace_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received set all trace status control message @@ -634,11 +521,8 @@ void dlt_daemon_control_set_all_trace_status(int sock, * @param msg pointer to received control message DLT version 2 * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_all_trace_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_all_trace_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to set timing packets control message @@ -648,11 +532,8 @@ void dlt_daemon_control_set_all_trace_status_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_timing_packets(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_set_timing_packets( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to set timing packets control message @@ -663,11 +544,8 @@ void dlt_daemon_control_set_timing_packets(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_set_timing_packets_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_set_timing_packets_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Send time control message @@ -676,7 +554,7 @@ void dlt_daemon_control_set_timing_packets_v2(int sock, * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +void dlt_daemon_control_message_time(int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Service offline logstorage command request * @param sock connection handle used for sending response @@ -685,11 +563,8 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_service_logstorage(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_service_logstorage( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Service offline logstorage command request for DLT V2 @@ -699,11 +574,8 @@ void dlt_daemon_control_service_logstorage(int sock, * @param msg pointer to received control message version 2 * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_service_logstorage_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_service_logstorage_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received passive node connect control @@ -714,11 +586,8 @@ void dlt_daemon_control_service_logstorage_v2(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_passive_node_connect(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessage *msg, - int verbose); +void dlt_daemon_control_passive_node_connect( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessage* msg, int verbose); /** * Process and generate response to received passive node connect control @@ -729,11 +598,8 @@ void dlt_daemon_control_passive_node_connect(int sock, * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_passive_node_connect_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - int verbose); +void dlt_daemon_control_passive_node_connect_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, DltMessageV2* msg, int verbose); /** * Process and generate response to received passive node connection status @@ -743,10 +609,8 @@ void dlt_daemon_control_passive_node_connect_v2(int sock, * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_passive_node_connect_status(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose); +void dlt_daemon_control_passive_node_connect_status( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Process and generate response to received passive node connection status @@ -756,8 +620,6 @@ void dlt_daemon_control_passive_node_connect_status(int sock, * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_passive_node_connect_status_v2(int sock, - DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose); +void dlt_daemon_control_passive_node_connect_status_v2( + int sock, DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); #endif /* DLT_DAEMON_CLIENT_H */ diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index a34f26fb6..635b77586 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -88,47 +88,47 @@ #include "dlt_daemon_serial.h" #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE -# include +#include #endif -char *app_recv_buffer = NULL; /* pointer to receiver buffer for application msges */ +char* app_recv_buffer = NULL; /* pointer to receiver buffer for application msges */ -static int dlt_daemon_cmp_apid(const void *m1, const void *m2) +static int dlt_daemon_cmp_apid(const void* m1, const void* m2) { if ((m1 == NULL) || (m2 == NULL)) return -1; - const DltDaemonApplication *mi1 = (const DltDaemonApplication *)m1; - const DltDaemonApplication *mi2 = (const DltDaemonApplication *)m2; + const DltDaemonApplication* mi1 = (const DltDaemonApplication*)m1; + const DltDaemonApplication* mi2 = (const DltDaemonApplication*)m2; return memcmp(mi1->apid, mi2->apid, DLT_ID_SIZE); } -static int dlt_daemon_cmp_apid_v2(const void *m1, const void *m2) +static int dlt_daemon_cmp_apid_v2(const void* m1, const void* m2) { if ((m1 == NULL) || (m2 == NULL)) return -1; - const DltDaemonApplication *mi1 = (const DltDaemonApplication *)m1; - const DltDaemonApplication *mi2 = (const DltDaemonApplication *)m2; + const DltDaemonApplication* mi1 = (const DltDaemonApplication*)m1; + const DltDaemonApplication* mi2 = (const DltDaemonApplication*)m2; - if (mi1->apid2len < mi2->apid2len){ + if (mi1->apid2len < mi2->apid2len) { return -1; - }else if (mi1->apid2len > mi2->apid2len){ + } else if (mi1->apid2len > mi2->apid2len) { return 1; } return memcmp(mi1->apid2, mi2->apid2, mi1->apid2len); } -static int dlt_daemon_cmp_apid_ctid(const void *m1, const void *m2) +static int dlt_daemon_cmp_apid_ctid(const void* m1, const void* m2) { if ((m1 == NULL) || (m2 == NULL)) return -1; int ret, cmp; - const DltDaemonContext *mi1 = (const DltDaemonContext *)m1; - const DltDaemonContext *mi2 = (const DltDaemonContext *)m2; + const DltDaemonContext* mi1 = (const DltDaemonContext*)m1; + const DltDaemonContext* mi2 = (const DltDaemonContext*)m2; cmp = memcmp(mi1->apid, mi2->apid, DLT_ID_SIZE); @@ -142,41 +142,39 @@ static int dlt_daemon_cmp_apid_ctid(const void *m1, const void *m2) return ret; } -static int dlt_daemon_cmp_apid_ctid_v2(const void *m1, const void *m2) +static int dlt_daemon_cmp_apid_ctid_v2(const void* m1, const void* m2) { if ((m1 == NULL) || (m2 == NULL)) return -1; int cmp; - const DltDaemonContext *mi1 = (const DltDaemonContext *)m1; - const DltDaemonContext *mi2 = (const DltDaemonContext *)m2; + const DltDaemonContext* mi1 = (const DltDaemonContext*)m1; + const DltDaemonContext* mi2 = (const DltDaemonContext*)m2; - if (mi1->apid2len < mi2->apid2len){ + if (mi1->apid2len < mi2->apid2len) { return -1; - }else if (mi1->apid2len > mi2->apid2len){ + } else if (mi1->apid2len > mi2->apid2len) { return 1; } cmp = memcmp(mi1->apid2, mi2->apid2, mi1->apid2len); - if (cmp < 0){ + if (cmp < 0) { return -1; - }else if (cmp > 0){ + } else if (cmp > 0) { return 1; - }else { - if (mi1->ctid2len < mi2->ctid2len){ + } else { + if (mi1->ctid2len < mi2->ctid2len) { return -1; - }else if (mi1->ctid2len > mi2->ctid2len){ + } else if (mi1->ctid2len > mi2->ctid2len) { return 1; - }else{ + } else { return memcmp(mi1->ctid2, mi2->ctid2, mi1->ctid2len); } } } -DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon, - char *ecu, - int verbose) +DltDaemonRegisteredUsers* dlt_daemon_find_users_list(DltDaemon* daemon, char* ecu, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -184,7 +182,7 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon, if ((daemon == NULL) || (ecu == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameters", __func__); - return (DltDaemonRegisteredUsers *)NULL; + return (DltDaemonRegisteredUsers*)NULL; } for (i = 0; i < daemon->num_user_lists; i++) @@ -192,13 +190,10 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon, return &daemon->user_list[i]; dlt_vlog(LOG_ERR, "Cannot find user list for ECU: %4s\n", ecu); - return (DltDaemonRegisteredUsers *)NULL; + return (DltDaemonRegisteredUsers*)NULL; } -DltDaemonRegisteredUsers *dlt_daemon_find_users_list_v2(DltDaemon *daemon, - uint8_t eculen, - char *ecu, - int verbose) +DltDaemonRegisteredUsers* dlt_daemon_find_users_list_v2(DltDaemon* daemon, uint8_t eculen, char* ecu, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -206,7 +201,7 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list_v2(DltDaemon *daemon, if ((daemon == NULL) || (ecu == NULL) || (eculen == 0)) { dlt_vlog(LOG_ERR, "%s: Wrong parameters", __func__); - return (DltDaemonRegisteredUsers *)NULL; + return (DltDaemonRegisteredUsers*)NULL; } for (i = 0; i < daemon->num_user_lists; i++) @@ -214,17 +209,18 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list_v2(DltDaemon *daemon, return &daemon->user_list[i]; dlt_vlog(LOG_ERR, "Cannot find user list for ECU: %s\n", ecu); - return (DltDaemonRegisteredUsers *)NULL; + return (DltDaemonRegisteredUsers*)NULL; } #ifdef DLT_LOG_LEVEL_APP_CONFIG -static int dlt_daemon_cmp_log_settings(const void *lhs, const void *rhs) { +static int dlt_daemon_cmp_log_settings(const void* lhs, const void* rhs) +{ if ((lhs == NULL) || (rhs == NULL)) return -1; - DltDaemonContextLogSettings *settings1 = (DltDaemonContextLogSettings *)lhs; - DltDaemonContextLogSettings *settings2 = (DltDaemonContextLogSettings *)rhs; + DltDaemonContextLogSettings* settings1 = (DltDaemonContextLogSettings*)lhs; + DltDaemonContextLogSettings* settings2 = (DltDaemonContextLogSettings*)rhs; int cmp = memcmp(settings1->apid, settings2->apid, DLT_ID_SIZE); @@ -243,11 +239,12 @@ static int dlt_daemon_cmp_log_settings(const void *lhs, const void *rhs) { * @param ctid context id to use, can be NULL * @return pointer to log settings if found, otherwise NULL */ -DltDaemonContextLogSettings *dlt_daemon_find_configured_app_id_ctx_id_settings( - const DltDaemon *daemon, const char *apid, const char *ctid) { - DltDaemonContextLogSettings *app_id_settings = NULL; +DltDaemonContextLogSettings* dlt_daemon_find_configured_app_id_ctx_id_settings( + const DltDaemon* daemon, const char* apid, const char* ctid) +{ + DltDaemonContextLogSettings* app_id_settings = NULL; for (int i = 0; i < daemon->num_app_id_log_level_settings; ++i) { - DltDaemonContextLogSettings *settings = &daemon->app_id_log_level_settings[i]; + DltDaemonContextLogSettings* settings = &daemon->app_id_log_level_settings[i]; if (strncmp(apid, settings->apid, DLT_ID_SIZE) != 0) { if (app_id_settings != NULL) @@ -281,12 +278,13 @@ DltDaemonContextLogSettings *dlt_daemon_find_configured_app_id_ctx_id_settings( * @param ctid context id to use, can be NULL * @return pointer to log settings if found, otherwise NULL */ -DltDaemonContextLogSettingsV2 *dlt_daemon_find_configured_app_id_ctx_id_settings_v2( - const DltDaemon *daemon, const char *apid, const char *ctid) { - DltDaemonContextLogSettingsV2 *app_id_settings = NULL; +DltDaemonContextLogSettingsV2* dlt_daemon_find_configured_app_id_ctx_id_settings_v2( + const DltDaemon* daemon, const char* apid, const char* ctid) +{ + DltDaemonContextLogSettingsV2* app_id_settings = NULL; for (int i = 0; i < daemon->num_app_id_log_level_settings; ++i) { - DltDaemonContextLogSettingsV2 *settings = &daemon->app_id_log_level_settings[i]; - //TBD: Check settings->apid, settings->apid2len in runtime + DltDaemonContextLogSettingsV2* settings = &daemon->app_id_log_level_settings[i]; + // TBD: Check settings->apid, settings->apid2len in runtime if (strncmp(apid, settings->apid, settings->apidlen) != 0) { if (app_id_settings != NULL) return app_id_settings; @@ -318,9 +316,9 @@ DltDaemonContextLogSettingsV2 *dlt_daemon_find_configured_app_id_ctx_id_settings * @return Pointer to DltDaemonApplicationLogSettings containing the log level * for the requested application or NULL if none found. */ -DltDaemonContextLogSettings *dlt_daemon_find_app_log_level_config( - const DltDaemonApplication *const app, const char *const ctid) { - +DltDaemonContextLogSettings* dlt_daemon_find_app_log_level_config( + const DltDaemonApplication* const app, const char* const ctid) +{ if (NULL == ctid) return NULL; @@ -329,12 +327,9 @@ DltDaemonContextLogSettings *dlt_daemon_find_app_log_level_config( memcpy(settings.ctid, ctid, DLT_ID_SIZE); DltDaemonContextLogSettings* log_settings = NULL; - log_settings = - (DltDaemonContextLogSettings *)bsearch( - &settings, app->context_log_level_settings, - (size_t)app->num_context_log_level_settings, - sizeof(DltDaemonContextLogSettings), - dlt_daemon_cmp_log_settings); + log_settings = (DltDaemonContextLogSettings*)bsearch( + &settings, app->context_log_level_settings, (size_t)app->num_context_log_level_settings, + sizeof(DltDaemonContextLogSettings), dlt_daemon_cmp_log_settings); return log_settings; } @@ -343,9 +338,10 @@ DltDaemonContextLogSettings *dlt_daemon_find_app_log_level_config( #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE -int dlt_daemon_compare_trace_load_settings(const void *a, const void *b) { - const DltTraceLoadSettings *s1 = (const DltTraceLoadSettings *)a; - const DltTraceLoadSettings *s2 = (const DltTraceLoadSettings *)b; +int dlt_daemon_compare_trace_load_settings(const void* a, const void* b) +{ + const DltTraceLoadSettings* s1 = (const DltTraceLoadSettings*)a; + const DltTraceLoadSettings* s2 = (const DltTraceLoadSettings*)b; int cmp = strncmp(s1->apid, s2->apid, DLT_ID_SIZE); if (cmp != 0) { @@ -356,7 +352,8 @@ int dlt_daemon_compare_trace_load_settings(const void *a, const void *b) { } DltReturnValue dlt_daemon_find_preconfigured_trace_load_settings( - DltDaemon *const daemon, const char *apid, const char *ctid, DltTraceLoadSettings **settings, int *num_settings, int verbose) + DltDaemon* const daemon, const char* apid, const char* ctid, DltTraceLoadSettings** settings, int* num_settings, + int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int i; @@ -390,10 +387,10 @@ DltReturnValue dlt_daemon_find_preconfigured_trace_load_settings( } // Reallocate memory for the settings array with an additional slot for the new setting - DltTraceLoadSettings *temp = realloc(*settings, (*num_settings + 1) * sizeof(DltTraceLoadSettings)); + DltTraceLoadSettings* temp = realloc(*settings, (*num_settings + 1) * sizeof(DltTraceLoadSettings)); if (temp == NULL) { dlt_vlog(LOG_ERR, "Failed to allocate memory for trace load settings\n"); - free(*settings); // Free any previously allocated memory + free(*settings); // Free any previously allocated memory *settings = NULL; *num_settings = 0; return DLT_RETURN_ERROR; @@ -404,13 +401,12 @@ DltReturnValue dlt_daemon_find_preconfigured_trace_load_settings( (*num_settings)++; } - qsort(*settings, (size_t)*num_settings, sizeof(DltTraceLoadSettings), - dlt_daemon_compare_trace_load_settings); + qsort(*settings, (size_t)*num_settings, sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); return DLT_RETURN_OK; } #endif -int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, const char *runtime_directory, int verbose) +int dlt_daemon_init_runtime_configuration(DltDaemon* daemon, const char* runtime_directory, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); size_t append_length = 0; @@ -430,52 +426,50 @@ int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, const char *runtime if (runtime_directory[0]) { strncpy(daemon->runtime_application_cfg, runtime_directory, append_length); daemon->runtime_application_cfg[append_length] = 0; - } - else { + } else { strncpy(daemon->runtime_application_cfg, DLT_RUNTIME_DEFAULT_DIRECTORY, append_length); daemon->runtime_application_cfg[append_length] = 0; } - strcat(daemon->runtime_application_cfg, DLT_RUNTIME_APPLICATION_CFG); /* strcat uncritical here, because max length already checked */ + strcat( + daemon->runtime_application_cfg, + DLT_RUNTIME_APPLICATION_CFG); /* strcat uncritical here, because max length already checked */ append_length = PATH_MAX - sizeof(DLT_RUNTIME_CONTEXT_CFG); if (runtime_directory[0]) { strncpy(daemon->runtime_context_cfg, runtime_directory, append_length); daemon->runtime_context_cfg[append_length] = 0; - } - else { + } else { strncpy(daemon->runtime_context_cfg, DLT_RUNTIME_DEFAULT_DIRECTORY, append_length); daemon->runtime_context_cfg[append_length] = 0; } - strcat(daemon->runtime_context_cfg, DLT_RUNTIME_CONTEXT_CFG); /* strcat uncritical here, because max length already checked */ + strcat( + daemon->runtime_context_cfg, + DLT_RUNTIME_CONTEXT_CFG); /* strcat uncritical here, because max length already checked */ append_length = PATH_MAX - sizeof(DLT_RUNTIME_CONFIGURATION); if (runtime_directory[0]) { strncpy(daemon->runtime_configuration, runtime_directory, append_length); daemon->runtime_configuration[append_length] = 0; - } - else { + } else { strncpy(daemon->runtime_configuration, DLT_RUNTIME_DEFAULT_DIRECTORY, append_length); daemon->runtime_configuration[append_length] = 0; } - strcat(daemon->runtime_configuration, DLT_RUNTIME_CONFIGURATION); /* strcat uncritical here, because max length already checked */ + strcat( + daemon->runtime_configuration, + DLT_RUNTIME_CONFIGURATION); /* strcat uncritical here, because max length already checked */ return DLT_RETURN_OK; } -int dlt_daemon_init(DltDaemon *daemon, - unsigned long RingbufferMinSize, - unsigned long RingbufferMaxSize, - unsigned long RingbufferStepSize, - const char *runtime_directory, - int InitialContextLogLevel, - int InitialContextTraceStatus, - int ForceLLTS, - int verbose) +int dlt_daemon_init( + DltDaemon* daemon, unsigned long RingbufferMinSize, unsigned long RingbufferMaxSize, + unsigned long RingbufferStepSize, const char* runtime_directory, int InitialContextLogLevel, + int InitialContextTraceStatus, int ForceLLTS, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -485,9 +479,9 @@ int dlt_daemon_init(DltDaemon *daemon, daemon->user_list = NULL; daemon->num_user_lists = 0; - daemon->default_log_level = (int8_t) InitialContextLogLevel; - daemon->default_trace_status = (int8_t) InitialContextTraceStatus; - daemon->force_ll_ts = (int8_t) ForceLLTS; + daemon->default_log_level = (int8_t)InitialContextLogLevel; + daemon->default_trace_status = (int8_t)InitialContextTraceStatus; + daemon->force_ll_ts = (int8_t)ForceLLTS; daemon->overflow_counter = 0; @@ -511,13 +505,13 @@ int dlt_daemon_init(DltDaemon *daemon, memset(daemon->ecuid2, 0, DLT_V2_ID_SIZE); /* initialize ring buffer for client connection */ - dlt_vlog(LOG_INFO, "Ringbuffer configuration: %lu/%lu/%lu\n", - RingbufferMinSize, RingbufferMaxSize, RingbufferStepSize); + dlt_vlog( + LOG_INFO, "Ringbuffer configuration: %lu/%lu/%lu\n", RingbufferMinSize, RingbufferMaxSize, RingbufferStepSize); - if (dlt_buffer_init_dynamic(&(daemon->client_ringbuffer), - (uint32_t) RingbufferMinSize, - (uint32_t) RingbufferMaxSize, - (uint32_t) RingbufferStepSize) < DLT_RETURN_OK) + if (dlt_buffer_init_dynamic( + &(daemon->client_ringbuffer), (uint32_t)RingbufferMinSize, (uint32_t)RingbufferMaxSize, + (uint32_t)RingbufferStepSize) + < DLT_RETURN_OK) return -1; daemon->storage_handle = NULL; @@ -527,10 +521,10 @@ int dlt_daemon_init(DltDaemon *daemon, return 0; } -int dlt_daemon_free(DltDaemon *daemon, int verbose) +int dlt_daemon_free(DltDaemon* daemon, int verbose) { int i = 0; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -552,7 +546,7 @@ int dlt_daemon_free(DltDaemon *daemon, int verbose) #ifdef DLT_LOG_LEVEL_APP_CONFIG if (daemon->app_id_log_level_settings != NULL) { - free(daemon->app_id_log_level_settings); + free(daemon->app_id_log_level_settings); } #endif @@ -565,10 +559,7 @@ int dlt_daemon_free(DltDaemon *daemon, int verbose) return 0; } -int dlt_daemon_init_user_information(DltDaemon *daemon, - DltGateway *gateway, - int gateway_mode, - int verbose) +int dlt_daemon_init_user_information(DltDaemon* daemon, DltGateway* gateway, int gateway_mode, int verbose) { int nodes = 1; int i = 1; @@ -580,7 +571,7 @@ int dlt_daemon_init_user_information(DltDaemon *daemon, if (gateway_mode == 0) { /* initialize application list */ - daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers)); + daemon->user_list = calloc((size_t)nodes, sizeof(DltDaemonRegisteredUsers)); if (daemon->user_list == NULL) { dlt_log(LOG_ERR, "Allocating memory for user information"); @@ -591,12 +582,11 @@ int dlt_daemon_init_user_information(DltDaemon *daemon, daemon->user_list[0].ecuid2len = daemon->ecuid2len; dlt_set_id_v2(daemon->user_list[0].ecuid2, daemon->ecuid2, daemon->ecuid2len); daemon->num_user_lists = 1; - } - else { /* gateway is active */ + } else { /* gateway is active */ nodes += gateway->num_connections; /* initialize application list */ - daemon->user_list = calloc((size_t) nodes, sizeof(DltDaemonRegisteredUsers)); + daemon->user_list = calloc((size_t)nodes, sizeof(DltDaemonRegisteredUsers)); if (daemon->user_list == NULL) { dlt_log(LOG_ERR, "Allocating memory for user information"); @@ -611,20 +601,18 @@ int dlt_daemon_init_user_information(DltDaemon *daemon, for (i = 1; i < nodes; i++) { dlt_set_id(daemon->user_list[i].ecu, gateway->connections[i - 1].ecuid); daemon->user_list[i].ecuid2len = gateway->connections[i - 1].ecuid2len; - dlt_set_id_v2(daemon->user_list[i].ecuid2, gateway->connections[i - 1].ecuid2, gateway->connections[i - 1].ecuid2len); + dlt_set_id_v2( + daemon->user_list[i].ecuid2, gateway->connections[i - 1].ecuid2, gateway->connections[i - 1].ecuid2len); } } return DLT_RETURN_OK; } -int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon, - char *ecu, - int fd, - int verbose) +int dlt_daemon_applications_invalidate_fd(DltDaemon* daemon, char* ecu, int fd, int verbose) { int i; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -644,13 +632,10 @@ int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon, return DLT_RETURN_ERROR; } -int dlt_daemon_applications_invalidate_fd_v2(DltDaemon *daemon, - char *ecu, - int fd, - int verbose) +int dlt_daemon_applications_invalidate_fd_v2(DltDaemon* daemon, char* ecu, int fd, int verbose) { int i; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -670,10 +655,10 @@ int dlt_daemon_applications_invalidate_fd_v2(DltDaemon *daemon, return DLT_RETURN_ERROR; } -int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose) +int dlt_daemon_applications_clear(DltDaemon* daemon, char* ecu, int verbose) { int i; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -687,7 +672,6 @@ int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose) for (i = 0; i < user_list->num_applications; i++) if (user_list->applications[i].application_description != NULL) { - #ifdef DLT_LOG_LEVEL_APP_CONFIG if (user_list->applications[i].context_log_level_settings) free(user_list->applications[i].context_log_level_settings); @@ -712,10 +696,10 @@ int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose) return 0; } -int dlt_daemon_applications_clear_v2(DltDaemon *daemon, char *ecu, int verbose) +int dlt_daemon_applications_clear_v2(DltDaemon* daemon, char* ecu, int verbose) { int i; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -731,7 +715,6 @@ int dlt_daemon_applications_clear_v2(DltDaemon *daemon, char *ecu, int verbose) for (i = 0; i < user_list->num_applications; i++) if (user_list->applications[i].application_description != NULL) { - #ifdef DLT_LOG_LEVEL_APP_CONFIG if (user_list->applications[i].context_log_level_settings) free(user_list->applications[i].context_log_level_settings); @@ -756,12 +739,10 @@ int dlt_daemon_applications_clear_v2(DltDaemon *daemon, char *ecu, int verbose) return 0; } -static void dlt_daemon_application_reset_user_handle(DltDaemon *daemon, - DltDaemonApplication *application, - int verbose) +static void dlt_daemon_application_reset_user_handle(DltDaemon* daemon, DltDaemonApplication* application, int verbose) { - DltDaemonRegisteredUsers *user_list; - DltDaemonContext *context; + DltDaemonRegisteredUsers* user_list; + DltDaemonContext* context; int i; if (application->user_handle == DLT_FD_INIT) @@ -783,18 +764,17 @@ static void dlt_daemon_application_reset_user_handle(DltDaemon *daemon, application->owns_user_handle = false; } -static void dlt_daemon_application_reset_user_handle_v2(DltDaemon *daemon, - DltDaemonApplication *application, - int verbose) +static void dlt_daemon_application_reset_user_handle_v2( + DltDaemon* daemon, DltDaemonApplication* application, int verbose) { - DltDaemonRegisteredUsers *user_list; - DltDaemonContext *context; + DltDaemonRegisteredUsers* user_list; + DltDaemonContext* context; int i; if (application->user_handle == DLT_FD_INIT) return; - user_list = dlt_daemon_find_users_list_v2(daemon, daemon->ecuid2len, daemon->ecuid2, verbose); + user_list = dlt_daemon_find_users_list_v2(daemon, daemon->ecuid2len, daemon->ecuid2, verbose); if (user_list != NULL) { for (i = 0; i < user_list->num_contexts; i++) { context = &user_list->contexts[i]; @@ -810,39 +790,34 @@ static void dlt_daemon_application_reset_user_handle_v2(DltDaemon *daemon, application->owns_user_handle = false; } -DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, - char *apid, - pid_t pid, - char *description, - int fd, - char *ecu, - int verbose) +DltDaemonApplication* dlt_daemon_application_add( + DltDaemon* daemon, char* apid, pid_t pid, char* description, int fd, char* ecu, int verbose) { - DltDaemonApplication *application; - DltDaemonApplication *old; + DltDaemonApplication* application; + DltDaemonApplication* old; int new_application; int dlt_user_handle; bool owns_user_handle; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; #ifdef DLT_DAEMON_USE_FIFO_IPC - (void)fd; /* To avoid compiler warning : unused variable */ + (void)fd; /* To avoid compiler warning : unused variable */ char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE]; #endif if ((daemon == NULL) || (apid == NULL) || (apid[0] == '\0') || (ecu == NULL)) - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; user_list = dlt_daemon_find_users_list(daemon, ecu, verbose); if (user_list == NULL) - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; if (user_list->applications == NULL) { - user_list->applications = (DltDaemonApplication *) - malloc(sizeof(DltDaemonApplication) * DLT_DAEMON_APPL_ALLOC_SIZE); + user_list->applications = + (DltDaemonApplication*)malloc(sizeof(DltDaemonApplication) * DLT_DAEMON_APPL_ALLOC_SIZE); if (user_list->applications == NULL) - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; } new_application = 0; @@ -857,20 +832,20 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, if ((user_list->num_applications % DLT_DAEMON_APPL_ALLOC_SIZE) == 0) { /* allocate memory in steps of DLT_DAEMON_APPL_ALLOC_SIZE, e.g. 100 */ old = user_list->applications; - user_list->applications = (DltDaemonApplication *) - malloc((size_t)sizeof(DltDaemonApplication) * - ((size_t)(user_list->num_applications / DLT_DAEMON_APPL_ALLOC_SIZE) + 1) * - (size_t)DLT_DAEMON_APPL_ALLOC_SIZE); + user_list->applications = (DltDaemonApplication*)malloc( + (size_t)sizeof(DltDaemonApplication) + * ((size_t)(user_list->num_applications / DLT_DAEMON_APPL_ALLOC_SIZE) + 1) + * (size_t)DLT_DAEMON_APPL_ALLOC_SIZE); if (user_list->applications == NULL) { user_list->applications = old; user_list->num_applications -= 1; - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; } - memcpy(user_list->applications, - old, - (size_t)sizeof(DltDaemonApplication) * (size_t)user_list->num_applications); + memcpy( + user_list->applications, old, + (size_t)sizeof(DltDaemonApplication) * (size_t)user_list->num_applications); free(old); } } @@ -890,15 +865,11 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, new_application = 1; - } - else if ((pid != application->pid) && (application->pid != 0)) - { - - dlt_vlog(LOG_WARNING, - "Duplicate registration of ApplicationID: '%.4s'; registering from PID %d, existing from PID %d\n", - apid, - pid, - application->pid); + } else if ((pid != application->pid) && (application->pid != 0)) { + dlt_vlog( + LOG_WARNING, + "Duplicate registration of ApplicationID: '%.4s'; registering from PID %d, existing from PID %d\n", apid, + pid, application->pid); } /* Store application description and pid of application */ @@ -915,7 +886,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, } else { dlt_log(LOG_ERR, "Cannot allocate memory to store application description\n"); free(application); - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; } } @@ -937,11 +908,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, #endif #ifdef DLT_DAEMON_USE_FIFO_IPC if (dlt_user_handle < DLT_FD_MINIMUM) { - int ret = snprintf(filename, - DLT_DAEMON_COMMON_TEXTBUFSIZE, - "%s/dltpipes/dlt%d", - dltFifoBaseDir, - (int)pid); + int ret = snprintf(filename, DLT_DAEMON_COMMON_TEXTBUFSIZE, "%s/dltpipes/dlt%d", dltFifoBaseDir, (int)pid); if (ret < 0 || ret >= DLT_DAEMON_COMMON_TEXTBUFSIZE) { filename[0] = '\0'; } @@ -957,7 +924,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, } #endif /* check if file descriptor was already used, and make it invalid if it - * is reused. This prevents sending messages to wrong file descriptor */ + * is reused. This prevents sending messages to wrong file descriptor */ dlt_daemon_applications_invalidate_fd(daemon, ecu, dlt_user_handle, verbose); dlt_daemon_contexts_invalidate_fd(daemon, ecu, dlt_user_handle, verbose); @@ -968,10 +935,9 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, /* Sort */ if (new_application) { - qsort(user_list->applications, - (size_t) user_list->num_applications, - sizeof(DltDaemonApplication), - dlt_daemon_cmp_apid); + qsort( + user_list->applications, (size_t)user_list->num_applications, sizeof(DltDaemonApplication), + dlt_daemon_cmp_apid); /* Find new position of application with apid*/ application = dlt_daemon_application_find(daemon, apid, ecu, verbose); @@ -986,30 +952,23 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, DltTraceLoadSettings* pre_configured_trace_load_settings = NULL; int num_settings = 0; DltReturnValue find_trace_settings_return_value = dlt_daemon_find_preconfigured_trace_load_settings( - daemon, - application->apid, - NULL /*load settings for all contexts*/, - &pre_configured_trace_load_settings, - &num_settings, - verbose); - - DltTraceLoadSettings *app_level = NULL; - if ((find_trace_settings_return_value == DLT_RETURN_OK) && - (pre_configured_trace_load_settings != NULL) && - (num_settings != 0)) { + daemon, application->apid, NULL /*load settings for all contexts*/, &pre_configured_trace_load_settings, + &num_settings, verbose); + + DltTraceLoadSettings* app_level = NULL; + if ((find_trace_settings_return_value == DLT_RETURN_OK) && (pre_configured_trace_load_settings != NULL) + && (num_settings != 0)) { application->trace_load_settings = pre_configured_trace_load_settings; application->trace_load_settings_count = num_settings; app_level = dlt_find_runtime_trace_load_settings( - application->trace_load_settings, - application->trace_load_settings_count, application->apid, - NULL); + application->trace_load_settings, application->trace_load_settings_count, application->apid, NULL); } // app is not configured, set daemon defaults if (app_level == NULL) { - DltTraceLoadSettings *temp = realloc(application->trace_load_settings, - (application->trace_load_settings_count + 1) * - sizeof(DltTraceLoadSettings)); + DltTraceLoadSettings* temp = realloc( + application->trace_load_settings, + (application->trace_load_settings_count + 1) * sizeof(DltTraceLoadSettings)); if (temp != NULL) { application->trace_load_settings = temp; @@ -1027,10 +986,9 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, // We inserted the application id at the end, to make sure // Lookups are working properly later on, we have to sort the list again. - qsort(application->trace_load_settings, - (size_t)application->trace_load_settings_count, - sizeof(DltTraceLoadSettings), - dlt_daemon_compare_trace_load_settings); + qsort( + application->trace_load_settings, (size_t)application->trace_load_settings_count, + sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); } } @@ -1039,42 +997,35 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, return application; } -DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - pid_t pid, - char *description, - int fd, - uint8_t eculen, - char *ecu, - int verbose) +DltDaemonApplication* dlt_daemon_application_add_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, pid_t pid, char* description, int fd, uint8_t eculen, char* ecu, + int verbose) { - DltDaemonApplication *application; - DltDaemonApplication *old; + DltDaemonApplication* application; + DltDaemonApplication* old; int new_application; int dlt_user_handle; bool owns_user_handle; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; #ifdef DLT_DAEMON_USE_FIFO_IPC - (void)fd; /* To avoid compiler warning : unused variable */ + (void)fd; /* To avoid compiler warning : unused variable */ char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE]; #endif - if ((daemon == NULL) || (apidlen == 0) || (eculen == 0) || - (apid == NULL) || (ecu == NULL)) - return (DltDaemonApplication *)NULL; + if ((daemon == NULL) || (apidlen == 0) || (eculen == 0) || (apid == NULL) || (ecu == NULL)) + return (DltDaemonApplication*)NULL; user_list = dlt_daemon_find_users_list_v2(daemon, eculen, ecu, verbose); if (user_list == NULL) - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; if (user_list->applications == NULL) { - user_list->applications = (DltDaemonApplication *) - malloc(sizeof(DltDaemonApplication) * DLT_DAEMON_APPL_ALLOC_SIZE); + user_list->applications = + (DltDaemonApplication*)malloc(sizeof(DltDaemonApplication) * DLT_DAEMON_APPL_ALLOC_SIZE); if (user_list->applications == NULL) - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; } new_application = 0; @@ -1089,20 +1040,19 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, if ((user_list->num_applications % DLT_DAEMON_APPL_ALLOC_SIZE) == 0) { /* allocate memory in steps of DLT_DAEMON_APPL_ALLOC_SIZE, e.g. 100 */ old = user_list->applications; - user_list->applications = (DltDaemonApplication *) - malloc(sizeof(DltDaemonApplication) * - (((size_t)user_list->num_applications / DLT_DAEMON_APPL_ALLOC_SIZE) + 1) * - DLT_DAEMON_APPL_ALLOC_SIZE); + user_list->applications = (DltDaemonApplication*)malloc( + sizeof(DltDaemonApplication) + * (((size_t)user_list->num_applications / DLT_DAEMON_APPL_ALLOC_SIZE) + 1) + * DLT_DAEMON_APPL_ALLOC_SIZE); if (user_list->applications == NULL) { user_list->applications = old; user_list->num_applications -= 1; - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; } - memcpy(user_list->applications, - old, - sizeof(DltDaemonApplication) * (size_t)user_list->num_applications); + memcpy( + user_list->applications, old, sizeof(DltDaemonApplication) * (size_t)user_list->num_applications); free(old); } } @@ -1123,15 +1073,11 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, #endif new_application = 1; - } - else if ((pid != application->pid) && (application->pid != 0)) - { - - dlt_vlog(LOG_WARNING, - "Duplicate registration of ApplicationID: '%s'; registering from PID %d, existing from PID %d\n", - apid, - pid, - application->pid); + } else if ((pid != application->pid) && (application->pid != 0)) { + dlt_vlog( + LOG_WARNING, + "Duplicate registration of ApplicationID: '%s'; registering from PID %d, existing from PID %d\n", apid, pid, + application->pid); } /* Store application description and pid of application */ @@ -1148,7 +1094,7 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, } else { dlt_log(LOG_ERR, "Cannot allocate memory to store application description\n"); free(application); - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; } } @@ -1170,11 +1116,7 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, #endif #ifdef DLT_DAEMON_USE_FIFO_IPC if (dlt_user_handle < DLT_FD_MINIMUM) { - int ret = snprintf(filename, - DLT_DAEMON_COMMON_TEXTBUFSIZE, - "%s/dltpipes/dlt%d", - dltFifoBaseDir, - pid); + int ret = snprintf(filename, DLT_DAEMON_COMMON_TEXTBUFSIZE, "%s/dltpipes/dlt%d", dltFifoBaseDir, pid); if (ret < 0 || ret >= DLT_DAEMON_COMMON_TEXTBUFSIZE) { dlt_log(LOG_ERR, "Failed to construct FIFO filename - path too long!\n"); @@ -1192,7 +1134,7 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, } #endif /* check if file descriptor was already used, and make it invalid if it - * is reused. This prevents sending messages to wrong file descriptor */ + * is reused. This prevents sending messages to wrong file descriptor */ dlt_daemon_applications_invalidate_fd(daemon, ecu, dlt_user_handle, verbose); dlt_daemon_contexts_invalidate_fd(daemon, ecu, dlt_user_handle, verbose); @@ -1203,10 +1145,9 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, /* Sort */ if (new_application) { - qsort(user_list->applications, - (size_t) user_list->num_applications, - sizeof(DltDaemonApplication), - dlt_daemon_cmp_apid_v2); + qsort( + user_list->applications, (size_t)user_list->num_applications, sizeof(DltDaemonApplication), + dlt_daemon_cmp_apid_v2); /* Find new position of application with apid*/ dlt_daemon_application_find_v2(daemon, apidlen, apid, eculen, ecu, verbose, &application); } @@ -1220,30 +1161,23 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, DltTraceLoadSettings* pre_configured_trace_load_settings = NULL; int num_settings = 0; DltReturnValue find_trace_settings_return_value = dlt_daemon_find_preconfigured_trace_load_settings( - daemon, - application->apid, - NULL /*load settings for all contexts*/, - &pre_configured_trace_load_settings, - &num_settings, - verbose); - - DltTraceLoadSettings *app_level = NULL; - if ((find_trace_settings_return_value == DLT_RETURN_OK) && - (pre_configured_trace_load_settings != NULL) && - (num_settings != 0)) { + daemon, application->apid, NULL /*load settings for all contexts*/, &pre_configured_trace_load_settings, + &num_settings, verbose); + + DltTraceLoadSettings* app_level = NULL; + if ((find_trace_settings_return_value == DLT_RETURN_OK) && (pre_configured_trace_load_settings != NULL) + && (num_settings != 0)) { application->trace_load_settings = pre_configured_trace_load_settings; application->trace_load_settings_count = num_settings; app_level = dlt_find_runtime_trace_load_settings( - application->trace_load_settings, - application->trace_load_settings_count, application->apid, - NULL); + application->trace_load_settings, application->trace_load_settings_count, application->apid, NULL); } // app is not configured, set daemon defaults if (app_level == NULL) { - DltTraceLoadSettings *temp = realloc(application->trace_load_settings, - (application->trace_load_settings_count + 1) * - sizeof(DltTraceLoadSettings)); + DltTraceLoadSettings* temp = realloc( + application->trace_load_settings, + (application->trace_load_settings_count + 1) * sizeof(DltTraceLoadSettings)); if (temp != NULL) { application->trace_load_settings = temp; @@ -1261,10 +1195,9 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, // We inserted the application id at the end, to make sure // Lookups are working properly later on, we have to sort the list again. - qsort(application->trace_load_settings, - (size_t)application->trace_load_settings_count, - sizeof(DltTraceLoadSettings), - dlt_daemon_compare_trace_load_settings); + qsort( + application->trace_load_settings, (size_t)application->trace_load_settings_count, + sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); } } @@ -1273,13 +1206,10 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, return application; } -int dlt_daemon_application_del(DltDaemon *daemon, - DltDaemonApplication *application, - char *ecu, - int verbose) +int dlt_daemon_application_del(DltDaemon* daemon, DltDaemonApplication* application, char* ecu, int verbose) { int pos; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1307,17 +1237,15 @@ int dlt_daemon_application_del(DltDaemon *daemon, application->trace_load_settings_count = 0; } #endif - pos = (int) (application - (user_list->applications)); + pos = (int)(application - (user_list->applications)); /* move all applications above pos to pos */ - memmove(&(user_list->applications[pos]), - &(user_list->applications[pos + 1]), - (size_t)sizeof(DltDaemonApplication) * (size_t)((user_list->num_applications - 1) - pos)); + memmove( + &(user_list->applications[pos]), &(user_list->applications[pos + 1]), + (size_t)sizeof(DltDaemonApplication) * (size_t)((user_list->num_applications - 1) - pos)); /* Clear last application */ - memset(&(user_list->applications[user_list->num_applications - 1]), - 0, - sizeof(DltDaemonApplication)); + memset(&(user_list->applications[user_list->num_applications - 1]), 0, sizeof(DltDaemonApplication)); user_list->num_applications--; } @@ -1325,14 +1253,11 @@ int dlt_daemon_application_del(DltDaemon *daemon, return 0; } -int dlt_daemon_application_del_v2(DltDaemon *daemon, - DltDaemonApplication *application, - uint8_t eculen, - char *ecu, - int verbose) +int dlt_daemon_application_del_v2( + DltDaemon* daemon, DltDaemonApplication* application, uint8_t eculen, char* ecu, int verbose) { int pos; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1360,19 +1285,17 @@ int dlt_daemon_application_del_v2(DltDaemon *daemon, application->trace_load_settings_count = 0; } #endif - pos = (int) (application - (user_list->applications)); + pos = (int)(application - (user_list->applications)); /* move all applications above pos to pos */ - memmove(&(user_list->applications[pos]), - &(user_list->applications[pos + 1]), - sizeof(DltDaemonApplication) * (size_t)((user_list->num_applications - 1) - pos)); - //TBD: Check usage of sizeof(DltDaemonApplication) since added new ptr members + memmove( + &(user_list->applications[pos]), &(user_list->applications[pos + 1]), + sizeof(DltDaemonApplication) * (size_t)((user_list->num_applications - 1) - pos)); + // TBD: Check usage of sizeof(DltDaemonApplication) since added new ptr members /* Clear last application */ - memset(&(user_list->applications[user_list->num_applications - 1]), - 0, - sizeof(DltDaemonApplication)); - //TBD: Check usage of sizeof(DltDaemonApplication) since added new ptr members + memset(&(user_list->applications[user_list->num_applications - 1]), 0, sizeof(DltDaemonApplication)); + // TBD: Check usage of sizeof(DltDaemonApplication) since added new ptr members user_list->num_applications--; } @@ -1380,64 +1303,50 @@ int dlt_daemon_application_del_v2(DltDaemon *daemon, return 0; } -DltDaemonApplication *dlt_daemon_application_find(DltDaemon *daemon, - char *apid, - char *ecu, - int verbose) +DltDaemonApplication* dlt_daemon_application_find(DltDaemon* daemon, char* apid, char* ecu, int verbose) { DltDaemonApplication application; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (daemon->user_list == NULL) || (apid == NULL) || - (apid[0] == '\0') || (ecu == NULL)) - return (DltDaemonApplication *)NULL; + if ((daemon == NULL) || (daemon->user_list == NULL) || (apid == NULL) || (apid[0] == '\0') || (ecu == NULL)) + return (DltDaemonApplication*)NULL; user_list = dlt_daemon_find_users_list(daemon, ecu, verbose); if ((user_list == NULL) || (user_list->num_applications == 0)) - return (DltDaemonApplication *)NULL; + return (DltDaemonApplication*)NULL; /* Check, if apid is smaller than smallest apid or greater than greatest apid */ - if ((memcmp(apid, user_list->applications[0].apid, DLT_ID_SIZE) < 0) || - (memcmp(apid, - user_list->applications[user_list->num_applications - 1].apid, - DLT_ID_SIZE) > 0)) - return (DltDaemonApplication *)NULL; + if ((memcmp(apid, user_list->applications[0].apid, DLT_ID_SIZE) < 0) + || (memcmp(apid, user_list->applications[user_list->num_applications - 1].apid, DLT_ID_SIZE) > 0)) + return (DltDaemonApplication*)NULL; dlt_set_id(application.apid, apid); - return (DltDaemonApplication *)bsearch(&application, - user_list->applications, - (size_t) user_list->num_applications, - sizeof(DltDaemonApplication), - dlt_daemon_cmp_apid); + return (DltDaemonApplication*)bsearch( + &application, user_list->applications, (size_t)user_list->num_applications, sizeof(DltDaemonApplication), + dlt_daemon_cmp_apid); } -void dlt_daemon_application_find_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - uint8_t eculen, - char *ecu, - int verbose, - DltDaemonApplication **application) +void dlt_daemon_application_find_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, uint8_t eculen, char* ecu, int verbose, + DltDaemonApplication** application) { - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); DltDaemonApplication search_app; memset(search_app.apid2, 0, DLT_V2_ID_SIZE); - if ((daemon == NULL) || (daemon->user_list == NULL) || - (apidlen == 0) || (apid == NULL) || - (eculen == 0) || (ecu == NULL)){ - + if ((daemon == NULL) || (daemon->user_list == NULL) || (apidlen == 0) || (apid == NULL) || (eculen == 0) + || (ecu == NULL)) { *application = NULL; return; - } + } user_list = dlt_daemon_find_users_list_v2(daemon, eculen, ecu, verbose); - if ((user_list == NULL) || (user_list->num_applications == 0)){ + if ((user_list == NULL) || (user_list->num_applications == 0)) { *application = NULL; return; } @@ -1446,23 +1355,21 @@ void dlt_daemon_application_find_v2(DltDaemon *daemon, dlt_set_id_v2(search_app.apid2, apid, apidlen); // Search using the temporary structure - *application = (DltDaemonApplication *)bsearch(&search_app, - user_list->applications, - (size_t) user_list->num_applications, - sizeof(DltDaemonApplication), - dlt_daemon_cmp_apid_v2); + *application = (DltDaemonApplication*)bsearch( + &search_app, user_list->applications, (size_t)user_list->num_applications, sizeof(DltDaemonApplication), + dlt_daemon_cmp_apid_v2); return; } -int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_applications_load(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; ID4 apid; char buf[DLT_DAEMON_COMMON_TEXTBUFSIZE]; - char *ret; - char *pb; + char* ret; + char* pb; PRINT_FUNCTION_VERBOSE(verbose); @@ -1472,11 +1379,7 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve fd = fopen(filename, "r"); if (fd == NULL) { - dlt_vlog(LOG_WARNING, - "%s: cannot open file %s: %s\n", - __func__, - filename, - strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: cannot open file %s: %s\n", __func__, filename, strerror(errno)); return -1; } @@ -1492,22 +1395,14 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve /* fgets always null pointer if the last byte of the file is a new line * We need to check here if there was an error or was it feof.*/ if (ferror(fd)) { - dlt_vlog(LOG_WARNING, - "%s: fgets(buf,sizeof(buf),fd) returned NULL. %s\n", - __func__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: fgets(buf,sizeof(buf),fd) returned NULL. %s\n", __func__, strerror(errno)); fclose(fd); return -1; - } - else if (feof(fd)) - { + } else if (feof(fd)) { fclose(fd); return 0; - } - else { - dlt_vlog(LOG_WARNING, - "%s: fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n", - __func__); + } else { + dlt_vlog(LOG_WARNING, "%s: fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n", __func__); fclose(fd); return -1; } @@ -1524,17 +1419,8 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve if (pb != NULL) { /* pb contains now the description */ /* pid is unknown at loading time */ - if (dlt_daemon_application_add(daemon, - apid, - 0, - pb, - -1, - daemon->ecuid, - verbose) == 0) { - dlt_vlog(LOG_WARNING, - "%s: dlt_daemon_application_add failed for %4s\n", - __func__, - apid); + if (dlt_daemon_application_add(daemon, apid, 0, pb, -1, daemon->ecuid, verbose) == 0) { + dlt_vlog(LOG_WARNING, "%s: dlt_daemon_application_add failed for %4s\n", __func__, apid); fclose(fd); return -1; } @@ -1548,13 +1434,13 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve return 0; } -int dlt_daemon_applications_save(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_applications_save(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; int i; char apid[DLT_ID_SIZE + 1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */ - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1575,34 +1461,28 @@ int dlt_daemon_applications_save(DltDaemon *daemon, const char *filename, int ve for (i = 0; i < user_list->num_applications; i++) { dlt_set_id(apid, user_list->applications[i].apid); - if ((user_list->applications[i].application_description) && - (user_list->applications[i].application_description[0] != '\0')) - fprintf(fd, - "%s:%s:\n", - apid, - user_list->applications[i].application_description); + if ((user_list->applications[i].application_description) + && (user_list->applications[i].application_description[0] != '\0')) + fprintf(fd, "%s:%s:\n", apid, user_list->applications[i].application_description); else fprintf(fd, "%s::\n", apid); } fclose(fd); - } - else { - dlt_vlog(LOG_ERR, "%s: open %s failed! No application information stored.\n", - __func__, - filename); + } else { + dlt_vlog(LOG_ERR, "%s: open %s failed! No application information stored.\n", __func__, filename); } } return 0; } -int dlt_daemon_applications_save_v2(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_applications_save_v2(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; int i; char apid[DLT_V2_ID_SIZE]; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1621,74 +1501,60 @@ int dlt_daemon_applications_save_v2(DltDaemon *daemon, const char *filename, int for (i = 0; i < user_list->num_applications; i++) { dlt_set_id_v2(apid, user_list->applications[i].apid2, user_list->applications[i].apid2len); - if ((user_list->applications[i].application_description) && - (user_list->applications[i].application_description[0] != '\0')) - fprintf(fd, - "%s:%s:\n", - apid, - user_list->applications[i].application_description); + if ((user_list->applications[i].application_description) + && (user_list->applications[i].application_description[0] != '\0')) + fprintf(fd, "%s:%s:\n", apid, user_list->applications[i].application_description); else fprintf(fd, "%s::\n", apid); } fclose(fd); - } - else { - dlt_vlog(LOG_ERR, "%s: open %s failed! No application information stored.\n", - __func__, - filename); + } else { + dlt_vlog(LOG_ERR, "%s: open %s failed! No application information stored.\n", __func__, filename); } } return 0; } -DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, - char *apid, - char *ctid, - int8_t log_level, - int8_t trace_status, - int log_level_pos, - int user_handle, - char *description, - char *ecu, - int verbose) +DltDaemonContext* dlt_daemon_context_add( + DltDaemon* daemon, char* apid, char* ctid, int8_t log_level, int8_t trace_status, int log_level_pos, + int user_handle, char* description, char* ecu, int verbose) { - DltDaemonApplication *application; - DltDaemonContext *context; - DltDaemonContext *old; + DltDaemonApplication* application; + DltDaemonContext* context; + DltDaemonContext* old; int new_context = 0; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (apid == NULL) || (apid[0] == '\0') || - (ctid == NULL) || (ctid[0] == '\0') || (ecu == NULL)) - return (DltDaemonContext *)NULL; + if ((daemon == NULL) || (apid == NULL) || (apid[0] == '\0') || (ctid == NULL) || (ctid[0] == '\0') || (ecu == NULL)) + return (DltDaemonContext*)NULL; if ((log_level < DLT_LOG_DEFAULT) || (log_level > DLT_LOG_VERBOSE)) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; if ((trace_status < DLT_TRACE_STATUS_DEFAULT) || (trace_status > DLT_TRACE_STATUS_ON)) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; user_list = dlt_daemon_find_users_list(daemon, ecu, verbose); if (user_list == NULL) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; if (user_list->contexts == NULL) { - user_list->contexts = (DltDaemonContext *)calloc(1, sizeof(DltDaemonContext) * DLT_DAEMON_CONTEXT_ALLOC_SIZE); + user_list->contexts = (DltDaemonContext*)calloc(1, sizeof(DltDaemonContext) * DLT_DAEMON_CONTEXT_ALLOC_SIZE); if (user_list->contexts == NULL) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } /* Check if application [apid] is available */ application = dlt_daemon_application_find(daemon, apid, ecu, verbose); if (application == NULL) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; /* Check if context [apid, ctid] is already available */ context = dlt_daemon_context_find(daemon, apid, ctid, ecu, verbose); @@ -1700,20 +1566,18 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, if ((user_list->num_contexts % DLT_DAEMON_CONTEXT_ALLOC_SIZE) == 0) { /* allocate memory for context in steps of DLT_DAEMON_CONTEXT_ALLOC_SIZE, e.g 100 */ old = user_list->contexts; - user_list->contexts = (DltDaemonContext *)calloc(1, (size_t) sizeof(DltDaemonContext) * - ((size_t)(user_list->num_contexts / - DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) * - (size_t)DLT_DAEMON_CONTEXT_ALLOC_SIZE); + user_list->contexts = (DltDaemonContext*)calloc( + 1, (size_t)sizeof(DltDaemonContext) + * ((size_t)(user_list->num_contexts / DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) + * (size_t)DLT_DAEMON_CONTEXT_ALLOC_SIZE); if (user_list->contexts == NULL) { user_list->contexts = old; user_list->num_contexts -= 1; - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } - memcpy(user_list->contexts, - old, - (size_t) sizeof(DltDaemonContext) * (size_t)user_list->num_contexts); + memcpy(user_list->contexts, old, (size_t)sizeof(DltDaemonContext) * (size_t)user_list->num_contexts); free(old); } } @@ -1748,31 +1612,28 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, #ifdef DLT_LOG_LEVEL_APP_CONFIG /* configure initial log level */ - DltDaemonContextLogSettings *settings = NULL; - settings = dlt_daemon_find_configured_app_id_ctx_id_settings( - daemon, context->apid, ctid); + DltDaemonContextLogSettings* settings = NULL; + settings = dlt_daemon_find_configured_app_id_ctx_id_settings(daemon, context->apid, ctid); if (settings != NULL) { /* set log level */ log_level = settings->log_level; - DltDaemonContextLogSettings *ct_settings = NULL; + DltDaemonContextLogSettings* ct_settings = NULL; ct_settings = dlt_daemon_find_app_log_level_config(application, ctid); /* ct_settings != null: context and app id combination already exists */ if (ct_settings == NULL) { - /* copy the configuration into the DltDaemonApplication for faster access later */ - DltDaemonContextLogSettings *tmp = - realloc(application->context_log_level_settings, - (++application->num_context_log_level_settings) * - sizeof(DltDaemonContextLogSettings)); - application->context_log_level_settings = tmp; - - ct_settings = - &application->context_log_level_settings[application->num_context_log_level_settings - 1]; - memcpy(ct_settings, settings, sizeof(DltDaemonContextLogSettings)); - memcpy(ct_settings->ctid, ctid, DLT_ID_SIZE); - } + /* copy the configuration into the DltDaemonApplication for faster access later */ + DltDaemonContextLogSettings* tmp = realloc( + application->context_log_level_settings, + (++application->num_context_log_level_settings) * sizeof(DltDaemonContextLogSettings)); + application->context_log_level_settings = tmp; + + ct_settings = &application->context_log_level_settings[application->num_context_log_level_settings - 1]; + memcpy(ct_settings, settings, sizeof(DltDaemonContextLogSettings)); + memcpy(ct_settings->ctid, ctid, DLT_ID_SIZE); + } } #endif @@ -1787,19 +1648,13 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, if (trace_status > daemon->default_trace_status) trace_status = daemon->default_trace_status; - dlt_vlog(LOG_NOTICE, - "Adapting ll_ts for context: %.4s:%.4s with %i %i\n", - apid, - ctid, - log_level, - trace_status); + dlt_vlog(LOG_NOTICE, "Adapting ll_ts for context: %.4s:%.4s with %i %i\n", apid, ctid, log_level, trace_status); } /* Store log level and trace status, * if this is a new context, or * if this is an old context and the runtime cfg was not loaded */ - if ((new_context == 1) || - ((new_context == 0) && (daemon->runtime_context_cfg_loaded == 0))) { + if ((new_context == 1) || ((new_context == 0) && (daemon->runtime_context_cfg_loaded == 0))) { context->log_level = log_level; context->trace_status = trace_status; } @@ -1817,10 +1672,7 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, /* Sort */ if (new_context) { - qsort(user_list->contexts, - (size_t) user_list->num_contexts, - sizeof(DltDaemonContext), - dlt_daemon_cmp_apid_ctid); + qsort(user_list->contexts, (size_t)user_list->num_contexts, sizeof(DltDaemonContext), dlt_daemon_cmp_apid_ctid); /* Find new position of context with apid, ctid */ context = dlt_daemon_context_find(daemon, apid, ctid, ecu, verbose); @@ -1829,56 +1681,45 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, return context; } -DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - uint8_t ctidlen, - char *ctid, - int8_t log_level, - int8_t trace_status, - int log_level_pos, - int user_handle, - char *description, - uint8_t eculen, - char *ecu, - int verbose) +DltDaemonContext* dlt_daemon_context_add_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, uint8_t ctidlen, char* ctid, int8_t log_level, int8_t trace_status, + int log_level_pos, int user_handle, char* description, uint8_t eculen, char* ecu, int verbose) { - DltDaemonContext *context; - DltDaemonContext *old; + DltDaemonContext* context; + DltDaemonContext* old; int new_context = 0; - DltDaemonRegisteredUsers *user_list = NULL; - DltDaemonApplication *application = NULL; + DltDaemonRegisteredUsers* user_list = NULL; + DltDaemonApplication* application = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (apid == NULL) || - (ctid == NULL) || (ecu == NULL) || (apidlen == 0) || (ctidlen == 0)) - return (DltDaemonContext *)NULL; + if ((daemon == NULL) || (apid == NULL) || (ctid == NULL) || (ecu == NULL) || (apidlen == 0) || (ctidlen == 0)) + return (DltDaemonContext*)NULL; if ((log_level < DLT_LOG_DEFAULT) || (log_level > DLT_LOG_VERBOSE)) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; if ((trace_status < DLT_TRACE_STATUS_DEFAULT) || (trace_status > DLT_TRACE_STATUS_ON)) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; user_list = dlt_daemon_find_users_list_v2(daemon, eculen, ecu, verbose); if (user_list == NULL) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; if (user_list->contexts == NULL) { - user_list->contexts = (DltDaemonContext *)calloc(1, sizeof(DltDaemonContext) * DLT_DAEMON_CONTEXT_ALLOC_SIZE); + user_list->contexts = (DltDaemonContext*)calloc(1, sizeof(DltDaemonContext) * DLT_DAEMON_CONTEXT_ALLOC_SIZE); if (user_list->contexts == NULL) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } /* Check if application [apid] is available */ dlt_daemon_application_find_v2(daemon, apidlen, apid, eculen, ecu, verbose, &application); - if (application == NULL){ - return (DltDaemonContext *)NULL; + if (application == NULL) { + return (DltDaemonContext*)NULL; } /* Check if context [apid, ctid] is already available */ @@ -1890,37 +1731,35 @@ DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, if ((user_list->num_contexts % DLT_DAEMON_CONTEXT_ALLOC_SIZE) == 0) { /* allocate memory for context in steps of DLT_DAEMON_CONTEXT_ALLOC_SIZE, e.g 100 */ old = user_list->contexts; - user_list->contexts = (DltDaemonContext *)calloc(1, (size_t) sizeof(DltDaemonContext) * - (((size_t)user_list->num_contexts / - DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) * - DLT_DAEMON_CONTEXT_ALLOC_SIZE); + user_list->contexts = (DltDaemonContext*)calloc( + 1, (size_t)sizeof(DltDaemonContext) + * (((size_t)user_list->num_contexts / DLT_DAEMON_CONTEXT_ALLOC_SIZE) + 1) + * DLT_DAEMON_CONTEXT_ALLOC_SIZE); if (user_list->contexts == NULL) { user_list->contexts = old; user_list->num_contexts -= 1; - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } - memcpy(user_list->contexts, - old, - (size_t) sizeof(DltDaemonContext) * (size_t)user_list->num_contexts); + memcpy(user_list->contexts, old, (size_t)sizeof(DltDaemonContext) * (size_t)user_list->num_contexts); free(old); } } context = &(user_list->contexts[user_list->num_contexts - 1]); memset(context, 0, sizeof(DltDaemonContext)); - context->apid2 = (char *)malloc(DLT_V2_ID_SIZE * sizeof(char)); + context->apid2 = (char*)malloc(DLT_V2_ID_SIZE * sizeof(char)); if (context->apid2 == NULL) { - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } dlt_set_id_v2(context->apid2, apid, apidlen); context->apid2len = apidlen; - context->ctid2 = (char *)malloc(DLT_V2_ID_SIZE * sizeof(char)); + context->ctid2 = (char*)malloc(DLT_V2_ID_SIZE * sizeof(char)); if (context->ctid2 == NULL) { free(context->apid2); context->apid2 = NULL; - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } dlt_set_id_v2(context->ctid2, ctid, ctidlen); context->ctid2len = ctidlen; @@ -1945,31 +1784,28 @@ DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, #ifdef DLT_LOG_LEVEL_APP_CONFIG /* configure initial log level */ - DltDaemonContextLogSettings *settings = NULL; - settings = dlt_daemon_find_configured_app_id_ctx_id_settings( - daemon, context->apid, ctid); + DltDaemonContextLogSettings* settings = NULL; + settings = dlt_daemon_find_configured_app_id_ctx_id_settings(daemon, context->apid, ctid); if (settings != NULL) { /* set log level */ log_level = settings->log_level; - DltDaemonContextLogSettings *ct_settings = NULL; + DltDaemonContextLogSettings* ct_settings = NULL; ct_settings = dlt_daemon_find_app_log_level_config(application, ctid); /* ct_settings != null: context and app id combination already exists */ if (ct_settings == NULL) { - /* copy the configuration into the DltDaemonApplication for faster access later */ - DltDaemonContextLogSettings *tmp = - realloc(application->context_log_level_settings, - (++application->num_context_log_level_settings) * - sizeof(DltDaemonContextLogSettings)); - application->context_log_level_settings = tmp; - - ct_settings = - &application->context_log_level_settings[application->num_context_log_level_settings - 1]; - memcpy(ct_settings, settings, sizeof(DltDaemonContextLogSettings)); - memcpy(ct_settings->ctid, ctid, DLT_ID_SIZE); - } + /* copy the configuration into the DltDaemonApplication for faster access later */ + DltDaemonContextLogSettings* tmp = realloc( + application->context_log_level_settings, + (++application->num_context_log_level_settings) * sizeof(DltDaemonContextLogSettings)); + application->context_log_level_settings = tmp; + + ct_settings = &application->context_log_level_settings[application->num_context_log_level_settings - 1]; + memcpy(ct_settings, settings, sizeof(DltDaemonContextLogSettings)); + memcpy(ct_settings->ctid, ctid, DLT_ID_SIZE); + } } #endif @@ -1984,19 +1820,15 @@ DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, if (trace_status > daemon->default_trace_status) trace_status = daemon->default_trace_status; - dlt_vlog(LOG_NOTICE, - "Adapting ll_ts for context: %s:%s with %i %i\n", - apid, - ctid, - log_level, - trace_status); //TBD: adjust length %.6s according to apidlen and ctidlen + dlt_vlog( + LOG_NOTICE, "Adapting ll_ts for context: %s:%s with %i %i\n", apid, ctid, log_level, + trace_status); // TBD: adjust length %.6s according to apidlen and ctidlen } /* Store log level and trace status, * if this is a new context, or * if this is an old context and the runtime cfg was not loaded */ - if ((new_context == 1) || - ((new_context == 0) && (daemon->runtime_context_cfg_loaded == 0))) { + if ((new_context == 1) || ((new_context == 0) && (daemon->runtime_context_cfg_loaded == 0))) { context->log_level = log_level; context->trace_status = trace_status; } @@ -2014,10 +1846,9 @@ DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, /* Sort */ if (new_context) { - qsort(user_list->contexts, - (size_t) user_list->num_contexts, - sizeof(DltDaemonContext), - dlt_daemon_cmp_apid_ctid_v2); + qsort( + user_list->contexts, (size_t)user_list->num_contexts, sizeof(DltDaemonContext), + dlt_daemon_cmp_apid_ctid_v2); /* Find new position of context with apid, ctid */ context = dlt_daemon_context_find_v2(daemon, apidlen, apid, ctidlen, ctid, eculen, ecu, verbose); @@ -2026,11 +1857,9 @@ DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, } #ifdef DLT_LOG_LEVEL_APP_CONFIG -static void dlt_daemon_free_context_log_settings( - DltDaemonApplication *application, - DltDaemonContext *context) +static void dlt_daemon_free_context_log_settings(DltDaemonApplication* application, DltDaemonContext* context) { - DltDaemonContextLogSettings *ct_settings; + DltDaemonContextLogSettings* ct_settings; int i; int skipped = 0; @@ -2042,34 +1871,31 @@ static void dlt_daemon_free_context_log_settings( /* move all data forward */ for (i = 0; i < application->num_context_log_level_settings; ++i) { /* skip given context to delete it */ - if (i + skipped < application->num_context_log_level_settings && - strncmp(application->context_log_level_settings[i+skipped].ctid, context->ctid, DLT_ID_SIZE) == 0) { + if (i + skipped < application->num_context_log_level_settings + && strncmp(application->context_log_level_settings[i + skipped].ctid, context->ctid, DLT_ID_SIZE) == 0) { ++skipped; continue; } - memcpy(&application->context_log_level_settings[i-skipped], - &application->context_log_level_settings[i], - sizeof(DltDaemonContextLogSettings)); + memcpy( + &application->context_log_level_settings[i - skipped], &application->context_log_level_settings[i], + sizeof(DltDaemonContextLogSettings)); } application->num_context_log_level_settings -= skipped; /* if size is equal to zero, and ptr is not NULL, then realloc is equivalent to free(ptr) */ - application->context_log_level_settings = realloc(application->context_log_level_settings, - sizeof(DltDaemonContextLogSettings) * (application->num_context_log_level_settings)); - + application->context_log_level_settings = realloc( + application->context_log_level_settings, + sizeof(DltDaemonContextLogSettings) * (application->num_context_log_level_settings)); } #endif -int dlt_daemon_context_del(DltDaemon *daemon, - DltDaemonContext *context, - char *ecu, - int verbose) +int dlt_daemon_context_del(DltDaemon* daemon, DltDaemonContext* context, char* ecu, int verbose) { int pos; - DltDaemonApplication *application; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonApplication* application; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2093,17 +1919,15 @@ int dlt_daemon_context_del(DltDaemon *daemon, context->context_description = NULL; } - pos = (int) (context - (user_list->contexts)); + pos = (int)(context - (user_list->contexts)); /* move all contexts above pos to pos */ - memmove(&(user_list->contexts[pos]), - &(user_list->contexts[pos + 1]), - (size_t)sizeof(DltDaemonContext) * (size_t)((user_list->num_contexts - 1) - pos)); + memmove( + &(user_list->contexts[pos]), &(user_list->contexts[pos + 1]), + (size_t)sizeof(DltDaemonContext) * (size_t)((user_list->num_contexts - 1) - pos)); /* Clear last context */ - memset(&(user_list->contexts[(size_t)(user_list->num_contexts - 1)]), - 0, - (size_t)sizeof(DltDaemonContext)); + memset(&(user_list->contexts[(size_t)(user_list->num_contexts - 1)]), 0, (size_t)sizeof(DltDaemonContext)); user_list->num_contexts--; @@ -2115,15 +1939,11 @@ int dlt_daemon_context_del(DltDaemon *daemon, return 0; } -int dlt_daemon_context_del_v2(DltDaemon *daemon, - DltDaemonContext *context, - uint8_t eculen, - char *ecu, - int verbose) +int dlt_daemon_context_del_v2(DltDaemon* daemon, DltDaemonContext* context, uint8_t eculen, char* ecu, int verbose) { int pos; - DltDaemonApplication *application; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonApplication* application; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2147,17 +1967,15 @@ int dlt_daemon_context_del_v2(DltDaemon *daemon, context->context_description = NULL; } - pos = (int) (context - (user_list->contexts)); + pos = (int)(context - (user_list->contexts)); /* move all contexts above pos to pos */ - memmove(&(user_list->contexts[pos]), - &(user_list->contexts[pos + 1]), - (size_t)sizeof(DltDaemonContext) * (size_t)((user_list->num_contexts - 1) - pos)); + memmove( + &(user_list->contexts[pos]), &(user_list->contexts[pos + 1]), + (size_t)sizeof(DltDaemonContext) * (size_t)((user_list->num_contexts - 1) - pos)); /* Clear last context */ - memset(&(user_list->contexts[user_list->num_contexts - 1]), - 0, - sizeof(DltDaemonContext)); + memset(&(user_list->contexts[user_list->num_contexts - 1]), 0, sizeof(DltDaemonContext)); user_list->num_contexts--; @@ -2169,84 +1987,67 @@ int dlt_daemon_context_del_v2(DltDaemon *daemon, return 0; } -DltDaemonContext *dlt_daemon_context_find(DltDaemon *daemon, - char *apid, - char *ctid, - char *ecu, - int verbose) +DltDaemonContext* dlt_daemon_context_find(DltDaemon* daemon, char* apid, char* ctid, char* ecu, int verbose) { DltDaemonContext context; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (apid == NULL) || (apid[0] == '\0') || - (ctid == NULL) || (ctid[0] == '\0') || (ecu == NULL)) - return (DltDaemonContext *)NULL; + if ((daemon == NULL) || (apid == NULL) || (apid[0] == '\0') || (ctid == NULL) || (ctid[0] == '\0') || (ecu == NULL)) + return (DltDaemonContext*)NULL; user_list = dlt_daemon_find_users_list(daemon, ecu, verbose); if ((user_list == NULL) || (user_list->num_contexts == 0)) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; /* Check, if apid is smaller than smallest apid or greater than greatest apid */ - if ((memcmp(apid, user_list->contexts[0].apid, DLT_ID_SIZE) < 0) || - (memcmp(apid, - user_list->contexts[user_list->num_contexts - 1].apid, - DLT_ID_SIZE) > 0)) - return (DltDaemonContext *)NULL; + if ((memcmp(apid, user_list->contexts[0].apid, DLT_ID_SIZE) < 0) + || (memcmp(apid, user_list->contexts[user_list->num_contexts - 1].apid, DLT_ID_SIZE) > 0)) + return (DltDaemonContext*)NULL; dlt_set_id(context.apid, apid); dlt_set_id(context.ctid, ctid); - return (DltDaemonContext *)bsearch(&context, - user_list->contexts, - (size_t) user_list->num_contexts, - sizeof(DltDaemonContext), - dlt_daemon_cmp_apid_ctid); + return (DltDaemonContext*)bsearch( + &context, user_list->contexts, (size_t)user_list->num_contexts, sizeof(DltDaemonContext), + dlt_daemon_cmp_apid_ctid); } -DltDaemonContext *dlt_daemon_context_find_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - uint8_t ctidlen, - char *ctid, - uint8_t eculen, - char *ecu, - int verbose) +DltDaemonContext* dlt_daemon_context_find_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, uint8_t ctidlen, char* ctid, uint8_t eculen, char* ecu, int verbose) { DltDaemonContext context; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (apidlen == 0) || (apid == NULL) || - (ctidlen == 0) || (ctid == NULL) || (eculen == 0) || (ecu == NULL)) - return (DltDaemonContext *)NULL; + if ((daemon == NULL) || (apidlen == 0) || (apid == NULL) || (ctidlen == 0) || (ctid == NULL) || (eculen == 0) + || (ecu == NULL)) + return (DltDaemonContext*)NULL; user_list = dlt_daemon_find_users_list_v2(daemon, eculen, ecu, verbose); if ((user_list == NULL) || (user_list->num_contexts == 0)) - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; - context.apid2 = (char *)malloc(DLT_V2_ID_SIZE * sizeof(char)); + context.apid2 = (char*)malloc(DLT_V2_ID_SIZE * sizeof(char)); if (context.apid2 == NULL) { - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } dlt_set_id_v2(context.apid2, apid, apidlen); context.apid2len = apidlen; - context.ctid2 = (char *)malloc(DLT_V2_ID_SIZE * sizeof(char)); + context.ctid2 = (char*)malloc(DLT_V2_ID_SIZE * sizeof(char)); if (context.ctid2 == NULL) { free(context.apid2); - return (DltDaemonContext *)NULL; + return (DltDaemonContext*)NULL; } dlt_set_id_v2(context.ctid2, ctid, ctidlen); context.ctid2len = ctidlen; - DltDaemonContext *result = (DltDaemonContext *)bsearch(&context, - user_list->contexts, - (size_t) user_list->num_contexts, - sizeof(DltDaemonContext), - dlt_daemon_cmp_apid_ctid_v2); + DltDaemonContext* result = (DltDaemonContext*)bsearch( + &context, user_list->contexts, (size_t)user_list->num_contexts, sizeof(DltDaemonContext), + dlt_daemon_cmp_apid_ctid_v2); // Free temporary allocated memory free(context.apid2); @@ -2255,13 +2056,10 @@ DltDaemonContext *dlt_daemon_context_find_v2(DltDaemon *daemon, return result; } -int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon, - char *ecu, - int fd, - int verbose) +int dlt_daemon_contexts_invalidate_fd(DltDaemon* daemon, char* ecu, int fd, int verbose) { int i; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2281,13 +2079,10 @@ int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon, return -1; } -int dlt_daemon_contexts_invalidate_fd_v2(DltDaemon *daemon, - char *ecu, - int fd, - int verbose) +int dlt_daemon_contexts_invalidate_fd_v2(DltDaemon* daemon, char* ecu, int fd, int verbose) { int i; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2307,10 +2102,10 @@ int dlt_daemon_contexts_invalidate_fd_v2(DltDaemon *daemon, return -1; } -int dlt_daemon_contexts_clear(DltDaemon *daemon, char *ecu, int verbose) +int dlt_daemon_contexts_clear(DltDaemon* daemon, char* ecu, int verbose) { int i; - DltDaemonRegisteredUsers *users = NULL; + DltDaemonRegisteredUsers* users = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2350,13 +2145,13 @@ int dlt_daemon_contexts_clear(DltDaemon *daemon, char *ecu, int verbose) return 0; } -int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_contexts_load(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; ID4 apid, ctid; char buf[DLT_DAEMON_COMMON_TEXTBUFSIZE]; - char *ret; - char *pb; + char* ret; + char* pb; int ll, ts; PRINT_FUNCTION_VERBOSE(verbose); @@ -2367,10 +2162,7 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos fd = fopen(filename, "r"); if (fd == NULL) { - dlt_vlog(LOG_WARNING, - "DLT runtime-context load, cannot open file %s: %s\n", - filename, - strerror(errno)); + dlt_vlog(LOG_WARNING, "DLT runtime-context load, cannot open file %s: %s\n", filename, strerror(errno)); return -1; } @@ -2386,22 +2178,14 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos /* fgets always returns null pointer if the last byte of the file is a new line. * We need to check here if there was an error or was it feof.*/ if (ferror(fd)) { - dlt_vlog(LOG_WARNING, - "%s fgets(buf,sizeof(buf),fd) returned NULL. %s\n", - __func__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "%s fgets(buf,sizeof(buf),fd) returned NULL. %s\n", __func__, strerror(errno)); fclose(fd); return -1; - } - else if (feof(fd)) - { + } else if (feof(fd)) { fclose(fd); return 0; - } - else { - dlt_vlog(LOG_WARNING, - "%s fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n", - __func__); + } else { + dlt_vlog(LOG_WARNING, "%s fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n", __func__); fclose(fd); return -1; } @@ -2431,19 +2215,10 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos /* pb contains now the description */ /* log_level_pos, and user_handle are unknown at loading time */ - if (dlt_daemon_context_add(daemon, - apid, - ctid, - (int8_t)ll, - (int8_t)ts, - 0, - 0, - pb, - daemon->ecuid, - verbose) == NULL) { - dlt_vlog(LOG_WARNING, - "%s dlt_daemon_context_add failed\n", - __func__); + if (dlt_daemon_context_add( + daemon, apid, ctid, (int8_t)ll, (int8_t)ts, 0, 0, pb, daemon->ecuid, verbose) + == NULL) { + dlt_vlog(LOG_WARNING, "%s dlt_daemon_context_add failed\n", __func__); fclose(fd); return -1; } @@ -2460,13 +2235,13 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos return 0; } -int dlt_daemon_contexts_save(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_contexts_save(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; int i; char apid[DLT_ID_SIZE + 1], ctid[DLT_ID_SIZE + 1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */ - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2489,39 +2264,34 @@ int dlt_daemon_contexts_save(DltDaemon *daemon, const char *filename, int verbos dlt_set_id(apid, user_list->contexts[i].apid); dlt_set_id(ctid, user_list->contexts[i].ctid); - if ((user_list->contexts[i].context_description) && - (user_list->contexts[i].context_description[0] != '\0')) - fprintf(fd, "%s:%s:%d:%d:%s:\n", apid, ctid, - (int)(user_list->contexts[i].log_level), - (int)(user_list->contexts[i].trace_status), - user_list->contexts[i].context_description); + if ((user_list->contexts[i].context_description) + && (user_list->contexts[i].context_description[0] != '\0')) + fprintf( + fd, "%s:%s:%d:%d:%s:\n", apid, ctid, (int)(user_list->contexts[i].log_level), + (int)(user_list->contexts[i].trace_status), user_list->contexts[i].context_description); else - fprintf(fd, "%s:%s:%d:%d::\n", apid, ctid, - (int)(user_list->contexts[i].log_level), - (int)(user_list->contexts[i].trace_status)); + fprintf( + fd, "%s:%s:%d:%d::\n", apid, ctid, (int)(user_list->contexts[i].log_level), + (int)(user_list->contexts[i].trace_status)); } fclose(fd); - } - else { - dlt_vlog(LOG_ERR, - "%s: Cannot open %s. No context information stored\n", - __func__, - filename); + } else { + dlt_vlog(LOG_ERR, "%s: Cannot open %s. No context information stored\n", __func__, filename); } } return 0; } -int dlt_daemon_contexts_save_v2(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_contexts_save_v2(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; int i; char apid[DLT_V2_ID_SIZE]; char ctid[DLT_V2_ID_SIZE]; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2541,34 +2311,29 @@ int dlt_daemon_contexts_save_v2(DltDaemon *daemon, const char *filename, int ver dlt_set_id_v2(apid, user_list->contexts[i].apid2, user_list->contexts[i].apid2len); dlt_set_id_v2(ctid, user_list->contexts[i].ctid2, user_list->contexts[i].ctid2len); - if ((user_list->contexts[i].context_description) && - (user_list->contexts[i].context_description[0] != '\0')) - fprintf(fd, "%s:%s:%d:%d:%s:\n", apid, ctid, - (int)(user_list->contexts[i].log_level), - (int)(user_list->contexts[i].trace_status), - user_list->contexts[i].context_description); + if ((user_list->contexts[i].context_description) + && (user_list->contexts[i].context_description[0] != '\0')) + fprintf( + fd, "%s:%s:%d:%d:%s:\n", apid, ctid, (int)(user_list->contexts[i].log_level), + (int)(user_list->contexts[i].trace_status), user_list->contexts[i].context_description); else - fprintf(fd, "%s:%s:%d:%d::\n", apid, ctid, - (int)(user_list->contexts[i].log_level), - (int)(user_list->contexts[i].trace_status)); + fprintf( + fd, "%s:%s:%d:%d::\n", apid, ctid, (int)(user_list->contexts[i].log_level), + (int)(user_list->contexts[i].trace_status)); } fclose(fd); - } - else { - dlt_vlog(LOG_ERR, - "%s: Cannot open %s. No context information stored\n", - __func__, - filename); + } else { + dlt_vlog(LOG_ERR, "%s: Cannot open %s. No context information stored\n", __func__, filename); } } return 0; } -int dlt_daemon_configuration_save(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_configuration_save(DltDaemon* daemon, const char* filename, int verbose) { - FILE *fd; + FILE* fd; PRINT_FUNCTION_VERBOSE(verbose); @@ -2587,26 +2352,26 @@ int dlt_daemon_configuration_save(DltDaemon *daemon, const char *filename, int v return 0; } -int dlt_daemon_configuration_load(DltDaemon *daemon, const char *filename, int verbose) +int dlt_daemon_configuration_load(DltDaemon* daemon, const char* filename, int verbose) { if ((daemon == NULL) || (filename == NULL)) return -1; - FILE *pFile; + FILE* pFile; char line[1024]; char token[1024]; char value[1024]; - char *pch; + char* pch; PRINT_FUNCTION_VERBOSE(verbose); - pFile = fopen (filename, "r"); + pFile = fopen(filename, "r"); if (pFile != NULL) { while (1) { /* fetch line from configuration file */ - if (fgets (line, 1024, pFile) != NULL) { - pch = strtok (line, " =\r\n"); + if (fgets(line, 1024, pFile) != NULL) { + pch = strtok(line, " =\r\n"); token[0] = 0; value[0] = 0; @@ -2617,49 +2382,43 @@ int dlt_daemon_configuration_load(DltDaemon *daemon, const char *filename, int v if (token[0] == 0) { strncpy(token, pch, sizeof(token) - 1); token[sizeof(token) - 1] = 0; - } - else { + } else { strncpy(value, pch, sizeof(value) - 1); value[sizeof(value) - 1] = 0; break; } - pch = strtok (NULL, " =\r\n"); + pch = strtok(NULL, " =\r\n"); } if (token[0] && value[0]) { /* parse arguments here */ if (strcmp(token, "LoggingMode") == 0) { daemon->mode = atoi(value); - dlt_vlog(LOG_INFO, "Runtime Option: %s=%d\n", token, - daemon->mode); - } - else { - dlt_vlog(LOG_WARNING, "Unknown option: %s=%s\n", token, - value); + dlt_vlog(LOG_INFO, "Runtime Option: %s=%d\n", token, daemon->mode); + } else { + dlt_vlog(LOG_WARNING, "Unknown option: %s=%s\n", token, value); } } - } - else { + } else { break; } } - fclose (pFile); - } - else { + fclose(pFile); + } else { dlt_vlog(LOG_INFO, "Cannot open configuration file: %s\n", filename); } return 0; } -int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, int verbose) +int dlt_daemon_user_send_log_level(DltDaemon* daemon, DltDaemonContext* context, int verbose) { DltUserHeader userheader; DltUserControlMsgLogLevel usercontext; DltReturnValue ret; - DltDaemonApplication *app; + DltDaemonApplication* app; PRINT_FUNCTION_VERBOSE(verbose); @@ -2673,37 +2432,33 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, return -1; } - if ((context->storage_log_level != DLT_LOG_DEFAULT) && - (daemon->maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF)) - usercontext.log_level = (uint8_t) (context->log_level > - context->storage_log_level ? context->log_level : context->storage_log_level); + if ((context->storage_log_level != DLT_LOG_DEFAULT) + && (daemon->maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF)) + usercontext.log_level = (uint8_t)(context->log_level > context->storage_log_level ? context->log_level : + context->storage_log_level); else /* Storage log level is not updated (is DEFAULT) then no device is yet connected so ignore */ usercontext.log_level = - (uint8_t) ((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); + (uint8_t)((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); usercontext.trace_status = - (uint8_t) ((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : context->trace_status); + (uint8_t)((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : + context->trace_status); usercontext.log_level_pos = context->log_level_pos; - dlt_vlog(LOG_NOTICE, "Send log-level to context: %.4s:%.4s [%i -> %i] [%i -> %i]\n", - context->apid, - context->ctid, - context->log_level, - usercontext.log_level, - context->trace_status, - usercontext.trace_status); + dlt_vlog( + LOG_NOTICE, "Send log-level to context: %.4s:%.4s [%i -> %i] [%i -> %i]\n", context->apid, context->ctid, + context->log_level, usercontext.log_level, context->trace_status, usercontext.trace_status); /* log to FIFO */ errno = 0; - ret = dlt_user_log_out2_with_timeout(context->user_handle, - &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgLogLevel)); + ret = dlt_user_log_out2_with_timeout( + context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgLogLevel)); if (ret < DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, "Failed to send data to application in %s: %s", - __func__, - errno != 0 ? strerror(errno) : "Unknown error"); + dlt_vlog( + LOG_ERR, "Failed to send data to application in %s: %s", __func__, + errno != 0 ? strerror(errno) : "Unknown error"); if (errno == EPIPE || errno == EBADF) { app = dlt_daemon_application_find(daemon, context->apid, daemon->ecuid, verbose); @@ -2715,12 +2470,12 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR; } -int dlt_daemon_user_send_log_level_v2(DltDaemon *daemon, DltDaemonContext *context, int verbose) +int dlt_daemon_user_send_log_level_v2(DltDaemon* daemon, DltDaemonContext* context, int verbose) { DltUserHeader userheader; DltUserControlMsgLogLevel usercontext; DltReturnValue ret; - DltDaemonApplication *app = NULL; + DltDaemonApplication* app = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2734,41 +2489,37 @@ int dlt_daemon_user_send_log_level_v2(DltDaemon *daemon, DltDaemonContext *conte return -1; } - if ((context->storage_log_level != DLT_LOG_DEFAULT) && - (daemon->maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF)) - usercontext.log_level = (uint8_t) (context->log_level > - context->storage_log_level ? context->log_level : context->storage_log_level); + if ((context->storage_log_level != DLT_LOG_DEFAULT) + && (daemon->maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF)) + usercontext.log_level = (uint8_t)(context->log_level > context->storage_log_level ? context->log_level : + context->storage_log_level); else /* Storage log level is not updated (is DEFAULT) then no device is yet connected so ignore */ usercontext.log_level = - (uint8_t) ((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); + (uint8_t)((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); usercontext.trace_status = - (uint8_t) ((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : context->trace_status); + (uint8_t)((context->trace_status == DLT_TRACE_STATUS_DEFAULT) ? daemon->default_trace_status : + context->trace_status); usercontext.log_level_pos = context->log_level_pos; - dlt_vlog(LOG_NOTICE, "Send log-level to context: %s:%s [%i -> %i] [%i -> %i]\n", - context->apid2, - context->ctid2, - context->log_level, - usercontext.log_level, - context->trace_status, - usercontext.trace_status); + dlt_vlog( + LOG_NOTICE, "Send log-level to context: %s:%s [%i -> %i] [%i -> %i]\n", context->apid2, context->ctid2, + context->log_level, usercontext.log_level, context->trace_status, usercontext.trace_status); /* log to FIFO */ errno = 0; - ret = dlt_user_log_out2_with_timeout(context->user_handle, - &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgLogLevel)); + ret = dlt_user_log_out2_with_timeout( + context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgLogLevel)); if (ret < DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, "Failed to send data to application in %s: %s", - __func__, - errno != 0 ? strerror(errno) : "Unknown error"); + dlt_vlog( + LOG_ERR, "Failed to send data to application in %s: %s", __func__, + errno != 0 ? strerror(errno) : "Unknown error"); if (errno == EPIPE || errno == EBADF) { - dlt_daemon_application_find_v2(daemon, context->apid2len, context->apid2, - daemon->ecuid2len, daemon->ecuid2, verbose, &app); + dlt_daemon_application_find_v2( + daemon, context->apid2len, context->apid2, daemon->ecuid2len, daemon->ecuid2, verbose, &app); if (app != NULL) dlt_daemon_application_reset_user_handle(daemon, app, verbose); } @@ -2776,7 +2527,7 @@ int dlt_daemon_user_send_log_level_v2(DltDaemon *daemon, DltDaemonContext *conte return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR; } -int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app, int verbose) +int dlt_daemon_user_send_log_state(DltDaemon* daemon, DltDaemonApplication* app, int verbose) { DltUserHeader userheader; DltUserControlMsgLogState logstate; @@ -2793,9 +2544,8 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app, logstate.log_state = (int8_t)daemon->connectionState; /* log to FIFO */ - ret = dlt_user_log_out2_with_timeout(app->user_handle, - &(userheader), sizeof(DltUserHeader), - &(logstate), sizeof(DltUserControlMsgLogState)); + ret = dlt_user_log_out2_with_timeout( + app->user_handle, &(userheader), sizeof(DltUserHeader), &(logstate), sizeof(DltUserControlMsgLogState)); if (ret < DLT_RETURN_OK) { if (errno == EPIPE || errno == EBADF) @@ -2805,7 +2555,7 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app, return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR; } -int dlt_daemon_user_send_log_state_v2(DltDaemon *daemon, DltDaemonApplication *app, int verbose) +int dlt_daemon_user_send_log_state_v2(DltDaemon* daemon, DltDaemonApplication* app, int verbose) { DltUserHeader userheader; DltUserControlMsgLogState logstate; @@ -2822,9 +2572,8 @@ int dlt_daemon_user_send_log_state_v2(DltDaemon *daemon, DltDaemonApplication *a logstate.log_state = (int8_t)daemon->connectionState; /* log to FIFO */ - ret = dlt_user_log_out2_with_timeout(app->user_handle, - &(userheader), sizeof(DltUserHeader), - &(logstate.log_state), sizeof(int8_t)); + ret = dlt_user_log_out2_with_timeout( + app->user_handle, &(userheader), sizeof(DltUserHeader), &(logstate.log_state), sizeof(int8_t)); if (ret < DLT_RETURN_OK) { if (errno == EPIPE || errno == EBADF) @@ -2834,15 +2583,11 @@ int dlt_daemon_user_send_log_state_v2(DltDaemon *daemon, DltDaemonApplication *a return (ret == DLT_RETURN_OK) ? DLT_RETURN_OK : DLT_RETURN_ERROR; } -void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon, - const char *filename, - const char *filename1, - int InitialContextLogLevel, - int InitialContextTraceStatus, - int InitialEnforceLlTsStatus, - int verbose) +void dlt_daemon_control_reset_to_factory_default( + DltDaemon* daemon, const char* filename, const char* filename1, int InitialContextLogLevel, + int InitialContextTraceStatus, int InitialEnforceLlTsStatus, int verbose) { - FILE *fd; + FILE* fd; PRINT_FUNCTION_VERBOSE(verbose); @@ -2863,8 +2608,7 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon, /* Close and delete file */ fclose(fd); if (unlink(filename) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); } } @@ -2874,14 +2618,13 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon, /* Close and delete file */ fclose(fd); if (unlink(filename1) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); } } - daemon->default_log_level = (int8_t) InitialContextLogLevel; - daemon->default_trace_status = (int8_t) InitialContextTraceStatus; - daemon->force_ll_ts = (int8_t) InitialEnforceLlTsStatus; + daemon->default_log_level = (int8_t)InitialContextLogLevel; + daemon->default_trace_status = (int8_t)InitialContextTraceStatus; + daemon->force_ll_ts = (int8_t)InitialEnforceLlTsStatus; /* Reset all other things (log level, trace status, etc. * to default values */ @@ -2890,15 +2633,11 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon, dlt_daemon_user_send_default_update(daemon, verbose); } -void dlt_daemon_control_reset_to_factory_default_v2(DltDaemon *daemon, - const char *filename, - const char *filename1, - int InitialContextLogLevel, - int InitialContextTraceStatus, - int InitialEnforceLlTsStatus, - int verbose) +void dlt_daemon_control_reset_to_factory_default_v2( + DltDaemon* daemon, const char* filename, const char* filename1, int InitialContextLogLevel, + int InitialContextTraceStatus, int InitialEnforceLlTsStatus, int verbose) { - FILE *fd; + FILE* fd; PRINT_FUNCTION_VERBOSE(verbose); @@ -2919,8 +2658,7 @@ void dlt_daemon_control_reset_to_factory_default_v2(DltDaemon *daemon, /* Close and delete file */ fclose(fd); if (unlink(filename) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); } } @@ -2930,14 +2668,13 @@ void dlt_daemon_control_reset_to_factory_default_v2(DltDaemon *daemon, /* Close and delete file */ fclose(fd); if (unlink(filename1) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); } } - daemon->default_log_level = (int8_t) InitialContextLogLevel; - daemon->default_trace_status = (int8_t) InitialContextTraceStatus; - daemon->force_ll_ts = (int8_t) InitialEnforceLlTsStatus; + daemon->default_log_level = (int8_t)InitialContextLogLevel; + daemon->default_trace_status = (int8_t)InitialContextTraceStatus; + daemon->force_ll_ts = (int8_t)InitialEnforceLlTsStatus; /* Reset all other things (log level, trace status, etc. * to default values */ @@ -2946,11 +2683,11 @@ void dlt_daemon_control_reset_to_factory_default_v2(DltDaemon *daemon, dlt_daemon_user_send_default_update_v2(daemon, verbose); } -void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose) +void dlt_daemon_user_send_default_update(DltDaemon* daemon, int verbose) { int32_t count; - DltDaemonContext *context; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonContext* context; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -2968,23 +2705,20 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose) context = &(user_list->contexts[count]); if (context != NULL) { - if ((context->log_level == DLT_LOG_DEFAULT) || - (context->trace_status == DLT_TRACE_STATUS_DEFAULT)) { + if ((context->log_level == DLT_LOG_DEFAULT) || (context->trace_status == DLT_TRACE_STATUS_DEFAULT)) { if (context->user_handle >= DLT_FD_MINIMUM) - if (dlt_daemon_user_send_log_level(daemon, - context, - verbose) == -1) + if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) dlt_vlog(LOG_WARNING, "Cannot update default of %.4s:%.4s\n", context->apid, context->ctid); } } } } -void dlt_daemon_user_send_default_update_v2(DltDaemon *daemon, int verbose) +void dlt_daemon_user_send_default_update_v2(DltDaemon* daemon, int verbose) { int32_t count; - DltDaemonContext *context; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonContext* context; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3002,27 +2736,21 @@ void dlt_daemon_user_send_default_update_v2(DltDaemon *daemon, int verbose) context = &(user_list->contexts[count]); if (context != NULL) { - if ((context->log_level == DLT_LOG_DEFAULT) || - (context->trace_status == DLT_TRACE_STATUS_DEFAULT)) { + if ((context->log_level == DLT_LOG_DEFAULT) || (context->trace_status == DLT_TRACE_STATUS_DEFAULT)) { if (context->user_handle >= DLT_FD_MINIMUM) - if (dlt_daemon_user_send_log_level_v2(daemon, - context, - verbose) == -1) + if (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == -1) dlt_vlog(LOG_WARNING, "Cannot update default of %.4s:%.4s\n", context->apid, context->ctid); } } } } -void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, - int enforce_context_ll_and_ts, - int8_t context_log_level, - int8_t log_level, - int verbose) +void dlt_daemon_user_send_all_log_level_update( + DltDaemon* daemon, int enforce_context_ll_and_ts, int8_t context_log_level, int8_t log_level, int verbose) { int32_t count = 0; - DltDaemonContext *context = NULL; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonContext* context = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3043,42 +2771,34 @@ void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, if (enforce_context_ll_and_ts) { #ifdef DLT_LOG_LEVEL_APP_CONFIG - DltDaemonContextLogSettings *settings = - dlt_daemon_find_configured_app_id_ctx_id_settings( - daemon, context->apid, context->ctid); + DltDaemonContextLogSettings* settings = + dlt_daemon_find_configured_app_id_ctx_id_settings(daemon, context->apid, context->ctid); if (settings != NULL) { if (log_level > settings->log_level) { - context->log_level = settings->log_level; + context->log_level = settings->log_level; } } else #endif - if (log_level > context_log_level) { + if (log_level > context_log_level) { context->log_level = (int8_t)context_log_level; } } - if (dlt_daemon_user_send_log_level(daemon, - context, - verbose) == -1) - dlt_vlog(LOG_WARNING, - "Cannot send log level %.4s:%.4s -> %i\n", - context->apid, - context->ctid, - context->log_level); + if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) + dlt_vlog( + LOG_WARNING, "Cannot send log level %.4s:%.4s -> %i\n", context->apid, context->ctid, + context->log_level); } } } } -void dlt_daemon_user_send_all_log_level_update_v2(DltDaemon *daemon, - int enforce_context_ll_and_ts, - int8_t context_log_level, - int8_t log_level, - int verbose) +void dlt_daemon_user_send_all_log_level_update_v2( + DltDaemon* daemon, int enforce_context_ll_and_ts, int8_t context_log_level, int8_t log_level, int verbose) { int32_t count = 0; - DltDaemonContext *context = NULL; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonContext* context = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3099,39 +2819,34 @@ void dlt_daemon_user_send_all_log_level_update_v2(DltDaemon *daemon, if (enforce_context_ll_and_ts) { #ifdef DLT_LOG_LEVEL_APP_CONFIG - //TBD: Check if function params require apid/ctid lengths - DltDaemonContextLogSettingsV2 *settings = - dlt_daemon_find_configured_app_id_ctx_id_settings_v2( - daemon, context->apid, context->ctid); + // TBD: Check if function params require apid/ctid lengths + DltDaemonContextLogSettingsV2* settings = + dlt_daemon_find_configured_app_id_ctx_id_settings_v2(daemon, context->apid, context->ctid); if (settings != NULL) { if (log_level > settings->log_level) { - context->log_level = settings->log_level; + context->log_level = settings->log_level; } } else #endif - if (log_level > context_log_level) { + if (log_level > context_log_level) { context->log_level = (int8_t)context_log_level; } } - if (dlt_daemon_user_send_log_level_v2(daemon, - context, - verbose) == -1) - dlt_vlog(LOG_WARNING, - "Cannot send log level %.4s:%.4s -> %i\n", - context->apid, - context->ctid, - context->log_level); + if (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == -1) + dlt_vlog( + LOG_WARNING, "Cannot send log level %.4s:%.4s -> %i\n", context->apid, context->ctid, + context->log_level); } } } } -void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trace_status, int verbose) +void dlt_daemon_user_send_all_trace_status_update(DltDaemon* daemon, int8_t trace_status, int verbose) { int32_t count = 0; - DltDaemonContext *context = NULL; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonContext* context = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3153,21 +2868,19 @@ void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trac context->trace_status = trace_status; if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) - dlt_vlog(LOG_WARNING, - "Cannot send trace status %.4s:%.4s -> %i\n", - context->apid, - context->ctid, - context->trace_status); + dlt_vlog( + LOG_WARNING, "Cannot send trace status %.4s:%.4s -> %i\n", context->apid, context->ctid, + context->trace_status); } } } } -void dlt_daemon_user_send_all_trace_status_update_v2(DltDaemon *daemon, int8_t trace_status, int verbose) +void dlt_daemon_user_send_all_trace_status_update_v2(DltDaemon* daemon, int8_t trace_status, int verbose) { int32_t count = 0; - DltDaemonContext *context = NULL; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonContext* context = NULL; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3189,23 +2902,19 @@ void dlt_daemon_user_send_all_trace_status_update_v2(DltDaemon *daemon, int8_t t context->trace_status = trace_status; if (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == -1) - dlt_vlog(LOG_WARNING, - "Cannot send trace status %.*s:%.*s -> %i\n", - context->apid2len, - context->apid2, - context->ctid2len, - context->ctid2, - context->trace_status); + dlt_vlog( + LOG_WARNING, "Cannot send trace status %.*s:%.*s -> %i\n", context->apid2len, context->apid2, + context->ctid2len, context->ctid2, context->trace_status); } } } } -void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose) +void dlt_daemon_user_send_all_log_state(DltDaemon* daemon, int verbose) { int32_t count; - DltDaemonApplication *app; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonApplication* app; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3225,17 +2934,19 @@ void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose) if (app != NULL) { if (app->user_handle >= DLT_FD_MINIMUM) { if (dlt_daemon_user_send_log_state(daemon, app, verbose) == -1) - dlt_vlog(LOG_WARNING, "Cannot send log state to Apid: %.4s, PID: %d %s\n", app->apid, app->pid, __func__); + dlt_vlog( + LOG_WARNING, "Cannot send log state to Apid: %.4s, PID: %d %s\n", app->apid, app->pid, + __func__); } } } } -void dlt_daemon_user_send_all_log_state_v2(DltDaemon *daemon, int verbose) +void dlt_daemon_user_send_all_log_state_v2(DltDaemon* daemon, int verbose) { int32_t count; - DltDaemonApplication *app; - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonApplication* app; + DltDaemonRegisteredUsers* user_list = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -3255,14 +2966,15 @@ void dlt_daemon_user_send_all_log_state_v2(DltDaemon *daemon, int verbose) if (app != NULL) { if (app->user_handle >= DLT_FD_MINIMUM) { if (dlt_daemon_user_send_log_state_v2(daemon, app, verbose) == -1) { - dlt_vlog(LOG_WARNING, "Cannot send log state to Apid: %s, PID: %d %s\n", app->apid2, app->pid, __func__); + dlt_vlog( + LOG_WARNING, "Cannot send log state to Apid: %s, PID: %d %s\n", app->apid2, app->pid, __func__); } } } } } -void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState) +void dlt_daemon_change_state(DltDaemon* daemon, DltDaemonState newState) { switch (newState) { case DLT_DAEMON_STATE_INIT: @@ -3289,7 +3001,8 @@ void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState) } #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE -bool dlt_daemon_trigger_systemd_watchdog_if_necessary(DltDaemon *daemon) { +bool dlt_daemon_trigger_systemd_watchdog_if_necessary(DltDaemon* daemon) +{ if (daemon->watchdog_trigger_interval == 0) { return false; } @@ -3302,8 +3015,7 @@ bool dlt_daemon_trigger_systemd_watchdog_if_necessary(DltDaemon *daemon) { if (sd_notify(0, "WATCHDOG=1") < 0) { dlt_vlog(LOG_WARNING, "%s: Could not reset systemd watchdog\n", __func__); return false; - } - else + } else daemon->watchdog_last_trigger_time = uptime_seconds; return true; @@ -3312,7 +3024,7 @@ bool dlt_daemon_trigger_systemd_watchdog_if_necessary(DltDaemon *daemon) { #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE -int dlt_daemon_user_send_trace_load_config(DltDaemon *const daemon, DltDaemonApplication *app, const int verbose) +int dlt_daemon_user_send_trace_load_config(DltDaemon* const daemon, DltDaemonApplication* app, const int verbose) { DltUserHeader userheader; DltUserControlMsgTraceSettingMsg* trace_load_settings_user_msg; @@ -3322,9 +3034,11 @@ int dlt_daemon_user_send_trace_load_config(DltDaemon *const daemon, DltDaemonApp PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (app == NULL)) return -1; + if ((daemon == NULL) || (app == NULL)) + return -1; - if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_TRACE_LOAD) < DLT_RETURN_OK) return -1; + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_TRACE_LOAD) < DLT_RETURN_OK) + return -1; DltTraceLoadSettings* app_settings = app->trace_load_settings; @@ -3339,23 +3053,17 @@ int dlt_daemon_user_send_trace_load_config(DltDaemon *const daemon, DltDaemonApp trace_load_settings_user_msg[i].hard_limit = app_settings[i].hard_limit; if (app_settings[i].ctid[0] == '\0') { - dlt_vlog(LOG_NOTICE, "Sending trace load config to app %.4s, soft limit %u, hard limit %u\n", - app->apid, - app_settings[i].soft_limit, - app_settings[i].hard_limit); + dlt_vlog( + LOG_NOTICE, "Sending trace load config to app %.4s, soft limit %u, hard limit %u\n", app->apid, + app_settings[i].soft_limit, app_settings[i].hard_limit); } else { - dlt_vlog(LOG_NOTICE, "Sending trace load config to app %.4s, ctid %.4s, soft limit %u, hard limit %u\n", - app->apid, - app_settings[i].ctid, - app_settings[i].soft_limit, - app_settings[i].hard_limit); + dlt_vlog( + LOG_NOTICE, "Sending trace load config to app %.4s, ctid %.4s, soft limit %u, hard limit %u\n", + app->apid, app_settings[i].ctid, app_settings[i].soft_limit, app_settings[i].hard_limit); } - } - } - else { - dlt_vlog(LOG_INFO, - "No trace load settings for application %s, setting daemon defaults.\n", app->apid); + } else { + dlt_vlog(LOG_INFO, "No trace load settings for application %s, setting daemon defaults.\n", app->apid); trace_load_settings_count = 1; trace_load_settings_user_msg = malloc(sizeof(DltUserControlMsgTraceSettingMsg)); @@ -3366,10 +3074,9 @@ int dlt_daemon_user_send_trace_load_config(DltDaemon *const daemon, DltDaemonApp } /* log to FIFO */ - ret = dlt_user_log_out3_with_timeout(app->user_handle, - &(userheader), sizeof(DltUserHeader), - &(trace_load_settings_count), sizeof(uint32_t), - trace_load_settings_user_msg, sizeof(DltUserControlMsgTraceSettingMsg) * trace_load_settings_count); + ret = dlt_user_log_out3_with_timeout( + app->user_handle, &(userheader), sizeof(DltUserHeader), &(trace_load_settings_count), sizeof(uint32_t), + trace_load_settings_user_msg, sizeof(DltUserControlMsgTraceSettingMsg) * trace_load_settings_count); if (ret < DLT_RETURN_OK) { if (errno == EPIPE || errno == EBADF) diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h index b77ee1497..21c4da6cc 100644 --- a/src/daemon/dlt_daemon_common.h +++ b/src/daemon/dlt_daemon_common.h @@ -67,7 +67,7 @@ */ #ifndef DLT_DAEMON_COMMON_H -# define DLT_DAEMON_COMMON_H +#define DLT_DAEMON_COMMON_H /** * \defgroup daemonapi DLT Daemon API @@ -75,53 +75,57 @@ \{ */ -# include -# include -# include -# include "dlt_common.h" -# include "dlt_log.h" -# include "dlt_user.h" -# include "dlt_offline_logstorage.h" -# include "dlt_gateway_types.h" +#include +#include +#include +#include "dlt_common.h" +#include "dlt_log.h" +#include "dlt_user.h" +#include "dlt_offline_logstorage.h" +#include "dlt_gateway_types.h" -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# define DLT_DAEMON_RINGBUFFER_MIN_SIZE 500000/**< Ring buffer size for storing log messages while no client is connected */ -# define DLT_DAEMON_RINGBUFFER_MAX_SIZE 10000000/**< Ring buffer size for storing log messages while no client is connected */ -# define DLT_DAEMON_RINGBUFFER_STEP_SIZE 500000/**< Ring buffer size for storing log messages while no client is connected */ +#define DLT_DAEMON_RINGBUFFER_MIN_SIZE \ + 500000 /**< Ring buffer size for storing log messages while no client is connected */ +#define DLT_DAEMON_RINGBUFFER_MAX_SIZE \ + 10000000 /**< Ring buffer size for storing log messages while no client is connected */ +#define DLT_DAEMON_RINGBUFFER_STEP_SIZE \ + 500000 /**< Ring buffer size for storing log messages while no client is connected */ -#define DLT_DAEMON_SEND_TO_ALL -3 /**< Constant value to identify the command "send to all" */ -#define DLT_DAEMON_SEND_FORCE -4 /**< Constant value to identify the command "send force to all" */ +#define DLT_DAEMON_SEND_TO_ALL -3 /**< Constant value to identify the command "send to all" */ +#define DLT_DAEMON_SEND_FORCE -4 /**< Constant value to identify the command "send force to all" */ /* UDPMulticart Default IP and Port */ -# ifdef UDP_CONNECTION_SUPPORT - # define MULTICASTIPADDRESS "225.0.0.37" - # define MULTICASTIPPORT 3491 - # define MULTICASTIP_MAX_SIZE 256 - # define MULTICAST_CONNECTION_DISABLED 0 - # define MULTICAST_CONNECTION_ENABLED 1 -# endif +#ifdef UDP_CONNECTION_SUPPORT +#define MULTICASTIPADDRESS "225.0.0.37" +#define MULTICASTIPPORT 3491 +#define MULTICASTIP_MAX_SIZE 256 +#define MULTICAST_CONNECTION_DISABLED 0 +#define MULTICAST_CONNECTION_ENABLED 1 +#endif /** * Definitions of DLT daemon logging states */ -typedef enum -{ - DLT_DAEMON_STATE_INIT = 0, /**< Initial state */ - DLT_DAEMON_STATE_BUFFER = 1, /**< logging is buffered until external logger is connected or internal logging is activated */ - DLT_DAEMON_STATE_BUFFER_FULL = 2, /**< then internal buffer is full, wait for connect from client */ - DLT_DAEMON_STATE_SEND_BUFFER = 3, /**< external logger is connected, but buffer is still not empty or external logger queue is full */ - DLT_DAEMON_STATE_SEND_DIRECT = 4 /**< External logger is connected or internal logging is active, and buffer is empty */ +typedef enum { + DLT_DAEMON_STATE_INIT = 0, /**< Initial state */ + DLT_DAEMON_STATE_BUFFER = + 1, /**< logging is buffered until external logger is connected or internal logging is activated */ + DLT_DAEMON_STATE_BUFFER_FULL = 2, /**< then internal buffer is full, wait for connect from client */ + DLT_DAEMON_STATE_SEND_BUFFER = + 3, /**< external logger is connected, but buffer is still not empty or external logger queue is full */ + DLT_DAEMON_STATE_SEND_DIRECT = + 4 /**< External logger is connected or internal logging is active, and buffer is empty */ } DltDaemonState; #ifdef DLT_LOG_LEVEL_APP_CONFIG /* * The parameter of level per app and context id settings */ -typedef struct -{ +typedef struct { char apid[DLT_ID_SIZE]; /**< Application id for which the settings are valid */ char ctid[DLT_ID_SIZE]; /**< Context id for which the settings are valid, empty if valid for all ap ids */ DltLogLevelType log_level; /**< Log level to use */ @@ -130,31 +134,29 @@ typedef struct /* * The parameter of level per app and context id settings for DLT Protocol v2 */ -typedef struct -{ - uint8_t apid2len; /**< length of application id */ - char *apid; /**< Application id for which the settings are valid */ - uint8_t ctid2len; /**< length of context id */ - char *ctid; /**< Context id for which the settings are valid, empty if valid for all ap ids */ - DltLogLevelType log_level; /**< Log level to use */ +typedef struct { + uint8_t apid2len; /**< length of application id */ + char* apid; /**< Application id for which the settings are valid */ + uint8_t ctid2len; /**< length of context id */ + char* ctid; /**< Context id for which the settings are valid, empty if valid for all ap ids */ + DltLogLevelType log_level; /**< Log level to use */ } DltDaemonContextLogSettingsV2; #endif /** * The parameters of a daemon application. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - uint8_t apid2len; /**< length of application id */ - char apid2[DLT_V2_ID_SIZE]; /**< application id */ - pid_t pid; /**< process id of user application */ - int user_handle; /**< connection handle for connection to user application */ - bool owns_user_handle; /**< user_handle should be closed when reset */ - char *application_description; /**< context description */ - int num_contexts; /**< number of contexts for this application */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + uint8_t apid2len; /**< length of application id */ + char apid2[DLT_V2_ID_SIZE]; /**< application id */ + pid_t pid; /**< process id of user application */ + int user_handle; /**< connection handle for connection to user application */ + bool owns_user_handle; /**< user_handle should be closed when reset */ + char* application_description; /**< context description */ + int num_contexts; /**< number of contexts for this application */ #ifdef DLT_LOG_LEVEL_APP_CONFIG - DltDaemonContextLogSettings *context_log_level_settings; + DltDaemonContextLogSettings* context_log_level_settings; int num_context_log_level_settings; #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE @@ -166,82 +168,80 @@ typedef struct /** * The parameters of a daemon context. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ - uint8_t apid2len; /** DLTv2 application id length */ - char *apid2; /**< application id */ - uint8_t ctid2len; /** DLTv2 context id length */ - char *ctid2; /**< context id */ - int8_t log_level; /**< the current log level of the context */ - int8_t trace_status; /**< the current trace status of the context */ - int log_level_pos; /**< offset of context in context field on user application */ - int user_handle; /**< connection handle for connection to user application */ - char *context_description; /**< context description */ - int8_t storage_log_level; /**< log level set for offline logstorage */ - bool predefined; /**< set to true if this context is predefined by runtime configuration file */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + uint8_t apid2len; /** DLTv2 application id length */ + char* apid2; /**< application id */ + uint8_t ctid2len; /** DLTv2 context id length */ + char* ctid2; /**< context id */ + int8_t log_level; /**< the current log level of the context */ + int8_t trace_status; /**< the current trace status of the context */ + int log_level_pos; /**< offset of context in context field on user application */ + int user_handle; /**< connection handle for connection to user application */ + char* context_description; /**< context description */ + int8_t storage_log_level; /**< log level set for offline logstorage */ + bool predefined; /**< set to true if this context is predefined by runtime configuration file */ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - DltTraceLoadSettings* trace_load_settings; /**< trace load setting for the context */ + DltTraceLoadSettings* trace_load_settings; /**< trace load setting for the context */ #endif } DltDaemonContext; /* * The parameter of registered users list */ -typedef struct -{ - DltDaemonApplication *applications; /**< Pointer to applications */ - int num_applications; /**< Number of available application */ - DltDaemonContext *contexts; /**< Pointer to contexts */ - int num_contexts; /**< Total number of all contexts in all applications in this list */ - char ecu[DLT_ID_SIZE]; /**< ECU ID of where contexts are registered */ - uint8_t ecuid2len; /**< Length of ECU ID of where contexts are registered */ +typedef struct { + DltDaemonApplication* applications; /**< Pointer to applications */ + int num_applications; /**< Number of available application */ + DltDaemonContext* contexts; /**< Pointer to contexts */ + int num_contexts; /**< Total number of all contexts in all applications in this list */ + char ecu[DLT_ID_SIZE]; /**< ECU ID of where contexts are registered */ + uint8_t ecuid2len; /**< Length of ECU ID of where contexts are registered */ char ecuid2[DLT_V2_ID_SIZE]; } DltDaemonRegisteredUsers; /** * The parameters of a daemon. */ -typedef struct -{ - DltDaemonRegisteredUsers *user_list; /**< registered users per ECU */ - int num_user_lists; /**< number of context lists */ - int8_t default_log_level; /**< Default log level (of daemon) */ - int8_t default_trace_status; /**< Default trace status (of daemon) */ - int8_t force_ll_ts; /**< Enforce ll and ts to not exceed default_log_level, default_trace_status */ - unsigned int overflow_counter; /**< counts the number of lost messages. */ - int runtime_context_cfg_loaded; /**< Set to one, if runtime context configuration has been loaded, zero otherwise */ - char ecuid[DLT_ID_SIZE]; /**< ECU ID of daemon */ - uint8_t ecuid2len; /**< Length of ECU ID of daemon for DLT V2*/ - char ecuid2[DLT_V2_ID_SIZE]; /**< ECU ID of daemon for DLT V2*/ - int sendserialheader; /**< 1: send serial header; 0 don't send serial header */ - int timingpackets; /**< 1: send continous timing packets; 0 don't send continous timing packets */ - DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */ - char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to path max, as it specifies a full path*/ - char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */ - char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */ - DltUserLogMode mode; /**< Mode used for tracing: off, external, internal, both */ - char connectionState; /**< state for tracing: 0 = no client connected, 1 = client connected */ - char *ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */ - DltDaemonState state; /**< the current logging state of dlt daemon. */ - DltLogStorage *storage_handle; /**< the storage handler. */ - int maintain_logstorage_loglevel; /**< Permission to maintain the logstorage loglevel*/ +typedef struct { + DltDaemonRegisteredUsers* user_list; /**< registered users per ECU */ + int num_user_lists; /**< number of context lists */ + int8_t default_log_level; /**< Default log level (of daemon) */ + int8_t default_trace_status; /**< Default trace status (of daemon) */ + int8_t force_ll_ts; /**< Enforce ll and ts to not exceed default_log_level, default_trace_status */ + unsigned int overflow_counter; /**< counts the number of lost messages. */ + int runtime_context_cfg_loaded; /**< Set to one, if runtime context configuration has been loaded, zero otherwise */ + char ecuid[DLT_ID_SIZE]; /**< ECU ID of daemon */ + uint8_t ecuid2len; /**< Length of ECU ID of daemon for DLT V2*/ + char ecuid2[DLT_V2_ID_SIZE]; /**< ECU ID of daemon for DLT V2*/ + int sendserialheader; /**< 1: send serial header; 0 don't send serial header */ + int timingpackets; /**< 1: send continous timing packets; 0 don't send continous timing packets */ + DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */ + char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to + path max, as it specifies a full path*/ + char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */ + char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */ + DltUserLogMode mode; /**< Mode used for tracing: off, external, internal, both */ + char connectionState; /**< state for tracing: 0 = no client connected, 1 = client connected */ + char* ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */ + DltDaemonState state; /**< the current logging state of dlt daemon. */ + DltLogStorage* storage_handle; /**< the storage handler. */ + int maintain_logstorage_loglevel; /**< Permission to maintain the logstorage loglevel*/ int daemon_version; #ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE int received_message_since_last_watchdog_interval; #endif #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - unsigned int watchdog_trigger_interval; /**< watchdog trigger interval in [s] */ - unsigned int watchdog_last_trigger_time; /**< when the watchdog was last triggered in [s] */ + unsigned int watchdog_trigger_interval; /**< watchdog trigger interval in [s] */ + unsigned int watchdog_last_trigger_time; /**< when the watchdog was last triggered in [s] */ #endif #ifdef DLT_LOG_LEVEL_APP_CONFIG - DltDaemonContextLogSettings *app_id_log_level_settings; /**< Settings for app id specific log levels */ - int num_app_id_log_level_settings; /**< count of log level settings */ + DltDaemonContextLogSettings* app_id_log_level_settings; /**< Settings for app id specific log levels */ + int num_app_id_log_level_settings; /**< count of log level settings */ #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - DltTraceLoadSettings *preconfigured_trace_load_settings; /**< Settings for trace load */ - int preconfigured_trace_load_settings_count; /**< count of trace load settings */ + DltTraceLoadSettings* preconfigured_trace_load_settings; /**< Settings for trace load */ + int preconfigured_trace_load_settings_count; /**< count of trace load settings */ int bytes_sent; int bytes_recv; #endif @@ -255,28 +255,25 @@ typedef struct * @param RingbufferMaxSize ringbuffer size * @param RingbufferStepSize ringbuffer size * @param runtime_directory Directory of persistent configuration - * @param InitialContextLogLevel loglevel to be sent to context when those register with loglevel default, read from dlt.conf - * @param InitialContextTraceStatus tracestatus to be sent to context when those register with tracestatus default, read from dlt.conf + * @param InitialContextLogLevel loglevel to be sent to context when those register with loglevel default, read from + * dlt.conf + * @param InitialContextTraceStatus tracestatus to be sent to context when those register with tracestatus default, read + * from dlt.conf * @param ForceLLTS force default log-level * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_init(DltDaemon *daemon, - unsigned long RingbufferMinSize, - unsigned long RingbufferMaxSize, - unsigned long RingbufferStepSize, - const char *runtime_directory, - int InitialContextLogLevel, - int InitialContextTraceStatus, - int ForceLLTS, - int verbose); +int dlt_daemon_init( + DltDaemon* daemon, unsigned long RingbufferMinSize, unsigned long RingbufferMaxSize, + unsigned long RingbufferStepSize, const char* runtime_directory, int InitialContextLogLevel, + int InitialContextTraceStatus, int ForceLLTS, int verbose); /** * De-Initialise the dlt daemon structure * @param daemon pointer to dlt daemon structure * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_free(DltDaemon *daemon, int verbose); +int dlt_daemon_free(DltDaemon* daemon, int verbose); /** * Initialize data structures to store information about applications running on same * or passive node. @@ -286,10 +283,7 @@ int dlt_daemon_free(DltDaemon *daemon, int verbose); * @param verbose if set to true verbose information is printed out * @return DLT_RETURN_OK on success, DLT_RETURN_ERROR otherwise */ -int dlt_daemon_init_user_information(DltDaemon *daemon, - DltGateway *gateway, - int gateway_mode, - int verbose); +int dlt_daemon_init_user_information(DltDaemon* daemon, DltGateway* gateway, int gateway_mode, int verbose); /** * Find information about application/contexts for a specific ECU * @param daemon pointer to dlt daemon structure @@ -297,9 +291,7 @@ int dlt_daemon_init_user_information(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out * @return pointer to user list, NULL otherwise */ -DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon, - char *ecu, - int verbose); +DltDaemonRegisteredUsers* dlt_daemon_find_users_list(DltDaemon* daemon, char* ecu, int verbose); /** * DLTv2 Find information about application/contexts for a specific ECU @@ -309,10 +301,7 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out * @return pointer to user list, NULL otherwise */ -DltDaemonRegisteredUsers *dlt_daemon_find_users_list_v2(DltDaemon *daemon, - uint8_t eculen, - char *ecu, - int verbose); +DltDaemonRegisteredUsers* dlt_daemon_find_users_list_v2(DltDaemon* daemon, uint8_t eculen, char* ecu, int verbose); #ifdef DLT_LOG_LEVEL_APP_CONFIG @@ -323,8 +312,8 @@ DltDaemonRegisteredUsers *dlt_daemon_find_users_list_v2(DltDaemon *daemon, * @param ctid context id to use, can be NULL * @return pointer to log settings if found, otherwise NULL */ -DltDaemonContextLogSettings *dlt_daemon_find_configured_app_id_ctx_id_settings( - const DltDaemon *daemon, const char *apid, const char *ctid); +DltDaemonContextLogSettings* dlt_daemon_find_configured_app_id_ctx_id_settings( + const DltDaemon* daemon, const char* apid, const char* ctid); /** * DLTv2 Find configuration for app/ctx id specific log settings configuration @@ -333,8 +322,8 @@ DltDaemonContextLogSettings *dlt_daemon_find_configured_app_id_ctx_id_settings( * @param ctid context id to use, can be NULL * @return pointer to log settings if found, otherwise NULL */ -DltDaemonContextLogSettings *dlt_daemon_find_configured_app_id_ctx_id_settings_v2( - const DltDaemon *daemon, const char *apid, const char *ctid); +DltDaemonContextLogSettings* dlt_daemon_find_configured_app_id_ctx_id_settings_v2( + const DltDaemon* daemon, const char* apid, const char* ctid); /** * Find configured log levels in a given DltDaemonApplication for the passed context id. @@ -343,8 +332,7 @@ DltDaemonContextLogSettings *dlt_daemon_find_configured_app_id_ctx_id_settings_v * @return Pointer to DltDaemonApplicationLogSettings containing the log level * for the requested application or NULL if none found. */ -DltDaemonContextLogSettings *dlt_daemon_find_app_log_level_config( - const DltDaemonApplication *app, const char *ctid); +DltDaemonContextLogSettings* dlt_daemon_find_app_log_level_config(const DltDaemonApplication* app, const char* ctid); #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE @@ -358,9 +346,10 @@ DltDaemonContextLogSettings *dlt_daemon_find_app_log_level_config( * @param verbose if set to true verbose information is printed out * @return pointer to load settings if found, NULL otherwise */ -DltReturnValue -dlt_daemon_find_preconfigured_trace_load_settings(DltDaemon *const daemon, const char *apid, const char *ctid, DltTraceLoadSettings **settings, int *num_settings, int verbose); -int dlt_daemon_compare_trace_load_settings(const void *a, const void *b); +DltReturnValue dlt_daemon_find_preconfigured_trace_load_settings( + DltDaemon* const daemon, const char* apid, const char* ctid, DltTraceLoadSettings** settings, int* num_settings, + int verbose); +int dlt_daemon_compare_trace_load_settings(const void* a, const void* b); #endif @@ -374,9 +363,7 @@ int dlt_daemon_compare_trace_load_settings(const void *a, const void *b); * @param verbose if set to true verbose information is printed out * @return DLT_RETURN_OK on success, DLT_RETURN_ERROR otherwise */ -int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, - const char *runtime_directory, - int verbose); +int dlt_daemon_init_runtime_configuration(DltDaemon* daemon, const char* runtime_directory, int verbose); /** * Add (new) application to internal application management @@ -389,13 +376,8 @@ int dlt_daemon_init_runtime_configuration(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to added context, null pointer on error */ -DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, - char *apid, - pid_t pid, - char *description, - int fd, - char *ecu, - int verbose); +DltDaemonApplication* dlt_daemon_application_add( + DltDaemon* daemon, char* apid, pid_t pid, char* description, int fd, char* ecu, int verbose); /** * DLTv2 Add (new) application to internal application management @@ -410,15 +392,9 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to added context, null pointer on error */ -DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - pid_t pid, - char *description, - int fd, - uint8_t eculen, - char *ecu, - int verbose); +DltDaemonApplication* dlt_daemon_application_add_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, pid_t pid, char* description, int fd, uint8_t eculen, char* ecu, + int verbose); /** * Delete application from internal application management @@ -428,10 +404,7 @@ DltDaemonApplication *dlt_daemon_application_add_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_application_del(DltDaemon *daemon, - DltDaemonApplication *application, - char *ecu, - int verbose); +int dlt_daemon_application_del(DltDaemon* daemon, DltDaemonApplication* application, char* ecu, int verbose); /** * DLTv2 Delete application from internal application management @@ -442,11 +415,8 @@ int dlt_daemon_application_del(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_application_del_v2(DltDaemon *daemon, - DltDaemonApplication *application, - uint8_t eculen, - char *ecu, - int verbose); +int dlt_daemon_application_del_v2( + DltDaemon* daemon, DltDaemonApplication* application, uint8_t eculen, char* ecu, int verbose); /** * Find application with specific application id @@ -456,10 +426,7 @@ int dlt_daemon_application_del_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to application, null pointer on error or not found */ -DltDaemonApplication *dlt_daemon_application_find(DltDaemon *daemon, - char *apid, - char *ecu, - int verbose); +DltDaemonApplication* dlt_daemon_application_find(DltDaemon* daemon, char* apid, char* ecu, int verbose); /** * DLTv2 Find application with specific application id @@ -471,13 +438,9 @@ DltDaemonApplication *dlt_daemon_application_find(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to application, null pointer on error or not found */ -void dlt_daemon_application_find_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - uint8_t eculen, - char *ecu, - int verbose, - DltDaemonApplication **application); +void dlt_daemon_application_find_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, uint8_t eculen, char* ecu, int verbose, + DltDaemonApplication** application); /** * Load applications from file to internal context management @@ -486,7 +449,7 @@ void dlt_daemon_application_find_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_applications_load(DltDaemon* daemon, const char* filename, int verbose); /** * Save applications from internal context management to file * @param daemon pointer to dlt daemon structure @@ -494,7 +457,7 @@ int dlt_daemon_applications_load(DltDaemon *daemon, const char *filename, int ve * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_save(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_applications_save(DltDaemon* daemon, const char* filename, int verbose); /** * DLTv2 Save applications from internal context management to file @@ -503,7 +466,7 @@ int dlt_daemon_applications_save(DltDaemon *daemon, const char *filename, int ve * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_save_v2(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_applications_save_v2(DltDaemon* daemon, const char* filename, int verbose); /** * Invalidate all applications fd, if fd is reused @@ -513,10 +476,7 @@ int dlt_daemon_applications_save_v2(DltDaemon *daemon, const char *filename, int * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon, - char *ecu, - int fd, - int verbose); +int dlt_daemon_applications_invalidate_fd(DltDaemon* daemon, char* ecu, int fd, int verbose); /** * Invalidate all applications fd, if fd is reused * @param daemon pointer to dlt daemon structure @@ -525,10 +485,7 @@ int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_invalidate_fd_v2(DltDaemon *daemon, - char *ecu, - int fd, - int verbose); +int dlt_daemon_applications_invalidate_fd_v2(DltDaemon* daemon, char* ecu, int fd, int verbose); /** * Clear all applications in internal application management of specific ecu * @param daemon pointer to dlt daemon structure @@ -536,7 +493,7 @@ int dlt_daemon_applications_invalidate_fd_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose); +int dlt_daemon_applications_clear(DltDaemon* daemon, char* ecu, int verbose); /** * DLTv2 Clear all applications in internal application management of specific ecu @@ -545,7 +502,7 @@ int dlt_daemon_applications_clear(DltDaemon *daemon, char *ecu, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_applications_clear_v2(DltDaemon *daemon, char *ecu, int verbose); +int dlt_daemon_applications_clear_v2(DltDaemon* daemon, char* ecu, int verbose); /** * Add (new) context to internal context management @@ -561,16 +518,9 @@ int dlt_daemon_applications_clear_v2(DltDaemon *daemon, char *ecu, int verbose); * @param verbose if set to true verbose information is printed out. * @return Pointer to added context, null pointer on error */ -DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, - char *apid, - char *ctid, - int8_t log_level, - int8_t trace_status, - int log_level_pos, - int user_handle, - char *description, - char *ecu, - int verbose); +DltDaemonContext* dlt_daemon_context_add( + DltDaemon* daemon, char* apid, char* ctid, int8_t log_level, int8_t trace_status, int log_level_pos, + int user_handle, char* description, char* ecu, int verbose); /** * DLTv2 Add (new) context to internal context management @@ -589,19 +539,9 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to added context, null pointer on error */ -DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - uint8_t ctidlen, - char *ctid, - int8_t log_level, - int8_t trace_status, - int log_level_pos, - int user_handle, - char *description, - uint8_t eculen, - char *ecu, - int verbose); +DltDaemonContext* dlt_daemon_context_add_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, uint8_t ctidlen, char* ctid, int8_t log_level, int8_t trace_status, + int log_level_pos, int user_handle, char* description, uint8_t eculen, char* ecu, int verbose); /** * Delete context from internal context management * @param daemon pointer to dlt daemon structure @@ -610,10 +550,7 @@ DltDaemonContext *dlt_daemon_context_add_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_context_del(DltDaemon *daemon, - DltDaemonContext *context, - char *ecu, - int verbose); +int dlt_daemon_context_del(DltDaemon* daemon, DltDaemonContext* context, char* ecu, int verbose); /** * DLTv2 Delete context from internal context management @@ -623,11 +560,7 @@ int dlt_daemon_context_del(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_context_del_v2(DltDaemon *daemon, - DltDaemonContext *context, - uint8_t eculen, - char *ecu, - int verbose); +int dlt_daemon_context_del_v2(DltDaemon* daemon, DltDaemonContext* context, uint8_t eculen, char* ecu, int verbose); /** * Find context with specific application id and context id @@ -638,11 +571,7 @@ int dlt_daemon_context_del_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to context, null pointer on error or not found */ -DltDaemonContext *dlt_daemon_context_find(DltDaemon *daemon, - char *apid, - char *ctid, - char *ecu, - int verbose); +DltDaemonContext* dlt_daemon_context_find(DltDaemon* daemon, char* apid, char* ctid, char* ecu, int verbose); /** * Find context with specific application id and context id @@ -656,14 +585,9 @@ DltDaemonContext *dlt_daemon_context_find(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return Pointer to context, null pointer on error or not found */ -DltDaemonContext *dlt_daemon_context_find_v2(DltDaemon *daemon, - uint8_t apidlen, - char *apid, - uint8_t ctidlen, - char *ctid, - uint8_t eculen, - char *ecu, - int verbose); +DltDaemonContext* dlt_daemon_context_find_v2( + DltDaemon* daemon, uint8_t apidlen, char* apid, uint8_t ctidlen, char* ctid, uint8_t eculen, char* ecu, + int verbose); /** * Invalidate all contexts fd, if fd is reused @@ -673,10 +597,7 @@ DltDaemonContext *dlt_daemon_context_find_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon, - char *ecu, - int fd, - int verbose); +int dlt_daemon_contexts_invalidate_fd(DltDaemon* daemon, char* ecu, int fd, int verbose); /** * Invalidate all contexts fd, if fd is reused * @param daemon pointer to dlt daemon structure @@ -685,10 +606,7 @@ int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_contexts_invalidate_fd_v2(DltDaemon *daemon, - char *ecu, - int fd, - int verbose); +int dlt_daemon_contexts_invalidate_fd_v2(DltDaemon* daemon, char* ecu, int fd, int verbose); /** * Clear all contexts in internal context management of specific ecu * @param daemon pointer to dlt daemon structure @@ -696,7 +614,7 @@ int dlt_daemon_contexts_invalidate_fd_v2(DltDaemon *daemon, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_contexts_clear(DltDaemon *daemon, char *ecu, int verbose); +int dlt_daemon_contexts_clear(DltDaemon* daemon, char* ecu, int verbose); /** * Load contexts from file to internal context management * @param daemon pointer to dlt daemon structure @@ -704,7 +622,7 @@ int dlt_daemon_contexts_clear(DltDaemon *daemon, char *ecu, int verbose); * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_contexts_load(DltDaemon* daemon, const char* filename, int verbose); /** * Save contexts from internal context management to file * @param daemon pointer to dlt daemon structure @@ -712,7 +630,7 @@ int dlt_daemon_contexts_load(DltDaemon *daemon, const char *filename, int verbos * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_contexts_save(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_contexts_save(DltDaemon* daemon, const char* filename, int verbose); /** * DLTv2 Save contexts from internal context management to file @@ -721,7 +639,7 @@ int dlt_daemon_contexts_save(DltDaemon *daemon, const char *filename, int verbos * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_contexts_save_v2(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_contexts_save_v2(DltDaemon* daemon, const char* filename, int verbose); /** * Load persistant configuration @@ -730,7 +648,7 @@ int dlt_daemon_contexts_save_v2(DltDaemon *daemon, const char *filename, int ver * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_configuration_load(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_configuration_load(DltDaemon* daemon, const char* filename, int verbose); /** * Save configuration persistantly * @param daemon pointer to dlt daemon structure @@ -738,7 +656,7 @@ int dlt_daemon_configuration_load(DltDaemon *daemon, const char *filename, int v * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_configuration_save(DltDaemon *daemon, const char *filename, int verbose); +int dlt_daemon_configuration_save(DltDaemon* daemon, const char* filename, int verbose); /** @@ -748,7 +666,7 @@ int dlt_daemon_configuration_save(DltDaemon *daemon, const char *filename, int v * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, int verbose); +int dlt_daemon_user_send_log_level(DltDaemon* daemon, DltDaemonContext* context, int verbose); /** * DLTv2 Send user message DLT_USER_MESSAGE_LOG_LEVEL to user application @@ -757,7 +675,7 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_user_send_log_level_v2(DltDaemon *daemon, DltDaemonContext *context, int verbose); +int dlt_daemon_user_send_log_level_v2(DltDaemon* daemon, DltDaemonContext* context, int verbose); /** * Send user message DLT_USER_MESSAGE_LOG_STATE to user application @@ -766,7 +684,7 @@ int dlt_daemon_user_send_log_level_v2(DltDaemon *daemon, DltDaemonContext *conte * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app, int verbose); +int dlt_daemon_user_send_log_state(DltDaemon* daemon, DltDaemonApplication* app, int verbose); /** * DLTv2 Send user message DLT_USER_MESSAGE_LOG_STATE to user application @@ -775,7 +693,7 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app, * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_user_send_log_state_v2(DltDaemon *daemon, DltDaemonApplication *app, int verbose); +int dlt_daemon_user_send_log_state_v2(DltDaemon* daemon, DltDaemonApplication* app, int verbose); #ifdef DLT_TRACE_LOAD_CTRL_ENABLE /** @@ -786,7 +704,7 @@ int dlt_daemon_user_send_log_state_v2(DltDaemon *daemon, DltDaemonApplication *a * @param verbose if set to true verbose information is printed out. * @return negative value if there was an error */ -int dlt_daemon_user_send_trace_load_config(DltDaemon *daemon, DltDaemonApplication *app, int verbose); +int dlt_daemon_user_send_trace_load_config(DltDaemon* daemon, DltDaemonApplication* app, int verbose); #endif /** @@ -795,7 +713,7 @@ int dlt_daemon_user_send_trace_load_config(DltDaemon *daemon, DltDaemonApplicati * @param daemon pointer to dlt daemon structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose); +void dlt_daemon_user_send_default_update(DltDaemon* daemon, int verbose); /** * DLTv2 Send user messages to all user applications using default context, or trace status @@ -803,7 +721,7 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose); * @param daemon pointer to dlt daemon structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_default_update_v2(DltDaemon *daemon, int verbose); +void dlt_daemon_user_send_default_update_v2(DltDaemon* daemon, int verbose); /** * Send user messages to all user applications context to update with the new log level @@ -813,11 +731,8 @@ void dlt_daemon_user_send_default_update_v2(DltDaemon *daemon, int verbose); * @param log_level new log level to be set * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, - int enforce_context_ll_and_ts, - int8_t context_log_level, - int8_t log_level, - int verbose); +void dlt_daemon_user_send_all_log_level_update( + DltDaemon* daemon, int enforce_context_ll_and_ts, int8_t context_log_level, int8_t log_level, int verbose); /** * DLTv2 Send user messages to all user applications context to update with the new log level @@ -827,11 +742,8 @@ void dlt_daemon_user_send_all_log_level_update(DltDaemon *daemon, * @param log_level new log level to be set * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_all_log_level_update_v2(DltDaemon *daemon, - int enforce_context_ll_and_ts, - int8_t context_log_level, - int8_t log_level, - int verbose); +void dlt_daemon_user_send_all_log_level_update_v2( + DltDaemon* daemon, int enforce_context_ll_and_ts, int8_t context_log_level, int8_t log_level, int verbose); /** * Send user messages to all user applications context to update with the new trace status @@ -839,7 +751,7 @@ void dlt_daemon_user_send_all_log_level_update_v2(DltDaemon *daemon, * @param trace_status new trace status to be set * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trace_status, int verbose); +void dlt_daemon_user_send_all_trace_status_update(DltDaemon* daemon, int8_t trace_status, int verbose); /** * DLTv2 Send user messages to all user applications context to update with the new trace status @@ -847,7 +759,7 @@ void dlt_daemon_user_send_all_trace_status_update(DltDaemon *daemon, int8_t trac * @param trace_status new trace status to be set * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_all_trace_status_update_v2(DltDaemon *daemon, int8_t trace_status, int verbose); +void dlt_daemon_user_send_all_trace_status_update_v2(DltDaemon* daemon, int8_t trace_status, int verbose); /** * Send user messages to all user applications the log status @@ -855,7 +767,7 @@ void dlt_daemon_user_send_all_trace_status_update_v2(DltDaemon *daemon, int8_t t * @param daemon pointer to dlt daemon structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose); +void dlt_daemon_user_send_all_log_state(DltDaemon* daemon, int verbose); /** * DLTv2 Send user messages to all user applications the log status @@ -863,7 +775,7 @@ void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose); * @param daemon pointer to dlt daemon structure * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_user_send_all_log_state_v2(DltDaemon *daemon, int verbose); +void dlt_daemon_user_send_all_log_state_v2(DltDaemon* daemon, int verbose); /** @@ -871,43 +783,39 @@ void dlt_daemon_user_send_all_log_state_v2(DltDaemon *daemon, int verbose); * @param daemon pointer to dlt daemon structure * @param filename name of file containing the runtime defaults for applications * @param filename1 name of file containing the runtime defaults for contexts - * @param InitialContextLogLevel loglevel to be sent to context when those register with loglevel default, read from dlt.conf - * @param InitialContextTraceStatus tracestatus to be sent to context when those register with tracestatus default, read from dlt.conf + * @param InitialContextLogLevel loglevel to be sent to context when those register with loglevel default, read from + * dlt.conf + * @param InitialContextTraceStatus tracestatus to be sent to context when those register with tracestatus default, read + * from dlt.conf * @param InitialEnforceLlTsStatus force default log-level * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon, - const char *filename, - const char *filename1, - int InitialContextLogLevel, - int InitialContextTraceStatus, - int InitialEnforceLlTsStatus, - int verbose); +void dlt_daemon_control_reset_to_factory_default( + DltDaemon* daemon, const char* filename, const char* filename1, int InitialContextLogLevel, + int InitialContextTraceStatus, int InitialEnforceLlTsStatus, int verbose); /** * DLTv2 Process reset to factory default control message * @param daemon pointer to dlt daemon structure * @param filename name of file containing the runtime defaults for applications * @param filename1 name of file containing the runtime defaults for contexts - * @param InitialContextLogLevel loglevel to be sent to context when those register with loglevel default, read from dlt.conf - * @param InitialContextTraceStatus tracestatus to be sent to context when those register with tracestatus default, read from dlt.conf + * @param InitialContextLogLevel loglevel to be sent to context when those register with loglevel default, read from + * dlt.conf + * @param InitialContextTraceStatus tracestatus to be sent to context when those register with tracestatus default, read + * from dlt.conf * @param InitialEnforceLlTsStatus force default log-level * @param verbose if set to true verbose information is printed out. */ -void dlt_daemon_control_reset_to_factory_default_v2(DltDaemon *daemon, - const char *filename, - const char *filename1, - int InitialContextLogLevel, - int InitialContextTraceStatus, - int InitialEnforceLlTsStatus, - int verbose); +void dlt_daemon_control_reset_to_factory_default_v2( + DltDaemon* daemon, const char* filename, const char* filename1, int InitialContextLogLevel, + int InitialContextTraceStatus, int InitialEnforceLlTsStatus, int verbose); /** * Change the logging state of dlt daemon * @param daemon pointer to dlt daemon structure * @param newState the requested new state */ -void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState); +void dlt_daemon_change_state(DltDaemon* daemon, DltDaemonState newState); #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE /** @@ -915,12 +823,12 @@ void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState); * @param daemon pointer to dlt daemon structure * @return true if the watchdog has been triggered */ -bool dlt_daemon_trigger_systemd_watchdog_if_necessary(DltDaemon *daemon); +bool dlt_daemon_trigger_systemd_watchdog_if_necessary(DltDaemon* daemon); #endif -# ifdef __cplusplus +#ifdef __cplusplus } -# endif +#endif /** \} diff --git a/src/daemon/dlt_daemon_common_cfg.h b/src/daemon/dlt_daemon_common_cfg.h index 9122f2080..8c0c30c8b 100644 --- a/src/daemon/dlt_daemon_common_cfg.h +++ b/src/daemon/dlt_daemon_common_cfg.h @@ -78,33 +78,35 @@ /* Path and filename for runtime configuration (applications) */ #define DLT_RUNTIME_APPLICATION_CFG "/dlt-runtime-application.cfg" /* Path and filename for runtime configuration (contexts) */ -#define DLT_RUNTIME_CONTEXT_CFG "/dlt-runtime-context.cfg" +#define DLT_RUNTIME_CONTEXT_CFG "/dlt-runtime-context.cfg" /* Path and filename for runtime configuration */ -#define DLT_RUNTIME_CONFIGURATION "/dlt-runtime.cfg" +#define DLT_RUNTIME_CONFIGURATION "/dlt-runtime.cfg" /* Default Path for control socket */ -#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \ +#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH \ + DLT_RUNTIME_DEFAULT_DIRECTORY \ "/dlt-ctrl.sock" #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC -#define DLT_DAEMON_DEFAULT_APP_SOCK_PATH DLT_RUNTIME_DEFAULT_DIRECTORY \ +#define DLT_DAEMON_DEFAULT_APP_SOCK_PATH \ + DLT_RUNTIME_DEFAULT_DIRECTORY \ "/dlt-app.sock" #endif /* Size of text buffer */ -#define DLT_DAEMON_COMMON_TEXTBUFSIZE 255 +#define DLT_DAEMON_COMMON_TEXTBUFSIZE 255 /* Application ID used when the dlt daemon creates a control message */ -#define DLT_DAEMON_CTRL_APID "DA1" +#define DLT_DAEMON_CTRL_APID "DA1" /* Context ID used when the dlt daemon creates a control message */ -#define DLT_DAEMON_CTRL_CTID "DC1" +#define DLT_DAEMON_CTRL_CTID "DC1" /* Number of entries to be allocated at one in application table, * when no more entries are available */ -#define DLT_DAEMON_APPL_ALLOC_SIZE 500 +#define DLT_DAEMON_APPL_ALLOC_SIZE 500 /* Number of entries to be allocated at one in context table, * when no more entries are available */ -#define DLT_DAEMON_CONTEXT_ALLOC_SIZE 1000 +#define DLT_DAEMON_CONTEXT_ALLOC_SIZE 1000 /* Debug get log info function, * set to 1 to enable, 0 to disable debugging */ @@ -115,7 +117,7 @@ /************************/ /* Minimum ID for an injection message */ -#define DLT_DAEMON_INJECTION_MIN 0xFFF +#define DLT_DAEMON_INJECTION_MIN 0xFFF /* Maximum ID for an injection message */ #define DLT_DAEMON_INJECTION_MAX 0xFFFFFFFF diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c index 456623cdb..0706cf08c 100644 --- a/src/daemon/dlt_daemon_connection.c +++ b/src/daemon/dlt_daemon_connection.c @@ -49,7 +49,7 @@ #include "dlt_daemon_socket.h" static DltConnectionId connectionId; -extern char *app_recv_buffer; +extern char* app_recv_buffer; /** @brief Generic sending function. * @@ -66,9 +66,7 @@ extern char *app_recv_buffer; * on send failure, DLT_DAEMON_ERROR_UNKNOWN otherwise. * errno is appropriately set. */ -DLT_STATIC int dlt_connection_send(DltConnection *conn, - const void *msg, - size_t msg_size) +DLT_STATIC int dlt_connection_send(DltConnection* conn, const void* msg, size_t msg_size) { DltConnectionType type = DLT_CONNECTION_TYPE_MAX; int ret = 0; @@ -88,9 +86,7 @@ DLT_STATIC int dlt_connection_send(DltConnection *conn, if (msg_size > INT_MAX) { return DLT_DAEMON_ERROR_UNKNOWN; } - ret = dlt_daemon_socket_sendreliable(conn->receiver->fd, - msg, - (int)msg_size); + ret = dlt_daemon_socket_sendreliable(conn->receiver->fd, msg, (int)msg_size); return ret; default: return DLT_DAEMON_ERROR_UNKNOWN; @@ -111,12 +107,8 @@ DLT_STATIC int dlt_connection_send(DltConnection *conn, * * @return DLT_DAEMON_ERROR_OK on success, -1 otherwise. errno is properly set. */ -int dlt_connection_send_multiple(DltConnection *con, - void *data1, - int size1, - void *data2, - int size2, - int sendserialheader) +int dlt_connection_send_multiple( + DltConnection* con, void* data1, int size1, void* data2, int size2, int sendserialheader) { int ret = 0; @@ -124,9 +116,7 @@ int dlt_connection_send_multiple(DltConnection *con, return DLT_DAEMON_ERROR_UNKNOWN; if (sendserialheader) - ret = dlt_connection_send(con, - (const void *)dltSerialHeader, - (size_t)sizeof(dltSerialHeader)); + ret = dlt_connection_send(con, (const void*)dltSerialHeader, (size_t)sizeof(dltSerialHeader)); if ((data1 != NULL) && (ret == DLT_RETURN_OK) && size1 > 0) { ret = dlt_connection_send(con, data1, (size_t)size1); @@ -151,7 +141,7 @@ int dlt_connection_send_multiple(DltConnection *con, * * @return The next available connection of the considered types or NULL. */ -DltConnection *dlt_connection_get_next(DltConnection *current, int type_mask) +DltConnection* dlt_connection_get_next(DltConnection* current, int type_mask) { while (current && !((1 << current->type) & type_mask)) current = current->next; @@ -159,7 +149,7 @@ DltConnection *dlt_connection_get_next(DltConnection *current, int type_mask) return current; } -DLT_STATIC void dlt_connection_destroy_receiver(DltConnection *con) +DLT_STATIC void dlt_connection_destroy_receiver(DltConnection* con) { if (!con) return; @@ -195,11 +185,9 @@ DLT_STATIC void dlt_connection_destroy_receiver(DltConnection *con) * * @return DltReceiver structure or NULL if none corresponds to the type. */ -DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local, - DltConnectionType type, - int fd) +DLT_STATIC DltReceiver* dlt_connection_get_receiver(DltDaemonLocal* daemon_local, DltConnectionType type, int fd) { - DltReceiver *ret = NULL; + DltReceiver* ret = NULL; DltReceiverType receiver_type = DLT_RECEIVE_FD; struct stat statbuf; @@ -233,8 +221,7 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local if (S_ISSOCK(statbuf.st_mode)) receiver_type = DLT_RECEIVE_SOCKET; } else { - dlt_vlog(LOG_WARNING, - "Failed to determine receive type for DLT_CONNECTION_APP_MSG, using \"FD\"\n"); + dlt_vlog(LOG_WARNING, "Failed to determine receive type for DLT_CONNECTION_APP_MSG, using \"FD\"\n"); } if (ret) @@ -243,7 +230,7 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local break; #if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE case DLT_CONNECTION_APP_CONNECT: - /* FALL THROUGH */ + /* FALL THROUGH */ #endif case DLT_CONNECTION_ONE_S_TIMER: /* FALL THROUGH */ @@ -282,9 +269,9 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local * * @return Function pointer or NULL. */ -void *dlt_connection_get_callback(DltConnection *con) +void* dlt_connection_get_callback(DltConnection* con) { - void *ret = NULL; + void* ret = NULL; DltConnectionType type = DLT_CONNECTION_TYPE_MAX; if (con) @@ -292,44 +279,44 @@ void *dlt_connection_get_callback(DltConnection *con) switch (type) { case DLT_CONNECTION_CLIENT_CONNECT: - ret = (void *)(intptr_t)dlt_daemon_process_client_connect; + ret = (void*)(intptr_t)dlt_daemon_process_client_connect; break; case DLT_CONNECTION_CLIENT_MSG_TCP: - ret = (void *)(intptr_t)dlt_daemon_process_client_messages; + ret = (void*)(intptr_t)dlt_daemon_process_client_messages; break; case DLT_CONNECTION_CLIENT_MSG_SERIAL: - ret = (void *)(intptr_t)dlt_daemon_process_client_messages_serial; + ret = (void*)(intptr_t)dlt_daemon_process_client_messages_serial; break; #if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE case DLT_CONNECTION_APP_CONNECT: - ret = (void *)(intptr_t)dlt_daemon_process_app_connect; + ret = (void*)(intptr_t)dlt_daemon_process_app_connect; break; #endif case DLT_CONNECTION_APP_MSG: - ret = (void *)(intptr_t)dlt_daemon_process_user_messages; + ret = (void*)(intptr_t)dlt_daemon_process_user_messages; break; case DLT_CONNECTION_ONE_S_TIMER: - ret = (void *)(intptr_t)dlt_daemon_process_one_s_timer; + ret = (void*)(intptr_t)dlt_daemon_process_one_s_timer; break; case DLT_CONNECTION_SIXTY_S_TIMER: - ret = (void *)(intptr_t)dlt_daemon_process_sixty_s_timer; + ret = (void*)(intptr_t)dlt_daemon_process_sixty_s_timer; break; #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE case DLT_CONNECTION_SYSTEMD_TIMER: - ret = (void *)(intptr_t)dlt_daemon_process_systemd_timer; + ret = (void*)(intptr_t)dlt_daemon_process_systemd_timer; break; #endif case DLT_CONNECTION_CONTROL_CONNECT: - ret = (void *)(intptr_t)dlt_daemon_process_control_connect; + ret = (void*)(intptr_t)dlt_daemon_process_control_connect; break; case DLT_CONNECTION_CONTROL_MSG: - ret = (void *)(intptr_t)dlt_daemon_process_control_messages; + ret = (void*)(intptr_t)dlt_daemon_process_control_messages; break; case DLT_CONNECTION_GATEWAY: - ret = (void *)(intptr_t)dlt_gateway_process_passive_node_messages; + ret = (void*)(intptr_t)dlt_gateway_process_passive_node_messages; break; case DLT_CONNECTION_GATEWAY_TIMER: - ret = (void *)(intptr_t)dlt_gateway_process_gateway_timer; + ret = (void*)(intptr_t)dlt_gateway_process_gateway_timer; break; default: ret = NULL; @@ -347,7 +334,7 @@ void *dlt_connection_get_callback(DltConnection *con) * * @param to_destroy Connection to be destroyed. */ -void dlt_connection_destroy(DltConnection *to_destroy) +void dlt_connection_destroy(DltConnection* to_destroy) { to_destroy->id = 0; close(to_destroy->receiver->fd); @@ -370,13 +357,9 @@ void dlt_connection_destroy(DltConnection *to_destroy) * * @return 0 On success, -1 otherwise. */ -int dlt_connection_create(DltDaemonLocal *daemon_local, - DltEventHandler *evh, - int fd, - int mask, - DltConnectionType type) +int dlt_connection_create(DltDaemonLocal* daemon_local, DltEventHandler* evh, int fd, int mask, DltConnectionType type) { - DltConnection *temp = NULL; + DltConnection* temp = NULL; if (fd < 0) /* Nothing to do */ @@ -390,7 +373,7 @@ int dlt_connection_create(DltDaemonLocal *daemon_local, */ return 0; - temp = (DltConnection *)malloc(sizeof(DltConnection)); + temp = (DltConnection*)malloc(sizeof(DltConnection)); if (temp == NULL) { dlt_log(LOG_CRIT, "Allocation of client handle failed\n"); @@ -402,8 +385,7 @@ int dlt_connection_create(DltDaemonLocal *daemon_local, temp->receiver = dlt_connection_get_receiver(daemon_local, type, fd); if (!temp->receiver) { - dlt_vlog(LOG_CRIT, "Unable to get receiver from %u connection.\n", - type); + dlt_vlog(LOG_CRIT, "Unable to get receiver from %u connection.\n", type); free(temp); return -1; } @@ -412,14 +394,14 @@ int dlt_connection_create(DltDaemonLocal *daemon_local, timeout.tv_sec = 5; timeout.tv_usec = 0; #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - char *watchdogUSec = getenv("WATCHDOG_USEC"); + char* watchdogUSec = getenv("WATCHDOG_USEC"); if (watchdogUSec) { timeout.tv_sec = atoi(watchdogUSec) / 1000000; timeout.tv_usec = atoi(watchdogUSec) % 1000000; } #endif - if (setsockopt (temp->receiver->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof timeout) < 0) { + if (setsockopt(temp->receiver->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof timeout) < 0) { dlt_vlog(LOG_WARNING, "Unable to set send timeout %s.\n", strerror(errno)); // as this function is used for non socket connection as well // we only can return an error here if it is a socket diff --git a/src/daemon/dlt_daemon_connection.h b/src/daemon/dlt_daemon_connection.h index 54e7bac51..77c763710 100644 --- a/src/daemon/dlt_daemon_connection.h +++ b/src/daemon/dlt_daemon_connection.h @@ -32,30 +32,22 @@ #include "dlt_daemon_event_handler_types.h" #include "dlt-daemon.h" -int dlt_connection_send_multiple(DltConnection *, void *, int, void *, int, int); +int dlt_connection_send_multiple(DltConnection*, void*, int, void*, int, int); -DltConnection *dlt_connection_get_next(DltConnection *, int); -int dlt_connection_create_remaining(DltDaemonLocal *); +DltConnection* dlt_connection_get_next(DltConnection*, int); +int dlt_connection_create_remaining(DltDaemonLocal*); -int dlt_connection_create(DltDaemonLocal *, - DltEventHandler *, - int, - int, - DltConnectionType); -void dlt_connection_destroy(DltConnection *); +int dlt_connection_create(DltDaemonLocal*, DltEventHandler*, int, int, DltConnectionType); +void dlt_connection_destroy(DltConnection*); -void *dlt_connection_get_callback(DltConnection *); +void* dlt_connection_get_callback(DltConnection*); #ifdef DLT_UNIT_TESTS -int dlt_connection_send(DltConnection *conn, - const void *msg, - size_t msg_size); +int dlt_connection_send(DltConnection* conn, const void* msg, size_t msg_size); -void dlt_connection_destroy_receiver(DltConnection *con); +void dlt_connection_destroy_receiver(DltConnection* con); -DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local, - DltConnectionType type, - int fd); +DltReceiver* dlt_connection_get_receiver(DltDaemonLocal* daemon_local, DltConnectionType type, int fd); #endif #endif /* DLT_DAEMON_CONNECTION_H */ diff --git a/src/daemon/dlt_daemon_connection_types.h b/src/daemon/dlt_daemon_connection_types.h index 5f197ca6b..65748a6cd 100644 --- a/src/daemon/dlt_daemon_connection_types.h +++ b/src/daemon/dlt_daemon_connection_types.h @@ -30,11 +30,11 @@ #include "dlt_common.h" typedef enum { - UNDEFINED, /* Undefined status */ - INACTIVE, /* Connection is inactive, excluded from poll handling */ - ACTIVE, /* Connection is actively handled by poll */ - DEACTIVATE,/* Request for deactivation of the connection */ - ACTIVATE /* Request for activation of the connection */ + UNDEFINED, /* Undefined status */ + INACTIVE, /* Connection is inactive, excluded from poll handling */ + ACTIVE, /* Connection is actively handled by poll */ + DEACTIVATE, /* Request for deactivation of the connection */ + ACTIVATE /* Request for activation of the connection */ } DltConnectionStatus; typedef enum { @@ -54,19 +54,19 @@ typedef enum { DLT_CONNECTION_TYPE_MAX } DltConnectionType; -#define DLT_CON_MASK_CLIENT_CONNECT (1 << DLT_CONNECTION_CLIENT_CONNECT) -#define DLT_CON_MASK_CLIENT_MSG_TCP (1 << DLT_CONNECTION_CLIENT_MSG_TCP) -#define DLT_CON_MASK_CLIENT_MSG_SERIAL (1 << DLT_CONNECTION_CLIENT_MSG_SERIAL) -#define DLT_CON_MASK_APP_MSG (1 << DLT_CONNECTION_APP_MSG) -#define DLT_CON_MASK_APP_CONNECT (1 << DLT_CONNECTION_APP_CONNECT) -#define DLT_CON_MASK_ONE_S_TIMER (1 << DLT_CONNECTION_ONE_S_TIMER) -#define DLT_CON_MASK_SIXTY_S_TIMER (1 << DLT_CONNECTION_SIXTY_S_TIMER) -#define DLT_CON_MASK_SYSTEMD_TIMER (1 << DLT_CONNECTION_SYSTEMD_TIMER) -#define DLT_CON_MASK_CONTROL_CONNECT (1 << DLT_CONNECTION_CONTROL_CONNECT) -#define DLT_CON_MASK_CONTROL_MSG (1 << DLT_CONNECTION_CONTROL_MSG) -#define DLT_CON_MASK_GATEWAY (1 << DLT_CONNECTION_GATEWAY) -#define DLT_CON_MASK_GATEWAY_TIMER (1 << DLT_CONNECTION_GATEWAY_TIMER) -#define DLT_CON_MASK_ALL (0xffff) +#define DLT_CON_MASK_CLIENT_CONNECT (1 << DLT_CONNECTION_CLIENT_CONNECT) +#define DLT_CON_MASK_CLIENT_MSG_TCP (1 << DLT_CONNECTION_CLIENT_MSG_TCP) +#define DLT_CON_MASK_CLIENT_MSG_SERIAL (1 << DLT_CONNECTION_CLIENT_MSG_SERIAL) +#define DLT_CON_MASK_APP_MSG (1 << DLT_CONNECTION_APP_MSG) +#define DLT_CON_MASK_APP_CONNECT (1 << DLT_CONNECTION_APP_CONNECT) +#define DLT_CON_MASK_ONE_S_TIMER (1 << DLT_CONNECTION_ONE_S_TIMER) +#define DLT_CON_MASK_SIXTY_S_TIMER (1 << DLT_CONNECTION_SIXTY_S_TIMER) +#define DLT_CON_MASK_SYSTEMD_TIMER (1 << DLT_CONNECTION_SYSTEMD_TIMER) +#define DLT_CON_MASK_CONTROL_CONNECT (1 << DLT_CONNECTION_CONTROL_CONNECT) +#define DLT_CON_MASK_CONTROL_MSG (1 << DLT_CONNECTION_CONTROL_MSG) +#define DLT_CON_MASK_GATEWAY (1 << DLT_CONNECTION_GATEWAY) +#define DLT_CON_MASK_GATEWAY_TIMER (1 << DLT_CONNECTION_GATEWAY_TIMER) +#define DLT_CON_MASK_ALL (0xffff) typedef uintptr_t DltConnectionId; @@ -75,13 +75,14 @@ typedef uintptr_t DltConnectionId; */ typedef struct DltConnection { DltConnectionId id; - DltReceiver *receiver; /**< Receiver structure for this connection */ - DltConnectionType type; /**< Represents what type of handle is this (like FIFO, serial, client, server) */ + DltReceiver* receiver; /**< Receiver structure for this connection */ + DltConnectionType type; /**< Represents what type of handle is this (like FIFO, serial, client, server) */ DltConnectionStatus status; /**< Status of connection */ - struct DltConnection *next; /**< For multiple client connection using linked list */ - int ev_mask; /**< Mask to set when registering the connection for events */ + struct DltConnection* next; /**< For multiple client connection using linked list */ + int ev_mask; /**< Mask to set when registering the connection for events */ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - int remaining_size; /**< Remaining data size for sending data. This value will be set to non-zero when data could not be sent fully */ + int remaining_size; /**< Remaining data size for sending data. This value will be set to non-zero when data could + not be sent fully */ #endif } DltConnection; diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c index 57763585c..8096628d4 100644 --- a/src/daemon/dlt_daemon_event_handler.c +++ b/src/daemon/dlt_daemon_event_handler.c @@ -51,7 +51,7 @@ * Set to 1 second to avoid unnecessary wake ups. */ #define DLT_EV_TIMEOUT_MSEC 1000 -#define DLT_EV_BASE_FD 16 +#define DLT_EV_BASE_FD 16 #define DLT_EV_MASK_REJECTED (POLLERR | POLLNVAL) @@ -61,7 +61,7 @@ * * @param pfd The element to initialize */ -static void init_poll_fd(struct pollfd *pfd) +static void init_poll_fd(struct pollfd* pfd) { pfd->fd = -1; pfd->events = 0; @@ -76,7 +76,7 @@ static void init_poll_fd(struct pollfd *pfd) * * @return 0 on success, -1 otherwise. */ -int dlt_daemon_prepare_event_handling(DltEventHandler *ev) +int dlt_daemon_prepare_event_handling(DltEventHandler* ev) { int i = 0; @@ -108,16 +108,15 @@ int dlt_daemon_prepare_event_handling(DltEventHandler *ev) * @param fd The file descriptor to add * @param mask The mask of event to be watched */ -static void dlt_event_handler_enable_fd(DltEventHandler *ev, int fd, int mask) +static void dlt_event_handler_enable_fd(DltEventHandler* ev, int fd, int mask) { if (ev->max_nfds <= ev->nfds) { nfds_t i = ev->nfds; nfds_t max = 2 * ev->max_nfds; - struct pollfd *tmp = realloc(ev->pfd, (size_t)max * sizeof(*ev->pfd)); + struct pollfd* tmp = realloc(ev->pfd, (size_t)max * sizeof(*ev->pfd)); if (!tmp) { - dlt_log(LOG_CRIT, - "Unable to register new fd for the event handler.\n"); + dlt_log(LOG_CRIT, "Unable to register new fd for the event handler.\n"); return; } @@ -141,7 +140,7 @@ static void dlt_event_handler_enable_fd(DltEventHandler *ev, int fd, int mask) * @param ev The event handler structure containing the list * @param fd The file descriptor to be removed */ -static void dlt_event_handler_disable_fd(DltEventHandler *ev, int fd) +static void dlt_event_handler_disable_fd(DltEventHandler* ev, int fd) { unsigned int i = 0; unsigned int j = 0; @@ -162,8 +161,7 @@ static void dlt_event_handler_disable_fd(DltEventHandler *ev, int fd) ev->pfd[i].fd = ev->pfd[j].fd; ev->pfd[i].events = ev->pfd[j].events; ev->pfd[i].revents = ev->pfd[j].revents; - } - else { + } else { init_poll_fd(&ev->pfd[i]); } } @@ -181,13 +179,11 @@ static void dlt_event_handler_disable_fd(DltEventHandler *ev, int fd) * * @return 0 on success, -1 otherwise. May be interrupted. */ -int dlt_daemon_handle_event(DltEventHandler *pEvent, - DltDaemon *daemon, - DltDaemonLocal *daemon_local) +int dlt_daemon_handle_event(DltEventHandler* pEvent, DltDaemon* daemon, DltDaemonLocal* daemon_local) { int ret = 0; unsigned int i = 0; - int (*callback)(DltDaemon *, DltDaemonLocal *, DltReceiver *, int) = NULL; + int (*callback)(DltDaemon*, DltDaemonLocal*, DltReceiver*, int) = NULL; if ((pEvent == NULL) || (daemon == NULL) || (daemon_local == NULL)) return DLT_RETURN_ERROR; @@ -209,7 +205,7 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent, for (i = 0; i < pEvent->nfds; i++) { int fd = 0; - DltConnection *con = NULL; + DltConnection* con = NULL; DltConnectionType type = DLT_CONNECTION_TYPE_MAX; if (pEvent->pfd[i].revents == 0) @@ -220,8 +216,7 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent, if (con && con->receiver) { type = con->type; fd = con->receiver->fd; - } - else { /* connection might have been destroyed in the meanwhile */ + } else { /* connection might have been destroyed in the meanwhile */ dlt_event_handler_disable_fd(pEvent, pEvent->pfd[i].fd); continue; } @@ -237,36 +232,29 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent, */ dlt_daemon_close_socket(fd, daemon, daemon_local, 0); else - dlt_event_handler_unregister_connection(pEvent, - daemon_local, - fd); + dlt_event_handler_unregister_connection(pEvent, daemon_local, fd); continue; } /* Get the function to be used to handle the event */ union { - void *ptr; - int (*callback_func)(DltDaemon *, DltDaemonLocal *, DltReceiver *, int); + void* ptr; + int (*callback_func)(DltDaemon*, DltDaemonLocal*, DltReceiver*, int); } callback_converter; callback_converter.ptr = dlt_connection_get_callback(con); callback = callback_converter.callback_func; if (!callback) { - dlt_vlog(LOG_CRIT, "Unable to find function for %u handle type.\n", - type); + dlt_vlog(LOG_CRIT, "Unable to find function for %u handle type.\n", type); /* keep handling remaining events */ continue; } /* From now on, callback is correct */ - if (callback(daemon, - daemon_local, - con->receiver, - daemon_local->flags.vflag) == -1) { - dlt_vlog(LOG_CRIT, "Processing from %u handle type failed!\n", - type); + if (callback(daemon, daemon_local, con->receiver, daemon_local->flags.vflag) == -1) { + dlt_vlog(LOG_CRIT, "Processing from %u handle type failed!\n", type); return -1; } #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE @@ -290,9 +278,9 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent, * * @return The found connection pointer, NULL otherwise. */ -DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev, int fd) +DltConnection* dlt_event_handler_find_connection(DltEventHandler* ev, int fd) { - DltConnection *temp = ev->connections; + DltConnection* temp = ev->connections; while (temp != NULL) { if ((temp->receiver != NULL) && (temp->receiver->fd == fd)) @@ -313,14 +301,13 @@ DltConnection *dlt_event_handler_find_connection(DltEventHandler *ev, int fd) * * @return 0 on success, -1 if the connection is not found. */ -DLT_STATIC int dlt_daemon_remove_connection(DltEventHandler *ev, - DltConnection *to_remove) +DLT_STATIC int dlt_daemon_remove_connection(DltEventHandler* ev, DltConnection* to_remove) { if ((ev == NULL) || (to_remove == NULL)) return DLT_RETURN_ERROR; - DltConnection *curr = ev->connections; - DltConnection *prev = curr; + DltConnection* curr = ev->connections; + DltConnection* prev = curr; /* Find the address where to_remove value is registered */ while (curr && (curr != to_remove)) { @@ -332,12 +319,9 @@ DLT_STATIC int dlt_daemon_remove_connection(DltEventHandler *ev, /* Must not be possible as we check for existence before */ dlt_log(LOG_CRIT, "Connection not found for removal.\n"); return -1; - } - else if (curr == ev->connections) - { + } else if (curr == ev->connections) { ev->connections = curr->next; - } - else { + } else { prev->next = curr->next; } @@ -353,7 +337,7 @@ DLT_STATIC int dlt_daemon_remove_connection(DltEventHandler *ev, * * @param ev Pointer to the event handler structure. */ -void dlt_event_handler_cleanup_connections(DltEventHandler *ev) +void dlt_event_handler_cleanup_connections(DltEventHandler* ev) { unsigned int i = 0; @@ -378,11 +362,9 @@ void dlt_event_handler_cleanup_connections(DltEventHandler *ev) * @param ev The event handler structure where the connection list is. * @param connection The connection to be added. */ -DLT_STATIC void dlt_daemon_add_connection(DltEventHandler *ev, - DltConnection *connection) +DLT_STATIC void dlt_daemon_add_connection(DltEventHandler* ev, DltConnection* connection) { - - DltConnection **temp = &ev->connections; + DltConnection** temp = &ev->connections; while (*temp != NULL) temp = &(*temp)->next; @@ -403,9 +385,7 @@ DLT_STATIC void dlt_daemon_add_connection(DltEventHandler *ev, * * @return 0 on success, -1 otherwise */ -int dlt_connection_check_activate(DltEventHandler *evhdl, - DltConnection *con, - int activation_type) +int dlt_connection_check_activate(DltEventHandler* evhdl, DltConnection* con, int activation_type) { if (!evhdl || !con || !con->receiver) { dlt_vlog(LOG_ERR, "%s: wrong parameters.\n", __func__); @@ -432,9 +412,7 @@ int dlt_connection_check_activate(DltEventHandler *evhdl, if (activation_type == ACTIVATE) { dlt_vlog(LOG_INFO, "Activate connection type: %u\n", con->type); - dlt_event_handler_enable_fd(evhdl, - con->receiver->fd, - con->ev_mask); + dlt_event_handler_enable_fd(evhdl, con->receiver->fd, con->ev_mask); con->status = ACTIVE; } @@ -464,10 +442,8 @@ int dlt_connection_check_activate(DltEventHandler *evhdl, * * @return 0 on success, -1 otherwise. */ -int dlt_event_handler_register_connection(DltEventHandler *evhdl, - DltDaemonLocal *daemon_local, - DltConnection *connection, - int mask) +int dlt_event_handler_register_connection( + DltEventHandler* evhdl, DltDaemonLocal* daemon_local, DltConnection* connection, int mask) { if (!evhdl || !connection || !connection->receiver) { dlt_log(LOG_ERR, "Wrong parameters when registering connection.\n"); @@ -476,8 +452,7 @@ int dlt_event_handler_register_connection(DltEventHandler *evhdl, dlt_daemon_add_connection(evhdl, connection); - if ((connection->type == DLT_CONNECTION_CLIENT_MSG_TCP) || - (connection->type == DLT_CONNECTION_CLIENT_MSG_SERIAL)) + if ((connection->type == DLT_CONNECTION_CLIENT_MSG_TCP) || (connection->type == DLT_CONNECTION_CLIENT_MSG_SERIAL)) daemon_local->client_connections++; /* On creation the connection is not active by default */ @@ -486,9 +461,7 @@ int dlt_event_handler_register_connection(DltEventHandler *evhdl, connection->next = NULL; connection->ev_mask = mask; - return dlt_connection_check_activate(evhdl, - connection, - ACTIVATE); + return dlt_connection_check_activate(evhdl, connection, ACTIVATE); } /** @brief Unregisters a connection from the event handler and destroys it. @@ -505,9 +478,7 @@ int dlt_event_handler_register_connection(DltEventHandler *evhdl, * * @return 0 on success, -1 otherwise. */ -int dlt_event_handler_unregister_connection(DltEventHandler *evhdl, - DltDaemonLocal *daemon_local, - int fd) +int dlt_event_handler_unregister_connection(DltEventHandler* evhdl, DltDaemonLocal* daemon_local, int fd) { if ((evhdl == NULL) || (daemon_local == NULL)) return DLT_RETURN_ERROR; @@ -515,15 +486,14 @@ int dlt_event_handler_unregister_connection(DltEventHandler *evhdl, /* Look for the pointer in the client list. * There shall be only one event handler with the same fd. */ - DltConnection *temp = dlt_event_handler_find_connection(evhdl, fd); + DltConnection* temp = dlt_event_handler_find_connection(evhdl, fd); if (!temp) { dlt_log(LOG_ERR, "Connection not found for unregistration.\n"); return -1; } - if ((temp->type == DLT_CONNECTION_CLIENT_MSG_TCP) || - (temp->type == DLT_CONNECTION_CLIENT_MSG_SERIAL)) { + if ((temp->type == DLT_CONNECTION_CLIENT_MSG_TCP) || (temp->type == DLT_CONNECTION_CLIENT_MSG_SERIAL)) { daemon_local->client_connections--; if (daemon_local->client_connections < 0) { @@ -532,9 +502,7 @@ int dlt_event_handler_unregister_connection(DltEventHandler *evhdl, } } - if (dlt_connection_check_activate(evhdl, - temp, - DEACTIVATE) < 0) + if (dlt_connection_check_activate(evhdl, temp, DEACTIVATE) < 0) dlt_log(LOG_ERR, "Unable to unregister event.\n"); /* Cannot fail as far as dlt_daemon_find_connection succeed */ diff --git a/src/daemon/dlt_daemon_event_handler.h b/src/daemon/dlt_daemon_event_handler.h index 4c37032e9..33816b31b 100644 --- a/src/daemon/dlt_daemon_event_handler.h +++ b/src/daemon/dlt_daemon_event_handler.h @@ -34,33 +34,22 @@ #ifndef DLT_DAEMON_EVENT_HANDLER_H #define DLT_DAEMON_EVENT_HANDLER_H -int dlt_daemon_prepare_event_handling(DltEventHandler *); -int dlt_daemon_handle_event(DltEventHandler *, DltDaemon *, DltDaemonLocal *); +int dlt_daemon_prepare_event_handling(DltEventHandler*); +int dlt_daemon_handle_event(DltEventHandler*, DltDaemon*, DltDaemonLocal*); -DltConnection *dlt_event_handler_find_connection_by_id(DltEventHandler *, - DltConnectionId); -DltConnection *dlt_event_handler_find_connection(DltEventHandler *, - int); +DltConnection* dlt_event_handler_find_connection_by_id(DltEventHandler*, DltConnectionId); +DltConnection* dlt_event_handler_find_connection(DltEventHandler*, int); -void dlt_event_handler_cleanup_connections(DltEventHandler *); +void dlt_event_handler_cleanup_connections(DltEventHandler*); -int dlt_event_handler_register_connection(DltEventHandler *, - DltDaemonLocal *, - DltConnection *, - int); +int dlt_event_handler_register_connection(DltEventHandler*, DltDaemonLocal*, DltConnection*, int); -int dlt_event_handler_unregister_connection(DltEventHandler *, - DltDaemonLocal *, - int); +int dlt_event_handler_unregister_connection(DltEventHandler*, DltDaemonLocal*, int); -int dlt_connection_check_activate(DltEventHandler *, - DltConnection *, - int); +int dlt_connection_check_activate(DltEventHandler*, DltConnection*, int); #ifdef DLT_UNIT_TESTS -int dlt_daemon_remove_connection(DltEventHandler *ev, - DltConnection *to_remove); +int dlt_daemon_remove_connection(DltEventHandler* ev, DltConnection* to_remove); -void dlt_daemon_add_connection(DltEventHandler *ev, - DltConnection *connection); +void dlt_daemon_add_connection(DltEventHandler* ev, DltConnection* connection); #endif #endif /* DLT_DAEMON_EVENT_HANDLER_H */ diff --git a/src/daemon/dlt_daemon_event_handler_types.h b/src/daemon/dlt_daemon_event_handler_types.h index 92a6ff0c5..80f6f4dbe 100644 --- a/src/daemon/dlt_daemon_event_handler_types.h +++ b/src/daemon/dlt_daemon_event_handler_types.h @@ -49,10 +49,10 @@ typedef enum { } DltTimers; typedef struct { - struct pollfd *pfd; + struct pollfd* pfd; nfds_t nfds; nfds_t max_nfds; - DltConnection *connections; + DltConnection* connections; } DltEventHandler; #endif /* DLT_DAEMON_EVENT_HANDLER_TYPES_H */ diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c index 6b35e9379..c0055cd05 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.c +++ b/src/daemon/dlt_daemon_offline_logstorage.c @@ -40,11 +40,7 @@ * @param ctid Context id as .* stored here * @return 0 on success -1 on error */ -DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid(char *key, - int len, - char *ecuid, - char *apid, - char *ctid) +DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid(char* key, int len, char* ecuid, char* apid, char* ctid) { if ((len > (DLT_ID_SIZE + 2)) || (len < 2)) return DLT_RETURN_ERROR; @@ -68,10 +64,7 @@ unsigned int g_logstorage_cache_max; * @param ctid Context id from key stored here * @return 0 on success -1 on error */ -DLT_STATIC DltReturnValue dlt_logstorage_split_ctid(char *key, - int len, - char *apid, - char *ctid) +DLT_STATIC DltReturnValue dlt_logstorage_split_ctid(char* key, int len, char* apid, char* ctid) { if ((len > (DLT_ID_SIZE + 2)) || (len < 1)) return DLT_RETURN_ERROR; @@ -93,10 +86,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_ctid(char *key, * @param ctid Context id as .* stored here * @return 0 on success -1 on error */ -DLT_STATIC DltReturnValue dlt_logstorage_split_apid(char *key, - int len, - char *apid, - char *ctid) +DLT_STATIC DltReturnValue dlt_logstorage_split_apid(char* key, int len, char* apid, char* ctid) { if ((len > (DLT_ID_SIZE + 2)) || (len < 2)) return DLT_RETURN_ERROR; @@ -118,12 +108,9 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_apid(char *key, * @param ctid CContext id from key is stored here * @return 0 on success -1 on error */ -DLT_STATIC DltReturnValue dlt_logstorage_split_apid_ctid(char *key, - int len, - char *apid, - char *ctid) +DLT_STATIC DltReturnValue dlt_logstorage_split_apid_ctid(char* key, int len, char* apid, char* ctid) { - char *tok = NULL; + char* tok = NULL; if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) return DLT_RETURN_ERROR; @@ -158,13 +145,9 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_apid_ctid(char *key, * @param ctid Context id as .* stored here * @return 0 on success -1 on error */ -DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid_apid(char *key, - int len, - char *ecuid, - char *apid, - char *ctid) +DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid_apid(char* key, int len, char* ecuid, char* apid, char* ctid) { - char *tok = NULL; + char* tok = NULL; if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) return DLT_RETURN_ERROR; @@ -202,13 +185,9 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid_apid(char *key, * @param ctid Context ID * @return None */ -DLT_STATIC DltReturnValue dlt_logstorage_split_multi(char *key, - int len, - char *ecuid, - char *apid, - char *ctid) +DLT_STATIC DltReturnValue dlt_logstorage_split_multi(char* key, int len, char* ecuid, char* apid, char* ctid) { - char *tok = NULL; + char* tok = NULL; if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) return DLT_RETURN_ERROR; @@ -229,8 +208,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_multi(char *key, strncpy(ctid, tok, DLT_ID_SIZE); memcpy(apid, ".*", 2); - } - else { + } else { strncpy(ecuid, tok, DLT_ID_SIZE); tok = strtok(NULL, ":"); @@ -260,18 +238,17 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_multi(char *key, * @param ecuid ECU id * @return 0 on success, -1 on error */ -DLT_STATIC DltReturnValue dlt_logstorage_split_key(char *key, char *apid, - char *ctid, char *ecuid) +DLT_STATIC DltReturnValue dlt_logstorage_split_key(char* key, char* apid, char* ctid, char* ecuid) { int len = 0; - char *sep = NULL; + char* sep = NULL; if ((key == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL)) return DLT_RETURN_WRONG_PARAMETER; len = (int)strlen(key); - sep = strchr (key, ':'); + sep = strchr(key, ':'); if (sep == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -307,21 +284,16 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_key(char *key, char *apid, * @param verbose verbosity flag */ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context( - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *ecuid, - int loglevel, - int verbose) + DltDaemonLocal* daemon_local, char* apid, char* ctid, char* ecuid, int loglevel, int verbose) { - DltServiceSetLogLevel req = { 0 }; - DltPassiveControlMessage ctrl = { 0 }; - DltGatewayConnection *con = NULL; + DltServiceSetLogLevel req = {0}; + DltPassiveControlMessage ctrl = {0}; + DltGatewayConnection* con = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) || - (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { + if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) || (loglevel > DLT_LOG_VERBOSE) + || (loglevel < DLT_LOG_DEFAULT)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -329,9 +301,7 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context( con = dlt_gateway_get_connection(&daemon_local->pGateway, ecuid, verbose); if (con == NULL) { - dlt_vlog(LOG_ERR, - "Failed to fond connection to passive node %s\n", - ecuid); + dlt_vlog(LOG_ERR, "Failed to fond connection to passive node %s\n", ecuid); return DLT_RETURN_ERROR; } @@ -343,10 +313,8 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context( req.log_level = (uint8_t)loglevel; - if (dlt_gateway_send_control_message(con, &ctrl, (void *)&req, verbose) != 0) { - dlt_vlog(LOG_ERR, - "Failed to forward SET_LOG_LEVEL message to passive node %s\n", - ecuid); + if (dlt_gateway_send_control_message(con, &ctrl, (void*)&req, verbose) != 0) { + dlt_vlog(LOG_ERR, "Failed to forward SET_LOG_LEVEL message to passive node %s\n", ecuid); return DLT_RETURN_ERROR; } @@ -365,21 +333,16 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context( * @param verbose verbosity flag */ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context_v2( - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *ecuid, - int loglevel, - int verbose) + DltDaemonLocal* daemon_local, char* apid, char* ctid, char* ecuid, int loglevel, int verbose) { - DltServiceSetLogLevelV2 req = { 0 }; - DltPassiveControlMessage ctrl = { 0 }; - DltGatewayConnection *con = NULL; + DltServiceSetLogLevelV2 req = {0}; + DltPassiveControlMessage ctrl = {0}; + DltGatewayConnection* con = NULL; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) || - (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { + if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) || (loglevel > DLT_LOG_VERBOSE) + || (loglevel < DLT_LOG_DEFAULT)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -388,9 +351,7 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context_v2( con = dlt_gateway_get_connection_v2(&daemon_local->pGateway, ecuid, verbose); if (con == NULL) { - dlt_vlog(LOG_ERR, - "Failed to fond connection to passive node %s\n", - ecuid); + dlt_vlog(LOG_ERR, "Failed to fond connection to passive node %s\n", ecuid); return DLT_RETURN_ERROR; } @@ -409,10 +370,8 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context_v2( req.ctid = ctid_buf; req.log_level = (uint8_t)loglevel; /* Check if need to pass ecuidlen also */ - if (dlt_gateway_send_control_message_v2(con, &ctrl, (void *)&req, verbose) != 0) { - dlt_vlog(LOG_ERR, - "Failed to forward SET_LOG_LEVEL message to passive node %s\n", - ecuid); + if (dlt_gateway_send_control_message_v2(con, &ctrl, (void*)&req, verbose) != 0) { + dlt_vlog(LOG_ERR, "Failed to forward SET_LOG_LEVEL message to passive node %s\n", ecuid); return DLT_RETURN_ERROR; } @@ -434,18 +393,14 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context_v2( * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - char *ecuid, - int loglevel, - int verbose) +DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, char* ecuid, int loglevel, int verbose) { int old_log_level = -1; int ll = DLT_LOG_DEFAULT; - if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || - (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || (context == NULL) + || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -453,8 +408,7 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level(DltDaemon *daemon if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) == 0) { old_log_level = context->storage_log_level; - context->storage_log_level = (int8_t)DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, - context->storage_log_level); + context->storage_log_level = (int8_t)DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, context->storage_log_level); if (context->storage_log_level > old_log_level) { if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) { @@ -462,20 +416,14 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level(DltDaemon *daemon return DLT_RETURN_ERROR; } } - } - else { - + } else { old_log_level = context->log_level; ll = DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, context->log_level); if (ll > old_log_level) - return dlt_daemon_logstorage_update_passive_node_context(daemon_local, - context->apid, - context->ctid, - ecuid, - ll, - verbose); + return dlt_daemon_logstorage_update_passive_node_context( + daemon_local, context->apid, context->ctid, ecuid, ll, verbose); } return DLT_RETURN_OK; @@ -495,18 +443,14 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level(DltDaemon *daemon * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - char *ecuid, - int loglevel, - int verbose) +DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, char* ecuid, int loglevel, int verbose) { int old_log_level = -1; int ll = DLT_LOG_DEFAULT; - if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || - (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || (context == NULL) + || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -514,8 +458,7 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level_v2(DltDaemon *dae if (strncmp(ecuid, daemon->ecuid2, daemon->ecuid2len) == 0) { old_log_level = context->storage_log_level; - context->storage_log_level = (int8_t)DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, - context->storage_log_level); + context->storage_log_level = (int8_t)DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, context->storage_log_level); if (context->storage_log_level > old_log_level) { if (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == -1) { @@ -523,20 +466,14 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level_v2(DltDaemon *dae return DLT_RETURN_ERROR; } } - } - else { - + } else { old_log_level = context->log_level; ll = DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, context->log_level); if (ll > old_log_level) - return dlt_daemon_logstorage_update_passive_node_context_v2(daemon_local, - context->apid, - context->ctid, - ecuid, - ll, - verbose); + return dlt_daemon_logstorage_update_passive_node_context_v2( + daemon_local, context->apid, context->ctid, ecuid, ll, verbose); } return DLT_RETURN_OK; @@ -557,15 +494,11 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level_v2(DltDaemon *dae * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DLT_STATIC DltReturnValue dlt_daemon_logstorage_reset_log_level(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltDaemonContext *context, - char *ecuid, - int loglevel, - int verbose) +DLT_STATIC DltReturnValue dlt_daemon_logstorage_reset_log_level( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltDaemonContext* context, char* ecuid, int loglevel, int verbose) { - if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || - (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || (context == NULL) + || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -575,20 +508,13 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_reset_log_level(DltDaemon *daemo if (loglevel == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL) { if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) == 0) { - if (dlt_daemon_user_send_log_level(daemon, - context, - verbose) == DLT_RETURN_ERROR) { + if (dlt_daemon_user_send_log_level(daemon, context, verbose) == DLT_RETURN_ERROR) { dlt_log(LOG_ERR, "Unable to update log level\n"); return DLT_RETURN_ERROR; } - } - else { /* forward set log level to passive node */ - return dlt_daemon_logstorage_update_passive_node_context(daemon_local, - context->apid, - context->ctid, - ecuid, - DLT_LOG_DEFAULT, - verbose); + } else { /* forward set log level to passive node */ + return dlt_daemon_logstorage_update_passive_node_context( + daemon_local, context->apid, context->ctid, ecuid, DLT_LOG_DEFAULT, verbose); } } @@ -609,21 +535,16 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_reset_log_level(DltDaemon *daemo * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *ecuid, - int loglevel, - int verbose) +DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* apid, char* ctid, char* ecuid, int loglevel, int verbose) { int ll = DLT_LOG_DEFAULT; int num = 0; int i = 0; - DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + DltLogStorageFilterConfig* config[DLT_CONFIG_FILE_SECTIONS_MAX] = {0}; - if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || - (apid == NULL) || (ctid == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { + if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || (apid == NULL) || (ctid == NULL) + || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -636,9 +557,9 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *dae } if ((num == 0) || (config[0] == NULL)) { - dlt_vlog(LOG_ERR, - "%s: No information about APID: %s, CTID: %s, ECU: %s in Logstorage configuration\n", - __func__, apid, ctid, ecuid); + dlt_vlog( + LOG_ERR, "%s: No information about APID: %s, CTID: %s, ECU: %s in Logstorage configuration\n", __func__, + apid, ctid, ecuid); return DLT_RETURN_ERROR; } @@ -647,9 +568,7 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *dae else ll = config[0]->log_level; - return dlt_daemon_logstorage_update_passive_node_context(daemon_local, apid, - ctid, ecuid, ll, verbose); - + return dlt_daemon_logstorage_update_passive_node_context(daemon_local, apid, ctid, ecuid, ll, verbose); } /** @@ -671,21 +590,16 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *dae * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DltReturnValue dlt_logstorage_update_all_contexts(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *id, - int curr_log_level, - int cmp_flag, - char *ecuid, - int verbose) +DltReturnValue dlt_logstorage_update_all_contexts( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* id, int curr_log_level, int cmp_flag, char* ecuid, + int verbose) { - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; int i = 0; - char tmp_id[DLT_ID_SIZE + 1] = { '\0' }; + char tmp_id[DLT_ID_SIZE + 1] = {'\0'}; - if ((daemon == NULL) || (daemon_local == NULL) || (id == NULL) || - (ecuid == NULL) || (cmp_flag <= DLT_DAEMON_LOGSTORAGE_CMP_MIN) || - (cmp_flag >= DLT_DAEMON_LOGSTORAGE_CMP_MAX)) { + if ((daemon == NULL) || (daemon_local == NULL) || (id == NULL) || (ecuid == NULL) + || (cmp_flag <= DLT_DAEMON_LOGSTORAGE_CMP_MIN) || (cmp_flag >= DLT_DAEMON_LOGSTORAGE_CMP_MAX)) { dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -706,19 +620,11 @@ DltReturnValue dlt_logstorage_update_all_contexts(DltDaemon *daemon, if (strncmp(id, tmp_id, DLT_ID_SIZE) == 0) { if (curr_log_level > 0) - dlt_daemon_logstorage_send_log_level(daemon, - daemon_local, - &user_list->contexts[i], - ecuid, - curr_log_level, - verbose); + dlt_daemon_logstorage_send_log_level( + daemon, daemon_local, &user_list->contexts[i], ecuid, curr_log_level, verbose); else /* The request is to reset log levels */ - dlt_daemon_logstorage_reset_log_level(daemon, - daemon_local, - &user_list->contexts[i], - ecuid, - curr_log_level, - verbose); + dlt_daemon_logstorage_reset_log_level( + daemon, daemon_local, &user_list->contexts[i], ecuid, curr_log_level, verbose); } } @@ -744,22 +650,17 @@ DltReturnValue dlt_logstorage_update_all_contexts(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DltReturnValue dlt_logstorage_update_all_contexts_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *id, - int curr_log_level, - int cmp_flag, - char *ecuid, - int verbose) +DltReturnValue dlt_logstorage_update_all_contexts_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* id, int curr_log_level, int cmp_flag, char* ecuid, + int verbose) { - DltDaemonRegisteredUsers *user_list = NULL; + DltDaemonRegisteredUsers* user_list = NULL; int i = 0; uint8_t tmp_id_size = 0; char tmp_id[DLT_V2_ID_SIZE]; - if ((daemon == NULL) || (daemon_local == NULL) || (id == NULL) || - (ecuid == NULL) || (cmp_flag <= DLT_DAEMON_LOGSTORAGE_CMP_MIN) || - (cmp_flag >= DLT_DAEMON_LOGSTORAGE_CMP_MAX)) { + if ((daemon == NULL) || (daemon_local == NULL) || (id == NULL) || (ecuid == NULL) + || (cmp_flag <= DLT_DAEMON_LOGSTORAGE_CMP_MIN) || (cmp_flag >= DLT_DAEMON_LOGSTORAGE_CMP_MAX)) { dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -775,33 +676,23 @@ DltReturnValue dlt_logstorage_update_all_contexts_v2(DltDaemon *daemon, /* Check tmp_id_size = apid2len + 1 is required for null termination */ tmp_id_size = (uint8_t)(user_list->contexts[i].apid2len + 1); dlt_set_id_v2(tmp_id, user_list->contexts[i].apid2, user_list->contexts[i].apid2len); - } - else if (cmp_flag == DLT_DAEMON_LOGSTORAGE_CMP_CTID) { + } else if (cmp_flag == DLT_DAEMON_LOGSTORAGE_CMP_CTID) { /* Check tmp_id_size = ctid2len + 1 is required for null termination */ tmp_id_size = (uint8_t)(user_list->contexts[i].ctid2len + 1); dlt_set_id_v2(tmp_id, user_list->contexts[i].ctid2, user_list->contexts[i].ctid2len); - } - else { + } else { /* this is for the case when both apid and ctid are wildcard */ dlt_set_id(tmp_id, ".*"); - tmp_id_size = (uint8_t)strlen(tmp_id); // 3 (2 chars + null termination) + tmp_id_size = (uint8_t)strlen(tmp_id); // 3 (2 chars + null termination) } if (strncmp(id, tmp_id, tmp_id_size) == 0) { if (curr_log_level > 0) - dlt_daemon_logstorage_send_log_level(daemon, - daemon_local, - &user_list->contexts[i], - ecuid, - curr_log_level, - verbose); + dlt_daemon_logstorage_send_log_level( + daemon, daemon_local, &user_list->contexts[i], ecuid, curr_log_level, verbose); else /* The request is to reset log levels */ - dlt_daemon_logstorage_reset_log_level(daemon, - daemon_local, - &user_list->contexts[i], - ecuid, - curr_log_level, - verbose); + dlt_daemon_logstorage_reset_log_level( + daemon, daemon_local, &user_list->contexts[i], ecuid, curr_log_level, verbose); } } @@ -825,18 +716,13 @@ DltReturnValue dlt_logstorage_update_all_contexts_v2(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DltReturnValue dlt_logstorage_update_context(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *ecuid, - int curr_log_level, - int verbose) +DltReturnValue dlt_logstorage_update_context( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* apid, char* ctid, char* ecuid, int curr_log_level, + int verbose) { - DltDaemonContext *context = NULL; + DltDaemonContext* context = NULL; - if ((daemon == NULL) || (daemon_local == NULL) || (apid == NULL) - || (ctid == NULL) || (ecuid == NULL)) { + if ((daemon == NULL) || (daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL)) { dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -845,41 +731,19 @@ DltReturnValue dlt_logstorage_update_context(DltDaemon *daemon, if (context != NULL) { if (curr_log_level > 0) - return dlt_daemon_logstorage_send_log_level(daemon, - daemon_local, - context, - ecuid, - curr_log_level, - verbose); + return dlt_daemon_logstorage_send_log_level(daemon, daemon_local, context, ecuid, curr_log_level, verbose); else /* The request is to reset log levels */ - return dlt_daemon_logstorage_reset_log_level(daemon, - daemon_local, - context, - ecuid, - curr_log_level, - verbose); - } - else { + return dlt_daemon_logstorage_reset_log_level(daemon, daemon_local, context, ecuid, curr_log_level, verbose); + } else { if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) != 0) { /* we intentionally have no data provided by passive node. */ /* We blindly send the log level or reset log level */ - return dlt_daemon_logstorage_force_reset_level(daemon, - daemon_local, - apid, - ctid, - ecuid, - curr_log_level, - verbose); - } - else { - dlt_vlog(LOG_WARNING, - "%s: No information about APID: %s, CTID: %s, ECU: %s\n", - __func__, - apid, - ctid, - ecuid); + return dlt_daemon_logstorage_force_reset_level( + daemon, daemon_local, apid, ctid, ecuid, curr_log_level, verbose); + } else { + dlt_vlog( + LOG_WARNING, "%s: No information about APID: %s, CTID: %s, ECU: %s\n", __func__, apid, ctid, ecuid); return DLT_RETURN_ERROR; - } } @@ -898,16 +762,13 @@ DltReturnValue dlt_logstorage_update_context(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *key, - int curr_log_level, - int verbose) +DltReturnValue dlt_logstorage_update_context_loglevel( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* key, int curr_log_level, int verbose) { int cmp_flag = 0; - char apid[DLT_ID_SIZE + 1] = { '\0' }; - char ctid[DLT_ID_SIZE + 1] = { '\0' }; - char ecuid[DLT_ID_SIZE + 1] = { '\0' }; + char apid[DLT_ID_SIZE + 1] = {'\0'}; + char ctid[DLT_ID_SIZE + 1] = {'\0'}; + char ecuid[DLT_ID_SIZE + 1] = {'\0'}; PRINT_FUNCTION_VERBOSE(verbose); @@ -915,8 +776,7 @@ DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon, return DLT_RETURN_WRONG_PARAMETER; if (dlt_logstorage_split_key(key, apid, ctid, ecuid) != 0) { - dlt_log(LOG_ERR, - "Error while updating application log levels (split key)\n"); + dlt_log(LOG_ERR, "Error while updating application log levels (split key)\n"); return DLT_RETURN_ERROR; } @@ -927,51 +787,27 @@ DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon, if (strcmp(ctid, ".*") == 0 && strcmp(apid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_ECID; - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - apid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) + if (dlt_logstorage_update_all_contexts(daemon, daemon_local, apid, curr_log_level, cmp_flag, ecuid, verbose) + != 0) return DLT_RETURN_ERROR; - } - else if (strcmp(ctid, ".*") == 0) { + } else if (strcmp(ctid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_APID; - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - apid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) + if (dlt_logstorage_update_all_contexts(daemon, daemon_local, apid, curr_log_level, cmp_flag, ecuid, verbose) + != 0) return DLT_RETURN_ERROR; } /* wildcard for application id, find all contexts with context id */ - else if (strcmp(apid, ".*") == 0) - { + else if (strcmp(apid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_CTID; - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - ctid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) + if (dlt_logstorage_update_all_contexts(daemon, daemon_local, ctid, curr_log_level, cmp_flag, ecuid, verbose) + != 0) return DLT_RETURN_ERROR; } /* In case of given application id, context id pair, call available context * find function */ - else if (dlt_logstorage_update_context(daemon, - daemon_local, - apid, - ctid, - ecuid, - curr_log_level, - verbose) != 0) - { + else if (dlt_logstorage_update_context(daemon, daemon_local, apid, ctid, ecuid, curr_log_level, verbose) != 0) { return DLT_RETURN_ERROR; } @@ -990,26 +826,22 @@ DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 on error */ -DltReturnValue dlt_logstorage_update_context_loglevel_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *key, - int curr_log_level, - int verbose) +DltReturnValue dlt_logstorage_update_context_loglevel_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* key, int curr_log_level, int verbose) { int cmp_flag = 0; - char apid[DLT_ID_SIZE + 1] = { '\0' }; - char ctid[DLT_ID_SIZE + 1] = { '\0' }; - char ecuid[DLT_ID_SIZE + 1] = { '\0' }; + char apid[DLT_ID_SIZE + 1] = {'\0'}; + char ctid[DLT_ID_SIZE + 1] = {'\0'}; + char ecuid[DLT_ID_SIZE + 1] = {'\0'}; PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (daemon_local == NULL) || (key == NULL)) return DLT_RETURN_WRONG_PARAMETER; - //TBD: REVIEW Add dlt_logstorage_split_key_v2 function to handle variable length IDs + // TBD: REVIEW Add dlt_logstorage_split_key_v2 function to handle variable length IDs if (dlt_logstorage_split_key(key, apid, ctid, ecuid) != 0) { - dlt_log(LOG_ERR, - "Error while updating application log levels (split key)\n"); + dlt_log(LOG_ERR, "Error while updating application log levels (split key)\n"); return DLT_RETURN_ERROR; } @@ -1020,51 +852,27 @@ DltReturnValue dlt_logstorage_update_context_loglevel_v2(DltDaemon *daemon, if (strcmp(ctid, ".*") == 0 && strcmp(apid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_ECID; - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - apid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) + if (dlt_logstorage_update_all_contexts(daemon, daemon_local, apid, curr_log_level, cmp_flag, ecuid, verbose) + != 0) return DLT_RETURN_ERROR; - } - else if (strcmp(ctid, ".*") == 0) { + } else if (strcmp(ctid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_APID; - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - apid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) + if (dlt_logstorage_update_all_contexts(daemon, daemon_local, apid, curr_log_level, cmp_flag, ecuid, verbose) + != 0) return DLT_RETURN_ERROR; } /* wildcard for application id, find all contexts with context id */ - else if (strcmp(apid, ".*") == 0) - { + else if (strcmp(apid, ".*") == 0) { cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_CTID; - if (dlt_logstorage_update_all_contexts(daemon, - daemon_local, - ctid, - curr_log_level, - cmp_flag, - ecuid, - verbose) != 0) + if (dlt_logstorage_update_all_contexts(daemon, daemon_local, ctid, curr_log_level, cmp_flag, ecuid, verbose) + != 0) return DLT_RETURN_ERROR; } /* In case of given application id, context id pair, call available context * find function */ - else if (dlt_logstorage_update_context(daemon, - daemon_local, - apid, - ctid, - ecuid, - curr_log_level, - verbose) != 0) - { + else if (dlt_logstorage_update_context(daemon, daemon_local, apid, ctid, ecuid, curr_log_level, verbose) != 0) { return DLT_RETURN_ERROR; } @@ -1086,59 +894,45 @@ DltReturnValue dlt_logstorage_update_context_loglevel_v2(DltDaemon *daemon, * @param max_device Maximum storage devices setup by the daemon * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int dev_num, - int max_device, - int verbose) +void dlt_daemon_logstorage_reset_application_loglevel( + DltDaemon* daemon, DltDaemonLocal* daemon_local, int dev_num, int max_device, int verbose) { - DltLogStorage *handle = NULL; - DltLogStorageFilterList **tmp = NULL; + DltLogStorage* handle = NULL; + DltLogStorageFilterList** tmp = NULL; int i = 0; - char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' }; + char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {'\0'}; unsigned int status; int log_level = 0; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (daemon_local == NULL) || - (daemon->storage_handle == NULL) || (dev_num < 0)) { - dlt_vlog(LOG_ERR, - "Invalid function parameters used for %s\n", - __func__); + if ((daemon == NULL) || (daemon_local == NULL) || (daemon->storage_handle == NULL) || (dev_num < 0)) { + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return; } handle = &(daemon->storage_handle[dev_num]); - if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || - (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return; /* for all filters (keys) check if application context are already running * and log level need to be reset*/ tmp = &(handle->config_list); - while (*(tmp) != NULL) - { - for (i = 0; i < (*tmp)->num_keys; i++) - { + while (*(tmp) != NULL) { + for (i = 0; i < (*tmp)->num_keys; i++) { memset(key, 0, sizeof(key)); - strncpy(key, ((*tmp)->key_list - + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + strncpy( + key, ((*tmp)->key_list + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); /* dlt-daemon wants to reset loglevel if * a logstorage device is disconnected. */ log_level = DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL; - dlt_logstorage_update_context_loglevel( - daemon, - daemon_local, - key, - log_level, - verbose); + dlt_logstorage_update_context_loglevel(daemon, daemon_local, key, log_level, verbose); } tmp = &(*tmp)->next; } @@ -1151,10 +945,7 @@ void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, continue; if (status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) - dlt_daemon_logstorage_update_application_loglevel(daemon, - daemon_local, - i, - verbose); + dlt_daemon_logstorage_update_application_loglevel(daemon, daemon_local, i, verbose); } return; @@ -1173,60 +964,47 @@ void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, * @param dev_num Number of attached DLT Logstorage device * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int dev_num, - int verbose) +void dlt_daemon_logstorage_update_application_loglevel( + DltDaemon* daemon, DltDaemonLocal* daemon_local, int dev_num, int verbose) { - DltLogStorage *handle = NULL; - DltLogStorageFilterList **tmp = NULL; - char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' }; + DltLogStorage* handle = NULL; + DltLogStorageFilterList** tmp = NULL; + char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {'\0'}; int i = 0; int log_level = 0; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (daemon_local == NULL) || (dev_num < 0)) - { - dlt_vlog(LOG_ERR, - "Invalid function parameters used for %s\n", - __func__); + if ((daemon == NULL) || (daemon_local == NULL) || (dev_num < 0)) { + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return; } handle = &(daemon->storage_handle[dev_num]); - if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || - (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return; /* for all filters (keys) check if application or context already running * and log level need to be updated*/ tmp = &(handle->config_list); - while (*(tmp) != NULL) - { - for (i = 0; i < (*tmp)->num_keys; i++) - { + while (*(tmp) != NULL) { + for (i = 0; i < (*tmp)->num_keys; i++) { memset(key, 0, sizeof(key)); - strncpy(key, ((*tmp)->key_list - + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + strncpy( + key, ((*tmp)->key_list + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); /* Obtain storage configuration data */ log_level = dlt_logstorage_get_loglevel_by_key(handle, key); - if (log_level < 0) - { + if (log_level < 0) { dlt_log(LOG_ERR, "Failed to get log level by key \n"); return; } /* Update context log level with storage configuration log level */ - dlt_logstorage_update_context_loglevel(daemon, - daemon_local, - key, - log_level, - verbose); + dlt_logstorage_update_context_loglevel(daemon, daemon_local, key, log_level, verbose); } tmp = &(*tmp)->next; } @@ -1247,60 +1025,47 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, * @param dev_num Number of attached DLT Logstorage device * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_update_application_loglevel_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int dev_num, - int verbose) +void dlt_daemon_logstorage_update_application_loglevel_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, int dev_num, int verbose) { - DltLogStorage *handle = NULL; - DltLogStorageFilterList **tmp = NULL; - char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' }; + DltLogStorage* handle = NULL; + DltLogStorageFilterList** tmp = NULL; + char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {'\0'}; int i = 0; int log_level = 0; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (daemon_local == NULL) || (dev_num < 0)) - { - dlt_vlog(LOG_ERR, - "Invalid function parameters used for %s\n", - __func__); + if ((daemon == NULL) || (daemon_local == NULL) || (dev_num < 0)) { + dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); return; } handle = &(daemon->storage_handle[dev_num]); - if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || - (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return; /* for all filters (keys) check if application or context already running * and log level need to be updated*/ tmp = &(handle->config_list); - while (*(tmp) != NULL) - { - for (i = 0; i < (*tmp)->num_keys; i++) - { + while (*(tmp) != NULL) { + for (i = 0; i < (*tmp)->num_keys; i++) { memset(key, 0, sizeof(key)); - strncpy(key, ((*tmp)->key_list - + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + strncpy( + key, ((*tmp)->key_list + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); /* Obtain storage configuration data */ log_level = dlt_logstorage_get_loglevel_by_key(handle, key); - if (log_level < 0) - { + if (log_level < 0) { dlt_log(LOG_ERR, "Failed to get log level by key \n"); return; } /* Update context log level with storage configuration log level */ - dlt_logstorage_update_context_loglevel(daemon, - daemon_local, - key, - log_level, - verbose); + dlt_logstorage_update_context_loglevel(daemon, daemon_local, key, log_level, verbose); } tmp = &(*tmp)->next; } @@ -1320,12 +1085,9 @@ void dlt_daemon_logstorage_update_application_loglevel_v2(DltDaemon *daemon, * @param ctid Context ID * @return Log level on success, -1 on error */ -int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, - int max_device, - char *apid, - char *ctid) +int dlt_daemon_logstorage_get_loglevel(DltDaemon* daemon, int max_device, char* apid, char* ctid) { - DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + DltLogStorageFilterConfig* config[DLT_CONFIG_FILE_SECTIONS_MAX] = {0}; int i = 0; int j = 0; int8_t storage_loglevel = -1; @@ -1336,21 +1098,15 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, return DLT_RETURN_WRONG_PARAMETER; for (i = 0; i < max_device; i++) - if (daemon->storage_handle[i].config_status == - DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { - num_config = dlt_logstorage_get_config(&(daemon->storage_handle[i]), - config, - apid, - ctid, - daemon->ecuid); + if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { + num_config = dlt_logstorage_get_config(&(daemon->storage_handle[i]), config, apid, ctid, daemon->ecuid); if (num_config == 0) { dlt_log(LOG_DEBUG, "No valid filter configuration found\n"); continue; } - for (j = 0; j < num_config; j++) - { + for (j = 0; j < num_config; j++) { if (config[j] == NULL) continue; @@ -1362,9 +1118,7 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, } configured_loglevel = (int8_t)config[j]->log_level; - storage_loglevel = (int8_t)DLT_OFFLINE_LOGSTORAGE_MAX( - configured_loglevel, - storage_loglevel); + storage_loglevel = (int8_t)DLT_OFFLINE_LOGSTORAGE_MAX(configured_loglevel, storage_loglevel); } } @@ -1388,26 +1142,18 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, * @param size3 message data size * @return 0 on success, -1 on error, 1 on disable network routing */ -int dlt_daemon_logstorage_write(DltDaemon *daemon, - DltDaemonFlags *user_config, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3) +int dlt_daemon_logstorage_write( + DltDaemon* daemon, DltDaemonFlags* user_config, unsigned char* data1, int size1, unsigned char* data2, int size2, + unsigned char* data3, int size3) { static bool disable_nw_warning_sent = false; int i = 0; int ret = 0; DltLogStorageUserConfig file_config; - if ((daemon == NULL) || (user_config == NULL) || - (user_config->offlineLogstorageMaxDevices <= 0) || (data1 == NULL) || - (data2 == NULL) || (data3 == NULL)) { - dlt_vlog(LOG_DEBUG, - "%s: message type is not LOG. Skip storing.\n", - __func__); + if ((daemon == NULL) || (user_config == NULL) || (user_config->offlineLogstorageMaxDevices <= 0) || (data1 == NULL) + || (data2 == NULL) || (data3 == NULL)) { + dlt_vlog(LOG_DEBUG, "%s: message type is not LOG. Skip storing.\n", __func__); return -1; /* Log Level changed callback */ } @@ -1417,41 +1163,33 @@ int dlt_daemon_logstorage_write(DltDaemon *daemon, file_config.logfile_delimiter = user_config->offlineLogstorageDelimiter; file_config.logfile_maxcounter = user_config->offlineLogstorageMaxCounter; file_config.logfile_optional_counter = user_config->offlineLogstorageOptionalCounter; - file_config.logfile_counteridxlen = - user_config->offlineLogstorageMaxCounterIdx; + file_config.logfile_counteridxlen = user_config->offlineLogstorageMaxCounterIdx; for (i = 0; i < user_config->offlineLogstorageMaxDevices; i++) { - if (daemon->storage_handle[i].config_status == - DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { + if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { int disable_nw = 0; - if ((ret = dlt_logstorage_write(&(daemon->storage_handle[i]), - &file_config, - data1, - size1, - data2, - size2, - data3, - size3, - &disable_nw)) < 0) { - dlt_log(LOG_ERR, - "dlt_daemon_logstorage_write: failed. " - "Disable storage device\n"); + if ((ret = dlt_logstorage_write( + &(daemon->storage_handle[i]), &file_config, data1, size1, data2, size2, data3, size3, &disable_nw)) + < 0) { + dlt_log( + LOG_ERR, + "dlt_daemon_logstorage_write: failed. " + "Disable storage device\n"); /* DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS happened, * therefore remove logstorage device */ dlt_logstorage_device_disconnected( - &(daemon->storage_handle[i]), - DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); + &(daemon->storage_handle[i]), DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); } if (disable_nw == 1) { if (i == 0) { ret = 1; - } - else if (disable_nw_warning_sent == false) { + } else if (disable_nw_warning_sent == false) { disable_nw_warning_sent = true; - dlt_vlog(LOG_WARNING, - "%s: DisableNetwork is not supported for more " - "than one device yet\n", - __func__); + dlt_vlog( + LOG_WARNING, + "%s: DisableNetwork is not supported for more " + "than one device yet\n", + __func__); } } } @@ -1471,10 +1209,8 @@ int dlt_daemon_logstorage_write(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return 0 on sucess, -1 otherwise */ -int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *path, - int verbose) +int dlt_daemon_logstorage_setup_internal_storage( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* path, int verbose) { int ret = 0; @@ -1493,19 +1229,14 @@ int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, } /* check if log level of running application need an update */ - dlt_daemon_logstorage_update_application_loglevel(daemon, - daemon_local, - 0, - verbose); - - if (daemon->storage_handle[0].maintain_logstorage_loglevel != - DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) { - daemon->maintain_logstorage_loglevel = - daemon->storage_handle[0].maintain_logstorage_loglevel; - - dlt_vlog(LOG_DEBUG, "[%s] Startup with maintain loglevel: [%d]\n", - __func__, - daemon->storage_handle[0].maintain_logstorage_loglevel); + dlt_daemon_logstorage_update_application_loglevel(daemon, daemon_local, 0, verbose); + + if (daemon->storage_handle[0].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) { + daemon->maintain_logstorage_loglevel = daemon->storage_handle[0].maintain_logstorage_loglevel; + + dlt_vlog( + LOG_DEBUG, "[%s] Startup with maintain loglevel: [%d]\n", __func__, + daemon->storage_handle[0].maintain_logstorage_loglevel); } return ret; @@ -1517,9 +1248,7 @@ void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size) g_logstorage_cache_max = size * 1024; } -int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +int dlt_daemon_logstorage_cleanup(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { int i = 0; @@ -1530,35 +1259,25 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) /* call disconnect on all currently connected devices */ - if (daemon->storage_handle[i].connection_type == - DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) - { + if (daemon->storage_handle[i].connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { (&daemon->storage_handle[i])->uconfig.logfile_counteridxlen = - daemon_local->flags.offlineLogstorageMaxCounterIdx; - (&daemon->storage_handle[i])->uconfig.logfile_delimiter = - daemon_local->flags.offlineLogstorageDelimiter; - (&daemon->storage_handle[i])->uconfig.logfile_maxcounter = - daemon_local->flags.offlineLogstorageMaxCounter; - (&daemon->storage_handle[i])->uconfig.logfile_timestamp = - daemon_local->flags.offlineLogstorageTimestamp; + daemon_local->flags.offlineLogstorageMaxCounterIdx; + (&daemon->storage_handle[i])->uconfig.logfile_delimiter = daemon_local->flags.offlineLogstorageDelimiter; + (&daemon->storage_handle[i])->uconfig.logfile_maxcounter = daemon_local->flags.offlineLogstorageMaxCounter; + (&daemon->storage_handle[i])->uconfig.logfile_timestamp = daemon_local->flags.offlineLogstorageTimestamp; (&daemon->storage_handle[i])->uconfig.logfile_optional_counter = - daemon_local->flags.offlineLogstorageOptionalCounter; + daemon_local->flags.offlineLogstorageOptionalCounter; - dlt_logstorage_device_disconnected( - &daemon->storage_handle[i], - DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT); + dlt_logstorage_device_disconnected(&daemon->storage_handle[i], DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT); } return 0; } -int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *mnt_point, - int verbose) +int dlt_daemon_logstorage_sync_cache(DltDaemon* daemon, DltDaemonLocal* daemon_local, char* mnt_point, int verbose) { int i = 0; - DltLogStorage *handle = NULL; + DltLogStorage* handle = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1566,43 +1285,29 @@ int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, return DLT_RETURN_WRONG_PARAMETER; if (strlen(mnt_point) > 0) { /* mount point is given */ - handle = dlt_daemon_logstorage_get_device(daemon, - daemon_local, - mnt_point, - verbose); + handle = dlt_daemon_logstorage_get_device(daemon, daemon_local, mnt_point, verbose); if (handle == NULL) { return DLT_RETURN_ERROR; - } - else { - handle->uconfig.logfile_counteridxlen = - daemon_local->flags.offlineLogstorageMaxCounterIdx; - handle->uconfig.logfile_delimiter = - daemon_local->flags.offlineLogstorageDelimiter; - handle->uconfig.logfile_maxcounter = - daemon_local->flags.offlineLogstorageMaxCounter; - handle->uconfig.logfile_timestamp = - daemon_local->flags.offlineLogstorageTimestamp; - handle->uconfig.logfile_optional_counter = - daemon_local->flags.offlineLogstorageOptionalCounter; + } else { + handle->uconfig.logfile_counteridxlen = daemon_local->flags.offlineLogstorageMaxCounterIdx; + handle->uconfig.logfile_delimiter = daemon_local->flags.offlineLogstorageDelimiter; + handle->uconfig.logfile_maxcounter = daemon_local->flags.offlineLogstorageMaxCounter; + handle->uconfig.logfile_timestamp = daemon_local->flags.offlineLogstorageTimestamp; + handle->uconfig.logfile_optional_counter = daemon_local->flags.offlineLogstorageOptionalCounter; if (dlt_logstorage_sync_caches(handle) != 0) return DLT_RETURN_ERROR; } - } - else { /* sync caches for all connected logstorage devices */ + } else { /* sync caches for all connected logstorage devices */ for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) - if (daemon->storage_handle[i].connection_type == - DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { + if (daemon->storage_handle[i].connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { daemon->storage_handle[i].uconfig.logfile_counteridxlen = daemon_local->flags.offlineLogstorageMaxCounterIdx; - daemon->storage_handle[i].uconfig.logfile_delimiter = - daemon_local->flags.offlineLogstorageDelimiter; - daemon->storage_handle[i].uconfig.logfile_maxcounter = - daemon_local->flags.offlineLogstorageMaxCounter; - daemon->storage_handle[i].uconfig.logfile_timestamp = - daemon_local->flags.offlineLogstorageTimestamp; + daemon->storage_handle[i].uconfig.logfile_delimiter = daemon_local->flags.offlineLogstorageDelimiter; + daemon->storage_handle[i].uconfig.logfile_maxcounter = daemon_local->flags.offlineLogstorageMaxCounter; + daemon->storage_handle[i].uconfig.logfile_timestamp = daemon_local->flags.offlineLogstorageTimestamp; daemon->storage_handle[i].uconfig.logfile_optional_counter = daemon_local->flags.offlineLogstorageOptionalCounter; @@ -1614,10 +1319,8 @@ int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, return 0; } -DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *mnt_point, - int verbose) +DltLogStorage* dlt_daemon_logstorage_get_device( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* mnt_point, int verbose) { int i = 0; int len = 0; diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h index 668c94c98..b64a1ca21 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.h +++ b/src/daemon/dlt_daemon_offline_logstorage.h @@ -39,14 +39,14 @@ ******************************************************************************/ /******************************************************************************* -* Author Identity ** -******************************************************************************* -* ** -* Initials Name Company ** -* -------- ------------------------- ---------------------------------- ** -* sh Syed Hameed ADIT ** -* cl Christoph Lipka ADIT ** -*******************************************************************************/ + * Author Identity ** + ******************************************************************************* + * ** + * Initials Name Company ** + * -------- ------------------------- ---------------------------------- ** + * sh Syed Hameed ADIT ** + * cl Christoph Lipka ADIT ** + *******************************************************************************/ #ifndef DLT_DAEMON_OFFLINE_LOGSTORAGE_H #define DLT_DAEMON_OFFLINE_LOGSTORAGE_H @@ -55,8 +55,8 @@ #include "dlt_offline_logstorage.h" -#define DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL -1 -#define DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL 0 +#define DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL -1 +#define DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL 0 typedef enum { DLT_DAEMON_LOGSTORAGE_CMP_MIN = 0, @@ -78,10 +78,7 @@ typedef enum { * @param ctid Context ID * @return Log level on success, -1 on error */ -int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, - int max_device, - char *apid, - char *ctid); +int dlt_daemon_logstorage_get_loglevel(DltDaemon* daemon, int max_device, char* apid, char* ctid); /** * dlt_daemon_logstorage_reset_application_loglevel * @@ -92,11 +89,8 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, * @param dev_num Number of attached DLT Logstorage device * @param verbose If set to true verbose information is printed out */ -void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int dev_num, - int max_device, - int verbose); +void dlt_daemon_logstorage_reset_application_loglevel( + DltDaemon* daemon, DltDaemonLocal* daemon_local, int dev_num, int max_device, int verbose); /** * dlt_daemon_logstorage_update_application_loglevel * @@ -110,10 +104,8 @@ void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, * @param dev_num Number of attached DLT Logstorage device * @param verbose if set to true verbose information is printed out */ -void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int dev_num, - int verbose); +void dlt_daemon_logstorage_update_application_loglevel( + DltDaemon* daemon, DltDaemonLocal* daemon_local, int dev_num, int verbose); /** * dlt_daemon_logstorage_update_application_loglevel_v2 @@ -128,10 +120,8 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, * @param dev_num Number of attached DLT Logstorage device * @param verbose if set to true verbose information is printed out */ -void dlt_daemon_logstorage_update_application_loglevel_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int dev_num, - int verbose); +void dlt_daemon_logstorage_update_application_loglevel_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, int dev_num, int verbose); /** * dlt_daemon_logstorage_write @@ -150,14 +140,9 @@ void dlt_daemon_logstorage_update_application_loglevel_v2(DltDaemon *daemon, * @param size3 message data size * @return 0 on success, -1 on error, 1 on disable network routing */ -int dlt_daemon_logstorage_write(DltDaemon *daemon, - DltDaemonFlags *user_config, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3); +int dlt_daemon_logstorage_write( + DltDaemon* daemon, DltDaemonFlags* user_config, unsigned char* data1, int size1, unsigned char* data2, int size2, + unsigned char* data3, int size3); /** * dlt_daemon_logstorage_setup_internal_storage @@ -169,10 +154,8 @@ int dlt_daemon_logstorage_write(DltDaemon *daemon, * @param path User configured internal storage path * @param verbose If set to true verbose information is printed out */ -int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *path, - int verbose); +int dlt_daemon_logstorage_setup_internal_storage( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* path, int verbose); /** * Set max size of logstorage cache. Stored internally in bytes @@ -188,9 +171,7 @@ void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size); * @param daemon_local Pointer to Dlt Daemon Local structure * @param verbose If set to true verbose information is printed out */ -int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose); +int dlt_daemon_logstorage_cleanup(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose); /** * Sync logstorage caches @@ -201,10 +182,7 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return 0 on success, -1 otherwise */ -int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *mnt_point, - int verbose); +int dlt_daemon_logstorage_sync_cache(DltDaemon* daemon, DltDaemonLocal* daemon_local, char* mnt_point, int verbose); /** * dlt_logstorage_get_device @@ -217,9 +195,7 @@ int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, * @param verbose If set to true verbose information is printed out * @return handle to Logstorage device on success, NULL otherwise */ -DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *mnt_point, - int verbose); +DltLogStorage* dlt_daemon_logstorage_get_device( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* mnt_point, int verbose); #endif /* DLT_DAEMON_OFFLINE_LOGSTORAGE_H */ diff --git a/src/daemon/dlt_daemon_offline_logstorage_internal.h b/src/daemon/dlt_daemon_offline_logstorage_internal.h index b0a959317..13c07dfd2 100644 --- a/src/daemon/dlt_daemon_offline_logstorage_internal.h +++ b/src/daemon/dlt_daemon_offline_logstorage_internal.h @@ -37,56 +37,35 @@ ******************************************************************************/ /******************************************************************************* -* Author Identity ** -******************************************************************************* -* ** -* Initials Name Company ** -* -------- ------------------------- ---------------------------------- ** -* ap Aditya Paluri ADIT ** -*******************************************************************************/ + * Author Identity ** + ******************************************************************************* + * ** + * Initials Name Company ** + * -------- ------------------------- ---------------------------------- ** + * ap Aditya Paluri ADIT ** + *******************************************************************************/ #ifndef DLT_DAEMON_OFFLINE_LOGSTORAGE_INTERNAL_H #define DLT_DAEMON_OFFLINE_LOGSTORAGE_INTERNAL_H -DLT_STATIC DltReturnValue dlt_logstorage_split_key(char *key, - char *apid, - char *ctid, - char *ecuid); +DLT_STATIC DltReturnValue dlt_logstorage_split_key(char* key, char* apid, char* ctid, char* ecuid); -DltReturnValue dlt_logstorage_update_all_contexts(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *id, - int curr_log_level, - int cmp_flag, - char *ecuid, - int verbose); +DltReturnValue dlt_logstorage_update_all_contexts( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* id, int curr_log_level, int cmp_flag, char* ecuid, + int verbose); -DltReturnValue dlt_logstorage_update_all_contexts_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *id, - int curr_log_level, - int cmp_flag, - char *ecuid, - int verbose); +DltReturnValue dlt_logstorage_update_all_contexts_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* id, int curr_log_level, int cmp_flag, char* ecuid, + int verbose); -DltReturnValue dlt_logstorage_update_context(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *apid, - char *ctid, - char *ecuid, - int curr_log_level, - int verbose); +DltReturnValue dlt_logstorage_update_context( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* apid, char* ctid, char* ecuid, int curr_log_level, + int verbose); -DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *key, - int curr_log_level, - int verbose); +DltReturnValue dlt_logstorage_update_context_loglevel( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* key, int curr_log_level, int verbose); -DltReturnValue dlt_logstorage_update_context_loglevel_v2(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *key, - int curr_log_level, - int verbose); +DltReturnValue dlt_logstorage_update_context_loglevel_v2( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* key, int curr_log_level, int verbose); #endif diff --git a/src/daemon/dlt_daemon_serial.c b/src/daemon/dlt_daemon_serial.c index f71fef4cb..9aec8ecce 100644 --- a/src/daemon/dlt_daemon_serial.c +++ b/src/daemon/dlt_daemon_serial.c @@ -66,12 +66,7 @@ #include "dlt_daemon_serial.h" -int dlt_daemon_serial_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader) +int dlt_daemon_serial_send(int sock, void* data1, int size1, void* data2, int size2, char serialheader) { /* Optional: Send serial header, if requested */ if (serialheader) { diff --git a/src/daemon/dlt_daemon_serial.h b/src/daemon/dlt_daemon_serial.h index fa611e48a..cdc2cddc6 100644 --- a/src/daemon/dlt_daemon_serial.h +++ b/src/daemon/dlt_daemon_serial.h @@ -60,11 +60,6 @@ #include "dlt_common.h" #include "dlt_user.h" -int dlt_daemon_serial_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader); +int dlt_daemon_serial_send(int sock, void* data1, int size1, void* data2, int size2, char serialheader); #endif /* DLT_DAEMON_SERIAL_H */ diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c index cf163189f..681222c36 100644 --- a/src/daemon/dlt_daemon_socket.c +++ b/src/daemon/dlt_daemon_socket.c @@ -36,9 +36,9 @@ #pragma GCC diagnostic push #pragma GCC diagnostic pop -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() */ #include #include #include @@ -65,7 +65,7 @@ #include "dlt_daemon_socket.h" -int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip) +int dlt_daemon_socket_open(int* sock, unsigned int servPort, char* ip) { int yes = 1; int ret_inet_pton = 1; @@ -76,8 +76,7 @@ int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip) /* create socket */ if ((*sock = socket(AF_INET6, SOCK_STREAM, 0)) == -1) { lastErrno = errno; - dlt_vlog(LOG_ERR, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, - strerror(lastErrno)); + dlt_vlog(LOG_ERR, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, strerror(lastErrno)); return -1; } @@ -85,8 +84,7 @@ int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip) if ((*sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { lastErrno = errno; - dlt_vlog(LOG_ERR, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, - strerror(lastErrno)); + dlt_vlog(LOG_ERR, "dlt_daemon_socket_open: socket() error %d: %s\n", lastErrno, strerror(lastErrno)); return -1; } @@ -98,9 +96,7 @@ int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip) if (setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { lastErrno = errno; dlt_vlog( - LOG_ERR, - "dlt_daemon_socket_open: Setsockopt error %d in dlt_daemon_local_connection_init: %s\n", - lastErrno, + LOG_ERR, "dlt_daemon_socket_open: Setsockopt error %d in dlt_daemon_local_connection_init: %s\n", lastErrno, strerror(lastErrno)); return -1; } @@ -130,19 +126,15 @@ int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip) if (ret_inet_pton != 1) { lastErrno = errno; dlt_vlog( - LOG_WARNING, - "dlt_daemon_socket_open: inet_pton() error %d: %s. Cannot convert IP address: %s\n", - lastErrno, - strerror(lastErrno), - ip); + LOG_WARNING, "dlt_daemon_socket_open: inet_pton() error %d: %s. Cannot convert IP address: %s\n", lastErrno, + strerror(lastErrno), ip); return -1; } - if (bind(*sock, (struct sockaddr *)&forced_addr, sizeof(forced_addr)) == -1) { - lastErrno = errno; /*close() may set errno too */ + if (bind(*sock, (struct sockaddr*)&forced_addr, sizeof(forced_addr)) == -1) { + lastErrno = errno; /*close() may set errno too */ close(*sock); - dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: bind() error %d: %s\n", lastErrno, - strerror(lastErrno)); + dlt_vlog(LOG_WARNING, "dlt_daemon_socket_open: bind() error %d: %s\n", lastErrno, strerror(lastErrno)); return -1; } @@ -150,15 +142,14 @@ int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip) dlt_vlog(LOG_INFO, "%s: Listening on ip %s and port: %u\n", __func__, ip, servPort); /* get socket buffer size */ - dlt_vlog(LOG_INFO, "dlt_daemon_socket_open: Socket send queue size: %d\n", - dlt_daemon_socket_get_send_qeue_max_size(*sock)); + dlt_vlog( + LOG_INFO, "dlt_daemon_socket_open: Socket send queue size: %d\n", + dlt_daemon_socket_get_send_qeue_max_size(*sock)); if (listen(*sock, 3) < 0) { lastErrno = errno; - dlt_vlog(LOG_WARNING, - "dlt_daemon_socket_open: listen() failed with error %d: %s\n", - lastErrno, - strerror(lastErrno)); + dlt_vlog( + LOG_WARNING, "dlt_daemon_socket_open: listen() failed with error %d: %s\n", lastErrno, strerror(lastErrno)); return -1; } @@ -172,20 +163,13 @@ int dlt_daemon_socket_close(int sock) return 0; } -int dlt_daemon_socket_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader) +int dlt_daemon_socket_send(int sock, void* data1, int size1, void* data2, int size2, char serialheader) { int ret = DLT_RETURN_OK; /* Optional: Send serial header, if requested */ if (serialheader) { - ret = dlt_daemon_socket_sendreliable(sock, - dltSerialHeader, - sizeof(dltSerialHeader)); + ret = dlt_daemon_socket_sendreliable(sock, dltSerialHeader, sizeof(dltSerialHeader)); if (ret != DLT_RETURN_OK) { return ret; @@ -212,28 +196,23 @@ int dlt_daemon_socket_get_send_qeue_max_size(int sock) { int n = 0; socklen_t m = sizeof(n); - if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void *)&n, &m) < 0) { - dlt_vlog(LOG_ERR, - "%s: socket get failed!\n", __func__); + if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void*)&n, &m) < 0) { + dlt_vlog(LOG_ERR, "%s: socket get failed!\n", __func__); return -errno; } return n; } -int dlt_daemon_socket_sendreliable(int sock, const void *data_buffer, int message_size) +int dlt_daemon_socket_sendreliable(int sock, const void* data_buffer, int message_size) { int data_sent = 0; while (data_sent < message_size) { - ssize_t ret = send(sock, - (const uint8_t *)data_buffer + data_sent, - (size_t)(message_size - data_sent), - 0); + ssize_t ret = send(sock, (const uint8_t*)data_buffer + data_sent, (size_t)(message_size - data_sent), 0); if (ret < 0) { - dlt_vlog(LOG_WARNING, - "%s: socket send failed [errno: %d]!\n", __func__, errno); + dlt_vlog(LOG_WARNING, "%s: socket send failed [errno: %d]!\n", __func__, errno); #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE /* notify systemd here that we are still alive * otherwise we might miss notifying the watchdog when diff --git a/src/daemon/dlt_daemon_socket.h b/src/daemon/dlt_daemon_socket.h index 1919c23c0..5152a1ad1 100644 --- a/src/daemon/dlt_daemon_socket.h +++ b/src/daemon/dlt_daemon_socket.h @@ -60,25 +60,21 @@ #include "dlt_common.h" #include "dlt_user.h" -int dlt_daemon_socket_open(int *sock, unsigned int servPort, char *ip); +int dlt_daemon_socket_open(int* sock, unsigned int servPort, char* ip); int dlt_daemon_socket_close(int sock); int dlt_daemon_socket_get_send_qeue_max_size(int sock); -int dlt_daemon_socket_send(int sock, - void *data1, - int size1, - void *data2, - int size2, - char serialheader); +int dlt_daemon_socket_send(int sock, void* data1, int size1, void* data2, int size2, char serialheader); /** - * @brief dlt_daemon_socket_sendreliable - sends data to socket with additional checks and resending functionality - trying to be reliable + * @brief dlt_daemon_socket_sendreliable - sends data to socket with additional checks and resending functionality - + * trying to be reliable * @param sock * @param data_buffer * @param message_size * @return on sucess: DLT_DAEMON_ERROR_OK, on error: DLT_DAEMON_ERROR_SEND_FAILED */ -int dlt_daemon_socket_sendreliable(int sock, const void *data_buffer, int message_size); +int dlt_daemon_socket_sendreliable(int sock, const void* data_buffer, int message_size); #endif /* DLT_DAEMON_SOCKET_H */ diff --git a/src/daemon/dlt_daemon_unix_socket.c b/src/daemon/dlt_daemon_unix_socket.c index 4eea60485..ad1f26c59 100644 --- a/src/daemon/dlt_daemon_unix_socket.c +++ b/src/daemon/dlt_daemon_unix_socket.c @@ -29,10 +29,10 @@ #include #include #if defined(ANDROID) -# include /* for android_get_control_socket() */ -# include /* for basename() */ +#include /* for android_get_control_socket() */ +#include /* for basename() */ #else -# include /* for socket(), connect(), (), and recv() */ +#include /* for socket(), connect(), (), and recv() */ #endif #include #include @@ -49,29 +49,24 @@ #include "dlt_daemon_unix_socket.h" #ifdef ANDROID -DltReturnValue dlt_daemon_unix_android_get_socket(int *sock, const char *sock_path) +DltReturnValue dlt_daemon_unix_android_get_socket(int* sock, const char* sock_path) { DltReturnValue ret = DLT_RETURN_OK; if ((sock == NULL) || (sock_path == NULL)) { dlt_log(LOG_ERR, "dlt_daemon_unix_android_get_socket: arguments invalid"); ret = DLT_RETURN_WRONG_PARAMETER; - } - else { + } else { const char* sock_name = basename(sock_path); if (sock_name == NULL) { - dlt_log(LOG_WARNING, - "dlt_daemon_unix_android_get_socket: can't get socket name from its path"); + dlt_log(LOG_WARNING, "dlt_daemon_unix_android_get_socket: can't get socket name from its path"); ret = DLT_RETURN_ERROR; - } - else { + } else { *sock = android_get_control_socket(sock_name); if (*sock < 0) { - dlt_log(LOG_WARNING, - "dlt_daemon_unix_android_get_socket: can get socket from init"); + dlt_log(LOG_WARNING, "dlt_daemon_unix_android_get_socket: can get socket from init"); ret = DLT_RETURN_ERROR; - } - else { + } else { if (listen(*sock, 1) == -1) { dlt_vlog(LOG_WARNING, "unix socket: listen error: %s", strerror(errno)); ret = DLT_RETURN_ERROR; @@ -84,7 +79,7 @@ DltReturnValue dlt_daemon_unix_android_get_socket(int *sock, const char *sock_pa } #endif -int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) +int dlt_daemon_unix_socket_open(int* sock, char* sock_path, int type, int mask) { struct sockaddr_un addr; mode_t old_mask; @@ -96,7 +91,7 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) #ifdef DLT_SYSTEM_SOCKET_ACTIVATION_ENABLE - char **names = NULL; + char** names = NULL; const int num_fds = sd_listen_fds_with_names(0, &names); bool sd_socket_open = false; int i; @@ -110,9 +105,10 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) } if (sd_is_socket_unix(i + SD_LISTEN_FDS_START, type, 1, names[i], strlen(names[i])) < 0) { - dlt_vlog(LOG_WARNING, - "unix socket: socket with matching name is not of correct type or not in listen mode, error: %s\n", - strerror(errno)); + dlt_vlog( + LOG_WARNING, + "unix socket: socket with matching name is not of correct type or not in listen mode, error: %s\n", + strerror(errno)); continue; } @@ -136,40 +132,37 @@ int dlt_daemon_unix_socket_open(int *sock, char *sock_path, int type, int mask) dlt_vlog(LOG_INFO, "unix socket: sock_path %s no systemd socket found\n", sock_path); #endif - if ((*sock = socket(AF_UNIX, type, 0)) == -1) { - dlt_log(LOG_WARNING, "unix socket: socket() error"); - return -1; - } + if ((*sock = socket(AF_UNIX, type, 0)) == -1) { + dlt_log(LOG_WARNING, "unix socket: socket() error"); + return -1; + } - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - memcpy(addr.sun_path, sock_path, sizeof(addr.sun_path)); + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + memcpy(addr.sun_path, sock_path, sizeof(addr.sun_path)); - if (unlink(sock_path) != 0) { - dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", - __func__, strerror(errno)); - } + if (unlink(sock_path) != 0) { + dlt_vlog(LOG_WARNING, "%s: unlink() failed: %s\n", __func__, strerror(errno)); + } - /* set appropriate access permissions */ - old_mask = umask((mode_t)mask); + /* set appropriate access permissions */ + old_mask = umask((mode_t)mask); - if (bind(*sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { - dlt_vlog(LOG_WARNING, "%s: bind() error (%s)\n", __func__, - strerror(errno)); - return -1; - } + if (bind(*sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) { + dlt_vlog(LOG_WARNING, "%s: bind() error (%s)\n", __func__, strerror(errno)); + return -1; + } - if (listen(*sock, 1) == -1) { - dlt_vlog(LOG_WARNING, "%s: listen error (%s)\n", __func__, - strerror(errno)); - return -1; - } + if (listen(*sock, 1) == -1) { + dlt_vlog(LOG_WARNING, "%s: listen error (%s)\n", __func__, strerror(errno)); + return -1; + } - /* restore permissions */ - umask((mode_t)old_mask); + /* restore permissions */ + umask((mode_t)old_mask); #ifdef DLT_SYSTEM_SOCKET_ACTIVATION_ENABLE - } // end of: if (!sd_socket_open) { + } // end of: if (!sd_socket_open) { #endif diff --git a/src/daemon/dlt_daemon_unix_socket.h b/src/daemon/dlt_daemon_unix_socket.h index b6e33ac4d..24d00e2ec 100644 --- a/src/daemon/dlt_daemon_unix_socket.h +++ b/src/daemon/dlt_daemon_unix_socket.h @@ -57,9 +57,9 @@ #define DLT_DAEMON_UNIX_SOCKET_H #ifdef ANDROID -DltReturnValue dlt_daemon_unix_android_get_socket(int *sock, const char *sock_path); +DltReturnValue dlt_daemon_unix_android_get_socket(int* sock, const char* sock_path); #endif -int dlt_daemon_unix_socket_open(int *sock, char *socket_path, int type, int mask); +int dlt_daemon_unix_socket_open(int* sock, char* socket_path, int type, int mask); int dlt_daemon_unix_socket_close(int sock); #endif /* DLT_DAEMON_UNIX_SOCKET_H */ diff --git a/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h b/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h index c3f231bb1..053c5066a 100644 --- a/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h +++ b/src/daemon/udp_connection/dlt_daemon_udp_common_socket.h @@ -24,13 +24,13 @@ #ifndef DLT_DAEMON_UDP_COMMON_SOCKET_H #define DLT_DAEMON_UDP_COMMON_SOCKET_H -#include /* for sockaddr_in and inet_addr() */ +#include /* for sockaddr_in and inet_addr() */ #include #include #include #include -#include /* for atoi() and exit() */ -#include /* for memset() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ #include #include /* for socket(), connect(), (), and recv() */ #include /* for close() */ @@ -52,17 +52,15 @@ typedef struct sockaddr_storage CLIENT_ADDR_STRUCT; typedef socklen_t CLIENT_ADDR_STRUCT_SIZE; /* udp strutures */ -typedef struct -{ +typedef struct { CLIENT_ADDR_STRUCT clientaddr; CLIENT_ADDR_STRUCT_SIZE clientaddr_size; int isvalidflag; } DltDaemonClientSockInfo; /* Function prototype declaration */ -void dlt_daemon_udp_init_clientstruct(DltDaemonClientSockInfo *clientinfo_struct); -DltReturnValue dlt_daemon_udp_socket_open(int *sock, unsigned int servPort); -void dlt_daemon_udp_setmulticast_addr(DltDaemonLocal *daemon_local); +void dlt_daemon_udp_init_clientstruct(DltDaemonClientSockInfo* clientinfo_struct); +DltReturnValue dlt_daemon_udp_socket_open(int* sock, unsigned int servPort); +void dlt_daemon_udp_setmulticast_addr(DltDaemonLocal* daemon_local); #endif /* DLT_DAEMON_UDP_COMMON_SOCKET_H */ - diff --git a/src/daemon/udp_connection/dlt_daemon_udp_socket.c b/src/daemon/udp_connection/dlt_daemon_udp_socket.c index b3408773d..81e4b6aa9 100644 --- a/src/daemon/udp_connection/dlt_daemon_udp_socket.c +++ b/src/daemon/udp_connection/dlt_daemon_udp_socket.c @@ -23,8 +23,8 @@ #include "dlt_daemon_udp_common_socket.h" -static void dlt_daemon_udp_clientmsg_send(DltDaemonClientSockInfo *clientinfo, - void *data1, int size1, void *data2, int size2, int verbose); +static void dlt_daemon_udp_clientmsg_send( + DltDaemonClientSockInfo* clientinfo, void* data1, int size1, void* data2, int size2, int verbose); static int g_udp_sock_fd = -1; static DltDaemonClientSockInfo g_udpmulticast_addr; @@ -35,7 +35,7 @@ static DltDaemonClientSockInfo g_udpmulticast_addr; /* Description: client struct to be initilized to copy control/connect/disconnect */ /* client addr */ /* ************************************************************************** */ -void dlt_daemon_udp_init_clientstruct(DltDaemonClientSockInfo *clientinfo_struct) +void dlt_daemon_udp_init_clientstruct(DltDaemonClientSockInfo* clientinfo_struct) { if (clientinfo_struct == NULL) { dlt_vlog(LOG_ERR, "%s: NULL arg\n", __func__); @@ -54,7 +54,7 @@ void dlt_daemon_udp_init_clientstruct(DltDaemonClientSockInfo *clientinfo_struct /* Out Param : NIL */ /* Description: set the multicast addr to global variables */ /* ************************************************************************** */ -void dlt_daemon_udp_setmulticast_addr(DltDaemonLocal *daemon_local) +void dlt_daemon_udp_setmulticast_addr(DltDaemonLocal* daemon_local) { if (daemon_local == NULL) { dlt_vlog(LOG_ERR, "%s: NULL arg\n", __func__); @@ -78,7 +78,7 @@ void dlt_daemon_udp_setmulticast_addr(DltDaemonLocal *daemon_local) /* Out Param : status of udp connection setup and fd registration */ /* Description: DataGram socket fd connection is setup */ /* ************************************************************************** */ -DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal *daemon_local) +DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal* daemon_local) { int fd = DLT_FD_INIT; DltReturnValue ret_val = DLT_RETURN_WRONG_PARAMETER; @@ -88,8 +88,7 @@ DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal *daemon_local) if ((ret_val = dlt_daemon_udp_socket_open(&fd, daemon_local->flags.port)) != DLT_RETURN_OK) { dlt_log(LOG_ERR, "Could not initialize udp socket.\n"); - } - else { + } else { /* assign to global udp fd */ g_udp_sock_fd = fd; /* set global multicast addr */ @@ -107,14 +106,14 @@ DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal *daemon_local) /* Description: This funtion is used to setup DGRAM connection */ /* does socket()->bind() on udp port */ /* ************************************************************************** */ -DltReturnValue dlt_daemon_udp_socket_open(int *sock, unsigned int servPort) +DltReturnValue dlt_daemon_udp_socket_open(int* sock, unsigned int servPort) { int enable_reuse_addr = 1; int sockbuffer = DLT_DAEMON_RCVBUFSIZESOCK; - char portnumbuffer[SOCKPORT_MAX_LEN] = { 0 }; + char portnumbuffer[SOCKPORT_MAX_LEN] = {0}; struct addrinfo hints; - struct addrinfo *servinfo = NULL; - struct addrinfo *addrinfo_iterator = NULL; + struct addrinfo* servinfo = NULL; + struct addrinfo* addrinfo_iterator = NULL; int getaddrinfo_errorcode = -1; if (sock == NULL) @@ -126,47 +125,42 @@ DltReturnValue dlt_daemon_udp_socket_open(int *sock, unsigned int servPort) #else hints.ai_family = AF_INET; #endif - hints.ai_socktype = SOCK_DGRAM;/* UDP Connection */ - hints.ai_flags = AI_PASSIVE; /* use my IP address */ + hints.ai_socktype = SOCK_DGRAM; /* UDP Connection */ + hints.ai_flags = AI_PASSIVE; /* use my IP address */ snprintf(portnumbuffer, SOCKPORT_MAX_LEN, "%d", servPort); if ((getaddrinfo_errorcode = getaddrinfo(NULL, portnumbuffer, &hints, &servinfo)) != 0) { - dlt_vlog(LOG_WARNING, "[%s:%d] getaddrinfo: %s\n", __func__, __LINE__, - gai_strerror(getaddrinfo_errorcode)); + dlt_vlog(LOG_WARNING, "[%s:%d] getaddrinfo: %s\n", __func__, __LINE__, gai_strerror(getaddrinfo_errorcode)); return DLT_RETURN_ERROR; } for (addrinfo_iterator = servinfo; addrinfo_iterator != NULL; addrinfo_iterator = addrinfo_iterator->ai_next) { - if ((*sock = socket(addrinfo_iterator->ai_family, addrinfo_iterator->ai_socktype, - addrinfo_iterator->ai_protocol)) == SYSTEM_CALL_ERROR) { + if ((*sock = + socket(addrinfo_iterator->ai_family, addrinfo_iterator->ai_socktype, addrinfo_iterator->ai_protocol)) + == SYSTEM_CALL_ERROR) { dlt_log(LOG_WARNING, "socket() error\n"); continue; } - dlt_vlog(LOG_INFO, - "[%s:%d] Socket created - socket_family:%i socket_type:%i, protocol:%i\n", - __func__, __LINE__, addrinfo_iterator->ai_family, - addrinfo_iterator->ai_socktype, addrinfo_iterator->ai_protocol); + dlt_vlog( + LOG_INFO, "[%s:%d] Socket created - socket_family:%i socket_type:%i, protocol:%i\n", __func__, __LINE__, + addrinfo_iterator->ai_family, addrinfo_iterator->ai_socktype, addrinfo_iterator->ai_protocol); if (setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, &enable_reuse_addr, sizeof(enable_reuse_addr)) == SYSTEM_CALL_ERROR) { - dlt_vlog(LOG_WARNING, "[%s:%d] Setsockopt error %s\n", __func__, __LINE__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "[%s:%d] Setsockopt error %s\n", __func__, __LINE__, strerror(errno)); close(*sock); continue; } - if (setsockopt(*sock, SOL_SOCKET, SO_RCVBUF, &sockbuffer, sizeof(sockbuffer)) - == SYSTEM_CALL_ERROR) { - dlt_vlog(LOG_WARNING, "[%s:%d] Setsockopt error %s\n", __func__, __LINE__, - strerror(errno)); + if (setsockopt(*sock, SOL_SOCKET, SO_RCVBUF, &sockbuffer, sizeof(sockbuffer)) == SYSTEM_CALL_ERROR) { + dlt_vlog(LOG_WARNING, "[%s:%d] Setsockopt error %s\n", __func__, __LINE__, strerror(errno)); close(*sock); continue; } - if (bind(*sock, addrinfo_iterator->ai_addr, addrinfo_iterator->ai_addrlen) - == SYSTEM_CALL_ERROR) { + if (bind(*sock, addrinfo_iterator->ai_addr, addrinfo_iterator->ai_addrlen) == SYSTEM_CALL_ERROR) { close(*sock); dlt_log(LOG_WARNING, "bind() error\n"); continue; @@ -191,9 +185,7 @@ DltReturnValue dlt_daemon_udp_socket_open(int *sock, unsigned int servPort) /* Out Param : NIL */ /* Description: multicast UDP dlt-message packets to dlt-client */ /* ************************************************************************** */ -void dlt_daemon_udp_dltmsg_multicast(void *data1, int size1, - void *data2, int size2, - int verbose) +void dlt_daemon_udp_dltmsg_multicast(void* data1, int size1, void* data2, int size2, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -207,8 +199,7 @@ void dlt_daemon_udp_dltmsg_multicast(void *data1, int size1, return; } - dlt_daemon_udp_clientmsg_send(&g_udpmulticast_addr, data1, size1, - data2, size2, verbose); + dlt_daemon_udp_clientmsg_send(&g_udpmulticast_addr, data1, size1, data2, size2, verbose); } /* ************************************************************************** */ @@ -217,14 +208,13 @@ void dlt_daemon_udp_dltmsg_multicast(void *data1, int size1, /* Out Param : NIL */ /* Description: common interface to send data via UDP protocol */ /* ************************************************************************** */ -void dlt_daemon_udp_clientmsg_send(DltDaemonClientSockInfo *clientinfo, - void *data1, int size1, void *data2, int size2, int verbose) +void dlt_daemon_udp_clientmsg_send( + DltDaemonClientSockInfo* clientinfo, void* data1, int size1, void* data2, int size2, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); - if ((clientinfo->isvalidflag == ADDRESS_VALID) && - (size1 > 0) && (size2 > 0)) { - void *data = (void *)calloc((size_t)(size1 + size2), sizeof(char)); + if ((clientinfo->isvalidflag == ADDRESS_VALID) && (size1 > 0) && (size2 > 0)) { + void* data = (void*)calloc((size_t)(size1 + size2), sizeof(char)); if (data == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failure\n", __func__); @@ -234,15 +224,16 @@ void dlt_daemon_udp_clientmsg_send(DltDaemonClientSockInfo *clientinfo, memcpy(data, data1, (size_t)size1); memcpy((int*)data + size1, data2, (size_t)size2); - if (sendto(g_udp_sock_fd, data, (size_t)(size1 + size2), 0, (struct sockaddr *)&clientinfo->clientaddr, - clientinfo->clientaddr_size) < 0) + if (sendto( + g_udp_sock_fd, data, (size_t)(size1 + size2), 0, (struct sockaddr*)&clientinfo->clientaddr, + clientinfo->clientaddr_size) + < 0) dlt_vlog(LOG_ERR, "%s: Send UDP Packet Data failed\n", __func__); free(data); data = NULL; - } - else { + } else { if (clientinfo->isvalidflag != ADDRESS_VALID) dlt_vlog(LOG_ERR, "%s: clientinfo->isvalidflag != ADDRESS_VALID %d\n", __func__, clientinfo->isvalidflag); @@ -263,6 +254,5 @@ void dlt_daemon_udp_clientmsg_send(DltDaemonClientSockInfo *clientinfo, void dlt_daemon_udp_close_connection(void) { if (close(g_udp_sock_fd) == SYSTEM_CALL_ERROR) - dlt_vlog(LOG_WARNING, "[%s:%d] close error %s\n", __func__, __LINE__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "[%s:%d] close error %s\n", __func__, __LINE__, strerror(errno)); } diff --git a/src/daemon/udp_connection/dlt_daemon_udp_socket.h b/src/daemon/udp_connection/dlt_daemon_udp_socket.h index 6b5c82a2b..45269100c 100644 --- a/src/daemon/udp_connection/dlt_daemon_udp_socket.h +++ b/src/daemon/udp_connection/dlt_daemon_udp_socket.h @@ -26,9 +26,8 @@ #include "dlt-daemon.h" -DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal *daemon_local); -void dlt_daemon_udp_dltmsg_multicast(void *data1, int size1, void *data2, int size2, - int verbose); +DltReturnValue dlt_daemon_udp_connection_setup(DltDaemonLocal* daemon_local); +void dlt_daemon_udp_dltmsg_multicast(void* data1, int size1, void* data2, int size2, int verbose); void dlt_daemon_udp_close_connection(void); #endif /* DLT_DAEMON_UDP_SOCKET_H */ diff --git a/src/examples/dlt-example-filetransfer.c b/src/examples/dlt-example-filetransfer.c index c4af083fb..6f1fd8a49 100644 --- a/src/examples/dlt-example-filetransfer.c +++ b/src/examples/dlt-example-filetransfer.c @@ -58,24 +58,25 @@ #include #include -#include /*Needed for transferring files with the dlt protocol*/ -#include /*Needed for dlt logging*/ +#include /*Needed for transferring files with the dlt protocol*/ +#include /*Needed for dlt logging*/ #define MAXSTRLEN 1024 -#define FLTR_APP_DESC "Filetransfer application" -#define FLTR_CONTEXT_DESC "Filetransfer context" +#define FLTR_APP_DESC "Filetransfer application" +#define FLTR_CONTEXT_DESC "Filetransfer context" #define FLTR_APP "FLTR" #define FLTR_CONTEXT "FLTR" #define TIMEOUT 1 -/*!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this context in the dlt viewer. */ +/*!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this + * context in the dlt viewer. */ DLT_DECLARE_CONTEXT(fileContext) -char *file = 0; +char* file = 0; unsigned int timeout; int dflag = 0; bool shutdownStatus = false; @@ -84,12 +85,12 @@ bool shutdownStatus = false; * The function will set the flag (shutdownStatus) to true after .2 sec * @return Null to stop thread */ -void *cancel_filetransfer() +void* cancel_filetransfer() { // wait 200msec once a filetransfer is started and then set the flag to true struct timespec ts; ts.tv_sec = 0; - ts.tv_nsec = 200000000; // 200 ms + ts.tv_nsec = 200000000; // 200 ms nanosleep(&ts, NULL); shutdownStatus = true; return NULL; @@ -99,7 +100,7 @@ void *cancel_filetransfer() * The function will start dlt filetransfer and will throw error if status of shutdownStatus is high * @return Null to stop thread */ -void *filetransfer() +void* filetransfer() { int transferResult; @@ -109,7 +110,7 @@ void *filetransfer() } transferResult = dlt_user_log_file_data_cancelable(&fileContext, file, INT_MAX, timeout, &shutdownStatus); - if (transferResult < 0){ + if (transferResult < 0) { printf("File couldn't be transferred. Please check the dlt log messages.\n"); return NULL; } @@ -142,12 +143,11 @@ void usage() printf("-i - Flag to log file infos to DLT before transfer file (default: false)\n"); printf("-p - Flag to cancel file transfer on shutdown event (default: false)\n"); printf("-h - This help\n"); - } /*!Main program dlt-test-filestransfer starts here */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { /*char str[MAXSTRLEN]; */ int opt; @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) /*char version[255]; */ int index; int iflag = 0; - char *tvalue = 0; + char* tvalue = 0; bool fileCancelableFlag = false; dlt_set_id(apid, FLTR_APP); @@ -166,49 +166,41 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "idf:t:a:c:h:p")) != -1) switch (opt) { - case 'd': - { + case 'd': { dflag = 1; break; } - case 'i': - { + case 'i': { iflag = 1; break; } - case 't': - { + case 't': { tvalue = optarg; break; } - case 'a': - { + case 'a': { dlt_set_id(apid, optarg); break; } - case 'c': - { + case 'c': { dlt_set_id(ctid, optarg); break; } - case 'h': - { + case 'h': { usage(); break; } - case 'p': - { + case 'p': { fileCancelableFlag = true; break; } - case '?': - { + case '?': { if ((optopt == 'a') || (optopt == 'c') || (optopt == 't')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); @@ -243,15 +235,14 @@ int main(int argc, char *argv[]) dlt_user_log_file_infoAbout(&fileContext, file); } - if (fileCancelableFlag){ + if (fileCancelableFlag) { pthread_t cancel_filetransfer_thread, filetransfer_thread; pthread_create(&cancel_filetransfer_thread, NULL, cancel_filetransfer, NULL); pthread_create(&filetransfer_thread, NULL, filetransfer, NULL); pthread_join(cancel_filetransfer_thread, NULL); pthread_join(filetransfer_thread, NULL); - } - else { + } else { if (dlt_user_log_file_complete(&fileContext, file, dflag, timeout) < 0) printf("File couldn't be transferred. Please check the dlt log messages.\n"); } diff --git a/src/examples/dlt-example-multicast-clientmsg-view.c b/src/examples/dlt-example-multicast-clientmsg-view.c index f8920453d..4d0656e23 100644 --- a/src/examples/dlt-example-multicast-clientmsg-view.c +++ b/src/examples/dlt-example-multicast-clientmsg-view.c @@ -28,11 +28,11 @@ #include #include #include -#include /* for isprint() */ -#include /* for atoi() */ -#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ -#include /* for open() */ -#include /* for writev() */ +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ +#include /* for writev() */ #include #include #include @@ -48,15 +48,14 @@ #define HELLO_PORT 3491 #define HELLO_GROUP "225.0.0.37" -struct clientinfostruct -{ +struct clientinfostruct { int fd; struct sockaddr_in addr; socklen_t addlen; DltReceiver receiver; }; -int dlt_receiver_receive_socket_udp(struct clientinfostruct *clientinfo, DltReceiver *receiver) +int dlt_receiver_receive_socket_udp(struct clientinfostruct* clientinfo, DltReceiver* receiver) { if ((receiver == NULL) || (clientinfo == NULL)) { printf("NULL receiver or clientinfo in dlt_receiver_receive_socket_udp\n"); @@ -68,17 +67,16 @@ int dlt_receiver_receive_socket_udp(struct clientinfostruct *clientinfo, DltRece return -1; } - receiver->buf = (char *)receiver->buffer; + receiver->buf = (char*)receiver->buffer; receiver->lastBytesRcvd = receiver->bytesRcvd; /* wait for data from socket */ unsigned int addrlen = sizeof(clientinfo->addr); - if ((receiver->bytesRcvd = (int32_t)recvfrom(clientinfo->fd, - receiver->buf + receiver->lastBytesRcvd, - (size_t)(receiver->buffersize - receiver->lastBytesRcvd), - 0, - (struct sockaddr *)&(clientinfo->addr), &addrlen)) + if ((receiver->bytesRcvd = (int32_t)recvfrom( + clientinfo->fd, receiver->buf + receiver->lastBytesRcvd, + (size_t)(receiver->buffersize - receiver->lastBytesRcvd), 0, (struct sockaddr*)&(clientinfo->addr), + &addrlen)) <= 0) { printf("Error\n"); perror("recvfrom"); @@ -92,7 +90,7 @@ int dlt_receiver_receive_socket_udp(struct clientinfostruct *clientinfo, DltRece return receiver->bytesRcvd; } -int dlt_receive_message_callback_udp(DltMessage *message) +int dlt_receive_message_callback_udp(DltMessage* message) { static char text[DLT_RECEIVE_TEXTBUFSIZE]; @@ -145,7 +143,7 @@ int main() clientinfo.addr.sin_port = htons(HELLO_PORT); /* bind to receive address */ - if (bind(clientinfo.fd, (struct sockaddr *)&clientinfo.addr, sizeof(clientinfo.addr)) < 0) { + if (bind(clientinfo.fd, (struct sockaddr*)&clientinfo.addr, sizeof(clientinfo.addr)) < 0) { perror("bind"); exit(1); } @@ -164,10 +162,8 @@ int main() if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - if (dlt_receiver_init(&(clientinfo.receiver), - clientinfo.fd, - DLT_RECEIVE_UDP_SOCKET, - DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) + if (dlt_receiver_init(&(clientinfo.receiver), clientinfo.fd, DLT_RECEIVE_UDP_SOCKET, DLT_RECEIVE_BUFSIZE) + != DLT_RETURN_OK) return DLT_RETURN_ERROR; printf("Waiting for message on ip %s port : %d\n", HELLO_GROUP, HELLO_PORT); @@ -176,12 +172,13 @@ int main() /* wait for data from socket */ dlt_receiver_receive_socket_udp(&clientinfo, &(clientinfo.receiver)); - while (dlt_message_read(&msg, (unsigned char *)(clientinfo.receiver.buf), - (unsigned int)clientinfo.receiver.bytesRcvd, 0, 0) == DLT_MESSAGE_ERROR_OK) { + while (dlt_message_read( + &msg, (unsigned char*)(clientinfo.receiver.buf), (unsigned int)clientinfo.receiver.bytesRcvd, 0, 0) + == DLT_MESSAGE_ERROR_OK) { dlt_receive_message_callback_udp(&msg); - if (dlt_receiver_remove(&(clientinfo.receiver), - msg.headersize + msg.datasize - ((int32_t)(sizeof(DltStorageHeader)))) + if (dlt_receiver_remove( + &(clientinfo.receiver), msg.headersize + msg.datasize - ((int32_t)(sizeof(DltStorageHeader)))) == DLT_RETURN_ERROR) { /* Return value ignored */ dlt_message_free(&msg, 0); @@ -196,4 +193,3 @@ int main() } } } - diff --git a/src/examples/dlt-example-user-common-api.c b/src/examples/dlt-example-user-common-api.c index 8e4c25c1e..3c783e5b5 100644 --- a/src/examples/dlt-example-user-common-api.c +++ b/src/examples/dlt-example-user-common-api.c @@ -54,10 +54,10 @@ #include #include -#include /* for printf() and fprintf() */ -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() */ +#include /* for printf() and fprintf() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() */ #include "dlt_common_api.h" @@ -92,22 +92,22 @@ void usage() /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { #ifdef DLT_TEST_ENABLE int cflag = 0; - char *svalue = 0; - char *zvalue = 0; + char* svalue = 0; + char* zvalue = 0; #endif /* DLT_TEST_ENABLE */ int gflag = 0; - char *dvalue = 0; - char *nvalue = 0; - char *message = 0; + char* dvalue = 0; + char* nvalue = 0; + char* message = 0; int index; int c; - char *text; + char* text; int num, maxnum; int delay; struct timespec ts; @@ -117,62 +117,54 @@ int main(int argc, char *argv[]) opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgcd:n:z:s:")) != -1) + while ((c = getopt(argc, argv, "vgcd:n:z:s:")) != -1) #else - while ((c = getopt (argc, argv, "vgd:n:")) != -1) + while ((c = getopt(argc, argv, "vgd:n:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) { #ifdef DLT_TEST_ENABLE - case 'c': - { + case 'c': { cflag = 1; break; } - case 's': - { + case 's': { svalue = optarg; break; } - case 'z': - { + case 'z': { zvalue = optarg; break; } #endif /* DLT_TEST_ENABLE */ - case 'g': - { + case 'g': { gflag = 1; break; } - case 'd': - { + case 'd': { dvalue = optarg; break; } - case 'n': - { + case 'n': { nvalue = optarg; break; } - case '?': - { + case '?': { if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - break;/*for parasoft */ + default: { + abort(); + break; /*for parasoft */ } } } @@ -220,7 +212,7 @@ int main(int argc, char *argv[]) dlt_user_test_corrupt_message_size(1, atoi(svalue)); if (zvalue) { - char *buffer = malloc(atoi(zvalue)); + char* buffer = malloc(atoi(zvalue)); if (buffer == 0) { /* no message, show usage and terminate */ @@ -271,7 +263,4 @@ int main(int argc, char *argv[]) DLT_UNREGISTER_APP(); return 0; - } - - diff --git a/src/examples/dlt-example-user-func-v2.c b/src/examples/dlt-example-user-func-v2.c index ec096ba24..a0de4ad98 100644 --- a/src/examples/dlt-example-user-func-v2.c +++ b/src/examples/dlt-example-user-func-v2.c @@ -66,17 +66,17 @@ #include #include -#include /* for printf() and fprintf() */ -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() */ +#include /* for printf() and fprintf() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() */ #include "dlt.h" #include "dlt_common.h" /* for dlt_get_version() */ #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length); +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length); DltContext mycontext; DltContextData mycontextdata; @@ -104,68 +104,61 @@ void usage() /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int gflag = 0; int aflag = 0; - char *dvalue = 0; - char *fvalue = 0; - char *nvalue = 0; - char *message = 0; + char* dvalue = 0; + char* fvalue = 0; + char* nvalue = 0; + char* message = 0; int index; int c; - char *text; + char* text; int num, maxnum; int delay; struct timespec ts; opterr = 0; - while ((c = getopt (argc, argv, "vgad:f:n:")) != -1) + while ((c = getopt(argc, argv, "vgad:f:n:")) != -1) switch (c) { - case 'g': - { - //gflag = 1; /* Non verbose is not supported in V2 currently */ + case 'g': { + // gflag = 1; /* Non verbose is not supported in V2 currently */ break; } - case 'a': - { + case 'a': { aflag = 1; break; } - case 'd': - { + case 'd': { dvalue = optarg; break; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'n': - { + case 'n': { nvalue = optarg; break; } - case '?': - { + case '?': { if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1;/*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -192,7 +185,7 @@ int main(int argc, char *argv[]) dlt_with_ecu_id(1); dlt_with_filename_and_line_number(__FILENAME__, __LINE__); dlt_with_prlv(32); - dlt_with_tags("TAG1","TAG2","TAG3",NULL); + dlt_with_tags("TAG1", "TAG2", "TAG3", NULL); dlt_verbose_mode(); dlt_register_app_v2("LOGGER", "Test Application for Logging"); @@ -257,14 +250,13 @@ int main(int argc, char *argv[]) // dlt_user_log_write_string(&mycontextdata, text); // dlt_user_log_write_finish(&mycontextdata); // } - } - else - /* Verbose mode */ - if (dlt_user_log_write_start(&mycontext, &mycontextdata, DLT_LOG_WARN) > 0) { - dlt_user_log_write_int(&mycontextdata, num); - dlt_user_log_write_string(&mycontextdata, text); - dlt_user_log_write_finish_v2(&mycontextdata); - } + } else + /* Verbose mode */ + if (dlt_user_log_write_start(&mycontext, &mycontextdata, DLT_LOG_WARN) > 0) { + dlt_user_log_write_int(&mycontextdata, num); + dlt_user_log_write_string(&mycontextdata, text); + dlt_user_log_write_finish_v2(&mycontextdata); + } if (delay > 0) { ts.tv_sec = delay / 1000000000; @@ -280,7 +272,7 @@ int main(int argc, char *argv[]) return 0; } -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length) +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length) { char text[1024]; diff --git a/src/examples/dlt-example-user-func.c b/src/examples/dlt-example-user-func.c index 5836d4a63..ad2296b1f 100644 --- a/src/examples/dlt-example-user-func.c +++ b/src/examples/dlt-example-user-func.c @@ -66,15 +66,15 @@ */ #include #include -#include /* for printf() and fprintf() */ -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() */ +#include /* for printf() and fprintf() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() */ #include "dlt.h" #include "dlt_common.h" /* for dlt_get_version() */ -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length); +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length); DltContext mycontext; DltContextData mycontextdata; @@ -102,68 +102,61 @@ void usage() /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int gflag = 0; int aflag = 0; - char *dvalue = 0; - char *fvalue = 0; - char *nvalue = 0; - char *message = 0; + char* dvalue = 0; + char* fvalue = 0; + char* nvalue = 0; + char* message = 0; int index; int c; - char *text; + char* text; int num, maxnum; int delay; struct timespec ts; opterr = 0; - while ((c = getopt (argc, argv, "vgad:f:n:")) != -1) + while ((c = getopt(argc, argv, "vgad:f:n:")) != -1) switch (c) { - case 'g': - { + case 'g': { gflag = 1; break; } - case 'a': - { + case 'a': { aflag = 1; break; } - case 'd': - { + case 'd': { dvalue = optarg; break; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'n': - { + case 'n': { nvalue = optarg; break; } - case '?': - { + case '?': { if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1;/*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -247,14 +240,13 @@ int main(int argc, char *argv[]) dlt_user_log_write_string(&mycontextdata, text); dlt_user_log_write_finish(&mycontextdata); } - } - else - /* Verbose mode */ - if (dlt_user_log_write_start(&mycontext, &mycontextdata, DLT_LOG_WARN) > 0) { - dlt_user_log_write_int(&mycontextdata, num); - dlt_user_log_write_string(&mycontextdata, text); - dlt_user_log_write_finish(&mycontextdata); - } + } else + /* Verbose mode */ + if (dlt_user_log_write_start(&mycontext, &mycontextdata, DLT_LOG_WARN) > 0) { + dlt_user_log_write_int(&mycontextdata, num); + dlt_user_log_write_string(&mycontextdata, text); + dlt_user_log_write_finish(&mycontextdata); + } if (delay > 0) { ts.tv_sec = delay / 1000000000; @@ -270,7 +262,7 @@ int main(int argc, char *argv[]) return 0; } -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length) +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length) { char text[1024]; diff --git a/src/examples/dlt-example-user-v2.c b/src/examples/dlt-example-user-v2.c index b4879f279..337e05ae0 100644 --- a/src/examples/dlt-example-user-v2.c +++ b/src/examples/dlt-example-user-v2.c @@ -66,20 +66,20 @@ #include #include -#include /* for printf() and fprintf() */ -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() */ +#include /* for printf() and fprintf() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() */ #include "dlt.h" #include "dlt_common.h" /* for dlt_get_version() */ #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length); -int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void *data, uint32_t length, void *priv_data); +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length); +int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void* data, uint32_t length, void* priv_data); -void dlt_user_log_level_changed_callback_v2(char *context_id, uint8_t log_level, uint8_t trace_status); +void dlt_user_log_level_changed_callback_v2(char* context_id, uint8_t log_level, uint8_t trace_status); DLT_DECLARE_CONTEXT(mycontext1) DLT_DECLARE_CONTEXT(mycontext2) @@ -121,30 +121,30 @@ void usage() /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int gflag = 0; int aflag = 0; int kflag = 0; #ifdef DLT_TEST_ENABLE int cflag = 0; - char *svalue = 0; - char *zvalue = 0; + char* svalue = 0; + char* zvalue = 0; #endif /* DLT_TEST_ENABLE */ - char *dvalue = 0; - char *fvalue = 0; + char* dvalue = 0; + char* fvalue = 0; unsigned int filesize = 0; - char *nvalue = 0; - char *mvalue = 0; - char *message = 0; + char* nvalue = 0; + char* mvalue = 0; + char* message = 0; int lvalue = DLT_LOG_WARN; - char *tvalue = 0; + char* tvalue = 0; int rvalue = -1; int index; int c; - char *appID = "LOGGER"; - char *contextID = "TESTER"; - char *text; + char* appID = "LOGGER"; + char* contextID = "TESTER"; + char* text; int num, maxnum; int delay; struct timespec ts; @@ -154,113 +154,95 @@ int main(int argc, char *argv[]) opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgakcd:f:S:n:m:z:r:s:l:t:A:C:")) != -1) + while ((c = getopt(argc, argv, "vgakcd:f:S:n:m:z:r:s:l:t:A:C:")) != -1) #else - while ((c = getopt (argc, argv, "vgakd:f:S:n:m:l:r:t:A:C:")) != -1) + while ((c = getopt(argc, argv, "vgakd:f:S:n:m:l:r:t:A:C:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) { - case 'g': - { - //gflag = 1; /* Non verbose is not supported in V2 currently */ + case 'g': { + // gflag = 1; /* Non verbose is not supported in V2 currently */ break; } - case 'a': - { + case 'a': { aflag = 1; break; } - case 'k': - { + case 'k': { kflag = 1; break; } #ifdef DLT_TEST_ENABLE - case 'c': - { + case 'c': { cflag = 1; break; } - case 's': - { + case 's': { svalue = optarg; break; } - case 'z': - { + case 'z': { zvalue = optarg; break; } #endif /* DLT_TEST_ENABLE */ - case 'd': - { + case 'd': { dvalue = optarg; break; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'S': - { + case 'S': { filesize = (unsigned int)atoi(optarg); break; } - case 'n': - { + case 'n': { nvalue = optarg; break; } - case 'm': - { + case 'm': { mvalue = optarg; break; } - case 'l': - { + case 'l': { lvalue = atoi(optarg); break; } - case 'A': - { + case 'A': { appID = optarg; break; } - case 'C': - { + case 'C': { contextID = optarg; break; } - case 't': - { + case 't': { tvalue = optarg; break; } - case 'r': - { + case 'r': { rvalue = atoi(optarg); break; } - case '?': - { - if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n') || - (optopt == 'l') || (optopt == 't') || (optopt == 'S')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + case '?': { + if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n') || (optopt == 'l') || (optopt == 't') + || (optopt == 'S')) + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - break;/*for parasoft */ + default: { + abort(); + break; /*for parasoft */ } } } @@ -268,8 +250,7 @@ int main(int argc, char *argv[]) if (rvalue == -1) { for (index = optind; index < argc; index++) message = argv[index]; - } - else { /* allocate raw buffer */ + } else { /* allocate raw buffer */ message = calloc((size_t)rvalue, sizeof(char)); memset(message, 'X', (size_t)(rvalue - 1)); } @@ -298,18 +279,16 @@ int main(int argc, char *argv[]) dlt_verbose_mode(); DLT_REGISTER_APP_V2(appID, "Test Application for Logging"); DLT_REGISTER_CONTEXT_V2(mycontext1, contextID, "Test Context for Logging"); - DLT_REGISTER_CONTEXT_LLCCB_V2(mycontext2, "TS1", "Test Context1 for injection", dlt_user_log_level_changed_callback_v2); - DLT_REGISTER_CONTEXT_LLCCB_V2(mycontext3, "TS2", "Test Context2 for injection", dlt_user_log_level_changed_callback_v2); + DLT_REGISTER_CONTEXT_LLCCB_V2( + mycontext2, "TS1", "Test Context1 for injection", dlt_user_log_level_changed_callback_v2); + DLT_REGISTER_CONTEXT_LLCCB_V2( + mycontext3, "TS2", "Test Context2 for injection", dlt_user_log_level_changed_callback_v2); DLT_REGISTER_INJECTION_CALLBACK(mycontext1, 0x1000, dlt_user_injection_callback); - DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(mycontext2, - 0x1000, - dlt_user_injection_callback_with_specific_data, - (void *)"TS1 context"); + DLT_REGISTER_INJECTION_CALLBACK_WITH_ID( + mycontext2, 0x1000, dlt_user_injection_callback_with_specific_data, (void*)"TS1 context"); DLT_REGISTER_INJECTION_CALLBACK(mycontext2, 0x1001, dlt_user_injection_callback); - DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(mycontext3, - 0x1000, - dlt_user_injection_callback_with_specific_data, - (void *)"TS2 context"); + DLT_REGISTER_INJECTION_CALLBACK_WITH_ID( + mycontext3, 0x1000, dlt_user_injection_callback_with_specific_data, (void*)"TS2 context"); DLT_REGISTER_INJECTION_CALLBACK(mycontext3, 0x1001, dlt_user_injection_callback); DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK_V2(mycontext1, dlt_user_log_level_changed_callback_v2); @@ -361,7 +340,7 @@ int main(int argc, char *argv[]) dlt_user_test_corrupt_message_size(1, atoi(svalue)); if (zvalue) { - char *buffer = malloc(atoi(zvalue)); + char* buffer = malloc(atoi(zvalue)); if (buffer == 0) { /* no message, show usage and terminate */ @@ -394,15 +373,16 @@ int main(int argc, char *argv[]) if (gflag) { /* Non-verbose mode */ DLT_LOG_ID(mycontext1, lvalue, (uint32_t)num, DLT_INT(num), DLT_STRING(text)); - } - else { + } else { if (rvalue == -1) { /* Verbose mode */ - DLT_LOG_V2(mycontext1, lvalue, DLT_WITH_FILENAME_LINENUMBER(__FILENAME__, __LINE__), - DLT_WITH_TAGS("TAG1", "TAG2", "TAG3"), DLT_WITH_PRIVACYLEVEL(32), DLT_INT(num), DLT_STRING(text)); + DLT_LOG_V2( + mycontext1, lvalue, DLT_WITH_FILENAME_LINENUMBER(__FILENAME__, __LINE__), + DLT_WITH_TAGS("TAG1", "TAG2", "TAG3"), DLT_WITH_PRIVACYLEVEL(32), DLT_INT(num), DLT_STRING(text)); } else { - DLT_LOG_V2(mycontext1, lvalue, DLT_WITH_FILENAME_LINENUMBER(__FILENAME__, __LINE__), - DLT_WITH_TAGS("TAG1", "TAG2", "TAG3"), DLT_WITH_PRIVACYLEVEL(32), DLT_RAW(text, (uint16_t)rvalue)); + DLT_LOG_V2( + mycontext1, lvalue, DLT_WITH_FILENAME_LINENUMBER(__FILENAME__, __LINE__), + DLT_WITH_TAGS("TAG1", "TAG2", "TAG3"), DLT_WITH_PRIVACYLEVEL(32), DLT_RAW(text, (uint16_t)rvalue)); } } @@ -420,10 +400,9 @@ int main(int argc, char *argv[]) DLT_UNREGISTER_APP_V2(); return 0; - } -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length) +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length) { char text[1024]; @@ -439,7 +418,7 @@ int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length return 0; } -int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void *data, uint32_t length, void *priv_data) +int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void* data, uint32_t length, void* priv_data) { char text[1024]; @@ -455,7 +434,7 @@ int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void *da return 0; } -void dlt_user_log_level_changed_callback_v2(char *context_id, uint8_t log_level, uint8_t trace_status) +void dlt_user_log_level_changed_callback_v2(char* context_id, uint8_t log_level, uint8_t trace_status) { printf("Log level changed of context %s, LogLevel=%u, TraceState=%u\n", context_id, log_level, trace_status); } \ No newline at end of file diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index f6f0784a9..654fcda21 100644 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -66,16 +66,16 @@ */ #include #include -#include /* for printf() and fprintf() */ -#include /* for atoi() and exit() */ -#include /* for memset() */ -#include /* for close() */ +#include /* for printf() and fprintf() */ +#include /* for atoi() and exit() */ +#include /* for memset() */ +#include /* for close() */ #include "dlt.h" #include "dlt_common.h" /* for dlt_get_version() */ -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length); -int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void *data, uint32_t length, void *priv_data); +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length); +int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void* data, uint32_t length, void* priv_data); void dlt_user_log_level_changed_callback(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status); @@ -119,32 +119,32 @@ void usage() /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int gflag = 0; int aflag = 0; int kflag = 0; #ifdef DLT_TEST_ENABLE int cflag = 0; - char *svalue = 0; - char *zvalue = 0; + char* svalue = 0; + char* zvalue = 0; #endif /* DLT_TEST_ENABLE */ - char *dvalue = 0; - char *fvalue = 0; + char* dvalue = 0; + char* fvalue = 0; unsigned int filesize = 0; - char *nvalue = 0; - char *mvalue = 0; - char *message = 0; + char* nvalue = 0; + char* mvalue = 0; + char* message = 0; int lvalue = DLT_LOG_WARN; - char *tvalue = 0; + char* tvalue = 0; int rvalue = -1; int index; int c; - char *appID = "LOG"; - char *contextID = "TEST"; + char* appID = "LOG"; + char* contextID = "TEST"; - char *text; + char* text; int num, maxnum; int delay; struct timespec ts; @@ -154,113 +154,95 @@ int main(int argc, char *argv[]) opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgakcd:f:S:n:m:z:r:s:l:t:A:C:")) != -1) + while ((c = getopt(argc, argv, "vgakcd:f:S:n:m:z:r:s:l:t:A:C:")) != -1) #else - while ((c = getopt (argc, argv, "vgakd:f:S:n:m:l:r:t:A:C:")) != -1) + while ((c = getopt(argc, argv, "vgakd:f:S:n:m:l:r:t:A:C:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) { - case 'g': - { + case 'g': { gflag = 1; break; } - case 'a': - { + case 'a': { aflag = 1; break; } - case 'k': - { + case 'k': { kflag = 1; break; } #ifdef DLT_TEST_ENABLE - case 'c': - { + case 'c': { cflag = 1; break; } - case 's': - { + case 's': { svalue = optarg; break; } - case 'z': - { + case 'z': { zvalue = optarg; break; } #endif /* DLT_TEST_ENABLE */ - case 'd': - { + case 'd': { dvalue = optarg; break; } - case 'f': - { + case 'f': { fvalue = optarg; break; } - case 'S': - { + case 'S': { filesize = (unsigned int)atoi(optarg); break; } - case 'n': - { + case 'n': { nvalue = optarg; break; } - case 'm': - { + case 'm': { mvalue = optarg; break; } - case 'l': - { + case 'l': { lvalue = atoi(optarg); break; } - case 'A': - { + case 'A': { appID = optarg; break; } - case 'C': - { + case 'C': { contextID = optarg; break; } - case 't': - { + case 't': { tvalue = optarg; break; } - case 'r': - { + case 'r': { rvalue = atoi(optarg); break; } - case '?': - { - if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n') || - (optopt == 'l') || (optopt == 't') || (optopt == 'S')) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + case '?': { + if ((optopt == 'd') || (optopt == 'f') || (optopt == 'n') || (optopt == 'l') || (optopt == 't') + || (optopt == 'S')) + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - break;/*for parasoft */ + default: { + abort(); + break; /*for parasoft */ } } } @@ -268,8 +250,7 @@ int main(int argc, char *argv[]) if (rvalue == -1) { for (index = optind; index < argc; index++) message = argv[index]; - } - else { /* allocate raw buffer */ + } else { /* allocate raw buffer */ message = calloc((size_t)rvalue, sizeof(char)); memset(message, 'X', (size_t)(rvalue - 1)); } @@ -304,15 +285,11 @@ int main(int argc, char *argv[]) DLT_REGISTER_INJECTION_CALLBACK(mycontext1, 0x1000, dlt_user_injection_callback); - DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(mycontext2, - 0x1000, - dlt_user_injection_callback_with_specific_data, - (void *)"TS1 context"); + DLT_REGISTER_INJECTION_CALLBACK_WITH_ID( + mycontext2, 0x1000, dlt_user_injection_callback_with_specific_data, (void*)"TS1 context"); DLT_REGISTER_INJECTION_CALLBACK(mycontext2, 0x1001, dlt_user_injection_callback); - DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(mycontext3, - 0x1000, - dlt_user_injection_callback_with_specific_data, - (void *)"TS2 context"); + DLT_REGISTER_INJECTION_CALLBACK_WITH_ID( + mycontext3, 0x1000, dlt_user_injection_callback_with_specific_data, (void*)"TS2 context"); DLT_REGISTER_INJECTION_CALLBACK(mycontext3, 0x1001, dlt_user_injection_callback); DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(mycontext1, dlt_user_log_level_changed_callback); @@ -364,7 +341,7 @@ int main(int argc, char *argv[]) dlt_user_test_corrupt_message_size(1, atoi(svalue)); if (zvalue) { - char *buffer = malloc(atoi(zvalue)); + char* buffer = malloc(atoi(zvalue)); if (buffer == 0) { /* no message, show usage and terminate */ @@ -397,8 +374,7 @@ int main(int argc, char *argv[]) if (gflag) { /* Non-verbose mode */ DLT_LOG_ID(mycontext1, lvalue, (uint32_t)num, DLT_INT(num), DLT_STRING(text)); - } - else { + } else { if (rvalue == -1) /* Verbose mode */ DLT_LOG(mycontext1, lvalue, DLT_INT(num), DLT_STRING(text)); @@ -420,10 +396,9 @@ int main(int argc, char *argv[]) DLT_UNREGISTER_APP(); return 0; - } -int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length) +int dlt_user_injection_callback(uint32_t service_id, void* data, uint32_t length) { char text[1024]; @@ -439,7 +414,7 @@ int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length return 0; } -int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void *data, uint32_t length, void *priv_data) +int dlt_user_injection_callback_with_specific_data(uint32_t service_id, void* data, uint32_t length, void* priv_data) { char text[1024]; diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c index 219f360c9..ca5b0e21c 100644 --- a/src/gateway/dlt_gateway.c +++ b/src/gateway/dlt_gateway.c @@ -55,7 +55,7 @@ * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection* con, char* value) { if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -81,8 +81,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, char * } return DLT_RETURN_OK; - } - else { + } else { dlt_log(LOG_ERR, "IP address is not valid\n"); } @@ -96,8 +95,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, char * * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection* con, char* value) { long int tmp = -1; @@ -108,19 +106,16 @@ DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, errno = 0; tmp = strtol(value, NULL, 10); - if ((errno == ERANGE && (tmp == LONG_MAX || tmp == LONG_MIN)) - || (errno != 0 && tmp == 0)) { + if ((errno == ERANGE && (tmp == LONG_MAX || tmp == LONG_MIN)) || (errno != 0 && tmp == 0)) { dlt_vlog(LOG_ERR, "%s: cannot convert port number\n", __func__); return DLT_RETURN_ERROR; } /* port ranges for unprivileged applications */ - if ((tmp > IPPORT_RESERVED) && ((unsigned)tmp <= USHRT_MAX)) - { + if ((tmp > IPPORT_RESERVED) && ((unsigned)tmp <= USHRT_MAX)) { con->port = (int)tmp; return DLT_RETURN_OK; - } - else { + } else { dlt_log(LOG_ERR, "Port number is invalid\n"); } @@ -134,8 +129,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, * @param value string to be used as ECU identifier * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection* con, char* value) { if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -157,8 +151,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection* con, char* value) { if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -167,12 +160,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection if (strncasecmp(value, "OnStartup", strlen("OnStartup")) == 0) { con->trigger = DLT_GATEWAY_ON_STARTUP; - } - else if (strncasecmp(value, "OnDemand", strlen("OnDemand")) == 0) - { + } else if (strncasecmp(value, "OnDemand", strlen("OnDemand")) == 0) { con->trigger = DLT_GATEWAY_ON_DEMAND; - } - else { + } else { dlt_log(LOG_ERR, "Wrong connection trigger state given.\n"); con->trigger = DLT_GATEWAY_UNDEFINED; return DLT_RETURN_ERROR; @@ -188,8 +178,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection* con, char* value) { if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -212,8 +201,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection *con, * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_interval(DltGateway *gateway, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_interval(DltGateway* gateway, char* value) { if ((gateway == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -235,8 +223,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_interval(DltGateway *gateway, * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection* con, char* value) { if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -254,7 +241,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection *co * @param con DltGatewayConnection to be updated * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnection *con) +DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnection* con) { if (con == NULL) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -265,17 +252,14 @@ DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnec con->p_control_msgs = calloc(1, sizeof(DltPassiveControlMessage)); if (!con->p_control_msgs) { - dlt_log(LOG_ERR, - "Passive Control Message could not be allocated\n"); + dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; } - } - else { + } else { con->p_control_msgs->next = calloc(1, sizeof(DltPassiveControlMessage)); if (!con->p_control_msgs->next) { - dlt_log(LOG_ERR, - "Passive Control Message could not be allocated\n"); + dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; } @@ -292,13 +276,12 @@ DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnec * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnection* con, char* value) { /* list of allowed clients given */ - char *token = NULL; - char *rest = NULL; - DltPassiveControlMessage *head = NULL; + char* token = NULL; + char* rest = NULL; + DltPassiveControlMessage* head = NULL; if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -313,8 +296,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio while (token != NULL) { if (dlt_gateway_allocate_control_messages(con) != DLT_RETURN_OK) { - dlt_log(LOG_ERR, - "Passive Control Message could not be allocated\n"); + dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; } @@ -328,17 +310,12 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio head = con->p_control_msgs; if ((errno == EINVAL) || (errno == ERANGE)) { - dlt_vlog(LOG_ERR, - "Control message ID is not an integer: %s\n", - token); + dlt_vlog(LOG_ERR, "Control message ID is not an integer: %s\n", token); return DLT_RETURN_ERROR; - } - else if ((con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) || - (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY)) - { - dlt_vlog(LOG_ERR, - "Control message ID is not valid: %s\n", - token); + } else if ( + (con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) + || (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY)) { + dlt_vlog(LOG_ERR, "Control message ID is not valid: %s\n", token); return DLT_RETURN_ERROR; } @@ -359,13 +336,11 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio * @param value string to be tested * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( - DltGatewayConnection *con, - char *value) +DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages(DltGatewayConnection* con, char* value) { - char *token = NULL; - char *rest = NULL; - DltPassiveControlMessage *head = NULL; + char* token = NULL; + char* rest = NULL; + DltPassiveControlMessage* head = NULL; if ((con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -382,8 +357,8 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( token = strtok_r(value, ",", &rest); while (token != NULL) { - char *p_token = NULL; - char *p_rest = NULL; + char* p_token = NULL; + char* p_rest = NULL; uint32_t id = 0; p_token = strtok_r(token, ":", &p_rest); @@ -401,10 +376,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( con->p_control_msgs->interval = (unsigned int)strtol(p_rest, NULL, 10); if (con->p_control_msgs->interval == 0) - dlt_vlog(LOG_WARNING, - "%s interval is %d. It won't be send periodically.\n", - dlt_get_service_name(con->p_control_msgs->id), - con->p_control_msgs->interval); + dlt_vlog( + LOG_WARNING, "%s interval is %d. It won't be send periodically.\n", + dlt_get_service_name(con->p_control_msgs->id), con->p_control_msgs->interval); break; } @@ -426,8 +400,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( } if (dlt_gateway_allocate_control_messages(con) != DLT_RETURN_OK) { - dlt_log(LOG_ERR, - "Passive Control Message could not be allocated\n"); + dlt_log(LOG_ERR, "Passive Control Message could not be allocated\n"); return DLT_RETURN_ERROR; } @@ -438,10 +411,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( con->p_control_msgs->interval = (unsigned int)strtol(p_rest, NULL, 10); if (con->p_control_msgs->interval == 0) - dlt_vlog(LOG_WARNING, - "%s interval is %d. It won't be send periodically.\n", - dlt_get_service_name(con->p_control_msgs->id), - con->p_control_msgs->interval); + dlt_vlog( + LOG_WARNING, "%s interval is %d. It won't be send periodically.\n", + dlt_get_service_name(con->p_control_msgs->id), con->p_control_msgs->interval); if (head == NULL) head = con->p_control_msgs; @@ -449,17 +421,12 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( } if ((errno == EINVAL) || (errno == ERANGE)) { - dlt_vlog(LOG_ERR, - "Control message ID is not an integer: %s\n", - p_token); + dlt_vlog(LOG_ERR, "Control message ID is not an integer: %s\n", p_token); return DLT_RETURN_ERROR; - } - else if ((con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) || - (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY)) - { - dlt_vlog(LOG_ERR, - "Control message ID is not valid: %s\n", - p_token); + } else if ( + (con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) + || (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY)) { + dlt_vlog(LOG_ERR, "Control message ID is not valid: %s\n", p_token); return DLT_RETURN_ERROR; } @@ -479,55 +446,18 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( * dlt_gateway_check_param needs to be updated as well * */ DLT_STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT] = { - [GW_CONF_IP_ADDRESS] = { - .key = "IPaddress", - .func = dlt_gateway_check_ip, - .is_opt = 0 - }, - [GW_CONF_PORT] = { - .key = "Port", - .func = dlt_gateway_check_port, - .is_opt = 1 - }, - [GW_CONF_ECUID] = { - .key = "EcuID", - .func = dlt_gateway_check_ecu, - .is_opt = 0 - }, - [GW_CONF_CONNECT] = { - .key = "Connect", - .func = dlt_gateway_check_connect_trigger, - .is_opt = 1 - }, - [GW_CONF_TIMEOUT] = { - .key = "Timeout", - .func = dlt_gateway_check_timeout, - .is_opt = 0 - }, - [GW_CONF_SEND_CONTROL] = { - .key = "SendControl", - .func = dlt_gateway_check_control_messages, - .is_opt = 1 - }, - [GW_CONF_SEND_PERIODIC_CONTROL] = { - .key = "SendPeriodicControl", - .func = dlt_gateway_check_periodic_control_messages, - .is_opt = 1 - }, - [GW_CONF_SEND_SERIAL_HEADER] = { - .key = "SendSerialHeader", - .func = dlt_gateway_check_send_serial, - .is_opt = 1 - } -}; + [GW_CONF_IP_ADDRESS] = {.key = "IPaddress", .func = dlt_gateway_check_ip, .is_opt = 0}, + [GW_CONF_PORT] = {.key = "Port", .func = dlt_gateway_check_port, .is_opt = 1}, + [GW_CONF_ECUID] = {.key = "EcuID", .func = dlt_gateway_check_ecu, .is_opt = 0}, + [GW_CONF_CONNECT] = {.key = "Connect", .func = dlt_gateway_check_connect_trigger, .is_opt = 1}, + [GW_CONF_TIMEOUT] = {.key = "Timeout", .func = dlt_gateway_check_timeout, .is_opt = 0}, + [GW_CONF_SEND_CONTROL] = {.key = "SendControl", .func = dlt_gateway_check_control_messages, .is_opt = 1}, + [GW_CONF_SEND_PERIODIC_CONTROL] = + {.key = "SendPeriodicControl", .func = dlt_gateway_check_periodic_control_messages, .is_opt = 1}, + [GW_CONF_SEND_SERIAL_HEADER] = {.key = "SendSerialHeader", .func = dlt_gateway_check_send_serial, .is_opt = 1}}; DLT_STATIC DltGatewayGeneralConf general_entries[GW_CONF_COUNT] = { - [GW_CONF_GENERAL_INTERVAL] = { - .key = "Interval", - .func = dlt_gateway_check_interval, - .is_opt = 1 - } -}; + [GW_CONF_GENERAL_INTERVAL] = {.key = "Interval", .func = dlt_gateway_check_interval, .is_opt = 1}}; #define DLT_GATEWAY_NUM_PROPERTIES_MAX GW_CONF_COUNT @@ -539,9 +469,8 @@ DLT_STATIC DltGatewayGeneralConf general_entries[GW_CONF_COUNT] = { * @param value specified property value from configuration file * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_general_param(DltGateway *gateway, - DltGatewayGeneralConfType ctype, - char *value) +DLT_STATIC DltReturnValue +dlt_gateway_check_general_param(DltGateway* gateway, DltGatewayGeneralConfType ctype, char* value) { if ((gateway == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -563,10 +492,8 @@ DLT_STATIC DltReturnValue dlt_gateway_check_general_param(DltGateway *gateway, * @param value specified property value from configuration file * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_check_param(DltGateway *gateway, - DltGatewayConnection *con, - DltGatewayConfType ctype, - char *value) +DLT_STATIC DltReturnValue +dlt_gateway_check_param(DltGateway* gateway, DltGatewayConnection* con, DltGatewayConfType ctype, char* value) { if ((gateway == NULL) || (con == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -587,9 +514,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_param(DltGateway *gateway, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_store_connection(DltGateway *gateway, - DltGatewayConnection *tmp, - int verbose) +int dlt_gateway_store_connection(DltGateway* gateway, DltGatewayConnection* tmp, int verbose) { int i = 0; @@ -623,9 +548,7 @@ int dlt_gateway_store_connection(DltGateway *gateway, gateway->connections[i].head = tmp->head; gateway->connections[i].send_serial = tmp->send_serial; - if (dlt_client_init_port(&gateway->connections[i].client, - gateway->connections[i].port, - verbose) != 0) { + if (dlt_client_init_port(&gateway->connections[i].client, gateway->connections[i].port, verbose) != 0) { free(gateway->connections[i].ip_address); gateway->connections[i].ip_address = NULL; free(gateway->connections[i].ecuid); @@ -637,10 +560,8 @@ int dlt_gateway_store_connection(DltGateway *gateway, } /* setup DltClient Structure */ - if (dlt_client_set_server_ip(&gateway->connections[i].client, - gateway->connections[i].ip_address) == -1) { - dlt_log(LOG_ERR, - "dlt_client_set_server_ip() failed for gateway connection \n"); + if (dlt_client_set_server_ip(&gateway->connections[i].client, gateway->connections[i].ip_address) == -1) { + dlt_log(LOG_ERR, "dlt_client_set_server_ip() failed for gateway connection \n"); return DLT_RETURN_ERROR; } @@ -655,11 +576,11 @@ int dlt_gateway_store_connection(DltGateway *gateway, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) +int dlt_gateway_configure(DltGateway* gateway, char* config_file, int verbose) { int ret = 0; int i = 0; - DltConfigFile *file = NULL; + DltConfigFile* file = NULL; int num_sections = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -671,7 +592,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) /* read configuration file */ file = dlt_config_file_init(config_file); - if(file == NULL) { + if (file == NULL) { return DLT_RETURN_ERROR; } @@ -690,11 +611,9 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) * Try to use default for interval. */ gateway->num_connections = num_sections; - dlt_vlog(LOG_WARNING, - "Missing General section in gateway. Using default interval %d (secs)\n", - gateway->interval); - } - else { + dlt_vlog( + LOG_WARNING, "Missing General section in gateway. Using default interval %d (secs)\n", gateway->interval); + } else { /* * Since the General section is also counted in num_sections, * so number of connections must be number of sections - 1. @@ -702,8 +621,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) gateway->num_connections = num_sections - 1; } - gateway->connections = calloc((size_t)gateway->num_connections, - sizeof(DltGatewayConnection)); + gateway->connections = calloc((size_t)gateway->num_connections, sizeof(DltGatewayConnection)); if (gateway->connections == NULL) { dlt_config_file_release(file); @@ -716,8 +634,8 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) int invalid = 0; DltGatewayConfType j = 0; DltGatewayGeneralConfType g = 0; - char section[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; - char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; + char section[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {'\0'}; + char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {'\0'}; memset(&tmp, 0, sizeof(tmp)); @@ -731,26 +649,16 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) continue; } - if (strncmp(section, DLT_GATEWAY_GENERAL_SECTION_NAME, - sizeof(DLT_GATEWAY_GENERAL_SECTION_NAME)) == 0) { + if (strncmp(section, DLT_GATEWAY_GENERAL_SECTION_NAME, sizeof(DLT_GATEWAY_GENERAL_SECTION_NAME)) == 0) { for (g = 0; g < GW_CONF_GENEREL_COUNT; g++) { - ret = dlt_config_file_get_value(file, - section, - general_entries[g].key, - value); + ret = dlt_config_file_get_value(file, section, general_entries[g].key, value); if ((ret != 0) && general_entries[g].is_opt) { /* Use default values for this key */ - dlt_vlog(LOG_WARNING, - "Using default for %s.\n", - general_entries[g].key); + dlt_vlog(LOG_WARNING, "Using default for %s.\n", general_entries[g].key); continue; - } - else if (ret != 0) - { - dlt_vlog(LOG_WARNING, - "Missing configuration for %s.\n", - general_entries[g].key); + } else if (ret != 0) { + dlt_vlog(LOG_WARNING, "Missing configuration for %s.\n", general_entries[g].key); break; } @@ -758,30 +666,19 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) ret = dlt_gateway_check_general_param(gateway, g, value); if (ret != 0) - dlt_vlog(LOG_ERR, - "Configuration %s = %s is invalid. Using default.\n", - general_entries[g].key, value); + dlt_vlog( + LOG_ERR, "Configuration %s = %s is invalid. Using default.\n", general_entries[g].key, value); } - } - else { + } else { for (j = 0; j < GW_CONF_COUNT; j++) { - ret = dlt_config_file_get_value(file, - section, - configuration_entries[j].key, - value); + ret = dlt_config_file_get_value(file, section, configuration_entries[j].key, value); if ((ret != 0) && configuration_entries[j].is_opt) { /* Use default values for this key */ - dlt_vlog(LOG_WARNING, - "Using default for %s.\n", - configuration_entries[j].key); + dlt_vlog(LOG_WARNING, "Using default for %s.\n", configuration_entries[j].key); continue; - } - else if (ret != 0) - { - dlt_vlog(LOG_WARNING, - "Missing configuration for %s.\n", - configuration_entries[j].key); + } else if (ret != 0) { + dlt_vlog(LOG_WARNING, "Missing configuration for %s.\n", configuration_entries[j].key); invalid = 1; break; } @@ -790,10 +687,11 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) ret = dlt_gateway_check_param(gateway, &tmp, j, value); if (ret != 0) - dlt_vlog(LOG_ERR, - "Configuration %s = %s is invalid.\n" - "Using default.\n", - configuration_entries[j].key, value); + dlt_vlog( + LOG_ERR, + "Configuration %s = %s is invalid.\n" + "Using default.\n", + configuration_entries[j].key, value); } if (!tmp.ip_address) { @@ -801,12 +699,12 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) } if (invalid) { - dlt_vlog(LOG_ERR, - "%s configuration is invalid.\n" - "Ignoring.\n", - section); - } - else { + dlt_vlog( + LOG_ERR, + "%s configuration is invalid.\n" + "Ignoring.\n", + section); + } else { ret = dlt_gateway_store_connection(gateway, &tmp, verbose); if (ret != 0) @@ -829,7 +727,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose) return ret; } -int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose) +int dlt_gateway_init(DltDaemonLocal* daemon_local, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -838,21 +736,18 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose) return DLT_RETURN_WRONG_PARAMETER; } - DltGateway *gateway = &daemon_local->pGateway; + DltGateway* gateway = &daemon_local->pGateway; if (gateway != NULL) { /* Get default value from daemon_local */ gateway->send_serial = daemon_local->flags.lflag; gateway->interval = DLT_GATEWAY_TIMER_DEFAULT_INTERVAL; - if (dlt_gateway_configure(gateway, - daemon_local->flags.gatewayConfigFile, - verbose) != 0) { + if (dlt_gateway_configure(gateway, daemon_local->flags.gatewayConfigFile, verbose) != 0) { dlt_log(LOG_ERR, "Gateway initialization failed\n"); return DLT_RETURN_ERROR; } - } - else { + } else { dlt_log(LOG_CRIT, "Pointer to Gateway structure is NULL\n"); return DLT_RETURN_ERROR; } @@ -863,9 +758,9 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose) return DLT_RETURN_OK; } -void dlt_gateway_deinit(DltGateway *gateway, int verbose) +void dlt_gateway_deinit(DltGateway* gateway, int verbose) { - DltPassiveControlMessage *msg; + DltPassiveControlMessage* msg; int i = 0; if (gateway == NULL) { @@ -876,7 +771,7 @@ void dlt_gateway_deinit(DltGateway *gateway, int verbose) PRINT_FUNCTION_VERBOSE(verbose); for (i = 0; i < gateway->num_connections; i++) { - DltGatewayConnection *c = &gateway->connections[i]; + DltGatewayConnection* c = &gateway->connections[i]; dlt_client_cleanup(&c->client, verbose); free(c->ip_address); c->ip_address = NULL; @@ -902,11 +797,9 @@ void dlt_gateway_deinit(DltGateway *gateway, int verbose) * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, - DltGatewayConnection *con, - int verbose) +DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal* daemon_local, DltGatewayConnection* con, int verbose) { - DltPassiveControlMessage *control_msg = NULL; + DltPassiveControlMessage* control_msg = NULL; unsigned int sendtime = 1; if ((daemon_local == NULL) || (con == NULL)) { @@ -921,11 +814,8 @@ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, con->sendtime_cnt = 0; /* setup dlt connection and add to poll event loop here */ - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - con->client.sock, - POLLIN, - DLT_CONNECTION_GATEWAY) != 0) { + if (dlt_connection_create(daemon_local, &daemon_local->pEvent, con->client.sock, POLLIN, DLT_CONNECTION_GATEWAY) + != 0) { dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } @@ -934,19 +824,14 @@ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, control_msg = con->p_control_msgs; while (control_msg != NULL) { - if ((control_msg->type == CONTROL_MESSAGE_ON_STARTUP) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) { - if (dlt_gateway_send_control_message(con, - control_msg, - NULL, - verbose) == DLT_RETURN_OK) + if ((control_msg->type == CONTROL_MESSAGE_ON_STARTUP) || (control_msg->type == CONTROL_MESSAGE_BOTH)) { + if (dlt_gateway_send_control_message(con, control_msg, NULL, verbose) == DLT_RETURN_OK) control_msg->req = CONTROL_MESSAGE_REQUESTED; } /* multiply periodic sending time */ - if (((control_msg->type == CONTROL_MESSAGE_PERIODIC) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) && - (control_msg->interval > 0)) + if (((control_msg->type == CONTROL_MESSAGE_PERIODIC) || (control_msg->type == CONTROL_MESSAGE_BOTH)) + && (control_msg->interval > 0)) sendtime *= control_msg->interval; control_msg = control_msg->next; @@ -959,9 +844,7 @@ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, return DLT_RETURN_OK; } -int dlt_gateway_establish_connections(DltGateway *gateway, - DltDaemonLocal *daemon_local, - int verbose) +int dlt_gateway_establish_connections(DltGateway* gateway, DltDaemonLocal* daemon_local, int verbose) { int i = 0; int ret = 0; @@ -974,12 +857,11 @@ int dlt_gateway_establish_connections(DltGateway *gateway, } for (i = 0; i < gateway->num_connections; i++) { - DltGatewayConnection *con = &(gateway->connections[i]); - DltPassiveControlMessage *control_msg = NULL; + DltGatewayConnection* con = &(gateway->connections[i]); + DltPassiveControlMessage* control_msg = NULL; - if ((con->status != DLT_GATEWAY_CONNECTED) && - (con->trigger != DLT_GATEWAY_ON_DEMAND) && - (con->trigger != DLT_GATEWAY_DISABLED)) { + if ((con->status != DLT_GATEWAY_CONNECTED) && (con->trigger != DLT_GATEWAY_ON_DEMAND) + && (con->trigger != DLT_GATEWAY_DISABLED)) { ret = dlt_client_connect(&con->client, verbose); if (ret == 0) { @@ -988,35 +870,28 @@ int dlt_gateway_establish_connections(DltGateway *gateway, dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } - } - else { - dlt_log(LOG_DEBUG, - "Passive Node is not up. Connection failed.\n"); + } else { + dlt_log(LOG_DEBUG, "Passive Node is not up. Connection failed.\n"); con->timeout_cnt++; if (con->timeout > 0) { if (con->timeout_cnt > con->timeout) { con->trigger = DLT_GATEWAY_DISABLED; - dlt_log(LOG_WARNING, - "Passive Node connection retry timed out. " - "Give up.\n"); + dlt_log( + LOG_WARNING, + "Passive Node connection retry timed out. " + "Give up.\n"); } - } - else if (con->timeout == 0) { + } else if (con->timeout == 0) { dlt_vlog(LOG_DEBUG, "Retried [%d] times\n", con->timeout_cnt); } } - } - else if ((con->status == DLT_GATEWAY_CONNECTED) && - (con->trigger != DLT_GATEWAY_DISABLED)) - { + } else if ((con->status == DLT_GATEWAY_CONNECTED) && (con->trigger != DLT_GATEWAY_DISABLED)) { /* setup dlt connection and add to poll event loop here */ - if (dlt_connection_create(daemon_local, - &daemon_local->pEvent, - con->client.sock, - POLLIN, - DLT_CONNECTION_GATEWAY) != 0) { + if (dlt_connection_create( + daemon_local, &daemon_local->pEvent, con->client.sock, POLLIN, DLT_CONNECTION_GATEWAY) + != 0) { dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } @@ -1025,12 +900,8 @@ int dlt_gateway_establish_connections(DltGateway *gateway, control_msg = con->p_control_msgs; while (control_msg != NULL) { - if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) { - if (dlt_gateway_send_control_message(con, - control_msg, - NULL, - verbose) == DLT_RETURN_OK) + if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || (control_msg->type == CONTROL_MESSAGE_BOTH)) { + if (dlt_gateway_send_control_message(con, control_msg, NULL, verbose) == DLT_RETURN_OK) control_msg->req = CONTROL_MESSAGE_REQUESTED; } @@ -1049,7 +920,7 @@ int dlt_gateway_establish_connections(DltGateway *gateway, return DLT_RETURN_OK; } -DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd) +DltReceiver* dlt_gateway_get_connection_receiver(DltGateway* gateway, int fd) { int i = 0; @@ -1059,7 +930,7 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd) } for (i = 0; i < gateway->num_connections; i++) { - DltGatewayConnection *c = &gateway->connections[i]; + DltGatewayConnection* c = &gateway->connections[i]; if ((c->status == DLT_GATEWAY_CONNECTED) && (c->client.sock == fd)) return &c->client.receiver; @@ -1078,14 +949,11 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd) * @param verbose verbose flag * @return Value from DltReturnValue enum */ -DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, - char *ecu, - DltMessage *msg, - int req, - int verbose) +DLT_STATIC DltReturnValue +dlt_gateway_parse_get_log_info(DltDaemon* daemon, char* ecu, DltMessage* msg, int req, int verbose) { - char resp_text[DLT_RECEIVE_BUFSIZE] = { '\0' }; - DltServiceGetLogInfoResponse *resp = NULL; + char resp_text[DLT_RECEIVE_BUFSIZE] = {'\0'}; + DltServiceGetLogInfoResponse* resp = NULL; AppIDsType app; ContextIDsInfoType con; int i = 0; @@ -1117,20 +985,16 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, } /* check response */ - if (dlt_message_payload(msg, - resp_text, - DLT_RECEIVE_BUFSIZE, - DLT_OUTPUT_ASCII, 0) != DLT_RETURN_OK) { + if (dlt_message_payload(msg, resp_text, DLT_RECEIVE_BUFSIZE, DLT_OUTPUT_ASCII, 0) != DLT_RETURN_OK) { dlt_log(LOG_ERR, "GET_LOG_INFO payload failed\n"); return DLT_RETURN_ERROR; } /* prepare pointer to message request */ - resp = (DltServiceGetLogInfoResponse *)calloc(1, sizeof(DltServiceGetLogInfoResponse)); + resp = (DltServiceGetLogInfoResponse*)calloc(1, sizeof(DltServiceGetLogInfoResponse)); if (resp == NULL) { - dlt_log(LOG_ERR, - "Get Log Info Response could not be allocated\n"); + dlt_log(LOG_ERR, "Get Log Info Response could not be allocated\n"); return DLT_RETURN_ERROR; } @@ -1150,16 +1014,8 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, app = resp->log_info_type.app_ids[i]; /* add application */ - if (dlt_daemon_application_add(daemon, - app.app_id, - 0, - app.app_description, - -1, - ecu, - verbose) == 0) { - dlt_vlog(LOG_WARNING, - "%s: dlt_daemon_application_add failed\n", - __func__); + if (dlt_daemon_application_add(daemon, app.app_id, 0, app.app_description, -1, ecu, verbose) == 0) { + dlt_vlog(LOG_WARNING, "%s: dlt_daemon_application_add failed\n", __func__); dlt_client_cleanup_get_log_info(resp); return DLT_RETURN_ERROR; } @@ -1168,20 +1024,11 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, con = app.context_id_info[j]; /* add context */ - if (dlt_daemon_context_add(daemon, - app.app_id, - con.context_id, - (int8_t)con.log_level, - (int8_t)con.trace_status, - 0, - -1, - con.context_description, - ecu, - verbose) == 0) { - dlt_vlog(LOG_WARNING, - "%s: dlt_daemon_context_add failed for %4s\n", - __func__, - app.app_id); + if (dlt_daemon_context_add( + daemon, app.app_id, con.context_id, (int8_t)con.log_level, (int8_t)con.trace_status, 0, -1, + con.context_description, ecu, verbose) + == 0) { + dlt_vlog(LOG_WARNING, "%s: dlt_daemon_context_add failed for %4s\n", __func__, app.app_id); dlt_client_cleanup_get_log_info(resp); return DLT_RETURN_ERROR; } @@ -1204,14 +1051,11 @@ DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -DLT_STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - char *ecu, - DltMessage *msg, - int verbose) +DLT_STATIC int dlt_gateway_parse_get_default_log_level( + DltDaemon* daemon, DltDaemonLocal* daemon_local, char* ecu, DltMessage* msg, int verbose) { - DltServiceGetDefaultLogLevelResponse *resp = NULL; - DltGatewayConnection *con = NULL; + DltServiceGetDefaultLogLevelResponse* resp = NULL; + DltGatewayConnection* con = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1220,22 +1064,18 @@ DLT_STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon, return DLT_RETURN_WRONG_PARAMETER; } - if (dlt_check_rcv_data_size(msg->datasize, - sizeof(DltServiceGetDefaultLogLevelResponse)) < 0) { + if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceGetDefaultLogLevelResponse)) < 0) { dlt_log(LOG_ERR, "Received data incomplete.\n"); return DLT_RETURN_ERROR; } /* prepare pointer to message request */ - resp = (DltServiceGetDefaultLogLevelResponse *)(msg->databuffer); + resp = (DltServiceGetDefaultLogLevelResponse*)(msg->databuffer); - con = dlt_gateway_get_connection(&daemon_local->pGateway, - ecu, - verbose); + con = dlt_gateway_get_connection(&daemon_local->pGateway, ecu, verbose); if (con == NULL) { - dlt_vlog(LOG_ERR, "No information about passive ECU: %s\n", - ecu); + dlt_vlog(LOG_ERR, "No information about passive ECU: %s\n", ecu); return DLT_RETURN_ERROR; } @@ -1253,16 +1093,13 @@ DLT_STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon, * @param verbose int * @return 0 on success, -1 otherwise */ -DLT_STATIC int dlt_gateway_control_service_logstorage(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - int verbose) +DLT_STATIC int dlt_gateway_control_service_logstorage(DltDaemon* daemon, DltDaemonLocal* daemon_local, int verbose) { unsigned int connection_type = 0; int i = 0; if (daemon_local->flags.offlineLogstorageMaxDevices <= 0) { - dlt_log(LOG_INFO, - "Logstorage functionality not enabled or MAX device set is 0\n"); + dlt_log(LOG_INFO, "Logstorage functionality not enabled or MAX device set is 0\n"); return DLT_RETURN_ERROR; } @@ -1271,24 +1108,19 @@ DLT_STATIC int dlt_gateway_control_service_logstorage(DltDaemon *daemon, if (connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) /* Check if log level of running application needs an update */ - dlt_daemon_logstorage_update_application_loglevel(daemon, - daemon_local, - i, - verbose); + dlt_daemon_logstorage_update_application_loglevel(daemon, daemon_local, i, verbose); } return DLT_RETURN_OK; } -DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +DltReturnValue dlt_gateway_process_passive_node_messages( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { int i = 0; - DltGateway *gateway = NULL; - DltGatewayConnection *con = NULL; - DltMessage msg = { 0 }; + DltGateway* gateway = NULL; + DltGatewayConnection* con = NULL; + DltMessage msg = {0}; bool b_reset_receiver = false; if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) { @@ -1306,7 +1138,8 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, } for (i = 0; i < gateway->num_connections; i++) - if ((gateway->connections[i].status == DLT_GATEWAY_CONNECTED) && (gateway->connections[i].client.sock == receiver->fd)) { + if ((gateway->connections[i].status == DLT_GATEWAY_CONNECTED) + && (gateway->connections[i].client.sock == receiver->fd)) { con = &gateway->connections[i]; break; } @@ -1318,8 +1151,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, /* now the corresponding passive node connection is available */ if (dlt_message_init(&msg, verbose) == -1) { - dlt_log(LOG_ERR, - "Cannot initialize DLT message for passive node forwarding\n"); + dlt_log(LOG_ERR, "Cannot initialize DLT message for passive node forwarding\n"); return DLT_RETURN_ERROR; } @@ -1337,61 +1169,46 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, dlt_log(LOG_WARNING, "Try to reconnect.\n"); con->reconnect_cnt += 1; con->timeout_cnt = 0; - } - else { + } else { con->status = DLT_GATEWAY_DISCONNECTED; - if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, - daemon_local, - receiver->fd) != 0) + if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, daemon_local, receiver->fd) != 0) dlt_log(LOG_ERR, "Remove passive node Connection failed\n"); } return DLT_RETURN_OK; } - while (dlt_message_read(&msg, - (unsigned char *)receiver->buf, - (unsigned int)receiver->bytesRcvd, - 0, - verbose) == DLT_MESSAGE_ERROR_OK) { - DltStandardHeaderExtra *header = (DltStandardHeaderExtra *) - (msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader)); + while (dlt_message_read(&msg, (unsigned char*)receiver->buf, (unsigned int)receiver->bytesRcvd, 0, verbose) + == DLT_MESSAGE_ERROR_OK) { + DltStandardHeaderExtra* header = + (DltStandardHeaderExtra*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)); /* only forward messages if the received ECUid is the expected one */ if (strncmp(header->ecu, con->ecuid, DLT_ID_SIZE) == 0) { uint32_t id; uint32_t id_tmp; - DltPassiveControlMessage *control_msg = con->p_control_msgs; + DltPassiveControlMessage* control_msg = con->p_control_msgs; - dlt_vlog(LOG_DEBUG, - "Received ECUid (%.*s) similar to configured ECUid(%s). " - "Forwarding message (%s).\n", - DLT_ID_SIZE, - header->ecu, - con->ecuid, - msg.databuffer); + dlt_vlog( + LOG_DEBUG, + "Received ECUid (%.*s) similar to configured ECUid(%s). " + "Forwarding message (%s).\n", + DLT_ID_SIZE, header->ecu, con->ecuid, msg.databuffer); - id_tmp = *((uint32_t *)(msg.databuffer)); + id_tmp = *((uint32_t*)(msg.databuffer)); id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp); /* if ID is GET_LOG_INFO, parse msg */ if (id == DLT_SERVICE_ID_GET_LOG_INFO) { while (control_msg) { if (control_msg->id == id) { - if (dlt_gateway_parse_get_log_info(daemon, - header->ecu, - &msg, - control_msg->req, - verbose) == DLT_RETURN_ERROR) + if (dlt_gateway_parse_get_log_info(daemon, header->ecu, &msg, control_msg->req, verbose) + == DLT_RETURN_ERROR) dlt_log(LOG_WARNING, "Parsing GET_LOG_INFO message failed!\n"); /* Check for logstorage */ - dlt_gateway_control_service_logstorage(daemon, - daemon_local, - verbose); + dlt_gateway_control_service_logstorage(daemon, daemon_local, verbose); /* initialize the flag */ control_msg->req = CONTROL_MESSAGE_NOT_REQUESTED; @@ -1400,56 +1217,37 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, control_msg = control_msg->next; } - } - else if (id == DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL) - { - if (dlt_gateway_parse_get_default_log_level( - daemon, - daemon_local, - header->ecu, - &msg, - verbose) == DLT_RETURN_ERROR) - dlt_log(LOG_WARNING, - "Parsing GET_DEFAULT_LOG_LEVEL message failed!\n"); + } else if (id == DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL) { + if (dlt_gateway_parse_get_default_log_level(daemon, daemon_local, header->ecu, &msg, verbose) + == DLT_RETURN_ERROR) + dlt_log(LOG_WARNING, "Parsing GET_DEFAULT_LOG_LEVEL message failed!\n"); } /* prepare storage header */ - if (dlt_set_storageheader(msg.storageheader, - msg.headerextra.ecu) == DLT_RETURN_ERROR) { + if (dlt_set_storageheader(msg.storageheader, msg.headerextra.ecu) == DLT_RETURN_ERROR) { dlt_vlog(LOG_ERR, "%s: Can't set storage header\n", __func__); return DLT_RETURN_ERROR; } - dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, - daemon, - daemon_local, - msg.headerbuffer, - (int)sizeof(DltStorageHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (int)((size_t)msg.headersize - sizeof(DltStorageHeader)), - msg.databuffer, - (int)((size_t)msg.datasize), - verbose); + dlt_daemon_client_send( + DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local, msg.headerbuffer, (int)sizeof(DltStorageHeader), + msg.headerbuffer + sizeof(DltStorageHeader), (int)((size_t)msg.headersize - sizeof(DltStorageHeader)), + msg.databuffer, (int)((size_t)msg.datasize), verbose); } else { /* otherwise remove this connection and do not connect again */ - dlt_vlog(LOG_WARNING, - "Received ECUid (%.*s) differs to configured ECUid(%s). " - "Discard this message.\n", - DLT_ID_SIZE, - header->ecu, - con->ecuid); + dlt_vlog( + LOG_WARNING, + "Received ECUid (%.*s) differs to configured ECUid(%s). " + "Discard this message.\n", + DLT_ID_SIZE, header->ecu, con->ecuid); /* disconnect from passive node */ con->status = DLT_GATEWAY_DISCONNECTED; con->trigger = DLT_GATEWAY_DISABLED; - if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, - daemon_local, - receiver->fd) - != 0) + if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, daemon_local, receiver->fd) != 0) dlt_log(LOG_ERR, "Remove passive node Connection failed\n"); - dlt_log(LOG_WARNING, - "Disconnect from passive node due to invalid ECUid\n"); + dlt_log(LOG_WARNING, "Disconnect from passive node due to invalid ECUid\n"); /* it is possible that a partial log was received through the last recv call */ /* however, the rest will never be received since the socket will be closed by above method */ @@ -1458,20 +1256,18 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, } if (msg.found_serialheader) { - if (dlt_receiver_remove(receiver, - (int)((size_t)msg.headersize + - (size_t)msg.datasize - - sizeof(DltStorageHeader) + - sizeof(dltSerialHeader))) == -1) { + if (dlt_receiver_remove( + receiver, (int)((size_t)msg.headersize + (size_t)msg.datasize - sizeof(DltStorageHeader) + + sizeof(dltSerialHeader))) + == -1) { /* Return value ignored */ dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; } - } - else if (dlt_receiver_remove(receiver, - (int)((size_t)msg.headersize + - (size_t)msg.datasize - - sizeof(DltStorageHeader))) == -1) { + } else if ( + dlt_receiver_remove( + receiver, (int)((size_t)msg.headersize + (size_t)msg.datasize - sizeof(DltStorageHeader))) + == -1) { /* Return value ignored */ dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; @@ -1493,10 +1289,8 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, return DLT_RETURN_OK; } -int dlt_gateway_process_gateway_timer(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *receiver, - int verbose) +int dlt_gateway_process_gateway_timer( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* receiver, int verbose) { uint64_t expir = 0; ssize_t res = 0; @@ -1504,41 +1298,31 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon, PRINT_FUNCTION_VERBOSE(verbose); if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL)) { - dlt_vlog(LOG_ERR, - "%s: invalid parameters\n", - __func__); + dlt_vlog(LOG_ERR, "%s: invalid parameters\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } res = read(receiver->fd, &expir, sizeof(expir)); if (res < 0) - dlt_vlog(LOG_WARNING, - "%s: Fail to read timer (%s)\n", - __func__, - strerror(errno)); - /* Activity received on timer_wd, but unable to read the fd: - * let's go on sending notification */ + dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__, strerror(errno)); + /* Activity received on timer_wd, but unable to read the fd: + * let's go on sending notification */ /* try to connect to passive nodes */ - dlt_gateway_establish_connections(&daemon_local->pGateway, - daemon_local, - verbose); + dlt_gateway_establish_connections(&daemon_local->pGateway, daemon_local, verbose); dlt_log(LOG_DEBUG, "Gateway Timer\n"); return DLT_RETURN_OK; } -int dlt_gateway_forward_control_message(DltGateway *gateway, - DltDaemonLocal *daemon_local, - DltMessage *msg, - char *ecu, - int verbose) +int dlt_gateway_forward_control_message( + DltGateway* gateway, DltDaemonLocal* daemon_local, DltMessage* msg, char* ecu, int verbose) { int i = 0; int ret = 0; - DltGatewayConnection *con = NULL; + DltGatewayConnection* con = NULL; uint32_t id_tmp; uint32_t id; @@ -1550,9 +1334,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway, } for (i = 0; i < gateway->num_connections; i++) - if (strncmp(gateway->connections[i].ecuid, - ecu, - DLT_ID_SIZE) == 0) { + if (strncmp(gateway->connections[i].ecuid, ecu, DLT_ID_SIZE) == 0) { con = &gateway->connections[i]; break; } @@ -1570,10 +1352,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway, } if (con->send_serial) { /* send serial header */ - ret = (int)send(con->client.sock, - (const void *)dltSerialHeader, - sizeof(dltSerialHeader), - 0); + ret = (int)send(con->client.sock, (const void*)dltSerialHeader, sizeof(dltSerialHeader), 0); if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); @@ -1581,16 +1360,14 @@ int dlt_gateway_forward_control_message(DltGateway *gateway, } } - ret = (int)send(con->client.sock, - msg->headerbuffer + sizeof(DltStorageHeader), - (size_t)(msg->headersize - (int)sizeof(DltStorageHeader)), - 0); + ret = (int)send( + con->client.sock, msg->headerbuffer + sizeof(DltStorageHeader), + (size_t)(msg->headersize - (int)sizeof(DltStorageHeader)), 0); if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); return DLT_RETURN_ERROR; - } - else { + } else { ret = (int)send(con->client.sock, msg->databuffer, (size_t)msg->datasize, 0); if (ret == -1) { @@ -1599,25 +1376,19 @@ int dlt_gateway_forward_control_message(DltGateway *gateway, } } - id_tmp = *((uint32_t *)(msg->databuffer)); + id_tmp = *((uint32_t*)(msg->databuffer)); id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); - dlt_vlog(LOG_INFO, - "Control message forwarded : %s\n", - dlt_get_service_name(id)); + dlt_vlog(LOG_INFO, "Control message forwarded : %s\n", dlt_get_service_name(id)); return DLT_RETURN_OK; } -int dlt_gateway_forward_control_message_v2(DltGateway *gateway, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - uint8_t eculen, - char *ecu, - int verbose) +int dlt_gateway_forward_control_message_v2( + DltGateway* gateway, DltDaemonLocal* daemon_local, DltMessageV2* msg, uint8_t eculen, char* ecu, int verbose) { int i = 0; int ret = 0; - DltGatewayConnection *con = NULL; + DltGatewayConnection* con = NULL; uint32_t id_tmp; uint32_t id; @@ -1629,9 +1400,7 @@ int dlt_gateway_forward_control_message_v2(DltGateway *gateway, } for (i = 0; i < gateway->num_connections; i++) - if (strncmp(gateway->connections[i].ecuid2, - ecu, - eculen) == 0) { + if (strncmp(gateway->connections[i].ecuid2, ecu, eculen) == 0) { con = &gateway->connections[i]; break; } @@ -1649,10 +1418,7 @@ int dlt_gateway_forward_control_message_v2(DltGateway *gateway, } if (con->send_serial) { /* send serial header */ - ret = (int)send(con->client.sock, - (const void *)dltSerialHeader, - sizeof(dltSerialHeader), - 0); + ret = (int)send(con->client.sock, (const void*)dltSerialHeader, sizeof(dltSerialHeader), 0); if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); @@ -1660,18 +1426,16 @@ int dlt_gateway_forward_control_message_v2(DltGateway *gateway, } } - //TBD: Review if storage header needs to be sent for v2 - //TBD: Review msg->storageheadersizev2 or need to calculate size - ret = (int)send(con->client.sock, - (const void *)(msg->headerbufferv2 + msg->storageheadersizev2), - (size_t)(msg->headersizev2 - (int32_t)msg->storageheadersizev2), - 0); + // TBD: Review if storage header needs to be sent for v2 + // TBD: Review msg->storageheadersizev2 or need to calculate size + ret = (int)send( + con->client.sock, (const void*)(msg->headerbufferv2 + msg->storageheadersizev2), + (size_t)(msg->headersizev2 - (int32_t)msg->storageheadersizev2), 0); if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); return DLT_RETURN_ERROR; - } - else { + } else { ret = (int)send(con->client.sock, msg->databuffer, (size_t)msg->datasize, 0); if (ret == -1) { @@ -1680,25 +1444,20 @@ int dlt_gateway_forward_control_message_v2(DltGateway *gateway, } } - id_tmp = *((uint32_t *)(msg->databuffer)); - //TBD: Review id extraction for v2 + id_tmp = *((uint32_t*)(msg->databuffer)); + // TBD: Review id extraction for v2 id = DLT_ENDIAN_GET_32(msg->baseheaderv2->htyp2, id_tmp); - //TBD: Review check if dlt_get_service_name_v2 is needed - dlt_vlog(LOG_INFO, - "Control message forwarded : %s\n", - dlt_get_service_name(id)); + // TBD: Review check if dlt_get_service_name_v2 is needed + dlt_vlog(LOG_INFO, "Control message forwarded : %s\n", dlt_get_service_name(id)); return DLT_RETURN_OK; } -DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *gateway, - DltDaemonLocal *daemon_local, - char *node_id, - int conn_status, - int verbose) +DltReturnValue dlt_gateway_process_on_demand_request( + DltGateway* gateway, DltDaemonLocal* daemon_local, char* node_id, int conn_status, int verbose) { int i = 0; - DltGatewayConnection *con = NULL; + DltGatewayConnection* con = NULL; PRINT_FUNCTION_VERBOSE(verbose); @@ -1729,29 +1488,21 @@ DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *gateway, dlt_log(LOG_ERR, "Gateway connection creation failed\n"); return DLT_RETURN_ERROR; } - } - else { + } else { dlt_log(LOG_ERR, "Could not connect to passive node\n"); return DLT_RETURN_ERROR; } - } - else { + } else { dlt_log(LOG_INFO, "Passive node already connected\n"); } - } - else if (conn_status == 0) /* disconnect*/ + } else if (conn_status == 0) /* disconnect*/ { - con->status = DLT_GATEWAY_DISCONNECTED; con->trigger = DLT_GATEWAY_ON_DEMAND; - if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, - daemon_local, - con->client.sock) != 0) - dlt_log(LOG_ERR, - "Remove passive node event handler connection failed\n"); - } - else { + if (dlt_event_handler_unregister_connection(&daemon_local->pEvent, daemon_local, con->client.sock) != 0) + dlt_log(LOG_ERR, "Remove passive node event handler connection failed\n"); + } else { dlt_log(LOG_ERR, "Unknown command (connection_status)\n"); return DLT_RETURN_ERROR; } @@ -1759,19 +1510,15 @@ DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *gateway, return DLT_RETURN_OK; } -int dlt_gateway_send_control_message(DltGatewayConnection *con, - DltPassiveControlMessage *control_msg, - void *data, - int verbose) +int dlt_gateway_send_control_message( + DltGatewayConnection* con, DltPassiveControlMessage* control_msg, void* data, int verbose) { int ret = DLT_RETURN_OK; PRINT_FUNCTION_VERBOSE(verbose); if (con == NULL) { - dlt_vlog(LOG_WARNING, - "%s: Invalid parameter given\n", - __func__); + dlt_vlog(LOG_WARNING, "%s: Invalid parameter given\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -1785,18 +1532,14 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, if ((control_msg->interval) == 0) return DLT_RETURN_ERROR; - if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) { + if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || (control_msg->type == CONTROL_MESSAGE_BOTH)) { if ((con->sendtime_cnt - 1) % control_msg->interval != 0) return DLT_RETURN_ERROR; } } if (con->send_serial) { /* send serial header */ - ret = (int)send(con->client.sock, - (const void *)dltSerialHeader, - sizeof(dltSerialHeader), - 0); + ret = (int)send(con->client.sock, (const void*)dltSerialHeader, sizeof(dltSerialHeader), 0); if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); @@ -1817,40 +1560,31 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, case DLT_SERVICE_ID_SET_LOG_LEVEL: if (data == NULL) { - dlt_vlog(LOG_WARNING, - "Insufficient data for %s received. Send control request failed.\n", - dlt_get_service_name(control_msg->id)); + dlt_vlog( + LOG_WARNING, "Insufficient data for %s received. Send control request failed.\n", + dlt_get_service_name(control_msg->id)); return DLT_RETURN_ERROR; } - DltServiceSetLogLevel *req = (DltServiceSetLogLevel *)data; - return dlt_client_send_log_level(&con->client, - req->apid, - req->ctid, - req->log_level); + DltServiceSetLogLevel* req = (DltServiceSetLogLevel*)data; + return dlt_client_send_log_level(&con->client, req->apid, req->ctid, req->log_level); break; default: - dlt_vlog(LOG_WARNING, - "Cannot forward request: %s.\n", - dlt_get_service_name(control_msg->id)); + dlt_vlog(LOG_WARNING, "Cannot forward request: %s.\n", dlt_get_service_name(control_msg->id)); } return DLT_RETURN_OK; } -int dlt_gateway_send_control_message_v2(DltGatewayConnection *con, - DltPassiveControlMessage *control_msg, - void *data, - int verbose) +int dlt_gateway_send_control_message_v2( + DltGatewayConnection* con, DltPassiveControlMessage* control_msg, void* data, int verbose) { int ret = DLT_RETURN_OK; PRINT_FUNCTION_VERBOSE(verbose); if (con == NULL) { - dlt_vlog(LOG_WARNING, - "%s: Invalid parameter given\n", - __func__); + dlt_vlog(LOG_WARNING, "%s: Invalid parameter given\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -1864,18 +1598,14 @@ int dlt_gateway_send_control_message_v2(DltGatewayConnection *con, if (control_msg->interval == 0) return DLT_RETURN_ERROR; - if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || - (control_msg->type == CONTROL_MESSAGE_BOTH)) { + if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || (control_msg->type == CONTROL_MESSAGE_BOTH)) { if ((con->sendtime_cnt - 1) % control_msg->interval != 0) return DLT_RETURN_ERROR; } } if (con->send_serial) { /* send serial header */ - ret = (int)send(con->client.sock, - (const void *)dltSerialHeader, - sizeof(dltSerialHeader), - 0); + ret = (int)send(con->client.sock, (const void*)dltSerialHeader, sizeof(dltSerialHeader), 0); if (ret == -1) { dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n"); @@ -1896,32 +1626,25 @@ int dlt_gateway_send_control_message_v2(DltGatewayConnection *con, case DLT_SERVICE_ID_SET_LOG_LEVEL: if (data == NULL) { - dlt_vlog(LOG_WARNING, - "Insufficient data for %s received. Send control request failed.\n", - dlt_get_service_name(control_msg->id)); + dlt_vlog( + LOG_WARNING, "Insufficient data for %s received. Send control request failed.\n", + dlt_get_service_name(control_msg->id)); return DLT_RETURN_ERROR; } - DltServiceSetLogLevel *req = (DltServiceSetLogLevel *)data; - return dlt_client_send_log_level_v2(&con->client, - req->apid, - req->ctid, - req->log_level); + DltServiceSetLogLevel* req = (DltServiceSetLogLevel*)data; + return dlt_client_send_log_level_v2(&con->client, req->apid, req->ctid, req->log_level); break; default: - dlt_vlog(LOG_WARNING, - "Cannot forward request: %s.\n", - dlt_get_service_name(control_msg->id)); + dlt_vlog(LOG_WARNING, "Cannot forward request: %s.\n", dlt_get_service_name(control_msg->id)); } return DLT_RETURN_OK; } -DltGatewayConnection *dlt_gateway_get_connection(DltGateway *gateway, - char *ecu, - int verbose) +DltGatewayConnection* dlt_gateway_get_connection(DltGateway* gateway, char* ecu, int verbose) { - DltGatewayConnection *con = NULL; + DltGatewayConnection* con = NULL; int i = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -1943,11 +1666,9 @@ DltGatewayConnection *dlt_gateway_get_connection(DltGateway *gateway, return con; } -DltGatewayConnection *dlt_gateway_get_connection_v2(DltGateway *gateway, - char *ecu, - int verbose) +DltGatewayConnection* dlt_gateway_get_connection_v2(DltGateway* gateway, char* ecu, int verbose) { - DltGatewayConnection *con = NULL; + DltGatewayConnection* con = NULL; int i = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -1959,7 +1680,7 @@ DltGatewayConnection *dlt_gateway_get_connection_v2(DltGateway *gateway, for (i = 0; i < gateway->num_connections; i++) { con = &gateway->connections[i]; - //TBD: REVIEW strlen(ecu) usage + // TBD: REVIEW strlen(ecu) usage if (strncmp(con->ecuid2, ecu, strlen(ecu)) == 0) return con; } diff --git a/src/gateway/dlt_gateway.h b/src/gateway/dlt_gateway.h index 8a7c7c6f8..ae58a5004 100644 --- a/src/gateway/dlt_gateway.h +++ b/src/gateway/dlt_gateway.h @@ -67,7 +67,7 @@ * @param verbose verbose flag * @return 0 on success, -1 on error */ -int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose); +int dlt_gateway_init(DltDaemonLocal* daemon_local, int verbose); /** * De-initialize the gateway. All internal data will be freed. @@ -75,7 +75,7 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose); * @param g DltGateway pointer * @param verbose verbose flag */ -void dlt_gateway_deinit(DltGateway *g, int verbose); +void dlt_gateway_deinit(DltGateway* g, int verbose); /** * Establish all connections to passive nodes that are configured to be started @@ -89,9 +89,7 @@ void dlt_gateway_deinit(DltGateway *g, int verbose); * @param verbose verbose flag * @return 0 on success, -1 on error */ -int dlt_gateway_establish_connections(DltGateway *g, - DltDaemonLocal *daemon_local, - int verbose); +int dlt_gateway_establish_connections(DltGateway* g, DltDaemonLocal* daemon_local, int verbose); /** * Return the receiver for a given file descriptor @@ -100,7 +98,7 @@ int dlt_gateway_establish_connections(DltGateway *g, * @param fd file descriptor * @return Pointer to DltReceiver on success, NULL otherwise */ -DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *g, int fd); +DltReceiver* dlt_gateway_get_connection_receiver(DltGateway* g, int fd); /** @@ -112,10 +110,8 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *g, int fd); * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *recv, - int verbose); +DltReturnValue dlt_gateway_process_passive_node_messages( + DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* recv, int verbose); /** * Process gateway timer @@ -126,10 +122,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_process_gateway_timer(DltDaemon *daemon, - DltDaemonLocal *daemon_local, - DltReceiver *rec, - int verbose); +int dlt_gateway_process_gateway_timer(DltDaemon* daemon, DltDaemonLocal* daemon_local, DltReceiver* rec, int verbose); /** * Forward control messages to the specified passive node DLT Daemon. @@ -141,11 +134,8 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_forward_control_message(DltGateway *g, - DltDaemonLocal *daemon_local, - DltMessage *msg, - char *ecu, - int verbose); +int dlt_gateway_forward_control_message( + DltGateway* g, DltDaemonLocal* daemon_local, DltMessage* msg, char* ecu, int verbose); /** * DLTv2 Forward control messages to the specified passive node DLT Daemon. @@ -158,12 +148,8 @@ int dlt_gateway_forward_control_message(DltGateway *g, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_forward_control_message_v2(DltGateway *g, - DltDaemonLocal *daemon_local, - DltMessageV2 *msg, - uint8_t eculen, - char *ecu, - int verbose); +int dlt_gateway_forward_control_message_v2( + DltGateway* g, DltDaemonLocal* daemon_local, DltMessageV2* msg, uint8_t eculen, char* ecu, int verbose); /** * Process on demand connect/disconnect of passive nodes @@ -175,11 +161,8 @@ int dlt_gateway_forward_control_message_v2(DltGateway *g, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *g, - DltDaemonLocal *daemon_local, - char *node_id, - int connection_status, - int verbose); +DltReturnValue dlt_gateway_process_on_demand_request( + DltGateway* g, DltDaemonLocal* daemon_local, char* node_id, int connection_status, int verbose); /** * Send control message to passive node @@ -190,10 +173,8 @@ DltReturnValue dlt_gateway_process_on_demand_request(DltGateway *g, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_send_control_message(DltGatewayConnection *con, - DltPassiveControlMessage *control_msg, - void *data, - int verbose); +int dlt_gateway_send_control_message( + DltGatewayConnection* con, DltPassiveControlMessage* control_msg, void* data, int verbose); /** * DLTv2 Send control message to passive node for DLT version 2 @@ -204,10 +185,8 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, * @param verbose verbose flag * @return 0 on success, -1 otherwise */ -int dlt_gateway_send_control_message_v2(DltGatewayConnection *con, - DltPassiveControlMessage *control_msg, - void *data, - int verbose); +int dlt_gateway_send_control_message_v2( + DltGatewayConnection* con, DltPassiveControlMessage* control_msg, void* data, int verbose); /** * Gets the connection handle of passive node with specified ECU @@ -217,9 +196,7 @@ int dlt_gateway_send_control_message_v2(DltGatewayConnection *con, * @param verbose verbose flag * @returns Gateway connection handle on success, NULL otherwise */ -DltGatewayConnection *dlt_gateway_get_connection(DltGateway *g, - char *ecu, - int verbose); +DltGatewayConnection* dlt_gateway_get_connection(DltGateway* g, char* ecu, int verbose); /** * DLTv2 Gets the connection handle of passive node with specified ECU @@ -229,8 +206,6 @@ DltGatewayConnection *dlt_gateway_get_connection(DltGateway *g, * @param verbose verbose flag * @returns Gateway connection handle on success, NULL otherwise */ -DltGatewayConnection *dlt_gateway_get_connection_v2(DltGateway *g, - char *ecu, - int verbose); +DltGatewayConnection* dlt_gateway_get_connection_v2(DltGateway* g, char* ecu, int verbose); #endif diff --git a/src/gateway/dlt_gateway_internal.h b/src/gateway/dlt_gateway_internal.h index 0aa172630..dcab556e0 100644 --- a/src/gateway/dlt_gateway_internal.h +++ b/src/gateway/dlt_gateway_internal.h @@ -56,47 +56,32 @@ #ifndef DLT_GATEWAY_INTERNAL_H_ #define DLT_GATEWAY_INTERNAL_H_ -DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_ip(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_port(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_ecu(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_connect_trigger(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_timeout(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_send_serial(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnection *con); +DLT_STATIC DltReturnValue dlt_gateway_allocate_control_messages(DltGatewayConnection* con); -DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages(DltGatewayConnection *con, - char *value); +DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages(DltGatewayConnection* con, char* value); -DLT_STATIC DltReturnValue dlt_gateway_check_param(DltGateway *gateway, - DltGatewayConnection *con, - DltGatewayConfType ctype, - char *value); +DLT_STATIC DltReturnValue +dlt_gateway_check_param(DltGateway* gateway, DltGatewayConnection* con, DltGatewayConfType ctype, char* value); -int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose); +int dlt_gateway_configure(DltGateway* gateway, char* config_file, int verbose); -int dlt_gateway_store_connection(DltGateway *gateway, - DltGatewayConnection *tmp, - int verbose); +int dlt_gateway_store_connection(DltGateway* gateway, DltGatewayConnection* tmp, int verbose); -DLT_STATIC DltReturnValue dlt_gateway_parse_get_log_info(DltDaemon *daemon, - char *ecu, - DltMessage *msg, - int req, - int verbose); +DLT_STATIC DltReturnValue +dlt_gateway_parse_get_log_info(DltDaemon* daemon, char* ecu, DltMessage* msg, int req, int verbose); #endif diff --git a/src/gateway/dlt_gateway_types.h b/src/gateway/dlt_gateway_types.h index addf0084c..41e1ecbbb 100644 --- a/src/gateway/dlt_gateway_types.h +++ b/src/gateway/dlt_gateway_types.h @@ -69,92 +69,87 @@ * established */ #define DLT_GATEWAY_MAX_STARTUP_CTRL_MSG 10 -typedef enum -{ +typedef enum { DLT_GATEWAY_UNINITIALIZED, DLT_GATEWAY_INITIALIZED, DLT_GATEWAY_CONNECTED, DLT_GATEWAY_DISCONNECTED } connection_status; -typedef enum -{ +typedef enum { DLT_GATEWAY_UNDEFINED = -1, - DLT_GATEWAY_ON_STARTUP, /* connect directly on startup */ - DLT_GATEWAY_ON_DEMAND, /* connect on demand only */ - DLT_GATEWAY_DISABLED /* disable this connection due to problems */ + DLT_GATEWAY_ON_STARTUP, /* connect directly on startup */ + DLT_GATEWAY_ON_DEMAND, /* connect on demand only */ + DLT_GATEWAY_DISABLED /* disable this connection due to problems */ } connection_trigger; -typedef enum -{ +typedef enum { CONTROL_MESSAGE_UNDEFINED = -1, - CONTROL_MESSAGE_ON_STARTUP, /* send on startup */ - CONTROL_MESSAGE_PERIODIC, /* send periodically */ - CONTROL_MESSAGE_BOTH, /* send on startup and periodically */ - CONTROL_MESSAGE_ON_DEMAND /* send on demand only */ + CONTROL_MESSAGE_ON_STARTUP, /* send on startup */ + CONTROL_MESSAGE_PERIODIC, /* send periodically */ + CONTROL_MESSAGE_BOTH, /* send on startup and periodically */ + CONTROL_MESSAGE_ON_DEMAND /* send on demand only */ } control_msg_trigger; -typedef enum -{ +typedef enum { CONTROL_MESSAGE_REQUEST_UNDEFINED = -1, - CONTROL_MESSAGE_NOT_REQUESTED, /* control msg not requested (default) */ - CONTROL_MESSAGE_REQUESTED /* control msg requested */ + CONTROL_MESSAGE_NOT_REQUESTED, /* control msg not requested (default) */ + CONTROL_MESSAGE_REQUESTED /* control msg requested */ } control_msg_request; /* Passive control message */ typedef struct DltPassiveControlMessage { - uint32_t id; /* msg ID */ + uint32_t id; /* msg ID */ uint32_t user_id; - control_msg_trigger type; /* on startup or periodic or both */ - control_msg_request req; /* whether it is requested from gateway or not */ - unsigned int interval; /* interval for periodic sending. if on startup, -1 */ - struct DltPassiveControlMessage *next; /* for multiple passive control message */ + control_msg_trigger type; /* on startup or periodic or both */ + control_msg_request req; /* whether it is requested from gateway or not */ + unsigned int interval; /* interval for periodic sending. if on startup, -1 */ + struct DltPassiveControlMessage* next; /* for multiple passive control message */ } DltPassiveControlMessage; /* DLT Gateway connection structure */ typedef struct { - int handle; /* connection handle */ - connection_status status; /* connected/disconnected */ - char *ecuid; /* name of passive node */ - uint8_t ecuid2len; /* ecu id DLTv2 length */ - char *ecuid2; /* ecu id DLTv2 (flexible) */ - char *ip_address; /* IP address */ - int sock_domain; /* socket domain */ - int sock_type; /* socket type */ - int sock_protocol; /* socket protocol */ - int port; /* port */ - connection_trigger trigger; /* connection trigger */ - int timeout; /* connection timeout */ - int timeout_cnt; /* connection timeout counter */ - int reconnect_cnt; /* reconnection counter */ - unsigned int sendtime; /* periodic sending max time */ - unsigned int sendtime_cnt; /* periodic sending counter */ - DltPassiveControlMessage *p_control_msgs; /* passive control msgs */ - DltPassiveControlMessage *head; /* to go back to the head pointer of p_control_msgs */ - int send_serial; /* Send serial header with control messages */ - DltClient client; /* DltClient structure */ - int default_log_level; /* Default Log Level on passive node */ + int handle; /* connection handle */ + connection_status status; /* connected/disconnected */ + char* ecuid; /* name of passive node */ + uint8_t ecuid2len; /* ecu id DLTv2 length */ + char* ecuid2; /* ecu id DLTv2 (flexible) */ + char* ip_address; /* IP address */ + int sock_domain; /* socket domain */ + int sock_type; /* socket type */ + int sock_protocol; /* socket protocol */ + int port; /* port */ + connection_trigger trigger; /* connection trigger */ + int timeout; /* connection timeout */ + int timeout_cnt; /* connection timeout counter */ + int reconnect_cnt; /* reconnection counter */ + unsigned int sendtime; /* periodic sending max time */ + unsigned int sendtime_cnt; /* periodic sending counter */ + DltPassiveControlMessage* p_control_msgs; /* passive control msgs */ + DltPassiveControlMessage* head; /* to go back to the head pointer of p_control_msgs */ + int send_serial; /* Send serial header with control messages */ + DltClient client; /* DltClient structure */ + int default_log_level; /* Default Log Level on passive node */ } DltGatewayConnection; /* DltGateway structure */ -typedef struct -{ - int send_serial; /* Default: Send serial header with control messages */ - DltGatewayConnection *connections; /* pointer to connections */ - int num_connections; /* number of connections */ - unsigned int interval; /* interval of retry connection */ +typedef struct { + int send_serial; /* Default: Send serial header with control messages */ + DltGatewayConnection* connections; /* pointer to connections */ + int num_connections; /* number of connections */ + unsigned int interval; /* interval of retry connection */ } DltGateway; typedef struct { - char *key; /* The configuration key*/ - int (*func)(DltGatewayConnection *con, char *value); /* Conf handler */ - int is_opt; /* If the configuration is optional or not */ + char* key; /* The configuration key*/ + int (*func)(DltGatewayConnection* con, char* value); /* Conf handler */ + int is_opt; /* If the configuration is optional or not */ } DltGatewayConf; typedef struct { - char *key; /* The configuration key*/ - int (*func)(DltGateway *gateway, char *value); /* Conf handler */ - int is_opt; /* If the configuration is optional or not */ + char* key; /* The configuration key*/ + int (*func)(DltGateway* gateway, char* value); /* Conf handler */ + int is_opt; /* If the configuration is optional or not */ } DltGatewayGeneralConf; typedef enum { @@ -169,9 +164,6 @@ typedef enum { GW_CONF_COUNT } DltGatewayConfType; -typedef enum { - GW_CONF_GENERAL_INTERVAL = 0, - GW_CONF_GENEREL_COUNT -} DltGatewayGeneralConfType; +typedef enum { GW_CONF_GENERAL_INTERVAL = 0, GW_CONF_GENEREL_COUNT } DltGatewayGeneralConfType; #endif /* DLT_GATEWAY_TYPES_H_ */ diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c index 982f0b54e..c8a72838c 100644 --- a/src/lib/dlt_client.c +++ b/src/lib/dlt_client.c @@ -67,27 +67,27 @@ #include -#if defined (__WIN32__) || defined (_MSC_VER) -# pragma warning(disable : 4996) /* Switch off C4996 warnings */ -# include /* for socket(), connect(), send(), and recv() */ +#if defined(__WIN32__) || defined(_MSC_VER) +#pragma warning(disable : 4996) /* Switch off C4996 warnings */ +#include /* for socket(), connect(), send(), and recv() */ #else -# include /* for socket(), connect(), send(), and recv() */ +#include /* for socket(), connect(), send(), and recv() */ #pragma GCC diagnostic ignored "-Wconversion" -# include /* for sockaddr_in and inet_addr() */ +#include /* for sockaddr_in and inet_addr() */ #pragma GCC diagnostic push #pragma GCC diagnostic pop -# include -# include -# include +#include +#include +#include #endif #if defined(_MSC_VER) -# include +#include #else -# include -# include +#include +#include #endif #include @@ -106,32 +106,29 @@ // DLTv2 - DLT Version flag for multiplexing v1 and v2 messages uint8_t dlt_client_dlt_version = DLTProtocolV1; -static int (*message_callback_function)(DltMessage *message, void *data) = NULL; -static int (*message_callback_function_v2)(DltMessageV2 *message, void *data) = NULL; -static bool (*fetch_next_message_callback_function)(void *data) = NULL; +static int (*message_callback_function)(DltMessage* message, void* data) = NULL; +static int (*message_callback_function_v2)(DltMessageV2* message, void* data) = NULL; +static bool (*fetch_next_message_callback_function)(void* data) = NULL; -void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data)) +void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage* message, void* data)) { message_callback_function = registerd_callback; } -void dlt_client_register_message_callback_v2(int (*registerd_callback)(DltMessageV2 *message, void *data)) +void dlt_client_register_message_callback_v2(int (*registerd_callback)(DltMessageV2* message, void* data)) { message_callback_function_v2 = registerd_callback; } -void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void *data)) +void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void* data)) { fetch_next_message_callback_function = registerd_callback; } -DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose) +DltReturnValue dlt_client_init_port(DltClient* client, int port, int verbose) { if (verbose && (port != DLT_DAEMON_TCP_PORT)) - dlt_vlog(LOG_INFO, - "%s: Init dlt client struct with port %d\n", - __func__, - port); + dlt_vlog(LOG_INFO, "%s: Init dlt client struct with port %d\n", __func__, port); if (client == NULL) return DLT_RETURN_ERROR; @@ -151,9 +148,9 @@ DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_client_init(DltClient *client, int verbose) +DltReturnValue dlt_client_init(DltClient* client, int verbose) { - char *env_daemon_port; + char* env_daemon_port; int tmp_port; client->ecuid2 = NULL; /* the port may be specified by an environment variable, defaults to DLT_DAEMON_TCP_PORT */ @@ -166,26 +163,19 @@ DltReturnValue dlt_client_init(DltClient *client, int verbose) tmp_port = atoi(env_daemon_port); if ((tmp_port < IPPORT_RESERVED) || ((unsigned)tmp_port > USHRT_MAX)) { - dlt_vlog(LOG_ERR, - "%s: Specified port is out of possible range: %d.\n", - __func__, - tmp_port); + dlt_vlog(LOG_ERR, "%s: Specified port is out of possible range: %d.\n", __func__, tmp_port); return DLT_RETURN_ERROR; - } - else { + } else { servPort = (unsigned short)tmp_port; } } if (verbose) - dlt_vlog(LOG_INFO, - "%s: Init dlt client struct with default port: %hu.\n", - __func__, - servPort); + dlt_vlog(LOG_INFO, "%s: Init dlt client struct with default port: %hu.\n", __func__, servPort); return dlt_client_init_port(client, servPort, verbose); } -DltReturnValue dlt_client_connect(DltClient *client, int verbose) +DltReturnValue dlt_client_connect(DltClient* client, int verbose) { const int yes = 1; char portnumbuffer[33] = {0}; @@ -212,28 +202,19 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) snprintf(portnumbuffer, 32, "%d", client->port); if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) { - dlt_vlog(LOG_ERR, - "%s: getaddrinfo: %s\n", - __func__, - gai_strerror(rv)); + dlt_vlog(LOG_ERR, "%s: getaddrinfo: %s\n", __func__, gai_strerror(rv)); return DLT_RETURN_ERROR; } for (p = servinfo; p != NULL; p = p->ai_next) { if ((client->sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) { - dlt_vlog(LOG_WARNING, - "%s: socket() failed! %s\n", - __func__, - strerror(errno)); + dlt_vlog(LOG_WARNING, "%s: socket() failed! %s\n", __func__, strerror(errno)); continue; } /* Set socket to Non-blocking mode */ - if(fcntl(client->sock, F_SETFL, fcntl(client->sock,F_GETFL,0) | O_NONBLOCK) < 0) - { - dlt_vlog(LOG_WARNING, - "%s: Socket cannot be changed to NON BLOCK: %s\n", - __func__, strerror(errno)); + if (fcntl(client->sock, F_SETFL, fcntl(client->sock, F_GETFL, 0) | O_NONBLOCK) < 0) { + dlt_vlog(LOG_WARNING, "%s: Socket cannot be changed to NON BLOCK: %s\n", __func__, strerror(errno)); close(client->sock); continue; } @@ -244,38 +225,32 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) pfds[0].events = POLLOUT; ret = poll(pfds, 1, 500); if (ret < 0) { - dlt_vlog(LOG_ERR, "%s: Failed to poll with err [%s]\n", - __func__, strerror(errno)); + dlt_vlog(LOG_ERR, "%s: Failed to poll with err [%s]\n", __func__, strerror(errno)); close(client->sock); continue; - } - else if ((pfds[0].revents & POLLOUT) && - getsockopt(client->sock, SOL_SOCKET, - SO_ERROR, (void*)&n, &m) == 0) { + } else if ( + (pfds[0].revents & POLLOUT) + && getsockopt(client->sock, SOL_SOCKET, SO_ERROR, (void*)&n, &m) == 0) { if (n == 0) { dlt_vlog(LOG_DEBUG, "%s: Already connect\n", __func__); - if(fcntl(client->sock, F_SETFL, - fcntl(client->sock,F_GETFL,0) & ~O_NONBLOCK) < 0) { - dlt_vlog(LOG_WARNING, - "%s: Socket cannot be changed to BLOCK with err [%s]\n", - __func__, strerror(errno)); + if (fcntl(client->sock, F_SETFL, fcntl(client->sock, F_GETFL, 0) & ~O_NONBLOCK) < 0) { + dlt_vlog( + LOG_WARNING, "%s: Socket cannot be changed to BLOCK with err [%s]\n", __func__, + strerror(errno)); close(client->sock); continue; } - } - else { + } else { connect_errno = n; close(client->sock); continue; } - } - else { + } else { connect_errno = errno; close(client->sock); continue; } - } - else { + } else { connect_errno = errno; close(client->sock); continue; @@ -288,18 +263,12 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) freeaddrinfo(servinfo); if (p == NULL) { - dlt_vlog(LOG_ERR, - "%s: ERROR: failed to connect! %s\n", - __func__, - strerror(connect_errno)); + dlt_vlog(LOG_ERR, "%s: ERROR: failed to connect! %s\n", __func__, strerror(connect_errno)); return DLT_RETURN_ERROR; } if (verbose) { - dlt_vlog(LOG_INFO, - "%s: Connected to DLT daemon (%s)\n", - __func__, - client->servIP); + dlt_vlog(LOG_INFO, "%s: Connected to DLT daemon (%s)\n", __func__, client->servIP); } receiver_type = DLT_RECEIVE_SOCKET; @@ -310,45 +279,34 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) client->sock = open(client->serialDevice, O_RDWR); if (client->sock < 0) { - dlt_vlog(LOG_ERR, - "%s: ERROR: Failed to open device %s\n", - __func__, - client->serialDevice); + dlt_vlog(LOG_ERR, "%s: ERROR: Failed to open device %s\n", __func__, client->serialDevice); return DLT_RETURN_ERROR; } if (isatty(client->sock)) { - #if !defined (__WIN32__) +#if !defined(__WIN32__) if (dlt_setup_serial(client->sock, client->baudrate) < DLT_RETURN_OK) { - dlt_vlog(LOG_ERR, - "%s: ERROR: Failed to configure serial device %s (%s) \n", - __func__, - client->serialDevice, - strerror(errno)); + dlt_vlog( + LOG_ERR, "%s: ERROR: Failed to configure serial device %s (%s) \n", __func__, client->serialDevice, + strerror(errno)); return DLT_RETURN_ERROR; } - #else +#else return DLT_RETURN_ERROR; - #endif - } - else { +#endif + } else { if (verbose) - dlt_vlog(LOG_ERR, - "%s: ERROR: Device is not a serial device, device = %s (%s) \n", - __func__, - client->serialDevice, - strerror(errno)); + dlt_vlog( + LOG_ERR, "%s: ERROR: Device is not a serial device, device = %s (%s) \n", __func__, + client->serialDevice, strerror(errno)); return DLT_RETURN_ERROR; } if (verbose) - dlt_vlog(LOG_INFO, - "%s: Connected to %s\n", - __func__, - client->serialDevice); + dlt_vlog(LOG_INFO, "%s: Connected to %s\n", __func__, client->serialDevice); receiver_type = DLT_RECEIVE_FD; @@ -356,10 +314,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) case DLT_CLIENT_MODE_UNIX: if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - dlt_vlog(LOG_ERR, - "%s: ERROR: (unix) socket error: %s\n", - __func__, - strerror(errno)); + dlt_vlog(LOG_ERR, "%s: ERROR: (unix) socket error: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; } @@ -368,22 +323,14 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) addr.sun_family = AF_UNIX; strncpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path) - 1); - if (connect(client->sock, - (struct sockaddr *) &addr, - sizeof(addr)) == -1) { - dlt_vlog(LOG_ERR, - "%s: ERROR: (unix) connect error: %s\n", - __func__, - strerror(errno)); + if (connect(client->sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) { + dlt_vlog(LOG_ERR, "%s: ERROR: (unix) connect error: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; } if (client->sock < 0) { - dlt_vlog(LOG_ERR, - "%s: ERROR: Failed to open device %s\n", - __func__, - client->socketPath); + dlt_vlog(LOG_ERR, "%s: ERROR: Failed to open device %s\n", __func__, client->socketPath); return DLT_RETURN_ERROR; } @@ -393,23 +340,15 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) break; case DLT_CLIENT_MODE_UDP_MULTICAST: - if ((client->sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: socket error: %s\n", - __func__, - strerror(errno)); + if ((client->sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + dlt_vlog(LOG_ERR, "%s: ERROR: socket error: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; } /* allow multiple sockets to use the same PORT number */ - if (setsockopt(client->sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: Reusing address failed: %s\n", - __func__, - strerror(errno)); + if (setsockopt(client->sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { + dlt_vlog(LOG_ERR, "%s: ERROR: Reusing address failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; } @@ -420,26 +359,18 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) client->receiver.addr.sin_port = htons(client->port); /* bind to receive address */ - if (bind(client->sock, (struct sockaddr*) &client->receiver.addr, sizeof(client->receiver.addr)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: bind failed: %s\n", - __func__, - strerror(errno)); + if (bind(client->sock, (struct sockaddr*)&client->receiver.addr, sizeof(client->receiver.addr)) < 0) { + dlt_vlog(LOG_ERR, "%s: ERROR: bind failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; } mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if (client->hostip) - { + if (client->hostip) { mreq.imr_interface.s_addr = inet_addr(client->hostip); } - if (client->servIP == NULL) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: server address not set\n", - __func__); + if (client->servIP == NULL) { + dlt_vlog(LOG_ERR, "%s: ERROR: server address not set\n", __func__); return DLT_RETURN_ERROR; } @@ -447,24 +378,16 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) char delimiter[] = ","; char* servIP = strtok(client->servIP, delimiter); - while(servIP != NULL) { + while (servIP != NULL) { mreq.imr_multiaddr.s_addr = inet_addr(servIP); - if (mreq.imr_multiaddr.s_addr == (in_addr_t)-1) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: server address not not valid %s\n", - __func__, - servIP); + if (mreq.imr_multiaddr.s_addr == (in_addr_t)-1) { + dlt_vlog(LOG_ERR, "%s: ERROR: server address not not valid %s\n", __func__, servIP); return DLT_RETURN_ERROR; } - if (setsockopt(client->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq)) < 0) - { - dlt_vlog(LOG_ERR, - "%s: ERROR: setsockopt add membership failed: %s\n", - __func__, - strerror(errno)); + if (setsockopt(client->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0) { + dlt_vlog(LOG_ERR, "%s: ERROR: setsockopt add membership failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; } @@ -474,10 +397,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) break; default: - dlt_vlog(LOG_ERR, - "%s: ERROR: Mode not supported: %d\n", - __func__, - client->mode); + dlt_vlog(LOG_ERR, "%s: ERROR: Mode not supported: %d\n", __func__, client->mode); return DLT_RETURN_ERROR; } @@ -490,7 +410,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_client_cleanup(DltClient *client, int verbose) +DltReturnValue dlt_client_cleanup(DltClient* client, int verbose) { int ret = DLT_RETURN_OK; @@ -505,7 +425,7 @@ DltReturnValue dlt_client_cleanup(DltClient *client, int verbose) if (dlt_receiver_free(&(client->receiver)) != DLT_RETURN_OK) { dlt_vlog(LOG_WARNING, "%s: Failed to free receiver\n", __func__); - ret = DLT_RETURN_ERROR; + ret = DLT_RETURN_ERROR; } if (client->serialDevice) { @@ -535,7 +455,7 @@ DltReturnValue dlt_client_cleanup(DltClient *client, int verbose) return ret; } -DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) +DltReturnValue dlt_client_main_loop(DltClient* client, void* data, int verbose) { DltMessage msg; int ret; @@ -559,25 +479,21 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) return DLT_RETURN_TRUE; } - while (dlt_message_read(&msg, (unsigned char *)(client->receiver.buf), - (unsigned int)client->receiver.bytesRcvd, - client->resync_serial_header, - verbose) == DLT_MESSAGE_ERROR_OK) - { + while (dlt_message_read( + &msg, (unsigned char*)(client->receiver.buf), (unsigned int)client->receiver.bytesRcvd, + client->resync_serial_header, verbose) + == DLT_MESSAGE_ERROR_OK) { /* Call callback function */ if (message_callback_function) (*message_callback_function)(&msg, data); - int total_size = (int)((size_t)msg.headersize - + (size_t)msg.datasize - - sizeof(DltStorageHeader)); + int total_size = (int)((size_t)msg.headersize + (size_t)msg.datasize - sizeof(DltStorageHeader)); if (msg.found_serialheader) { total_size += (int)sizeof(dltSerialHeader); } - if (dlt_receiver_remove(&(client->receiver), - total_size) == DLT_RETURN_ERROR) { + if (dlt_receiver_remove(&(client->receiver), total_size) == DLT_RETURN_ERROR) { /* Return value ignored */ dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; @@ -590,7 +506,7 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) return DLT_RETURN_ERROR; } if (fetch_next_message_callback_function) - fetch_next_message = (*fetch_next_message_callback_function)(data); + fetch_next_message = (*fetch_next_message_callback_function)(data); } if (dlt_message_free(&msg, verbose) == DLT_RETURN_ERROR) @@ -599,7 +515,7 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbose) +DltReturnValue dlt_client_main_loop_v2(DltClient* client, void* data, int verbose) { DltMessageV2 msg; int ret; @@ -610,7 +526,6 @@ DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbos bool fetch_next_message = true; while (fetch_next_message) { - /* wait for data from socket or serial connection */ ret = dlt_receiver_receive(&(client->receiver)); @@ -622,18 +537,18 @@ DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbos return DLT_RETURN_TRUE; } - while (dlt_message_read_v2(&msg, (unsigned char *)(client->receiver.buf), - (unsigned int)client->receiver.bytesRcvd, - client->resync_serial_header, - verbose) == DLT_MESSAGE_ERROR_OK) - { + while (dlt_message_read_v2( + &msg, (unsigned char*)(client->receiver.buf), (unsigned int)client->receiver.bytesRcvd, + client->resync_serial_header, verbose) + == DLT_MESSAGE_ERROR_OK) { /* Call callback function */ if (message_callback_function_v2) { (*message_callback_function_v2)(&msg, data); } if (msg.found_serialheader) { - int64_t temp_remove_size = (int64_t)msg.headersizev2 + (int64_t)msg.datasize - (int64_t)msg.storageheadersizev2 + (int64_t)sizeof(dltSerialHeader); + int64_t temp_remove_size = (int64_t)msg.headersizev2 + (int64_t)msg.datasize + - (int64_t)msg.storageheadersizev2 + (int64_t)sizeof(dltSerialHeader); if (temp_remove_size < 0 || temp_remove_size > UINT32_MAX) { dlt_message_free_v2(&msg, verbose); return DLT_RETURN_ERROR; @@ -644,10 +559,11 @@ DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbos dlt_message_free_v2(&msg, verbose); return DLT_RETURN_ERROR; } - } - else if (dlt_receiver_remove(&(client->receiver), - (int) ((uint32_t)msg.headersizev2 + (uint32_t)msg.datasize - msg.storageheadersizev2)) == - DLT_RETURN_ERROR) { + } else if ( + dlt_receiver_remove( + &(client->receiver), + (int)((uint32_t)msg.headersizev2 + (uint32_t)msg.datasize - msg.storageheadersizev2)) + == DLT_RETURN_ERROR) { /* Return value ignored */ dlt_message_free_v2(&msg, verbose); return DLT_RETURN_ERROR; @@ -661,7 +577,7 @@ DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbos return DLT_RETURN_ERROR; } if (fetch_next_message_callback_function) - fetch_next_message = (*fetch_next_message_callback_function)(data); + fetch_next_message = (*fetch_next_message_callback_function)(data); } if (dlt_message_free_v2(&msg, verbose) == DLT_RETURN_ERROR) @@ -670,41 +586,33 @@ DltReturnValue dlt_client_main_loop_v2(DltClient *client, void *data, int verbos return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage *msg) +DltReturnValue dlt_client_send_message_to_socket(DltClient* client, DltMessage* msg) { int ret = 0; - if ((client == NULL) || (client->sock < 0) - || (msg == NULL) || (msg->databuffer == NULL)) - { + if ((client == NULL) || (client->sock < 0) || (msg == NULL) || (msg->databuffer == NULL)) { dlt_log(LOG_ERR, "Invalid parameters\n"); return DLT_RETURN_ERROR; } - if (client->send_serial_header) - { - ret = (int)send(client->sock, (const char *)dltSerialHeader, - sizeof(dltSerialHeader), 0); - if (ret < 0) - { - dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", - strerror(errno)); + if (client->send_serial_header) { + ret = (int)send(client->sock, (const char*)dltSerialHeader, sizeof(dltSerialHeader), 0); + if (ret < 0) { + dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } } - ret = (int)send(client->sock, - (const char *)(msg->headerbuffer + sizeof(DltStorageHeader)), - (size_t)((int32_t)msg->headersize - (int32_t)sizeof(DltStorageHeader)), 0); - if (ret < 0) - { + ret = (int)send( + client->sock, (const char*)(msg->headerbuffer + sizeof(DltStorageHeader)), + (size_t)((int32_t)msg->headersize - (int32_t)sizeof(DltStorageHeader)), 0); + if (ret < 0) { dlt_vlog(LOG_ERR, "Sending message header failed: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } - ret = (int)send(client->sock, (const char *)msg->databuffer, (size_t)msg->datasize, 0); - if ( ret < 0) - { + ret = (int)send(client->sock, (const char*)msg->databuffer, (size_t)msg->datasize, 0); + if (ret < 0) { dlt_vlog(LOG_ERR, "Sending message failed: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } @@ -712,41 +620,33 @@ DltReturnValue dlt_client_send_message_to_socket(DltClient *client, DltMessage * return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_message_to_socket_v2(DltClient *client, DltMessageV2 *msg) +DltReturnValue dlt_client_send_message_to_socket_v2(DltClient* client, DltMessageV2* msg) { int ret = 0; - if ((client == NULL) || (client->sock < 0) - || (msg == NULL) || (msg->databuffer == NULL)) - { + if ((client == NULL) || (client->sock < 0) || (msg == NULL) || (msg->databuffer == NULL)) { dlt_log(LOG_ERR, "Invalid parameters\n"); return DLT_RETURN_ERROR; } - if (client->send_serial_header) - { - ret = send(client->sock, (const char *)dltSerialHeader, - sizeof(dltSerialHeader), 0); - if (ret < 0) - { - dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", - strerror(errno)); + if (client->send_serial_header) { + ret = send(client->sock, (const char*)dltSerialHeader, sizeof(dltSerialHeader), 0); + if (ret < 0) { + dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } } - ret = send(client->sock, - (const char *)(msg->headerbufferv2 + msg->storageheadersizev2), - (uint32_t)msg->headersizev2 - msg->storageheadersizev2, 0); - if (ret < 0) - { + ret = send( + client->sock, (const char*)(msg->headerbufferv2 + msg->storageheadersizev2), + (uint32_t)msg->headersizev2 - msg->storageheadersizev2, 0); + if (ret < 0) { dlt_vlog(LOG_ERR, "Sending message header failed: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } - ret = send(client->sock, (const char *)msg->databuffer, (size_t)msg->datasize, 0); - if ( ret < 0) - { + ret = send(client->sock, (const char*)msg->databuffer, (size_t)msg->datasize, 0); + if (ret < 0) { dlt_vlog(LOG_ERR, "Sending message failed: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } @@ -754,7 +654,7 @@ DltReturnValue dlt_client_send_message_to_socket_v2(DltClient *client, DltMessag return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size) +DltReturnValue dlt_client_send_ctrl_msg(DltClient* client, char* apid, char* ctid, uint8_t* payload, uint32_t size) { DltMessage msg; int ret; @@ -779,7 +679,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } @@ -792,7 +692,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti memcpy(msg.databuffer, payload, size); /* prepare storage header */ - msg.storageheader = (DltStorageHeader *)msg.headerbuffer; + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; if (dlt_set_storageheader(msg.storageheader, "") == DLT_RETURN_ERROR) { dlt_message_free(&msg, 0); @@ -800,12 +700,12 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti } /* prepare standard header */ - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; - #if (BYTE_ORDER == BIG_ENDIAN) +#if (BYTE_ORDER == BIG_ENDIAN) msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF); - #endif +#endif msg.standardheader->mcnt = 0; @@ -821,10 +721,8 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti } /* prepare extended header */ - msg.extendedheader = (DltExtendedHeader *)(msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); msg.extendedheader->msin = DLT_MSIN_CONTROL_REQUEST; @@ -834,18 +732,14 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti dlt_set_id(msg.extendedheader->ctid, (ctid[0] == '\0') ? DLT_CLIENT_DUMMY_CON_ID : ctid); /* prepare length information */ - msg.headersize = (int32_t)(sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.headersize = (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); len = (int32_t)((size_t)msg.headersize - sizeof(DltStorageHeader) + (size_t)msg.datasize); if (len > UINT16_MAX) { - dlt_vlog(LOG_ERR, - "%s: Critical: Huge injection message discarded!\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Critical: Huge injection message discarded!\n", __func__); dlt_message_free(&msg, 0); @@ -857,20 +751,18 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti /* Send data (without storage header) */ if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) { /* via FileDescriptor */ - if (client->send_serial_header) - { + if (client->send_serial_header) { ret = write(client->sock, dltSerialHeader, sizeof(dltSerialHeader)); - if (ret < 0) - { + if (ret < 0) { dlt_log(LOG_ERR, "Sending message failed\n"); dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } } - ret = (int) write(client->sock, - msg.headerbuffer + sizeof(DltStorageHeader), - (size_t)((int32_t)msg.headersize - (int32_t)sizeof(DltStorageHeader))); + ret = (int)write( + client->sock, msg.headerbuffer + sizeof(DltStorageHeader), + (size_t)((int32_t)msg.headersize - (int32_t)sizeof(DltStorageHeader))); if (0 > ret) { dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__); @@ -878,9 +770,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti return DLT_RETURN_ERROR; } - ret = (int) write(client->sock, - msg.databuffer, - (size_t)msg.datasize); + ret = (int)write(client->sock, msg.databuffer, (size_t)msg.datasize); if (0 > ret) { dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__); @@ -888,18 +778,13 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti return DLT_RETURN_ERROR; } - id_tmp = *((uint32_t *)(msg.databuffer)); + id_tmp = *((uint32_t*)(msg.databuffer)); id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp); - dlt_vlog(LOG_INFO, - "%s: Control message forwarded : %s\n", - __func__, - dlt_get_service_name(id)); - } - else { + dlt_vlog(LOG_INFO, "%s: Control message forwarded : %s\n", __func__, dlt_get_service_name(id)); + } else { /* via Socket */ - if (dlt_client_send_message_to_socket(client, &msg) == DLT_RETURN_ERROR) - { + if (dlt_client_send_message_to_socket(client, &msg) == DLT_RETURN_ERROR) { dlt_log(LOG_ERR, "Sending message to socket failed\n"); dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; @@ -913,7 +798,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size) +DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient* client, char* apid, char* ctid, uint8_t* payload, uint32_t size) { DltMessageV2 msg; int ret; @@ -942,7 +827,7 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * } if (msg.databuffer == 0) { - msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize); + msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize); msg.databuffersize = msg.datasize; } @@ -954,15 +839,15 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * /* copy data */ memcpy(msg.databuffer, payload, size); - if (strcmp(apid, "") == 0){ + if (strcmp(apid, "") == 0) { appidlen = strlen(DLT_CLIENT_DUMMY_APP_ID); - }else { + } else { appidlen = strlen(apid); } - if (strcmp(ctid, "") == 0){ + if (strcmp(ctid, "") == 0) { ctxidlen = strlen(DLT_CLIENT_DUMMY_CON_ID); - }else { + } else { ctxidlen = strlen(ctid); } @@ -971,8 +856,8 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * msg.baseheaderextrasizev2 = (int32_t)dlt_message_get_extraparameters_size_v2(DLT_CONTROL_MSG); msg.extendedheadersizev2 = (uint32_t)(client->ecuid2len) + 1 + appidlen + 1 + ctxidlen + 1; - msg.headersizev2 = (int32_t) (msg.storageheadersizev2 + msg.baseheadersizev2 + - msg.baseheaderextrasizev2 + msg.extendedheadersizev2); + msg.headersizev2 = (int32_t)(msg.storageheadersizev2 + msg.baseheadersizev2 + msg.baseheaderextrasizev2 + + msg.extendedheadersizev2); if (msg.headerbufferv2 != NULL) { free(msg.headerbufferv2); @@ -992,7 +877,7 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * } /* prepare base header */ - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + msg.storageheadersizev2); + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + msg.storageheadersizev2); msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2; msg.baseheaderv2->htyp2 |= DLT_CONTROL_MSG; @@ -1005,51 +890,51 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * msg.headerextrav2.noar = 1; /* number of arguments */ memset(msg.headerextrav2.seconds, 0, 5); msg.headerextrav2.nanoseconds = 0; - #if defined (__WIN32__) || defined(_MSC_VER) +#if defined(__WIN32__) || defined(_MSC_VER) time_t t = time(NULL); - if (t==-1){ + if (t == -1) { uint32_t tcnt = (uint32_t)(GetTickCount()); /* GetTickCount() in 10 ms resolution */ tcnt_seconds = tcnt / 100; - tcnt_ns = (tcnt - (tcnt*100)) * 10000; - msg.headerextrav2.seconds[0]=(tcnt_seconds >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(tcnt_seconds >> 24) & 0xFF; - msg.headerextrav2.seconds[2]=(tcnt_seconds >> 16) & 0xFF; - msg.headerextrav2.seconds[3]=(tcnt_seconds >> 8) & 0xFF; - msg.headerextrav2.seconds[4]= tcnt_seconds & 0xFF; + tcnt_ns = (tcnt - (tcnt * 100)) * 10000; + msg.headerextrav2.seconds[0] = (tcnt_seconds >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (tcnt_seconds >> 24) & 0xFF; + msg.headerextrav2.seconds[2] = (tcnt_seconds >> 16) & 0xFF; + msg.headerextrav2.seconds[3] = (tcnt_seconds >> 8) & 0xFF; + msg.headerextrav2.seconds[4] = tcnt_seconds & 0xFF; if (ts.tv_nsec < 0x3B9ACA00) { msg.headerextrav2.nanoseconds = tcnt_ns; } - }else{ - msg.headerextrav2.seconds[0]=(t >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(t >> 24) & 0xFF; - msg.headerextrav2.seconds[2]=(t >> 16) & 0xFF; - msg.headerextrav2.seconds[3]=(t >> 8) & 0xFF; - msg.headerextrav2.seconds[4]= t & 0xFF; + } else { + msg.headerextrav2.seconds[0] = (t >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (t >> 24) & 0xFF; + msg.headerextrav2.seconds[2] = (t >> 16) & 0xFF; + msg.headerextrav2.seconds[3] = (t >> 8) & 0xFF; + msg.headerextrav2.seconds[4] = t & 0xFF; msg.headerextrav2.nanoseconds |= 0x80000000; } - #else +#else struct timespec ts; - if(clock_gettime(CLOCK_REALTIME, &ts) == 0) { - msg.headerextrav2.seconds[0]=((uint64_t)ts.tv_sec >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(ts.tv_sec >> 24) & 0xFF; - msg.headerextrav2.seconds[2]=(ts.tv_sec >> 16) & 0xFF; - msg.headerextrav2.seconds[3]=(ts.tv_sec >> 8) & 0xFF; - msg.headerextrav2.seconds[4]= ts.tv_sec & 0xFF; + if (clock_gettime(CLOCK_REALTIME, &ts) == 0) { + msg.headerextrav2.seconds[0] = ((uint64_t)ts.tv_sec >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (ts.tv_sec >> 24) & 0xFF; + msg.headerextrav2.seconds[2] = (ts.tv_sec >> 16) & 0xFF; + msg.headerextrav2.seconds[3] = (ts.tv_sec >> 8) & 0xFF; + msg.headerextrav2.seconds[4] = ts.tv_sec & 0xFF; if (ts.tv_nsec < 0x3B9ACA00) { - msg.headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } - }else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - msg.headerextrav2.seconds[0]=((uint64_t)ts.tv_sec >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(ts.tv_sec >> 24) & 0xFF; - msg.headerextrav2.seconds[2]=(ts.tv_sec >> 16) & 0xFF; - msg.headerextrav2.seconds[3]=(ts.tv_sec >> 8) & 0xFF; - msg.headerextrav2.seconds[4]= ts.tv_sec & 0xFF; + } else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + msg.headerextrav2.seconds[0] = ((uint64_t)ts.tv_sec >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (ts.tv_sec >> 24) & 0xFF; + msg.headerextrav2.seconds[2] = (ts.tv_sec >> 16) & 0xFF; + msg.headerextrav2.seconds[3] = (ts.tv_sec >> 8) & 0xFF; + msg.headerextrav2.seconds[4] = ts.tv_sec & 0xFF; if (ts.tv_nsec < 0x3B9ACA00) { - msg.headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } msg.headerextrav2.nanoseconds |= 0x80000000; } - #endif +#endif /* Copy header extra parameters to headerbuffer */ if (dlt_message_set_extraparameters_v2(&msg, 0) == DLT_RETURN_ERROR) { @@ -1099,12 +984,10 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * return DLT_RETURN_ERROR; } - len = msg.headersizev2 - (int32_t) msg.storageheadersizev2 + msg.datasize; + len = msg.headersizev2 - (int32_t)msg.storageheadersizev2 + msg.datasize; if (len > UINT16_MAX) { - dlt_vlog(LOG_ERR, - "%s: Critical: Huge injection message discarded!\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Critical: Huge injection message discarded!\n", __func__); dlt_message_free_v2(&msg, 0); return DLT_RETURN_ERROR; } @@ -1113,18 +996,17 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * /* Send data (without storage header) */ if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) { /* via FileDescriptor */ - if (client->send_serial_header) - { + if (client->send_serial_header) { ret = write(client->sock, dltSerialHeader, sizeof(dltSerialHeader)); - if (ret < 0) - { + if (ret < 0) { dlt_log(LOG_ERR, "Sending message failed\n"); dlt_message_free_v2(&msg, 0); return DLT_RETURN_ERROR; } } - ret = - (int) write(client->sock, msg.headerbufferv2 + msg.storageheadersizev2 , (uint32_t)msg.headersizev2 - msg.storageheadersizev2); + ret = (int)write( + client->sock, msg.headerbufferv2 + msg.storageheadersizev2, + (uint32_t)msg.headersizev2 - msg.storageheadersizev2); if (0 > ret) { dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__); @@ -1132,7 +1014,7 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * return DLT_RETURN_ERROR; } - ret = (int) write(client->sock, msg.databuffer, (uint32_t)msg.datasize); + ret = (int)write(client->sock, msg.databuffer, (uint32_t)msg.datasize); if (0 > ret) { dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__); @@ -1140,18 +1022,13 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * return DLT_RETURN_ERROR; } - id_tmp = *((uint32_t *)(msg.databuffer)); + id_tmp = *((uint32_t*)(msg.databuffer)); id = DLT_LETOH_32(id_tmp); - dlt_vlog(LOG_INFO, - "%s: Control message forwarded : %s\n", - __func__, - dlt_get_service_name(id)); - } - else { + dlt_vlog(LOG_INFO, "%s: Control message forwarded : %s\n", __func__, dlt_get_service_name(id)); + } else { /* via Socket */ - if (dlt_client_send_message_to_socket_v2(client, &msg) == DLT_RETURN_ERROR) - { + if (dlt_client_send_message_to_socket_v2(client, &msg) == DLT_RETURN_ERROR) { dlt_log(LOG_ERR, "Sending message to socket failed\n"); dlt_message_free_v2(&msg, 0); return DLT_RETURN_ERROR; @@ -1166,31 +1043,27 @@ DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient *client, char *apid, char * return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_inject_msg(DltClient *client, - char *apid, - char *ctid, - uint32_t serviceID, - uint8_t *buffer, - uint32_t size) +DltReturnValue dlt_client_send_inject_msg( + DltClient* client, char* apid, char* ctid, uint32_t serviceID, uint8_t* buffer, uint32_t size) { - uint8_t *payload; + uint8_t* payload; int offset; - payload = (uint8_t *)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size); + payload = (uint8_t*)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size); if (payload == 0) return DLT_RETURN_ERROR; offset = 0; memcpy(payload, &serviceID, sizeof(serviceID)); - offset += (int) sizeof(uint32_t); + offset += (int)sizeof(uint32_t); memcpy(payload + offset, &size, sizeof(size)); - offset += (int) sizeof(uint32_t); + offset += (int)sizeof(uint32_t); memcpy(payload + offset, buffer, size); /* free message */ - if (dlt_client_send_ctrl_msg(client, apid, ctid, payload, - (uint32_t) (sizeof(uint32_t) + sizeof(uint32_t) + size)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg(client, apid, ctid, payload, (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + size)) + == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -1198,34 +1071,29 @@ DltReturnValue dlt_client_send_inject_msg(DltClient *client, free(payload); return DLT_RETURN_OK; - } -DltReturnValue dlt_client_send_inject_msg_v2(DltClient *client, - char *apid, - char *ctid, - uint32_t serviceID, - uint8_t *buffer, - uint32_t size) +DltReturnValue dlt_client_send_inject_msg_v2( + DltClient* client, char* apid, char* ctid, uint32_t serviceID, uint8_t* buffer, uint32_t size) { - uint8_t *payload; + uint8_t* payload; int offset; - payload = (uint8_t *)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size); + payload = (uint8_t*)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size); if (payload == 0) return DLT_RETURN_ERROR; offset = 0; memcpy(payload, &serviceID, sizeof(serviceID)); - offset += (int) sizeof(uint32_t); + offset += (int)sizeof(uint32_t); memcpy(payload + offset, &size, sizeof(size)); - offset += (int) sizeof(uint32_t); + offset += (int)sizeof(uint32_t); memcpy(payload + offset, buffer, size); /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, apid, ctid, payload, - (uint32_t) (sizeof(uint32_t) + sizeof(uint32_t) + size)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg_v2(client, apid, ctid, payload, (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + size)) + == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -1233,12 +1101,11 @@ DltReturnValue dlt_client_send_inject_msg_v2(DltClient *client, free(payload); return DLT_RETURN_OK; - } -DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel) +DltReturnValue dlt_client_send_log_level(DltClient* client, char* apid, char* ctid, uint8_t logLevel) { - DltServiceSetLogLevel *req; + DltServiceSetLogLevel* req; int ret = DLT_RETURN_ERROR; if (client == NULL) @@ -1256,11 +1123,7 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct dlt_set_id(req->com, "remo"); /* free message */ - ret = dlt_client_send_ctrl_msg(client, - "APP", - "CON", - (uint8_t *)req, - sizeof(DltServiceSetLogLevel)); + ret = dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetLogLevel)); free(req); @@ -1268,11 +1131,11 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct return ret; } -DltReturnValue dlt_client_send_log_level_v2(DltClient *client, char *apid, char *ctid, uint8_t logLevel) +DltReturnValue dlt_client_send_log_level_v2(DltClient* client, char* apid, char* ctid, uint8_t logLevel) { DltServiceSetLogLevelV2 req; int ret = DLT_RETURN_ERROR; - uint8_t *buffer; + uint8_t* buffer; uint16_t buffersize; uint16_t offset = 0; @@ -1289,7 +1152,7 @@ DltReturnValue dlt_client_send_log_level_v2(DltClient *client, char *apid, char buffersize = DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2 + req.apidlen + req.ctidlen; - buffer = (uint8_t *)malloc(buffersize); + buffer = (uint8_t*)malloc(buffersize); if (buffer == NULL) return ret; @@ -1307,11 +1170,7 @@ DltReturnValue dlt_client_send_log_level_v2(DltClient *client, char *apid, char offset = offset + 1; memcpy(buffer + offset, req.com, 4); - ret = dlt_client_send_ctrl_msg_v2(client, - "APP", - "CON", - (uint8_t *)buffer, - buffersize); + ret = dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)buffer, buffersize); free(buffer); @@ -1319,15 +1178,15 @@ DltReturnValue dlt_client_send_log_level_v2(DltClient *client, char *apid, char return ret; } -DltReturnValue dlt_client_get_log_info(DltClient *client) +DltReturnValue dlt_client_get_log_info(DltClient* client) { - DltServiceGetLogInfoRequest *req; + DltServiceGetLogInfoRequest* req; int ret = DLT_RETURN_ERROR; if (client == NULL) return ret; - req = (DltServiceGetLogInfoRequest *)malloc(sizeof(DltServiceGetLogInfoRequest)); + req = (DltServiceGetLogInfoRequest*)malloc(sizeof(DltServiceGetLogInfoRequest)); if (req == NULL) return ret; @@ -1339,22 +1198,18 @@ DltReturnValue dlt_client_get_log_info(DltClient *client) dlt_set_id(req->com, "remo"); /* send control message to daemon*/ - ret = dlt_client_send_ctrl_msg(client, - "", - "", - (uint8_t *)req, - sizeof(DltServiceGetLogInfoRequest)); + ret = dlt_client_send_ctrl_msg(client, "", "", (uint8_t*)req, sizeof(DltServiceGetLogInfoRequest)); free(req); return ret; } -int dlt_client_get_log_info_v2(DltClient *client) +int dlt_client_get_log_info_v2(DltClient* client) { DltServiceGetLogInfoRequestV2 req; int ret = DLT_RETURN_ERROR; - uint8_t *buffer; + uint8_t* buffer; uint16_t buffersize; uint16_t offset = 0; @@ -1371,7 +1226,7 @@ int dlt_client_get_log_info_v2(DltClient *client) buffersize = DLT_SERVICE_GET_LOG_INFO_REQUEST_FIXED_SIZE_V2 + req.apidlen + req.ctidlen; - buffer = (uint8_t *)malloc(buffersize); + buffer = (uint8_t*)malloc(buffersize); if (buffer == NULL) return ret; @@ -1388,27 +1243,22 @@ int dlt_client_get_log_info_v2(DltClient *client) memcpy(buffer + offset, req.com, 4); /* send control message to daemon*/ - ret = dlt_client_send_ctrl_msg_v2(client, - "", - "", - (uint8_t *)buffer, - buffersize); + ret = dlt_client_send_ctrl_msg_v2(client, "", "", (uint8_t*)buffer, buffersize); free(buffer); return ret; } -DltReturnValue dlt_client_get_default_log_level(DltClient *client) +DltReturnValue dlt_client_get_default_log_level(DltClient* client) { - DltServiceGetDefaultLogLevelRequest *req; + DltServiceGetDefaultLogLevelRequest* req; int ret = DLT_RETURN_ERROR; if (client == NULL) return ret; - req = (DltServiceGetDefaultLogLevelRequest *) - malloc(sizeof(DltServiceGetDefaultLogLevelRequest)); + req = (DltServiceGetDefaultLogLevelRequest*)malloc(sizeof(DltServiceGetDefaultLogLevelRequest)); if (req == NULL) return ret; @@ -1416,27 +1266,22 @@ DltReturnValue dlt_client_get_default_log_level(DltClient *client) req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; /* send control message to daemon*/ - ret = dlt_client_send_ctrl_msg(client, - "", - "", - (uint8_t *)req, - sizeof(DltServiceGetDefaultLogLevelRequest)); + ret = dlt_client_send_ctrl_msg(client, "", "", (uint8_t*)req, sizeof(DltServiceGetDefaultLogLevelRequest)); free(req); return ret; } -DltReturnValue dlt_client_get_default_log_level_v2(DltClient *client) +DltReturnValue dlt_client_get_default_log_level_v2(DltClient* client) { - DltServiceGetDefaultLogLevelRequest *req; + DltServiceGetDefaultLogLevelRequest* req; int ret = DLT_RETURN_ERROR; if (client == NULL) return ret; - req = (DltServiceGetDefaultLogLevelRequest *) - malloc(sizeof(DltServiceGetDefaultLogLevelRequest)); + req = (DltServiceGetDefaultLogLevelRequest*)malloc(sizeof(DltServiceGetDefaultLogLevelRequest)); if (req == NULL) return ret; @@ -1444,70 +1289,58 @@ DltReturnValue dlt_client_get_default_log_level_v2(DltClient *client) req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; /* send control message to daemon*/ - ret = dlt_client_send_ctrl_msg_v2(client, - "", - "", - (uint8_t *)req, - sizeof(DltServiceGetDefaultLogLevelRequest)); + ret = dlt_client_send_ctrl_msg_v2(client, "", "", (uint8_t*)req, sizeof(DltServiceGetDefaultLogLevelRequest)); free(req); return ret; } -DltReturnValue dlt_client_get_software_version(DltClient *client) +DltReturnValue dlt_client_get_software_version(DltClient* client) { - DltServiceGetSoftwareVersion *req; + DltServiceGetSoftwareVersion* req; int ret = DLT_RETURN_ERROR; if (client == NULL) return ret; - req = (DltServiceGetSoftwareVersion *)malloc(sizeof(DltServiceGetSoftwareVersion)); + req = (DltServiceGetSoftwareVersion*)malloc(sizeof(DltServiceGetSoftwareVersion)); req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; /* send control message to daemon*/ - ret = dlt_client_send_ctrl_msg(client, - "", - "", - (uint8_t *)req, - sizeof(DltServiceGetSoftwareVersion)); + ret = dlt_client_send_ctrl_msg(client, "", "", (uint8_t*)req, sizeof(DltServiceGetSoftwareVersion)); free(req); return ret; } -int dlt_client_get_software_version_v2(DltClient *client) +int dlt_client_get_software_version_v2(DltClient* client) { - DltServiceGetSoftwareVersion *req; + DltServiceGetSoftwareVersion* req; int ret = DLT_RETURN_ERROR; if (client == NULL) return ret; - req = (DltServiceGetSoftwareVersion *)malloc(sizeof(DltServiceGetSoftwareVersion)); + req = (DltServiceGetSoftwareVersion*)malloc(sizeof(DltServiceGetSoftwareVersion)); req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; /* send control message to daemon*/ - ret = dlt_client_send_ctrl_msg_v2(client, - "", - "", - (uint8_t *)req, - sizeof(DltServiceGetSoftwareVersion)); + ret = dlt_client_send_ctrl_msg_v2(client, "", "", (uint8_t*)req, sizeof(DltServiceGetSoftwareVersion)); free(req); return ret; } -DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus) +DltReturnValue dlt_client_send_trace_status(DltClient* client, char* apid, char* ctid, uint8_t traceStatus) { - DltServiceSetLogLevel *req; + DltServiceSetLogLevel* req; - req = calloc(1,sizeof(DltServiceSetLogLevel)); + req = calloc(1, sizeof(DltServiceSetLogLevel)); if (req == 0) return DLT_RETURN_ERROR; @@ -1519,8 +1352,8 @@ DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetLogLevel)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1530,11 +1363,11 @@ DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_trace_status_v2(DltClient *client, char *apid, char *ctid, uint8_t traceStatus) +DltReturnValue dlt_client_send_trace_status_v2(DltClient* client, char* apid, char* ctid, uint8_t traceStatus) { DltServiceSetLogLevelV2 req; int ret = DLT_RETURN_ERROR; - uint8_t *buffer; + uint8_t* buffer; uint16_t buffersize; uint16_t offset = 0; @@ -1551,7 +1384,7 @@ DltReturnValue dlt_client_send_trace_status_v2(DltClient *client, char *apid, ch buffersize = DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2 + req.apidlen + req.ctidlen; - buffer = (uint8_t *)malloc(buffersize); + buffer = (uint8_t*)malloc(buffersize); if (buffer == NULL) return ret; @@ -1570,11 +1403,7 @@ DltReturnValue dlt_client_send_trace_status_v2(DltClient *client, char *apid, ch memcpy(buffer, req.com, 4); /* free message */ - ret = dlt_client_send_ctrl_msg_v2(client, - "APP", - "CON", - (uint8_t *)buffer, - buffersize); + ret = dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)buffer, buffersize); free(buffer); @@ -1582,9 +1411,9 @@ DltReturnValue dlt_client_send_trace_status_v2(DltClient *client, char *apid, ch return ret; } -DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel) +DltReturnValue dlt_client_send_default_log_level(DltClient* client, uint8_t defaultLogLevel) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); @@ -1596,8 +1425,8 @@ DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defa dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1607,9 +1436,9 @@ DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defa return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_default_log_level_v2(DltClient *client, uint8_t defaultLogLevel) +DltReturnValue dlt_client_send_default_log_level_v2(DltClient* client, uint8_t defaultLogLevel) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); @@ -1621,8 +1450,8 @@ DltReturnValue dlt_client_send_default_log_level_v2(DltClient *client, uint8_t d dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1632,9 +1461,9 @@ DltReturnValue dlt_client_send_default_log_level_v2(DltClient *client, uint8_t d return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel) +DltReturnValue dlt_client_send_all_log_level(DltClient* client, uint8_t LogLevel) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); @@ -1646,8 +1475,7 @@ DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == -1) { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) { free(req); return DLT_RETURN_ERROR; } @@ -1657,9 +1485,9 @@ DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_all_log_level_v2(DltClient *client, uint8_t LogLevel) +DltReturnValue dlt_client_send_all_log_level_v2(DltClient* client, uint8_t LogLevel) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); @@ -1671,8 +1499,7 @@ DltReturnValue dlt_client_send_all_log_level_v2(DltClient *client, uint8_t LogLe dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == -1) { + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) { free(req); return DLT_RETURN_ERROR; } @@ -1682,9 +1509,9 @@ DltReturnValue dlt_client_send_all_log_level_v2(DltClient *client, uint8_t LogLe return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus) +DltReturnValue dlt_client_send_default_trace_status(DltClient* client, uint8_t defaultTraceStatus) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); @@ -1696,8 +1523,8 @@ DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t d dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1707,9 +1534,9 @@ DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t d return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_default_trace_status_v2(DltClient *client, uint8_t defaultTraceStatus) +DltReturnValue dlt_client_send_default_trace_status_v2(DltClient* client, uint8_t defaultTraceStatus) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; req = calloc(1, sizeof(DltServiceSetDefaultLogLevel)); @@ -1721,8 +1548,8 @@ DltReturnValue dlt_client_send_default_trace_status_v2(DltClient *client, uint8_ dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1732,9 +1559,9 @@ DltReturnValue dlt_client_send_default_trace_status_v2(DltClient *client, uint8_ return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t traceStatus) +DltReturnValue dlt_client_send_all_trace_status(DltClient* client, uint8_t traceStatus) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; if (client == NULL) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -1753,9 +1580,9 @@ DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t trace dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == -1) { - free(req);; + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) { + free(req); + ; return DLT_RETURN_ERROR; } @@ -1764,9 +1591,9 @@ DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t trace return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_all_trace_status_v2(DltClient *client, uint8_t traceStatus) +DltReturnValue dlt_client_send_all_trace_status_v2(DltClient* client, uint8_t traceStatus) { - DltServiceSetDefaultLogLevel *req; + DltServiceSetDefaultLogLevel* req; if (client == NULL) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -1785,9 +1612,9 @@ DltReturnValue dlt_client_send_all_trace_status_v2(DltClient *client, uint8_t tr dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetDefaultLogLevel)) == -1) { - free(req);; + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) { + free(req); + ; return DLT_RETURN_ERROR; } @@ -1796,9 +1623,9 @@ DltReturnValue dlt_client_send_all_trace_status_v2(DltClient *client, uint8_t tr return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets) +DltReturnValue dlt_client_send_timing_pakets(DltClient* client, uint8_t timingPakets) { - DltServiceSetVerboseMode *req; + DltServiceSetVerboseMode* req; req = calloc(1, sizeof(DltServiceSetVerboseMode)); @@ -1809,8 +1636,8 @@ DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPa req->new_status = timingPakets; /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetVerboseMode)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1820,9 +1647,9 @@ DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPa return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_timing_pakets_v2(DltClient *client, uint8_t timingPakets) +DltReturnValue dlt_client_send_timing_pakets_v2(DltClient* client, uint8_t timingPakets) { - DltServiceSetVerboseMode *req; + DltServiceSetVerboseMode* req; req = calloc(1, sizeof(DltServiceSetVerboseMode)); @@ -1833,8 +1660,8 @@ DltReturnValue dlt_client_send_timing_pakets_v2(DltClient *client, uint8_t timin req->new_status = timingPakets; /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*) req, - sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR) { + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetVerboseMode)) + == DLT_RETURN_ERROR) { free(req); return DLT_RETURN_ERROR; } @@ -1844,59 +1671,59 @@ DltReturnValue dlt_client_send_timing_pakets_v2(DltClient *client, uint8_t timin return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_store_config(DltClient *client) +DltReturnValue dlt_client_send_store_config(DltClient* client) { uint32_t service_id; service_id = DLT_SERVICE_ID_STORE_CONFIG; /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t *)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_store_config_v2(DltClient *client) +DltReturnValue dlt_client_send_store_config_v2(DltClient* client) { uint32_t service_id; service_id = DLT_SERVICE_ID_STORE_CONFIG; /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t *)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client) +DltReturnValue dlt_client_send_reset_to_factory_default(DltClient* client) { uint32_t service_id; service_id = DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT; /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t *)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_reset_to_factory_default_v2(DltClient *client) +DltReturnValue dlt_client_send_reset_to_factory_default_v2(DltClient* client) { uint32_t service_id; service_id = DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT; /* free message */ - if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t *)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) + if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; return DLT_RETURN_OK; } -DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate) +DltReturnValue dlt_client_setbaudrate(DltClient* client, int baudrate) { if (client == 0) return DLT_RETURN_ERROR; @@ -1906,17 +1733,16 @@ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate) return DLT_RETURN_OK; } -DltReturnValue dlt_client_set_mode(DltClient *client, DltClientMode mode) +DltReturnValue dlt_client_set_mode(DltClient* client, DltClientMode mode) { if (client == 0) return DLT_RETURN_ERROR; client->mode = mode; return DLT_RETURN_OK; - } -int dlt_client_set_server_ip(DltClient *client, char *ipaddr) +int dlt_client_set_server_ip(DltClient* client, char* ipaddr) { client->servIP = strdup(ipaddr); @@ -1928,7 +1754,7 @@ int dlt_client_set_server_ip(DltClient *client, char *ipaddr) return DLT_RETURN_OK; } -int dlt_client_set_host_if_address(DltClient *client, char *hostip) +int dlt_client_set_host_if_address(DltClient* client, char* hostip) { client->hostip = strdup(hostip); @@ -1940,7 +1766,7 @@ int dlt_client_set_host_if_address(DltClient *client, char *hostip) return DLT_RETURN_OK; } -int dlt_client_set_serial_device(DltClient *client, char *serial_device) +int dlt_client_set_serial_device(DltClient* client, char* serial_device) { client->serialDevice = strdup(serial_device); @@ -1952,7 +1778,7 @@ int dlt_client_set_serial_device(DltClient *client, char *serial_device) return DLT_RETURN_OK; } -int dlt_client_set_socket_path(DltClient *client, char *socket_path) +int dlt_client_set_socket_path(DltClient* client, char* socket_path) { client->socketPath = strdup(socket_path); @@ -1969,11 +1795,10 @@ int dlt_client_set_socket_path(DltClient *client, char *socket_path) * @param resp DltServiceGetLogInfoResponse * @param count_app_ids number of app_ids which needs to be freed */ -DLT_STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoResponse *resp, - int count_app_ids) +DLT_STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoResponse* resp, int count_app_ids) { - AppIDsType *app = NULL; - ContextIDsInfoType *con = NULL; + AppIDsType* app = NULL; + ContextIDsInfoType* con = NULL; int i = 0; int j = 0; @@ -2007,11 +1832,10 @@ DLT_STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoR * @param resp DltServiceGetLogInfoResponse * @param count_app_ids number of app_ids which needs to be freed */ -DLT_STATIC void dlt_client_free_calloc_failed_get_log_info_v2(DltServiceGetLogInfoResponse *resp, - int count_app_ids) +DLT_STATIC void dlt_client_free_calloc_failed_get_log_info_v2(DltServiceGetLogInfoResponse* resp, int count_app_ids) { - AppIDsType *app = NULL; - ContextIDsInfoType *con = NULL; + AppIDsType* app = NULL; + ContextIDsInfoType* con = NULL; int i = 0; int j = 0; @@ -2042,71 +1866,58 @@ DLT_STATIC void dlt_client_free_calloc_failed_get_log_info_v2(DltServiceGetLogIn return; } -DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp, - char *resp_text) +DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse* resp, char* resp_text) { - AppIDsType *app = NULL; - ContextIDsInfoType *con = NULL; + AppIDsType* app = NULL; + ContextIDsInfoType* con = NULL; int i = 0; int j = 0; - char *rp = NULL; + char* rp = NULL; int rp_count = 0; if ((resp == NULL) || (resp_text == NULL)) return DLT_RETURN_WRONG_PARAMETER; /* ------------------------------------------------------ - * get_log_info data structure(all data is ascii) - * - * get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. - * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ - * cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. - * jj jj kk kk kk .. .. - * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ - * aa : get mode (fix value at 0x07) - * bb bb : list num of apid (little endian) - * cc cc cc cc: apid - * dd dd : list num of ctid (little endian) - * ee ee ee ee: ctid - * ff : log level - * gg : trace status - * hh hh : description length of ctid - * ii ii .. : description text of ctid - * jj jj : description length of apid - * kk kk .. : description text of apid - * ------------------------------------------------------ */ + * get_log_info data structure(all data is ascii) + * + * get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. + * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ + * cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. + * jj jj kk kk kk .. .. + * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ + * aa : get mode (fix value at 0x07) + * bb bb : list num of apid (little endian) + * cc cc cc cc: apid + * dd dd : list num of ctid (little endian) + * ee ee ee ee: ctid + * ff : log level + * gg : trace status + * hh hh : description length of ctid + * ii ii .. : description text of ctid + * jj jj : description length of apid + * kk kk .. : description text of apid + * ------------------------------------------------------ */ rp = resp_text + DLT_GET_LOG_INFO_HEADER; rp_count = 0; /* check if status is acceptable */ - if ((resp->status < GET_LOG_INFO_STATUS_MIN) || - (resp->status > GET_LOG_INFO_STATUS_MAX)) { + if ((resp->status < GET_LOG_INFO_STATUS_MIN) || (resp->status > GET_LOG_INFO_STATUS_MAX)) { if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX) - dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid: NO matching Context IDs\n", - __func__, - resp->status); + dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: NO matching Context IDs\n", __func__, resp->status); else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW) - dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid: Response data over flow\n", - __func__, - resp->status); + dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: Response data over flow\n", __func__, resp->status); else - dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid\n", - __func__, - resp->status); + dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid\n", __func__, resp->status); return DLT_RETURN_ERROR; } /* count_app_ids */ - resp->log_info_type.count_app_ids = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, - &rp_count); + resp->log_info_type.count_app_ids = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); - resp->log_info_type.app_ids = (AppIDsType *)calloc - (resp->log_info_type.count_app_ids, sizeof(AppIDsType)); + resp->log_info_type.app_ids = (AppIDsType*)calloc(resp->log_info_type.count_app_ids, sizeof(AppIDsType)); if (resp->log_info_type.app_ids == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for app_ids\n", __func__); @@ -2120,15 +1931,12 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id, DLT_ID_SIZE); /* count_con_ids */ - app->count_context_ids = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, - &rp_count); + app->count_context_ids = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); - app->context_id_info = (ContextIDsInfoType *)calloc - (app->count_context_ids, sizeof(ContextIDsInfoType)); + app->context_id_info = (ContextIDsInfoType*)calloc(app->count_context_ids, sizeof(ContextIDsInfoType)); if (app->context_id_info == NULL) { - dlt_vlog(LOG_ERR, - "%s: calloc failed for context_id_info\n", __func__); + dlt_vlog(LOG_ERR, "%s: calloc failed for context_id_info\n", __func__); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } @@ -2136,27 +1944,20 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo for (j = 0; j < app->count_context_ids; j++) { con = &(app->context_id_info[j]); /* get con id */ - dlt_getloginfo_conv_ascii_to_id(rp, - &rp_count, - con->context_id, - DLT_ID_SIZE); + dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, con->context_id, DLT_ID_SIZE); /* log_level */ if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7)) - con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, - &rp_count); + con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count); /* trace status */ if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7)) - con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, - &rp_count); + con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count); /* context desc */ if (resp->status == 7) { - con->len_context_description = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, - &rp_count); - con->context_description = (char *)calloc - ((size_t) (con->len_context_description + 1), sizeof(char)); + con->len_context_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); + con->context_description = (char*)calloc((size_t)(con->len_context_description + 1), sizeof(char)); if (con->context_description == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for context description\n", __func__); @@ -2164,19 +1965,15 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo return DLT_RETURN_ERROR; } - dlt_getloginfo_conv_ascii_to_string(rp, - &rp_count, - con->context_description, - con->len_context_description); + dlt_getloginfo_conv_ascii_to_string( + rp, &rp_count, con->context_description, con->len_context_description); } } /* application desc */ if (resp->status == 7) { - app->len_app_description = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, - &rp_count); - app->app_description = (char *)calloc - ((size_t) (app->len_app_description + 1), sizeof(char)); + app->len_app_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); + app->app_description = (char*)calloc((size_t)(app->len_app_description + 1), sizeof(char)); if (app->app_description == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for application description\n", __func__); @@ -2184,73 +1981,59 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo return DLT_RETURN_ERROR; } - dlt_getloginfo_conv_ascii_to_string(rp, - &rp_count, - app->app_description, - app->len_app_description); + dlt_getloginfo_conv_ascii_to_string(rp, &rp_count, app->app_description, app->len_app_description); } } return DLT_RETURN_OK; } -DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoResponse *resp, - char *resp_text) +DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoResponse* resp, char* resp_text) { - AppIDsType *app = NULL; - ContextIDsInfoType *con = NULL; + AppIDsType* app = NULL; + ContextIDsInfoType* con = NULL; int i = 0; int j = 0; - char *rp = NULL; + char* rp = NULL; int rp_count = 0; if ((resp == NULL) || (resp_text == NULL)) return DLT_RETURN_WRONG_PARAMETER; /* ------------------------------------------------------ - * get_log_info data structure(all data is ascii) - * - * get_log_info, aa, bb bb cc1 cc cc cc.... dd dd ee1 ee ee ee.... ff gg hh hh ii ii ii .. .. - * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ - * cc1 cc cc cc.... dd dd ee1 ee ee ee.... ff gg hh hh ii ii ii .. .. - * jj jj kk kk kk .. .. - * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ - * aa : get mode (fix value at 0x07) - * bb bb : list num of apid (little endian) - * cc1 : length of apid - * cc cc cc cc: apid - * dd dd : list num of ctid (little endian) - * ee1 : length of ctid - * ee ee ee ee: ctid - * ff : log level - * gg : trace status - * hh hh : description length of ctid - * ii ii .. : description text of ctid - * jj jj : description length of apid - * kk kk .. : description text of apid - * ------------------------------------------------------ */ + * get_log_info data structure(all data is ascii) + * + * get_log_info, aa, bb bb cc1 cc cc cc.... dd dd ee1 ee ee ee.... ff gg hh hh ii ii ii .. .. + * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ + * cc1 cc cc cc.... dd dd ee1 ee ee ee.... ff gg hh hh ii ii ii .. .. + * jj jj kk kk kk .. .. + * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ + * aa : get mode (fix value at 0x07) + * bb bb : list num of apid (little endian) + * cc1 : length of apid + * cc cc cc cc: apid + * dd dd : list num of ctid (little endian) + * ee1 : length of ctid + * ee ee ee ee: ctid + * ff : log level + * gg : trace status + * hh hh : description length of ctid + * ii ii .. : description text of ctid + * jj jj : description length of apid + * kk kk .. : description text of apid + * ------------------------------------------------------ */ rp = resp_text + DLT_GET_LOG_INFO_HEADER; rp_count = 0; /* check if status is acceptable */ - if ((resp->status < GET_LOG_INFO_STATUS_MIN) || - (resp->status > GET_LOG_INFO_STATUS_MAX)) { + if ((resp->status < GET_LOG_INFO_STATUS_MIN) || (resp->status > GET_LOG_INFO_STATUS_MAX)) { if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX) - dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid: NO matching Context IDs\n", - __func__, - resp->status); + dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: NO matching Context IDs\n", __func__, resp->status); else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW) - dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid: Response data over flow\n", - __func__, - resp->status); + dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: Response data over flow\n", __func__, resp->status); else - dlt_vlog(LOG_WARNING, - "%s: The status(%d) is invalid\n", - __func__, - resp->status); + dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid\n", __func__, resp->status); return DLT_RETURN_ERROR; } @@ -2259,8 +2042,7 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe uint16_t ret = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); resp->log_info_type.count_app_ids = ret; - resp->log_info_type.app_ids = (AppIDsType *)calloc - (resp->log_info_type.count_app_ids, sizeof(AppIDsType)); + resp->log_info_type.app_ids = (AppIDsType*)calloc(resp->log_info_type.count_app_ids, sizeof(AppIDsType)); if (resp->log_info_type.app_ids == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for app_ids\n", __func__); @@ -2272,7 +2054,7 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe app = &(resp->log_info_type.app_ids[i]); app->app_id2len = dlt_getloginfo_conv_ascii_to_uint8_t(rp, &rp_count); - app->app_id2 = (char *)calloc((size_t) (app->app_id2len + 1), sizeof(char)); + app->app_id2 = (char*)calloc((size_t)(app->app_id2len + 1), sizeof(char)); if (app->app_id2 == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for App Id\n", __func__); @@ -2285,11 +2067,10 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe /* count_con_ids */ ret = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); app->count_context_ids = ret; - app->context_id_info = (ContextIDsInfoType *)calloc(app->count_context_ids, sizeof(ContextIDsInfoType)); + app->context_id_info = (ContextIDsInfoType*)calloc(app->count_context_ids, sizeof(ContextIDsInfoType)); if (app->context_id_info == NULL) { - dlt_vlog(LOG_ERR, - "%s: calloc failed for context_id_info\n", __func__); + dlt_vlog(LOG_ERR, "%s: calloc failed for context_id_info\n", __func__); dlt_client_free_calloc_failed_get_log_info_v2(resp, i); return DLT_RETURN_ERROR; } @@ -2297,7 +2078,7 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe for (j = 0; j < app->count_context_ids; j++) { con = &(app->context_id_info[j]); con->context_id2len = dlt_getloginfo_conv_ascii_to_uint8_t(rp, &rp_count); - con->context_id2 = (char *)calloc((size_t) (con->context_id2len + 1), sizeof(char)); + con->context_id2 = (char*)calloc((size_t)(con->context_id2len + 1), sizeof(char)); if (con->context_id2 == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for Context Id\n", __func__); @@ -2305,27 +2086,20 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe return DLT_RETURN_ERROR; } /* get con id */ - dlt_getloginfo_conv_ascii_to_id(rp, - &rp_count, - con->context_id2, - con->context_id2len); + dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, con->context_id2, con->context_id2len); /* log_level */ if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7)) - con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, - &rp_count); + con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count); /* trace status */ if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7)) - con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, - &rp_count); + con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count); /* context desc */ if (resp->status == 7) { - con->len_context_description = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, - &rp_count); - con->context_description = (char *)calloc - ((size_t) (con->len_context_description + 1), sizeof(char)); + con->len_context_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); + con->context_description = (char*)calloc((size_t)(con->len_context_description + 1), sizeof(char)); if (con->context_description == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for context description\n", __func__); @@ -2333,19 +2107,15 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe return DLT_RETURN_ERROR; } - dlt_getloginfo_conv_ascii_to_string(rp, - &rp_count, - con->context_description, - con->len_context_description); + dlt_getloginfo_conv_ascii_to_string( + rp, &rp_count, con->context_description, con->len_context_description); } } /* application desc */ if (resp->status == 7) { - app->len_app_description = (uint16_t) dlt_getloginfo_conv_ascii_to_uint16_t(rp, - &rp_count); - app->app_description = (char *)calloc - ((size_t) (app->len_app_description + 1), sizeof(char)); + app->len_app_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); + app->app_description = (char*)calloc((size_t)(app->len_app_description + 1), sizeof(char)); if (app->app_description == NULL) { dlt_vlog(LOG_ERR, "%s: calloc failed for application description\n", __func__); @@ -2353,17 +2123,14 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoRe return DLT_RETURN_ERROR; } - dlt_getloginfo_conv_ascii_to_string(rp, - &rp_count, - app->app_description, - app->len_app_description); + dlt_getloginfo_conv_ascii_to_string(rp, &rp_count, app->app_description, app->len_app_description); } } return DLT_RETURN_OK; } -int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp) +int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse* resp) { AppIDsType app; int i = 0; @@ -2395,7 +2162,7 @@ int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp) return DLT_RETURN_OK; } -int dlt_client_cleanup_get_log_info_v2(DltServiceGetLogInfoResponse *resp) +int dlt_client_cleanup_get_log_info_v2(DltServiceGetLogInfoResponse* resp) { AppIDsType app; int i = 0; diff --git a/src/lib/dlt_client_cfg.h b/src/lib/dlt_client_cfg.h index c1d13f846..19a119e0b 100644 --- a/src/lib/dlt_client_cfg.h +++ b/src/lib/dlt_client_cfg.h @@ -78,10 +78,10 @@ #define DLT_CLIENT_DUMMY_CON_ID "CC1" /* Size of buffer */ -#define DLT_CLIENT_TEXTBUFSIZE 512 +#define DLT_CLIENT_TEXTBUFSIZE 512 /* Initial baudrate */ -#if !defined (__WIN32__) && !defined(_MSC_VER) +#if !defined(__WIN32__) && !defined(_MSC_VER) #define DLT_CLIENT_INITIAL_BAUDRATE B115200 #else #define DLT_CLIENT_INITIAL_BAUDRATE 0 diff --git a/src/lib/dlt_env_ll.c b/src/lib/dlt_env_ll.c index ba75cd876..6d3f608c1 100644 --- a/src/lib/dlt_env_ll.c +++ b/src/lib/dlt_env_ll.c @@ -55,7 +55,7 @@ * @param id Extracted ID * @return 0 if successful, -1 else */ -int dlt_env_extract_id(char **const env, char *id) +int dlt_env_extract_id(char** const env, char* id) { int i; @@ -87,7 +87,7 @@ int dlt_env_extract_id(char **const env, char *id) * * Stops end of string or if ';' is detected */ -int dlt_env_helper_to_lower(char **const env, char *result, int const res_len) +int dlt_env_helper_to_lower(char** const env, char* result, int const res_len) { int count = 0; char ch; @@ -123,7 +123,7 @@ int dlt_env_helper_to_lower(char **const env, char *result, int const res_len) } -int dlt_env_extract_symbolic_ll(char **const env, int8_t *ll) +int dlt_env_extract_symbolic_ll(char** const env, int8_t* ll) { char result[strlen("verbose") + 1]; @@ -195,7 +195,7 @@ int dlt_env_extract_symbolic_ll(char **const env, int8_t *ll) * @param ll Extracted log level * @return 0 if successful, -1 else */ -int dlt_env_extract_ll(char **const env, int8_t *ll) +int dlt_env_extract_ll(char** const env, int8_t* ll) { if (!env || !ll) { return -1; @@ -236,7 +236,7 @@ int dlt_env_extract_ll(char **const env, int8_t *ll) * * @return 0 if successful, -1 else */ -int dlt_env_extract_ll_item(char **const env, dlt_env_ll_item *const item) +int dlt_env_extract_ll_item(char** const env, dlt_env_ll_item* const item) { int ret = -1; @@ -281,14 +281,14 @@ int dlt_env_extract_ll_item(char **const env, dlt_env_ll_item *const item) * @return -1 if memory could not be allocated * @return 0 on success */ -int dlt_env_init_ll_set(dlt_env_ll_set *const ll_set) +int dlt_env_init_ll_set(dlt_env_ll_set* const ll_set) { if (!ll_set) { return -1; } ll_set->array_size = DLT_ENV_LL_SET_INCREASE; - ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); + ll_set->item = (dlt_env_ll_item*)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); if (!ll_set->item) { /* should trigger a warning: no memory left */ @@ -304,7 +304,7 @@ int dlt_env_init_ll_set(dlt_env_ll_set *const ll_set) /** * @brief release ll_set */ -void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set) +void dlt_env_free_ll_set(dlt_env_ll_set* const ll_set) { if (!ll_set) { return; @@ -326,9 +326,9 @@ void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set) * @return -1 if memory could not be allocated * @return 0 on success */ -int dlt_env_increase_ll_set(dlt_env_ll_set *const ll_set) +int dlt_env_increase_ll_set(dlt_env_ll_set* const ll_set) { - dlt_env_ll_item *old_set; + dlt_env_ll_item* old_set; size_t old_size; if (!ll_set) { @@ -339,7 +339,7 @@ int dlt_env_increase_ll_set(dlt_env_ll_set *const ll_set) old_size = ll_set->array_size; ll_set->array_size += DLT_ENV_LL_SET_INCREASE; - ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); + ll_set->item = (dlt_env_ll_item*)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); if (!ll_set->item) { /* should trigger a warning: no memory left */ @@ -361,7 +361,7 @@ int dlt_env_increase_ll_set(dlt_env_ll_set *const ll_set) * * @return 0 if successful, -1 else */ -int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set) +int dlt_env_extract_ll_set(char** const env, dlt_env_ll_set* const ll_set) { if (!env || !ll_set) { return -1; @@ -400,7 +400,7 @@ int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set) * * @return 1 if matching, 0 if not */ -int dlt_env_ids_match(char const *const a, char const *const b) +int dlt_env_ids_match(char const* const a, char const* const b) { if (a[0] != b[0]) { return 0; @@ -426,7 +426,7 @@ int dlt_env_ids_match(char const *const a, char const *const b) * DLTv2 * @return 1 if matching, 0 if not */ -int dlt_env_ids_match_v2(char const *const a, char const *const b, uint8_t len) +int dlt_env_ids_match_v2(char const* const a, char const* const b, uint8_t len) { if (strncmp(a, b, (size_t)len)) { return 0; @@ -446,9 +446,7 @@ int dlt_env_ids_match_v2(char const *const a, char const *const b, uint8_t len) * * In case of error, -1 is returned. */ -int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const *const item, - char const *const apid, - char const *const ctid) +int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const* const item, char const* const apid, char const* const ctid) { if ((!item) || (!apid) || (!ctid)) { return -1; @@ -482,11 +480,8 @@ int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const *const item, * * In case of error, -1 is returned. */ -int dlt_env_ll_item_get_matching_prio_v2(dlt_env_ll_item const *const item, - char const *const apid, - uint8_t apidlen, - char const *const ctid, - uint8_t ctidlen) +int dlt_env_ll_item_get_matching_prio_v2( + dlt_env_ll_item const* const item, char const* const apid, uint8_t apidlen, char const* const ctid, uint8_t ctidlen) { if ((!item) || (!apid) || (!ctid)) { return -1; @@ -519,10 +514,8 @@ int dlt_env_ll_item_get_matching_prio_v2(dlt_env_ll_item const *const item, * * If no item matches or in case of error, the original log-level (\param ll) is returned */ -int dlt_env_adjust_ll_from_env(dlt_env_ll_set const *const ll_set, - char const *const apid, - char const *const ctid, - int const ll) +int dlt_env_adjust_ll_from_env( + dlt_env_ll_set const* const ll_set, char const* const apid, char const* const ctid, int const ll) { if ((!ll_set) || (!apid) || (!ctid)) { return ll; @@ -557,12 +550,9 @@ int dlt_env_adjust_ll_from_env(dlt_env_ll_set const *const ll_set, * * If no item matches or in case of error, the original log-level (\param ll) is returned */ -int dlt_env_adjust_ll_from_env_v2(dlt_env_ll_set const *const ll_set, - char const *const apid, - uint8_t apidlen, - char const *const ctid, - uint8_t ctidlen, - int const ll) +int dlt_env_adjust_ll_from_env_v2( + dlt_env_ll_set const* const ll_set, char const* const apid, uint8_t apidlen, char const* const ctid, + uint8_t ctidlen, int const ll) { if ((!ll_set) || (!apid) || (!ctid)) { return ll; diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index 5b6d88884..6ae13eae4 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -61,7 +61,8 @@ /*!Defines the buffer size of a single file package which will be logged to dlt */ #define BUFFER_SIZE 1024 -/*!Defines the minimum timeout between two dlt logs. This is important because dlt should not be flooded with too many logs in a short period of time. */ +/*!Defines the minimum timeout between two dlt logs. This is important because dlt should not be flooded with too many + * logs in a short period of time. */ #define MIN_TIMEOUT 20 @@ -81,7 +82,7 @@ unsigned char buffer[BUFFER_SIZE]; * @param ok Result of stat * @return Returns the size of the file (if it is a regular file or a symbolic link) in bytes. */ -uint32_t getFilesize(const char *file, int *ok) +uint32_t getFilesize(const char* file, int* ok) { struct stat st; @@ -100,7 +101,7 @@ uint32_t getFilesize(const char *file, int *ok) * @param hash start and result value for hash computation * */ -void stringHash(const char *str, uint32_t *hash) +void stringHash(const char* str, uint32_t* hash) { if (!str || !hash) { return; @@ -126,7 +127,7 @@ void stringHash(const char *str, uint32_t *hash) * @param ok *ok == 0 -> error; *ok == 1 -> ok * @return Returns a unique number associated with each filename */ -uint32_t getFileSerialNumber(const char *file, int *ok) +uint32_t getFileSerialNumber(const char* file, int* ok) { struct stat st; uint32_t ret; @@ -152,7 +153,7 @@ uint32_t getFileSerialNumber(const char *file, int *ok) * @param ok Result of stat * @return Returns the creation date of a file */ -time_t getFileCreationDate(const char *file, int *ok) +time_t getFileCreationDate(const char* file, int* ok) { struct stat st; @@ -172,7 +173,7 @@ time_t getFileCreationDate(const char *file, int *ok) * @param date Local time * @return Returns the creation date of a file */ -void getFileCreationDate2(const char *file, int *ok, char *date) +void getFileCreationDate2(const char* file, int* ok, char* date) { struct stat st; struct tm ts; @@ -193,10 +194,10 @@ void getFileCreationDate2(const char *file, int *ok, char *date) /**@param file Absolute file path * @return Returns 1 if the file exists, 0 if the file does not exist */ -int isFile (const char *file) +int isFile(const char* file) { struct stat st; - return stat (file, &st) == 0; + return stat(file, &st) == 0; } /*!Waits a period of time */ @@ -231,67 +232,53 @@ int checkUserBufferForFreeSpace(void) /*!Deletes the given file */ /** * @param filename Absolute file path - * @return If the file is successfully deleted, a zero value is returned.If the file can not be deleted a nonzero value is returned. + * @return If the file is successfully deleted, a zero value is returned.If the file can not be deleted a nonzero value + * is returned. */ -int doRemoveFile(const char *filename) +int doRemoveFile(const char* filename) { return remove(filename); } -void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filename, int errorCode) +void dlt_user_log_file_errorMessage(DltContext* fileContext, const char* filename, int errorCode) { - if (errno != ENOENT) { int ok = 0; uint32_t fserial = getFileSerialNumber(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_errorMessage, error in getFileSerialNumber for: "), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_errorMessage, error in getFileSerialNumber for: "), DLT_STRING(filename)); } uint32_t fsize = getFilesize(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), + DLT_STRING(filename)); } char fcreationdate[50] = {0}; getFileCreationDate2(filename, &ok, fcreationdate); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), + DLT_STRING(filename)); } int package_count = dlt_user_log_file_packagesCount(fileContext, filename); - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("FLER"), - DLT_INT(errorCode), - DLT_INT(-errno), - DLT_UINT(fserial), - DLT_STRING(filename), - DLT_UINT(fsize), - DLT_STRING(fcreationdate), - DLT_INT(package_count), - DLT_UINT(BUFFER_SIZE), - DLT_STRING("FLER") - ); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("FLER"), DLT_INT(errorCode), DLT_INT(-errno), DLT_UINT(fserial), + DLT_STRING(filename), DLT_UINT(fsize), DLT_STRING(fcreationdate), DLT_INT(package_count), + DLT_UINT(BUFFER_SIZE), DLT_STRING("FLER")); } else { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("FLER"), - DLT_INT(errorCode), - DLT_INT(-errno), - DLT_STRING(filename), - DLT_STRING("FLER") - ); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("FLER"), DLT_INT(errorCode), DLT_INT(-errno), DLT_STRING(filename), + DLT_STRING("FLER")); } } @@ -303,50 +290,41 @@ void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filenam * @param filename Absolute file path * @return Returns 0 if everything was okey.If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) +int dlt_user_log_file_infoAbout(DltContext* fileContext, const char* filename) { - if (isFile(filename)) { int ok; uint32_t fsize = getFilesize(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_infoAbout, Error getting size of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting size of file:"), + DLT_STRING(filename)); } uint32_t fserialnumber = getFileSerialNumber(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_infoAbout, Error getting serial number of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_infoAbout, Error getting serial number of file:"), DLT_STRING(filename)); } char creationdate[50] = {0}; getFileCreationDate2(filename, &ok, creationdate); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_infoAbout, Error getting creation date of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_infoAbout, Error getting creation date of file:"), DLT_STRING(filename)); } - DLT_LOG(*fileContext, DLT_LOG_INFO, - DLT_STRING("FLIF"), - DLT_STRING("file serialnumber"), DLT_UINT(fserialnumber), - DLT_STRING("filename"), DLT_STRING(filename), - DLT_STRING("file size in bytes"), DLT_UINT(fsize), - DLT_STRING("file creation date"), DLT_STRING(creationdate), - DLT_STRING("number of packages"), - DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), - DLT_STRING("FLIF") - ); + DLT_LOG( + *fileContext, DLT_LOG_INFO, DLT_STRING("FLIF"), DLT_STRING("file serialnumber"), DLT_UINT(fserialnumber), + DLT_STRING("filename"), DLT_STRING(filename), DLT_STRING("file size in bytes"), DLT_UINT(fsize), + DLT_STRING("file creation date"), DLT_STRING(creationdate), DLT_STRING("number of packages"), + DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), DLT_STRING("FLIF")); return 0; } else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_INFO_ABOUT); @@ -359,17 +337,16 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) * In the next step some generic informations about the file will be logged to dlt. * Now the header will be logged to dlt. See the method dlt_user_log_file_header for more informations. * Then the method dlt_user_log_data will be called with the parameter to log all packages in a loop with some timeout. - * At last dlt_user_log_end is called to signal that the complete file transfer was okey. This is important for the plugin of the dlt viewer. + * At last dlt_user_log_end is called to signal that the complete file transfer was okey. This is important for the + * plugin of the dlt viewer. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path * @param deleteFlag Flag if the file will be deleted after transfer. 1->delete, 0->notDelete - * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to many messages in a short period of time. + * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to + * many messages in a short period of time. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_complete(DltContext *fileContext, - const char *filename, - int deleteFlag, - unsigned int timeout) +int dlt_user_log_file_complete(DltContext* fileContext, const char* filename, int deleteFlag, unsigned int timeout) { if (!isFile(filename)) { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_COMPLETE); @@ -380,8 +357,7 @@ int dlt_user_log_file_complete(DltContext *fileContext, return DLT_FILETRANSFER_ERROR_FILE_COMPLETE1; } - if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, - timeout) != 0) { + if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, timeout) != 0) { return DLT_FILETRANSFER_ERROR_FILE_COMPLETE2; } @@ -401,7 +377,7 @@ int dlt_user_log_file_complete(DltContext *fileContext, * @param filename Absolute file path * @return Returns the number of packages if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filename) +int dlt_user_log_file_packagesCount(DltContext* fileContext, const char* filename) { int packages; uint32_t filesize; @@ -412,11 +388,9 @@ int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filenam filesize = getFilesize(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("Error in: dlt_user_log_file_packagesCount, isFile"), - DLT_STRING(filename), - DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("Error in: dlt_user_log_file_packagesCount, isFile"), + DLT_STRING(filename), DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); return -1; } @@ -432,11 +406,9 @@ int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filenam } } } else { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("Error in: dlt_user_log_file_packagesCount, !isFile"), - DLT_STRING(filename), - DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("Error in: dlt_user_log_file_packagesCount, !isFile"), + DLT_STRING(filename), DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); return -1; } } @@ -451,51 +423,43 @@ int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filenam * @param alias Alias for the file. An alternative name to show in the receiving end * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename, const char *alias) +int dlt_user_log_file_header_alias(DltContext* fileContext, const char* filename, const char* alias) { - if (isFile(filename)) { int ok; uint32_t fserialnumber = getFileSerialNumber(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header_alias, Error getting serial number of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header_alias, Error getting serial number of file:"), + DLT_STRING(filename)); return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } uint32_t fsize = getFilesize(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header_alias, Error getting size of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_header_alias, Error getting size of file:"), + DLT_STRING(filename)); } char fcreationdate[50] = {0}; getFileCreationDate2(filename, &ok, fcreationdate); if (!ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header_alias, Error getting creation date of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header_alias, Error getting creation date of file:"), + DLT_STRING(filename)); } - DLT_LOG(*fileContext, DLT_LOG_INFO, - DLT_STRING("FLST"), - DLT_UINT(fserialnumber), - DLT_STRING(alias), - DLT_UINT(fsize), - DLT_STRING(fcreationdate); - DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), - DLT_UINT(BUFFER_SIZE), - DLT_STRING("FLST") - ); + DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), DLT_UINT(fserialnumber), DLT_STRING(alias), + DLT_UINT(fsize), DLT_STRING(fcreationdate); + DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), DLT_UINT(BUFFER_SIZE), + DLT_STRING("FLST")); return 0; } else { @@ -513,50 +477,40 @@ int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename * @param filename Absolute file path * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_header(DltContext *fileContext, const char *filename) +int dlt_user_log_file_header(DltContext* fileContext, const char* filename) { - if (isFile(filename)) { int ok; uint32_t fserialnumber = getFileSerialNumber(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header, Error getting serial number of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header, Error getting serial number of file:"), DLT_STRING(filename)); } uint32_t fsize = getFilesize(filename, &ok); if (!ok) { - DLT_LOG(*fileContext, - DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_header, Error getting size of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_header, Error getting size of file:"), + DLT_STRING(filename)); } char fcreationdate[50] = {0}; getFileCreationDate2(filename, &ok, fcreationdate); if (!ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING( - "dlt_user_log_file_header, Error getting creation date of file:"), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header, Error getting creation date of file:"), DLT_STRING(filename)); } - DLT_LOG(*fileContext, DLT_LOG_INFO, - DLT_STRING("FLST"), - DLT_UINT(fserialnumber), - DLT_STRING(filename), - DLT_UINT(fsize), - DLT_STRING(fcreationdate); - DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), - DLT_UINT(BUFFER_SIZE), - DLT_STRING("FLST") - ); + DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), DLT_UINT(fserialnumber), DLT_STRING(filename), + DLT_UINT(fsize), DLT_STRING(fcreationdate); + DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), DLT_UINT(BUFFER_SIZE), + DLT_STRING("FLST")); return 0; } else { @@ -569,60 +523,57 @@ int dlt_user_log_file_header(DltContext *fileContext, const char *filename) /**See the Mainpages.c for more informations. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path - * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred with a specific timeout - * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. + * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred + * with a specific timeout + * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is + * defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_data(DltContext *fileContext, - const char *filename, - int packageToTransfer, - unsigned int timeout) +int dlt_user_log_file_data(DltContext* fileContext, const char* filename, int packageToTransfer, unsigned int timeout) { bool fileCancelTransferFlag = false; - return dlt_user_log_file_data_cancelable(fileContext, filename, packageToTransfer, timeout, &fileCancelTransferFlag); + return dlt_user_log_file_data_cancelable( + fileContext, filename, packageToTransfer, timeout, &fileCancelTransferFlag); } /* !Transfer the content data of a cancelable file*/ /**See the Mainpages.c for more informations. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path - * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred with a specific timeout - * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. - * @param fileCancelTransferFlag is a bool pointer to cancel the filetransfer on demand. For example in case of application shutdown event outstanding file transfer should abort and return + * @param packageToTransfer Package number to transfer. If this param is LONG_MAX, the whole file will be transferred + * with a specific timeout + * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is + * defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. + * @param fileCancelTransferFlag is a bool pointer to cancel the filetransfer on demand. For example in case of + * application shutdown event outstanding file transfer should abort and return * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -int dlt_user_log_file_data_cancelable(DltContext *fileContext, - const char *filename, - int packageToTransfer, - unsigned int timeout, - bool *const fileCancelTransferFlag) +int dlt_user_log_file_data_cancelable( + DltContext* fileContext, const char* filename, int packageToTransfer, unsigned int timeout, + bool* const fileCancelTransferFlag) { - FILE *file; + FILE* file; int pkgNumber; uint32_t readBytes; if (isFile(filename)) { - - file = fopen (filename, "rb"); + file = fopen(filename, "rb"); if (file == NULL) { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_DATA); return DLT_FILETRANSFER_ERROR_FILE_DATA; } - if (((packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) && - (packageToTransfer > - dlt_user_log_file_packagesCount(fileContext, - filename))) || (packageToTransfer <= 0)) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("Error at dlt_user_log_file_data: packageToTransfer out of scope"), - DLT_STRING("packageToTransfer:"), - DLT_UINT((unsigned int)packageToTransfer), - DLT_STRING("numberOfMaximalPackages:"), - DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), - DLT_STRING("for File:"), - DLT_STRING(filename) - ); + if (((packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) + && (packageToTransfer > dlt_user_log_file_packagesCount(fileContext, filename))) + || (packageToTransfer <= 0)) { + DLT_LOG( + *fileContext, DLT_LOG_ERROR, + DLT_STRING("Error at dlt_user_log_file_data: packageToTransfer out of scope"), + DLT_STRING("packageToTransfer:"), DLT_UINT((unsigned int)packageToTransfer), + DLT_STRING("numberOfMaximalPackages:"), + DLT_UINT((unsigned int)dlt_user_log_file_packagesCount(fileContext, filename)), DLT_STRING("for File:"), + DLT_STRING(filename)); fclose(file); return DLT_FILETRANSFER_ERROR_FILE_DATA; } @@ -630,19 +581,17 @@ int dlt_user_log_file_data_cancelable(DltContext *fileContext, readBytes = 0; if (packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) { -/* If a single package should be transferred. The user has to check that the free space in the user buffer > 50% */ -/* if(checkUserBufferForFreeSpace()<0) */ -/* return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; */ - - if (0 != fseek (file, (packageToTransfer - 1) * BUFFER_SIZE, SEEK_SET)) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("failed to fseek in file: "), - DLT_STRING(filename), - DLT_STRING("ferror:"), - DLT_INT(ferror(file)) - ); - - fclose (file); + /* If a single package should be transferred. The user has to check that the free space in + * the user buffer > 50% */ + /* if(checkUserBufferForFreeSpace()<0) */ + /* return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; */ + + if (0 != fseek(file, (packageToTransfer - 1) * BUFFER_SIZE, SEEK_SET)) { + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("failed to fseek in file: "), DLT_STRING(filename), + DLT_STRING("ferror:"), DLT_INT(ferror(file))); + + fclose(file); return -1; } @@ -652,26 +601,21 @@ int dlt_user_log_file_data_cancelable(DltContext *fileContext, uint32_t fserial = getFileSerialNumber(filename, &ok); if (1 != ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("failed to get FileSerialNumber for: "), - DLT_STRING(filename)); - fclose (file); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), + DLT_STRING(filename)); + fclose(file); return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } - DLT_LOG(*fileContext, DLT_LOG_INFO, - DLT_STRING("FLDA"), - DLT_UINT(fserial), - DLT_UINT((unsigned int)packageToTransfer), - DLT_RAW(buffer, (uint16_t)readBytes), - DLT_STRING("FLDA") - ); - - if(*fileCancelTransferFlag) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("FLER"), - DLT_INT(DLT_FILETRANSFER_ERROR_FILE_END_USER_CANCELLED) - ); + DLT_LOG( + *fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), DLT_UINT(fserial), + DLT_UINT((unsigned int)packageToTransfer), DLT_RAW(buffer, (uint16_t)readBytes), DLT_STRING("FLDA")); + + if (*fileCancelTransferFlag) { + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("FLER"), + DLT_INT(DLT_FILETRANSFER_ERROR_FILE_END_USER_CANCELLED)); return DLT_FILETRANSFER_ERROR_FILE_END_USER_CANCELLED; } doTimeout(timeout); @@ -679,8 +623,8 @@ int dlt_user_log_file_data_cancelable(DltContext *fileContext, pkgNumber = 0; while (!feof(file)) { -/* If the complete file should be transferred, the user buffer will be checked. */ -/* If free space < 50% the package won't be transferred. */ + /* If the complete file should be transferred, the user buffer will be checked. */ + /* If free space < 50% the package won't be transferred. */ if (checkUserBufferForFreeSpace() > 0) { pkgNumber++; readBytes = (uint32_t)fread(buffer, sizeof(char), BUFFER_SIZE, file); @@ -696,28 +640,23 @@ int dlt_user_log_file_data_cancelable(DltContext *fileContext, uint32_t fserial = getFileSerialNumber(filename, &ok); if (1 != ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("failed to get FileSerialNumber for: "), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), + DLT_STRING(filename)); fclose(file); return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } - DLT_LOG(*fileContext, DLT_LOG_INFO, - DLT_STRING("FLDA"), - DLT_UINT(fserial), - DLT_UINT((unsigned int)pkgNumber), - DLT_RAW(buffer, (uint16_t)readBytes), - DLT_STRING("FLDA") - ); - if(*fileCancelTransferFlag) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("FLER"), - DLT_INT(DLT_FILETRANSFER_ERROR_FILE_END_USER_CANCELLED) - ); + DLT_LOG( + *fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), DLT_UINT(fserial), + DLT_UINT((unsigned int)pkgNumber), DLT_RAW(buffer, (uint16_t)readBytes), DLT_STRING("FLDA")); + if (*fileCancelTransferFlag) { + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("FLER"), + DLT_INT(DLT_FILETRANSFER_ERROR_FILE_END_USER_CANCELLED)); return DLT_FILETRANSFER_ERROR_FILE_END_USER_CANCELLED; } - } else { + } else { fclose(file); return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; } @@ -742,32 +681,23 @@ int dlt_user_log_file_data_cancelable(DltContext *fileContext, * @param deleteFlag Flag to delete the file after the whole file is transferred (logged to dlt).1->delete,0->NotDelete * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_end(DltContext *fileContext, const char *filename, int deleteFlag) +int dlt_user_log_file_end(DltContext* fileContext, const char* filename, int deleteFlag) { - if (isFile(filename)) { - int ok; uint32_t fserial = getFileSerialNumber(filename, &ok); if (1 != ok) { - DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("failed to get FileSerialNumber for: "), - DLT_STRING(filename)); + DLT_LOG( + *fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); return DLT_FILETRANSFER_FILE_SERIAL_NUMBER; } - DLT_LOG(*fileContext, DLT_LOG_INFO, - DLT_STRING("FLFI"), - DLT_UINT(fserial), - DLT_STRING("FLFI") - ); + DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLFI"), DLT_UINT(fserial), DLT_STRING("FLFI")); if (deleteFlag) { if (doRemoveFile(filename) != 0) { - dlt_user_log_file_errorMessage(fileContext, - filename, - DLT_FILETRANSFER_ERROR_FILE_END); + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); return -1; } } diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index ee21f01eb..12e003ad1 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -30,10 +30,10 @@ #include #include /* for signal(), SIGPIPE, SIG_IGN */ -#if !defined (__WIN32__) -# include /* for LOG_... */ -# include -# include /* POSIX Threads */ +#if !defined(__WIN32__) +#include /* for LOG_... */ +#include +#include /* POSIX Threads */ #endif #include @@ -48,7 +48,7 @@ #include #ifdef linux -# include /* for PR_SET_NAME */ +#include /* for PR_SET_NAME */ #endif #include /* needed for getpid() */ @@ -60,19 +60,19 @@ #include #if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC -# include +#include #endif #ifdef DLT_LIB_USE_UNIX_SOCKET_IPC -# include +#include #endif #ifdef DLT_LIB_USE_VSOCK_IPC -# ifdef linux -# include -# endif -# ifdef __QNX__ -# include -# endif +#ifdef linux +#include +#endif +#ifdef __QNX__ +#include +#endif #endif #include "dlt_user.h" @@ -83,23 +83,18 @@ #include "dlt_user_cfg.h" #ifdef DLT_FATAL_LOG_RESET_ENABLE -# define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) \ - do { \ - if (LOGLEVEL == DLT_LOG_FATAL) { \ - int *p = NULL; \ - *p = 0; \ - } \ +#define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) \ + do { \ + if (LOGLEVEL == DLT_LOG_FATAL) { \ + int* p = NULL; \ + *p = 0; \ + } \ } while (false) #else /* DLT_FATAL_LOG_RESET_ENABLE */ -# define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) +#define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) #endif /* DLT_FATAL_LOG_RESET_ENABLE */ -enum InitState { - INIT_UNITIALIZED, - INIT_IN_PROGRESS, - INIT_ERROR, - INIT_DONE -}; +enum InitState { INIT_UNITIALIZED, INIT_IN_PROGRESS, INIT_ERROR, INIT_DONE }; static DltUser dlt_user; static _Atomic enum InitState dlt_user_init_state = INIT_UNITIALIZED; @@ -143,19 +138,14 @@ static int g_dlt_is_child = 0; static const char STR_TRUNCATED_MESSAGE[] = "... <>"; /* Enum for type of string */ -enum StringType -{ - ASCII_STRING = 0, - UTF8_STRING = 1 -}; +enum StringType { ASCII_STRING = 0, UTF8_STRING = 1 }; /* Data type holding "Variable Info" (VARI) properties * Some of the supported data types (eg. bool, string, raw) have only "name", but not "unit". */ -typedef struct VarInfo -{ - const char *name; // the "name" attribute (can be NULL) - const char *unit; // the "unit" attribute (can be NULL) +typedef struct VarInfo { + const char* name; // the "name" attribute (can be NULL) + const char* unit; // the "unit" attribute (can be NULL) bool with_unit; // true if the "unit" field is to be considered } VarInfo; @@ -163,7 +153,7 @@ typedef struct VarInfo /* Network trace */ #ifdef DLT_NETWORK_TRACE_ENABLE -#define DLT_USER_SEGMENTED_THREAD (1<<2) +#define DLT_USER_SEGMENTED_THREAD (1 << 2) /* Segmented Network Trace */ #define DLT_MAX_TRACE_SEGMENT_SIZE 1024 @@ -175,77 +165,72 @@ pthread_mutex_t mq_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t mq_init_condition; #endif /* DLT_NETWORK_TRACE_ENABLE */ -void dlt_lock_mutex(pthread_mutex_t *mutex) +void dlt_lock_mutex(pthread_mutex_t* mutex) { int32_t lock_mutex_result = pthread_mutex_lock(mutex); if (lock_mutex_result != 0) - dlt_vlog(LOG_ERR, - "Mutex lock failed unexpected pid=%i with result %i!\n", - getpid(), lock_mutex_result); + dlt_vlog(LOG_ERR, "Mutex lock failed unexpected pid=%i with result %i!\n", getpid(), lock_mutex_result); } -void dlt_unlock_mutex(pthread_mutex_t *mutex) +void dlt_unlock_mutex(pthread_mutex_t* mutex) { pthread_mutex_unlock(mutex); } /* Structure to pass data to segmented thread */ -typedef struct -{ - DltContext *handle; +typedef struct { + DltContext* handle; uint32_t id; DltNetworkTraceType nw_trace_type; uint32_t header_len; - void *header; + void* header; uint32_t payload_len; - void *payload; + void* payload; } s_segmented_data; /* Function prototypes for internally used functions */ -static void *dlt_user_housekeeperthread_function(void *ptr); +static void* dlt_user_housekeeperthread_function(void* ptr); static void dlt_user_atexit_handler(void); -static DltReturnValue dlt_user_log_init(DltContext *handle, DltContextData *log); -static DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype, int *sent_size); -static DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, DltHtyp2ContentType msgcontent, int *const sent_size); +static DltReturnValue dlt_user_log_init(DltContext* handle, DltContextData* log); +static DltReturnValue dlt_user_log_send_log(DltContextData* log, int mtype, int* sent_size); +static DltReturnValue dlt_user_log_send_log_v2( + DltContextData* log, const int mtype, DltHtyp2ContentType msgcontent, int* const sent_size); static DltReturnValue dlt_user_log_send_register_application(void); static DltReturnValue dlt_user_log_send_register_application_v2(void); static DltReturnValue dlt_user_log_send_unregister_application(void); static DltReturnValue dlt_user_log_send_unregister_application_v2(void); -static DltReturnValue dlt_user_log_send_register_context(DltContextData *log); -static DltReturnValue dlt_user_log_send_register_context_v2(DltContextData *log); -static DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log); -static DltReturnValue dlt_user_log_send_unregister_context_v2(DltContextData *log); -static DltReturnValue dlt_send_app_ll_ts_limit(const char *apid, - DltLogLevelType loglevel, - DltTraceStatusType tracestatus); -static DltReturnValue dlt_send_app_ll_ts_limit_v2(const char *apid, - DltLogLevelType loglevel, - DltTraceStatusType tracestatus); +static DltReturnValue dlt_user_log_send_register_context(DltContextData* log); +static DltReturnValue dlt_user_log_send_register_context_v2(DltContextData* log); +static DltReturnValue dlt_user_log_send_unregister_context(DltContextData* log); +static DltReturnValue dlt_user_log_send_unregister_context_v2(DltContextData* log); +static DltReturnValue dlt_send_app_ll_ts_limit( + const char* apid, DltLogLevelType loglevel, DltTraceStatusType tracestatus); +static DltReturnValue dlt_send_app_ll_ts_limit_v2( + const char* apid, DltLogLevelType loglevel, DltTraceStatusType tracestatus); static DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode, uint8_t version); static DltReturnValue dlt_user_log_send_marker(void); -static DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log); -static DltReturnValue dlt_user_print_msg_v2(DltMessageV2 *msg, DltContextData *log); +static DltReturnValue dlt_user_print_msg(DltMessage* msg, DltContextData* log); +static DltReturnValue dlt_user_print_msg_v2(DltMessageV2* msg, DltContextData* log); static DltReturnValue dlt_user_log_check_user_message(void); static void dlt_user_log_reattach_to_daemon(void); static DltReturnValue dlt_user_log_send_overflow(void); -static DltReturnValue dlt_user_log_out_error_handling(void *ptr1, - size_t len1, - void *ptr2, - size_t len2, - void *ptr3, - size_t len3); -static void dlt_user_cleanup_handler(void *arg); +static DltReturnValue dlt_user_log_out_error_handling( + void* ptr1, size_t len1, void* ptr2, size_t len2, void* ptr3, size_t len3); +static void dlt_user_cleanup_handler(void* arg); static int dlt_start_threads(void); static void dlt_stop_threads(void); static void dlt_fork_child_fork_handler(void); #ifdef DLT_NETWORK_TRACE_ENABLE -static void *dlt_user_trace_network_segmented_thread(void *unused); -static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data); +static void* dlt_user_trace_network_segmented_thread(void* unused); +static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data* data); #endif -static DltReturnValue dlt_user_log_write_string_utils_attr(DltContextData *log, const char *text, const enum StringType type, const char *name, bool with_var_info); -static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData *log, const char *text, size_t length, const enum StringType type, const char *name, bool with_var_info); +static DltReturnValue dlt_user_log_write_string_utils_attr( + DltContextData* log, const char* text, const enum StringType type, const char* name, bool with_var_info); +static DltReturnValue dlt_user_log_write_sized_string_utils_attr( + DltContextData* log, const char* text, size_t length, const enum StringType type, const char* name, + bool with_var_info); static DltReturnValue dlt_unregister_app_util(bool force_sending_messages); @@ -254,7 +239,7 @@ static int dlt_get_extendedheadersize_v2(DltUser dlt_user_param, int contextIDSi #ifdef DLT_TRACE_LOAD_CTRL_ENABLE /* For trace load control feature */ -static DltReturnValue dlt_user_output_internal_msg(DltLogLevelType loglevel, const char *text, void* params); +static DltReturnValue dlt_user_output_internal_msg(DltLogLevelType loglevel, const char* text, void* params); DltContext trace_load_context = {0}; DltTraceLoadSettings* trace_load_settings = NULL; uint32_t trace_load_settings_count = 0; @@ -264,11 +249,12 @@ pthread_rwlock_t trace_load_rw_lock = PTHREAD_RWLOCK_INITIALIZER; #include /* Safely cast size_t to int32_t, clamp to INT32_MAX if needed */ -static int32_t safe_size_to_int32(size_t val) { +static int32_t safe_size_to_int32(size_t val) +{ return (val > (size_t)INT32_MAX) ? INT32_MAX : (int32_t)val; } -DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version) +DltReturnValue dlt_user_check_library_version(const char* user_major_version, const char* user_minor_version) { char lib_major_version[DLT_USER_MAX_LIB_VERSION_LENGTH]; char lib_minor_version[DLT_USER_MAX_LIB_VERSION_LENGTH]; @@ -277,13 +263,11 @@ DltReturnValue dlt_user_check_library_version(const char *user_major_version, co dlt_get_minor_version(lib_minor_version, DLT_USER_MAX_LIB_VERSION_LENGTH); if ((strcmp(lib_major_version, user_major_version) != 0) || (strcmp(lib_minor_version, user_minor_version) != 0)) { - dlt_vnlog(LOG_WARNING, - DLT_USER_BUFFER_LENGTH, - "DLT Library version check failed! Installed DLT library version is %s.%s - Application using DLT library version %s.%s\n", - lib_major_version, - lib_minor_version, - user_major_version, - user_minor_version); + dlt_vnlog( + LOG_WARNING, DLT_USER_BUFFER_LENGTH, + "DLT Library version check failed! Installed DLT library version is %s.%s - Application using DLT library " + "version %s.%s\n", + lib_major_version, lib_minor_version, user_major_version, user_minor_version); return DLT_RETURN_ERROR; } @@ -339,29 +323,22 @@ static DltReturnValue dlt_initialize_socket_connection(void) strncpy(remote.sun_path, dltSockBaseDir, sizeof(remote.sun_path)); if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX) - dlt_vlog(LOG_INFO, - "Provided path too long...trimming it to path[%s]\n", - dltSockBaseDir); + dlt_vlog(LOG_INFO, "Provided path too long...trimming it to path[%s]\n", dltSockBaseDir); - if (connect(sockfd, (struct sockaddr *)&remote, sizeof(remote)) == -1) { + if (connect(sockfd, (struct sockaddr*)&remote, sizeof(remote)) == -1) { if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { - dlt_vlog(LOG_INFO, - "Socket %s cannot be opened (errno=%d). Retrying later...\n", - dltSockBaseDir, errno); + dlt_vlog(LOG_INFO, "Socket %s cannot be opened (errno=%d). Retrying later...\n", dltSockBaseDir, errno); dlt_user.connection_state = DLT_USER_RETRY_CONNECT; } close(sockfd); dlt_user.dlt_log_handle = -1; - } - else { + } else { dlt_user.dlt_log_handle = sockfd; dlt_user.connection_state = DLT_USER_CONNECTED; - if (dlt_receiver_init(&(dlt_user.receiver), - sockfd, - DLT_RECEIVE_SOCKET, - DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { + if (dlt_receiver_init(&(dlt_user.receiver), sockfd, DLT_RECEIVE_SOCKET, DLT_USER_RCVBUF_MAX_SIZE) + == DLT_RETURN_ERROR) { dlt_user_init_state = INIT_UNITIALIZED; close(sockfd); dlt_mutex_unlock(); @@ -391,7 +368,7 @@ static DltReturnValue dlt_initialize_vsock_connection() remote.svm_port = DLT_VSOCK_PORT; remote.svm_cid = VMADDR_CID_HOST; - if (connect(sockfd, (struct sockaddr *)&remote, sizeof(remote)) == -1) { + if (connect(sockfd, (struct sockaddr*)&remote, sizeof(remote)) == -1) { if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { dlt_vlog(LOG_INFO, "VSOCK socket cannot be opened. Retrying later...\n"); dlt_user.connection_state = DLT_USER_RETRY_CONNECT; @@ -399,8 +376,7 @@ static DltReturnValue dlt_initialize_vsock_connection() close(sockfd); dlt_user.dlt_log_handle = -1; - } - else { + } else { /* Set to non-blocking after connect() to avoid EINPROGRESS. DltUserConntextionState needs "connecting" state if connect() should be non-blocking. */ if (dlt_socket_set_nonblock_and_linger(sockfd) != DLT_RETURN_OK) { @@ -412,10 +388,8 @@ static DltReturnValue dlt_initialize_vsock_connection() dlt_user.dlt_log_handle = sockfd; dlt_user.connection_state = DLT_USER_CONNECTED; - if (dlt_receiver_init(&(dlt_user.receiver), - sockfd, - DLT_RECEIVE_SOCKET, - DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { + if (dlt_receiver_init(&(dlt_user.receiver), sockfd, DLT_RECEIVE_SOCKET, DLT_USER_RCVBUF_MAX_SIZE) + == DLT_RETURN_ERROR) { dlt_user_init_state = INIT_UNITIALIZED; close(sockfd); dlt_mutex_unlock(); @@ -461,9 +435,9 @@ static DltReturnValue dlt_initialize_fifo_connection(void) /* if dlt pipes directory is created by the application also chmod the directory */ if (ret == 0) { /* S_ISGID cannot be set by mkdir, let's reassign right bits */ - ret = chmod(dlt_user_dir, - S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | - S_ISVTX); + ret = chmod( + dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH + | S_ISGID | S_ISVTX); if (ret == -1) { dlt_vnlog(LOG_ERR, DLT_USER_BUFFER_LENGTH, "FIFO user dir %s cannot be chmoded!\n", dlt_user_dir); @@ -509,8 +483,7 @@ static DltReturnValue dlt_initialize_fifo_connection(void) /* This is a normal usecase. It is OK that the daemon (and thus the FIFO /tmp/dlt) * starts later and some DLT users have already been started before. * Thus it is OK if the FIFO can't be opened. */ - dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "FIFO %s cannot be opened. Retrying later...\n", - dlt_daemon_fifo); + dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "FIFO %s cannot be opened. Retrying later...\n", dlt_daemon_fifo); return DLT_RETURN_OK; } @@ -566,8 +539,11 @@ DltReturnValue dlt_init(void) /* init shared memory */ if (dlt_shm_init_client(&(dlt_user.dlt_shm), dltShmName) < DLT_RETURN_OK) - dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Logging disabled," - " Shared memory %s cannot be created!\n", dltShmName); + dlt_vnlog( + LOG_WARNING, DLT_USER_BUFFER_LENGTH, + "Logging disabled," + " Shared memory %s cannot be created!\n", + dltShmName); #endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE @@ -619,10 +595,8 @@ DltReturnValue dlt_init(void) return DLT_RETURN_ERROR; } - if (dlt_receiver_init(&(dlt_user.receiver), - dlt_user.dlt_user_handle, - DLT_RECEIVE_FD, - DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { + if (dlt_receiver_init(&(dlt_user.receiver), dlt_user.dlt_user_handle, DLT_RECEIVE_FD, DLT_USER_RCVBUF_MAX_SIZE) + == DLT_RETURN_ERROR) { dlt_user_init_state = INIT_ERROR; dlt_free(); return DLT_RETURN_ERROR; @@ -652,7 +626,7 @@ DltReturnValue dlt_init(void) return DLT_RETURN_OK; } -DltReturnValue dlt_get_appid(char *appid) +DltReturnValue dlt_get_appid(char* appid) { if (appid != NULL) { strncpy(appid, dlt_user.appID, 4); @@ -663,7 +637,7 @@ DltReturnValue dlt_get_appid(char *appid) } } -DltReturnValue dlt_get_appid_v2(char **appid) +DltReturnValue dlt_get_appid_v2(char** appid) { if (appid != NULL) { strncpy(*appid, dlt_user.appID2, dlt_user.appID2len); @@ -674,7 +648,7 @@ DltReturnValue dlt_get_appid_v2(char **appid) } } -DltReturnValue dlt_init_file(const char *name) +DltReturnValue dlt_init_file(const char* name) { /* check null pointer */ if (!name) @@ -701,8 +675,7 @@ DltReturnValue dlt_init_file(const char *name) dlt_user.dlt_is_file = 1; /* open DLT output file */ - dlt_user.dlt_log_handle = open(name, O_WRONLY | O_CREAT, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + dlt_user.dlt_log_handle = open(name, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ if (dlt_user.dlt_log_handle == -1) { dlt_vnlog(LOG_ERR, DLT_USER_BUFFER_LENGTH, "Log file %s cannot be opened!\n", name); @@ -716,21 +689,17 @@ DltReturnValue dlt_init_file(const char *name) DltReturnValue dlt_set_filesize_max(unsigned int filesize) { - if (dlt_user.dlt_is_file == 0) - { - dlt_vlog(LOG_ERR, "%s: Library is not configured to log to file\n", - __func__); + if (dlt_user.dlt_is_file == 0) { + dlt_vlog(LOG_ERR, "%s: Library is not configured to log to file\n", __func__); return DLT_RETURN_ERROR; } if (filesize == 0) { dlt_user.filesize_max = UINT_MAX; - } - else { + } else { dlt_user.filesize_max = filesize; } - dlt_vlog(LOG_DEBUG, "%s: Defined filesize_max is [%d]\n", __func__, - dlt_user.filesize_max); + dlt_vlog(LOG_DEBUG, "%s: Defined filesize_max is [%d]\n", __func__, dlt_user.filesize_max); return DLT_RETURN_OK; } @@ -740,8 +709,7 @@ DltReturnValue dlt_init_message_queue(void) { dlt_lock_mutex(&mq_mutex); - if ((dlt_user.dlt_segmented_queue_read_handle >= 0) && - (dlt_user.dlt_segmented_queue_write_handle >= 0)) { + if ((dlt_user.dlt_segmented_queue_read_handle >= 0) && (dlt_user.dlt_segmented_queue_write_handle >= 0)) { /* Already intialized */ dlt_unlock_mutex(&mq_mutex); return DLT_RETURN_OK; @@ -755,16 +723,15 @@ DltReturnValue dlt_init_message_queue(void) struct mq_attr mqatr; mqatr.mq_flags = 0; mqatr.mq_maxmsg = 10; - mqatr.mq_msgsize = sizeof(s_segmented_data *); + mqatr.mq_msgsize = sizeof(s_segmented_data*); mqatr.mq_curmsgs = 0; /** * Create the message queue. It must be newly created * if old one was left by a crashing process. * */ - dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, O_CREAT | O_RDONLY | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, - &mqatr); + dlt_user.dlt_segmented_queue_read_handle = mq_open( + queue_name, O_CREAT | O_RDONLY | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, &mqatr); if (dlt_user.dlt_segmented_queue_read_handle < 0) { if (errno == EEXIST) { @@ -774,10 +741,9 @@ DltReturnValue dlt_init_message_queue(void) dlt_vnlog(LOG_CRIT, 256, "Could not delete existing message queue!: %s \n", strerror(errno)); else /* Retry */ - dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, - O_CREAT | O_RDONLY | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, - &mqatr); + dlt_user.dlt_segmented_queue_read_handle = mq_open( + queue_name, O_CREAT | O_RDONLY | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, + &mqatr); } if (dlt_user.dlt_segmented_queue_read_handle < 0) { @@ -790,7 +756,6 @@ DltReturnValue dlt_init_message_queue(void) dlt_user.dlt_segmented_queue_write_handle = mq_open(queue_name, O_WRONLY | O_NONBLOCK); if (dlt_user.dlt_segmented_queue_write_handle < 0) { - dlt_vnlog(LOG_CRIT, 256, "Can't open message queue write handle!: %s \n", strerror(errno)); dlt_unlock_mutex(&mq_mutex); return DLT_RETURN_ERROR; @@ -810,16 +775,16 @@ static inline bool is_verbose_mode(int8_t dltuser_verbose_mode, const DltContext DltReturnValue dlt_init_common(void) { - char *env_local_print; - char *env_initial_log_level; - char *env_buffer_min; + char* env_local_print; + char* env_initial_log_level; + char* env_buffer_min; uint32_t buffer_min = DLT_USER_RINGBUFFER_MIN_SIZE; - char *env_buffer_max; + char* env_buffer_max; uint32_t buffer_max = DLT_USER_RINGBUFFER_MAX_SIZE; - char *env_buffer_step; + char* env_buffer_step; uint32_t buffer_step = DLT_USER_RINGBUFFER_STEP_SIZE; - char *env_disable_extended_header_for_nonverbose; - char *env_log_buffer_len; + char* env_disable_extended_header_for_nonverbose; + char* env_log_buffer_len; uint32_t buffer_max_configured = 0; uint32_t header_size = 0; @@ -828,9 +793,9 @@ DltReturnValue dlt_init_common(void) return DLT_RETURN_OK; } - if ((pthread_mutexattr_init(&dlt_mutex_attr) != 0) || - (pthread_mutexattr_settype(&dlt_mutex_attr, PTHREAD_MUTEX_RECURSIVE) != 0) || - (pthread_mutex_init(&dlt_mutex, &dlt_mutex_attr) != 0)) { + if ((pthread_mutexattr_init(&dlt_mutex_attr) != 0) + || (pthread_mutexattr_settype(&dlt_mutex_attr, PTHREAD_MUTEX_RECURSIVE) != 0) + || (pthread_mutex_init(&dlt_mutex, &dlt_mutex_attr) != 0)) { dlt_user_init_state = INIT_UNITIALIZED; return DLT_RETURN_ERROR; } @@ -865,26 +830,21 @@ DltReturnValue dlt_init_common(void) /* header_size is used for resend buffer * so it won't include DltStorageHeader */ - header_size = sizeof(DltUserHeader) + sizeof(DltStandardHeader) + - sizeof(DltStandardHeaderExtra); + header_size = sizeof(DltUserHeader) + sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra); /* Use extended header for non verbose is enabled by default */ - dlt_user.use_extended_header_for_non_verbose = - DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE; + dlt_user.use_extended_header_for_non_verbose = DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE; /* Use extended header for non verbose is modified as per environment variable */ - env_disable_extended_header_for_nonverbose = - getenv(DLT_USER_ENV_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE); + env_disable_extended_header_for_nonverbose = getenv(DLT_USER_ENV_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE); if (env_disable_extended_header_for_nonverbose) { if (strcmp(env_disable_extended_header_for_nonverbose, "1") == 0) - dlt_user.use_extended_header_for_non_verbose = - DLT_USER_NO_USE_EXTENDED_HEADER_FOR_NONVERBOSE; + dlt_user.use_extended_header_for_non_verbose = DLT_USER_NO_USE_EXTENDED_HEADER_FOR_NONVERBOSE; } - if (dlt_user.use_extended_header_for_non_verbose == - DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE) - header_size += (uint32_t) sizeof(DltExtendedHeader); + if (dlt_user.use_extended_header_for_non_verbose == DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE) + header_size += (uint32_t)sizeof(DltExtendedHeader); /* With session id is enabled by default */ dlt_user.with_session_id = DLT_USER_WITH_SESSION_ID; @@ -932,9 +892,9 @@ DltReturnValue dlt_init_common(void) if (env_initial_log_level != NULL) { if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0) - dlt_vlog(LOG_WARNING, - "Unable to parse initial set of log-levels from environment! Env:\n%s\n", - getenv("DLT_INITIAL_LOG_LEVEL")); + dlt_vlog( + LOG_WARNING, "Unable to parse initial set of log-levels from environment! Env:\n%s\n", + getenv("DLT_INITIAL_LOG_LEVEL")); } /* Initialize LogLevel/TraceStatus field */ @@ -951,9 +911,7 @@ DltReturnValue dlt_init_common(void) buffer_min = (uint32_t)strtol(env_buffer_min, NULL, 10); if ((errno == EINVAL) || (errno == ERANGE)) { - dlt_vlog(LOG_ERR, - "Wrong value specified for %s. Using default\n", - DLT_USER_ENV_BUFFER_MIN_SIZE); + dlt_vlog(LOG_ERR, "Wrong value specified for %s. Using default\n", DLT_USER_ENV_BUFFER_MIN_SIZE); buffer_min = DLT_USER_RINGBUFFER_MIN_SIZE; } } @@ -962,9 +920,7 @@ DltReturnValue dlt_init_common(void) buffer_max = (uint32_t)strtol(env_buffer_max, NULL, 10); if ((errno == EINVAL) || (errno == ERANGE)) { - dlt_vlog(LOG_ERR, - "Wrong value specified for %s. Using default\n", - DLT_USER_ENV_BUFFER_MAX_SIZE); + dlt_vlog(LOG_ERR, "Wrong value specified for %s. Using default\n", DLT_USER_ENV_BUFFER_MAX_SIZE); buffer_max = DLT_USER_RINGBUFFER_MAX_SIZE; } } @@ -973,9 +929,7 @@ DltReturnValue dlt_init_common(void) buffer_step = (uint32_t)strtol(env_buffer_step, NULL, 10); if ((errno == EINVAL) || (errno == ERANGE)) { - dlt_vlog(LOG_ERR, - "Wrong value specified for %s. Using default\n", - DLT_USER_ENV_BUFFER_STEP_SIZE); + dlt_vlog(LOG_ERR, "Wrong value specified for %s. Using default\n", DLT_USER_ENV_BUFFER_STEP_SIZE); buffer_step = DLT_USER_RINGBUFFER_STEP_SIZE; } } @@ -989,14 +943,10 @@ DltReturnValue dlt_init_common(void) if (buffer_max_configured > DLT_LOG_MSG_BUF_MAX_SIZE) { dlt_user.log_buf_len = DLT_LOG_MSG_BUF_MAX_SIZE; - dlt_vlog(LOG_WARNING, - "Configured size exceeds maximum allowed size,restricting to max [65535 bytes]\n"); - } - else { - dlt_user.log_buf_len = (uint16_t) buffer_max_configured; - dlt_vlog(LOG_INFO, - "Configured buffer size to [%u bytes]\n", - buffer_max_configured); + dlt_vlog(LOG_WARNING, "Configured size exceeds maximum allowed size,restricting to max [65535 bytes]\n"); + } else { + dlt_user.log_buf_len = (uint16_t)buffer_max_configured; + dlt_vlog(LOG_INFO, "Configured buffer size to [%u bytes]\n", buffer_max_configured); } } @@ -1017,17 +967,14 @@ DltReturnValue dlt_init_common(void) dlt_user.disable_injection_msg = 1; } - if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer), - buffer_min, - buffer_max, - buffer_step) == DLT_RETURN_ERROR) { + if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer), buffer_min, buffer_max, buffer_step) == DLT_RETURN_ERROR) { dlt_user_init_state = INIT_UNITIALIZED; dlt_mutex_unlock(); return DLT_RETURN_ERROR; } dlt_mutex_unlock(); - signal(SIGPIPE, SIG_IGN); /* ignore pipe signals */ + signal(SIGPIPE, SIG_IGN); /* ignore pipe signals */ if (atexit_registered == 0) { atexit_registered = 1; @@ -1052,7 +999,9 @@ void dlt_user_atexit_handler(void) return; if (!DLT_USER_INITIALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); /* close file */ dlt_log_free(); return; @@ -1079,7 +1028,6 @@ void dlt_user_atexit_handler(void) int dlt_user_atexit_blow_out_user_buffer(void) { - int count, ret; struct timespec ts; @@ -1098,10 +1046,8 @@ int dlt_user_atexit_blow_out_user_buffer(void) if ((dlt_user.dlt_log_handle != -1) && (dlt_user.overflow_counter)) { if (dlt_user_log_send_overflow() == 0) { - dlt_vnlog(LOG_WARNING, - DLT_USER_BUFFER_LENGTH, - "%u messages discarded!\n", - dlt_user.overflow_counter); + dlt_vnlog( + LOG_WARNING, DLT_USER_BUFFER_LENGTH, "%u messages discarded!\n", dlt_user.overflow_counter); dlt_user.overflow_counter = 0; } } @@ -1132,7 +1078,7 @@ int dlt_user_atexit_blow_out_user_buffer(void) return count; } -static void dlt_user_free_buffer(unsigned char **buffer) +static void dlt_user_free_buffer(unsigned char** buffer) { if (*buffer) { free(*buffer); @@ -1194,8 +1140,7 @@ DltReturnValue dlt_free(void) if (ret < 0) { dlt_vlog(LOG_WARNING, "%s: shutdown failed: %s\n", __func__, strerror(errno)); - } - else { + } else { ssize_t bytes_read = 0; int prev_errno = 0; struct pollfd nfd[1]; @@ -1209,29 +1154,28 @@ DltReturnValue dlt_free(void) * continue to close socket anyway. * */ if (ret < 0) { - dlt_vlog(LOG_WARNING, "[%s] Failed to poll with error [%s]\n", - __func__, strerror(errno)); + dlt_vlog(LOG_WARNING, "[%s] Failed to poll with error [%s]\n", __func__, strerror(errno)); break; - } - else if (ret == 0) { + } else if (ret == 0) { dlt_vlog(LOG_DEBUG, "[%s] Polling timeout\n", __func__); break; - } - else { + } else { /* It could take some time to get the socket is shutdown * So it means there could be some data available to read. * Try to consume the data and poll the socket again. * If read fails, time to close the socket then. */ - dlt_vlog(LOG_DEBUG, "[%s] polling returns [%d] with revent [0x%x]." - "There are something to read\n", __func__, ret, (unsigned int)nfd[0].revents); + dlt_vlog( + LOG_DEBUG, + "[%s] polling returns [%d] with revent [0x%x]." + "There are something to read\n", + __func__, ret, (unsigned int)nfd[0].revents); bytes_read = read(dlt_user.dlt_log_handle, dlt_user.resend_buffer, dlt_user.log_buf_len); prev_errno = errno; if (bytes_read < 0) { - dlt_vlog(LOG_WARNING, "[%s] Failed to read with error [%s]\n", - __func__, strerror(prev_errno)); + dlt_vlog(LOG_WARNING, "[%s] Failed to read with error [%s]\n", __func__, strerror(prev_errno)); if ((prev_errno == EAGAIN) || (EWOULDBLOCK != EAGAIN && prev_errno == EWOULDBLOCK)) continue; @@ -1239,12 +1183,12 @@ DltReturnValue dlt_free(void) break; } if (bytes_read >= 0) { - dlt_vlog(LOG_DEBUG, "%s - %d: %d bytes read from resend buffer\n", - __func__, __LINE__, (int)bytes_read); + dlt_vlog( + LOG_DEBUG, "%s - %d: %d bytes read from resend buffer\n", __func__, __LINE__, + (int)bytes_read); if (!bytes_read) break; - dlt_vlog(LOG_NOTICE, "[%s] data is still readable... [%zd] bytes read\n", - __func__, bytes_read); + dlt_vlog(LOG_NOTICE, "[%s] data is still readable... [%zd] bytes read\n", __func__, bytes_read); } } } @@ -1290,7 +1234,7 @@ DltReturnValue dlt_free(void) if (dlt_user.dlt_ll_ts) { for (i = 0; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { if (dlt_user.dlt_ll_ts[i].context_description != NULL) { - free (dlt_user.dlt_ll_ts[i].context_description); + free(dlt_user.dlt_ll_ts[i].context_description); dlt_user.dlt_ll_ts[i].context_description = NULL; } @@ -1334,8 +1278,7 @@ DltReturnValue dlt_free(void) if (dlt_user.dlt_segmented_queue_read_handle > 0) (void)mq_close(dlt_user.dlt_segmented_queue_read_handle); - if ((dlt_user.dlt_segmented_queue_write_handle > 0) || - (dlt_user.dlt_segmented_queue_read_handle > 0)) + if ((dlt_user.dlt_segmented_queue_write_handle > 0) || (dlt_user.dlt_segmented_queue_read_handle > 0)) (void)mq_unlink(queue_name); dlt_user.dlt_segmented_queue_write_handle = DLT_FD_INIT; @@ -1362,12 +1305,12 @@ DltReturnValue dlt_free(void) return DLT_RETURN_OK; } -DltReturnValue dlt_check_library_version(const char *user_major_version, const char *user_minor_version) +DltReturnValue dlt_check_library_version(const char* user_major_version, const char* user_minor_version) { return dlt_user_check_library_version(user_major_version, user_minor_version); } -DltReturnValue dlt_register_app(const char *apid, const char *description) +DltReturnValue dlt_register_app(const char* apid, const char* description) { DltReturnValue ret = DLT_RETURN_OK; @@ -1390,25 +1333,15 @@ DltReturnValue dlt_register_app(const char *apid, const char *description) if (apid[1] == 0) { if (apid[0] == dlt_user.appID[0]) return DLT_RETURN_OK; - } - else if (apid[2] == 0) - { - if ((apid[0] == dlt_user.appID[0]) && - (apid[1] == dlt_user.appID[1])) + } else if (apid[2] == 0) { + if ((apid[0] == dlt_user.appID[0]) && (apid[1] == dlt_user.appID[1])) return DLT_RETURN_OK; - } - else if (apid[3] == 0) - { - if ((apid[0] == dlt_user.appID[0]) && - (apid[1] == dlt_user.appID[1]) && - (apid[2] == dlt_user.appID[2])) + } else if (apid[3] == 0) { + if ((apid[0] == dlt_user.appID[0]) && (apid[1] == dlt_user.appID[1]) && (apid[2] == dlt_user.appID[2])) return DLT_RETURN_OK; - } - else if ((apid[0] == dlt_user.appID[0]) && - (apid[1] == dlt_user.appID[1]) && - (apid[2] == dlt_user.appID[2]) && - (apid[3] == dlt_user.appID[3])) - { + } else if ( + (apid[0] == dlt_user.appID[0]) && (apid[1] == dlt_user.appID[1]) && (apid[2] == dlt_user.appID[2]) + && (apid[3] == dlt_user.appID[3])) { return DLT_RETURN_OK; } @@ -1440,12 +1373,10 @@ DltReturnValue dlt_register_app(const char *apid, const char *description) pthread_rwlock_wrlock(&trace_load_rw_lock); strncpy(trace_load_settings[0].apid, dlt_user.appID, DLT_ID_SIZE); pthread_rwlock_unlock(&trace_load_rw_lock); - if (!trace_load_context.contextID[0]) - { + if (!trace_load_context.contextID[0]) { // Register Special Context ID for output DLT library internal message ret = dlt_register_context(&trace_load_context, DLT_TRACE_LOAD_CONTEXT_ID, "DLT user library internal context"); - if (ret < DLT_RETURN_OK) - { + if (ret < DLT_RETURN_OK) { return ret; } } @@ -1459,7 +1390,7 @@ DltReturnValue dlt_register_app(const char *apid, const char *description) return ret; } -DltReturnValue dlt_register_app_v2(const char *apid, const char *description) +DltReturnValue dlt_register_app_v2(const char* apid, const char* description) { DltReturnValue ret = DLT_RETURN_OK; /* forbid dlt usage in child after fork */ @@ -1527,7 +1458,7 @@ DltReturnValue dlt_register_app_v2(const char *apid, const char *description) return ret; } -DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char *description) +DltReturnValue dlt_register_context(DltContext* handle, const char* contextid, const char* description) { /* check nullpointer */ if (handle == NULL) @@ -1547,14 +1478,11 @@ DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, c if ((contextid == NULL) || (contextid[0] == '\0')) return DLT_RETURN_WRONG_PARAMETER; - return dlt_register_context_ll_ts(handle, - contextid, - description, - DLT_USER_LOG_LEVEL_NOT_SET, - DLT_USER_TRACE_STATUS_NOT_SET); + return dlt_register_context_ll_ts( + handle, contextid, description, DLT_USER_LOG_LEVEL_NOT_SET, DLT_USER_TRACE_STATUS_NOT_SET); } -DltReturnValue dlt_register_context_v2(DltContext *handle, const char *contextid, const char *description) +DltReturnValue dlt_register_context_v2(DltContext* handle, const char* contextid, const char* description) { /* check nullpointer */ if (handle == NULL) @@ -1579,21 +1507,13 @@ DltReturnValue dlt_register_context_v2(DltContext *handle, const char *contextid return DLT_RETURN_WRONG_PARAMETER; } - return dlt_register_context_ll_ts_v2(handle, - contextid, - description, - DLT_USER_LOG_LEVEL_NOT_SET, - DLT_USER_TRACE_STATUS_NOT_SET); + return dlt_register_context_ll_ts_v2( + handle, contextid, description, DLT_USER_LOG_LEVEL_NOT_SET, DLT_USER_TRACE_STATUS_NOT_SET); } -DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, - const char *contextid, - const char *description, - int loglevel, - int tracestatus, - void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], - uint8_t log_level, - uint8_t trace_status)) +DltReturnValue dlt_register_context_ll_ts_llccb( + DltContext* handle, const char* contextid, const char* description, int loglevel, int tracestatus, + void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status)) { DltContextData log; uint32_t i; @@ -1633,7 +1553,7 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, /* Allocate or expand context array */ if (dlt_user.dlt_ll_ts == NULL) { - dlt_user.dlt_ll_ts = (dlt_ll_ts_type *)malloc(sizeof(dlt_ll_ts_type) * DLT_USER_CONTEXT_ALLOC_SIZE); + dlt_user.dlt_ll_ts = (dlt_ll_ts_type*)malloc(sizeof(dlt_ll_ts_type) * DLT_USER_CONTEXT_ALLOC_SIZE); if (dlt_user.dlt_ll_ts == NULL) { dlt_mutex_unlock(); @@ -1660,21 +1580,17 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, dlt_user.dlt_ll_ts[i].nrcallbacks = 0; dlt_user.dlt_ll_ts[i].log_level_changed_callback = 0; } - } - else if ((dlt_user.dlt_ll_ts_num_entries % DLT_USER_CONTEXT_ALLOC_SIZE) == 0) - { + } else if ((dlt_user.dlt_ll_ts_num_entries % DLT_USER_CONTEXT_ALLOC_SIZE) == 0) { /* allocate memory in steps of DLT_USER_CONTEXT_ALLOC_SIZE, e.g. 500 */ - dlt_ll_ts_type *old_ll_ts; + dlt_ll_ts_type* old_ll_ts; uint32_t old_max_entries; old_ll_ts = dlt_user.dlt_ll_ts; old_max_entries = dlt_user.dlt_ll_ts_max_num_entries; - dlt_user.dlt_ll_ts_max_num_entries = ((dlt_user.dlt_ll_ts_num_entries - / DLT_USER_CONTEXT_ALLOC_SIZE) + 1) - * DLT_USER_CONTEXT_ALLOC_SIZE; - dlt_user.dlt_ll_ts = (dlt_ll_ts_type *)malloc(sizeof(dlt_ll_ts_type) * - dlt_user.dlt_ll_ts_max_num_entries); + dlt_user.dlt_ll_ts_max_num_entries = + ((dlt_user.dlt_ll_ts_num_entries / DLT_USER_CONTEXT_ALLOC_SIZE) + 1) * DLT_USER_CONTEXT_ALLOC_SIZE; + dlt_user.dlt_ll_ts = (dlt_ll_ts_type*)malloc(sizeof(dlt_ll_ts_type) * dlt_user.dlt_ll_ts_max_num_entries); if (dlt_user.dlt_ll_ts == NULL) { dlt_user.dlt_ll_ts = old_ll_ts; @@ -1707,7 +1623,7 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, } /* New context entry to be initialized */ - dlt_ll_ts_type *ctx_entry; + dlt_ll_ts_type* ctx_entry; ctx_entry = &dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries]; /* Store locally context id and context description */ @@ -1749,26 +1665,22 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, } /* check if the log level is set in the environement */ - envLogLevel = dlt_env_adjust_ll_from_env(&dlt_user.initial_ll_set, - dlt_user.appID, - contextid, - DLT_USER_LOG_LEVEL_NOT_SET); + envLogLevel = + dlt_env_adjust_ll_from_env(&dlt_user.initial_ll_set, dlt_user.appID, contextid, DLT_USER_LOG_LEVEL_NOT_SET); if (envLogLevel != DLT_USER_LOG_LEVEL_NOT_SET) { - ctx_entry->log_level = (int8_t) envLogLevel; + ctx_entry->log_level = (int8_t)envLogLevel; loglevel = envLogLevel; - } - else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET) - { - ctx_entry->log_level = (int8_t) loglevel; + } else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET) { + ctx_entry->log_level = (int8_t)loglevel; } if (tracestatus != DLT_USER_TRACE_STATUS_NOT_SET) - ctx_entry->trace_status = (int8_t) tracestatus; + ctx_entry->trace_status = (int8_t)tracestatus; /* Prepare transfer struct */ dlt_set_id(handle->contextID, contextid); - handle->log_level_pos = (int32_t) dlt_user.dlt_ll_ts_num_entries; + handle->log_level_pos = (int32_t)dlt_user.dlt_ll_ts_num_entries; handle->log_level_ptr = ctx_entry->log_level_ptr; handle->trace_status_ptr = ctx_entry->trace_status_ptr; @@ -1776,7 +1688,7 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, log.context_description = ctx_entry->context_description; *(ctx_entry->log_level_ptr) = ctx_entry->log_level; - *(ctx_entry->trace_status_ptr) = ctx_entry->trace_status = (int8_t) tracestatus; + *(ctx_entry->trace_status_ptr) = ctx_entry->trace_status = (int8_t)tracestatus; ctx_entry->log_level_changed_callback = dlt_log_level_changed_callback; log.log_level = loglevel; @@ -1793,11 +1705,8 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, * the same time. */ pthread_rwlock_rdlock(&trace_load_rw_lock); - DltTraceLoadSettings *settings = dlt_find_runtime_trace_load_settings( - trace_load_settings, - trace_load_settings_count, - dlt_user.appID, - ctx_entry->contextID); + DltTraceLoadSettings* settings = dlt_find_runtime_trace_load_settings( + trace_load_settings, trace_load_settings_count, dlt_user.appID, ctx_entry->contextID); pthread_rwlock_unlock(&trace_load_rw_lock); dlt_mutex_lock(); @@ -1809,27 +1718,15 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, return dlt_user_log_send_register_context(&log); } -DltReturnValue dlt_register_context_ll_ts(DltContext *handle, - const char *contextid, - const char *description, - int loglevel, - int tracestatus) +DltReturnValue dlt_register_context_ll_ts( + DltContext* handle, const char* contextid, const char* description, int loglevel, int tracestatus) { - return dlt_register_context_ll_ts_llccb(handle, - contextid, - description, - loglevel, - tracestatus, - NULL); - + return dlt_register_context_ll_ts_llccb(handle, contextid, description, loglevel, tracestatus, NULL); } -DltReturnValue dlt_register_context_llccb(DltContext *handle, - const char *contextid, - const char *description, - void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], - uint8_t log_level, - uint8_t trace_status)) +DltReturnValue dlt_register_context_llccb( + DltContext* handle, const char* contextid, const char* description, + void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status)) { if ((handle == NULL) || (contextid == NULL) || (contextid[0] == '\0')) return DLT_RETURN_WRONG_PARAMETER; @@ -1845,22 +1742,14 @@ DltReturnValue dlt_register_context_llccb(DltContext *handle, } } - return dlt_register_context_ll_ts_llccb(handle, - contextid, - description, - DLT_USER_LOG_LEVEL_NOT_SET, - DLT_USER_TRACE_STATUS_NOT_SET, - dlt_log_level_changed_callback); + return dlt_register_context_ll_ts_llccb( + handle, contextid, description, DLT_USER_LOG_LEVEL_NOT_SET, DLT_USER_TRACE_STATUS_NOT_SET, + dlt_log_level_changed_callback); } -DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, - const char *contextid, - const char *description, - int loglevel, - int tracestatus, - void (*dlt_log_level_changed_callback_v2)(char *context_id, - uint8_t log_level, - uint8_t trace_status)) +DltReturnValue dlt_register_context_ll_ts_llccb_v2( + DltContext* handle, const char* contextid, const char* description, int loglevel, int tracestatus, + void (*dlt_log_level_changed_callback_v2)(char* context_id, uint8_t log_level, uint8_t trace_status)) { DltContextData log; uint32_t i; @@ -1906,7 +1795,7 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, /* Allocate or expand context array */ if (dlt_user.dlt_ll_ts == NULL) { - dlt_user.dlt_ll_ts = (dlt_ll_ts_type *)malloc(sizeof(dlt_ll_ts_type) * DLT_USER_CONTEXT_ALLOC_SIZE); + dlt_user.dlt_ll_ts = (dlt_ll_ts_type*)malloc(sizeof(dlt_ll_ts_type) * DLT_USER_CONTEXT_ALLOC_SIZE); if (dlt_user.dlt_ll_ts == NULL) { dlt_mutex_unlock(); @@ -1917,7 +1806,6 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, /* Initialize new entries */ for (i = 0; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { - /* At startup, logging and tracing is locally enabled */ /* the correct log level/status is set after received from daemon */ memset(dlt_user.dlt_ll_ts[i].contextID2, 0, DLT_V2_ID_SIZE); @@ -1934,21 +1822,17 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, dlt_user.dlt_ll_ts[i].nrcallbacks = 0; dlt_user.dlt_ll_ts[i].log_level_changed_callback_v2 = 0; } - } - else if ((dlt_user.dlt_ll_ts_num_entries % DLT_USER_CONTEXT_ALLOC_SIZE) == 0) - { + } else if ((dlt_user.dlt_ll_ts_num_entries % DLT_USER_CONTEXT_ALLOC_SIZE) == 0) { /* allocate memory in steps of DLT_USER_CONTEXT_ALLOC_SIZE, e.g. 500 */ - dlt_ll_ts_type *old_ll_ts; + dlt_ll_ts_type* old_ll_ts; uint32_t old_max_entries; old_ll_ts = dlt_user.dlt_ll_ts; old_max_entries = dlt_user.dlt_ll_ts_max_num_entries; - dlt_user.dlt_ll_ts_max_num_entries = ((dlt_user.dlt_ll_ts_num_entries - / DLT_USER_CONTEXT_ALLOC_SIZE) + 1) - * DLT_USER_CONTEXT_ALLOC_SIZE; - dlt_user.dlt_ll_ts = (dlt_ll_ts_type *)malloc(sizeof(dlt_ll_ts_type) * - dlt_user.dlt_ll_ts_max_num_entries); + dlt_user.dlt_ll_ts_max_num_entries = + ((dlt_user.dlt_ll_ts_num_entries / DLT_USER_CONTEXT_ALLOC_SIZE) + 1) * DLT_USER_CONTEXT_ALLOC_SIZE; + dlt_user.dlt_ll_ts = (dlt_ll_ts_type*)malloc(sizeof(dlt_ll_ts_type) * dlt_user.dlt_ll_ts_max_num_entries); if (dlt_user.dlt_ll_ts == NULL) { dlt_user.dlt_ll_ts = old_ll_ts; @@ -1962,7 +1846,6 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, /* Initialize new entries */ for (i = dlt_user.dlt_ll_ts_num_entries; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { - /* At startup, logging and tracing is locally enabled */ /* the correct log level/status is set after received from daemon */ memset(dlt_user.dlt_ll_ts[i].contextID2, 0, DLT_V2_ID_SIZE); @@ -1982,7 +1865,7 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, } /* New context entry to be initialized */ - dlt_ll_ts_type *ctx_entry; + dlt_ll_ts_type* ctx_entry; ctx_entry = &dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries]; /* Store locally context id and context description */ @@ -2031,30 +1914,25 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, } /* check if the log level is set in the environement */ - envLogLevel = dlt_env_adjust_ll_from_env_v2(&dlt_user.initial_ll_set, - dlt_user.appID2, - dlt_user.appID2len, - contextid, - contextidlen, - DLT_USER_LOG_LEVEL_NOT_SET); + envLogLevel = dlt_env_adjust_ll_from_env_v2( + &dlt_user.initial_ll_set, dlt_user.appID2, dlt_user.appID2len, contextid, contextidlen, + DLT_USER_LOG_LEVEL_NOT_SET); if (envLogLevel != DLT_USER_LOG_LEVEL_NOT_SET) { - ctx_entry->log_level = (int8_t) envLogLevel; + ctx_entry->log_level = (int8_t)envLogLevel; loglevel = envLogLevel; - } - else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET) - { - ctx_entry->log_level = (int8_t) loglevel; + } else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET) { + ctx_entry->log_level = (int8_t)loglevel; } if (tracestatus != DLT_USER_TRACE_STATUS_NOT_SET) - ctx_entry->trace_status = (int8_t) tracestatus; + ctx_entry->trace_status = (int8_t)tracestatus; /* Prepare transfer struct */ handle->contextID2 = ctx_entry->contextID2; dlt_set_id_v2(handle->contextID2, contextid, contextidlen); handle->contextID2len = (uint8_t)contextidlen; - handle->log_level_pos = (int32_t) dlt_user.dlt_ll_ts_num_entries; + handle->log_level_pos = (int32_t)dlt_user.dlt_ll_ts_num_entries; handle->log_level_ptr = ctx_entry->log_level_ptr; handle->trace_status_ptr = ctx_entry->trace_status_ptr; @@ -2062,7 +1940,7 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, log.context_description = ctx_entry->context_description; *(ctx_entry->log_level_ptr) = ctx_entry->log_level; - *(ctx_entry->trace_status_ptr) = ctx_entry->trace_status = (int8_t) tracestatus; + *(ctx_entry->trace_status_ptr) = ctx_entry->trace_status = (int8_t)tracestatus; ctx_entry->log_level_changed_callback_v2 = dlt_log_level_changed_callback_v2; log.log_level = loglevel; @@ -2075,27 +1953,15 @@ DltReturnValue dlt_register_context_ll_ts_llccb_v2(DltContext *handle, return dlt_user_log_send_register_context_v2(&log); } -DltReturnValue dlt_register_context_ll_ts_v2(DltContext *handle, - const char *contextid, - const char *description, - int loglevel, - int tracestatus) +DltReturnValue dlt_register_context_ll_ts_v2( + DltContext* handle, const char* contextid, const char* description, int loglevel, int tracestatus) { - return dlt_register_context_ll_ts_llccb_v2(handle, - contextid, - description, - loglevel, - tracestatus, - NULL); - + return dlt_register_context_ll_ts_llccb_v2(handle, contextid, description, loglevel, tracestatus, NULL); } -DltReturnValue dlt_register_context_llccb_v2(DltContext *handle, - const char *contextid, - const char *description, - void (*dlt_log_level_changed_callback_v2)(char *context_id, - uint8_t log_level, - uint8_t trace_status)) +DltReturnValue dlt_register_context_llccb_v2( + DltContext* handle, const char* contextid, const char* description, + void (*dlt_log_level_changed_callback_v2)(char* context_id, uint8_t log_level, uint8_t trace_status)) { size_t contextidlen_sz = strlen(contextid); if ((handle == NULL) || (contextid == NULL) || (contextidlen_sz == 0) || (contextidlen_sz > INT8_MAX)) @@ -2112,12 +1978,9 @@ DltReturnValue dlt_register_context_llccb_v2(DltContext *handle, } } - return dlt_register_context_ll_ts_llccb_v2(handle, - contextid, - description, - DLT_USER_LOG_LEVEL_NOT_SET, - DLT_USER_TRACE_STATUS_NOT_SET, - dlt_log_level_changed_callback_v2); + return dlt_register_context_ll_ts_llccb_v2( + handle, contextid, description, DLT_USER_LOG_LEVEL_NOT_SET, DLT_USER_TRACE_STATUS_NOT_SET, + dlt_log_level_changed_callback_v2); } /* If force_sending_messages is set to true, do not clean appIDs when there are @@ -2132,7 +1995,9 @@ DltReturnValue dlt_unregister_app_util(bool force_sending_messages) } if (!DLT_USER_INITIALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } @@ -2143,8 +2008,7 @@ DltReturnValue dlt_unregister_app_util(bool force_sending_messages) int count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); - if (!force_sending_messages || - (force_sending_messages && (count == 0))) { + if (!force_sending_messages || (force_sending_messages && (count == 0))) { /* Clear and free local stored application information */ dlt_set_id(dlt_user.appID, ""); @@ -2172,7 +2036,9 @@ DltReturnValue dlt_unregister_app_util_v2(bool force_sending_messages) } if (!DLT_USER_INITIALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } @@ -2183,8 +2049,7 @@ DltReturnValue dlt_unregister_app_util_v2(bool force_sending_messages) int count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); - if (!force_sending_messages || - (force_sending_messages && (count == 0))) { + if (!force_sending_messages || (force_sending_messages && (count == 0))) { /* Clear and free local stored application information */ memset(dlt_user.appID2, 0, DLT_V2_ID_SIZE); dlt_user.appID2len = 0; @@ -2220,7 +2085,9 @@ DltReturnValue dlt_unregister_app_flush_buffered_logs(void) return DLT_RETURN_ERROR; if (!DLT_USER_INITIALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } @@ -2233,7 +2100,7 @@ DltReturnValue dlt_unregister_app_flush_buffered_logs(void) return dlt_unregister_app_util(true); } -DltReturnValue dlt_unregister_context(DltContext *handle) +DltReturnValue dlt_unregister_context(DltContext* handle) { DltContextData log; DltReturnValue ret = DLT_RETURN_OK; @@ -2293,7 +2160,7 @@ DltReturnValue dlt_unregister_context(DltContext *handle) return ret; } -DltReturnValue dlt_unregister_context_v2(DltContext *handle) +DltReturnValue dlt_unregister_context_v2(DltContext* handle) { DltContextData log; DltReturnValue ret = DLT_RETURN_OK; @@ -2401,11 +2268,11 @@ DltReturnValue dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTrac dlt_mutex_unlock(); /* Inform DLT Daemon about update */ - if(dlt_user.appID[0] != '\0'){ + if (dlt_user.appID[0] != '\0') { return dlt_send_app_ll_ts_limit(dlt_user.appID, loglevel, tracestatus); - }else if (dlt_user.appID2len != 0){ + } else if (dlt_user.appID2len != 0) { return dlt_send_app_ll_ts_limit_v2(dlt_user.appID2, loglevel, tracestatus); - }else { + } else { return DLT_RETURN_ERROR; } } @@ -2477,10 +2344,8 @@ int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds) /* ********************************************************************************************* */ -DltReturnValue dlt_user_log_write_start_init(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - bool is_verbose) +DltReturnValue dlt_user_log_write_start_init( + DltContext* handle, DltContextData* log, DltLogLevelType loglevel, bool is_verbose) { DLT_LOG_FATAL_RESET_TRAP(loglevel); @@ -2497,30 +2362,22 @@ DltReturnValue dlt_user_log_write_start_init(DltContext *handle, return DLT_RETURN_TRUE; } -static DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - uint32_t messageid, - bool is_verbose); +static DltReturnValue dlt_user_log_write_start_internal( + DltContext* handle, DltContextData* log, DltLogLevelType loglevel, uint32_t messageid, bool is_verbose); -inline DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel) +inline DltReturnValue dlt_user_log_write_start(DltContext* handle, DltContextData* log, DltLogLevelType loglevel) { return dlt_user_log_write_start_internal(handle, log, loglevel, DLT_USER_DEFAULT_MSGID, true); } -DltReturnValue dlt_user_log_write_start_id(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - uint32_t messageid) +DltReturnValue dlt_user_log_write_start_id( + DltContext* handle, DltContextData* log, DltLogLevelType loglevel, uint32_t messageid) { return dlt_user_log_write_start_internal(handle, log, loglevel, messageid, false); } -DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - uint32_t messageid, - bool is_verbose) +DltReturnValue dlt_user_log_write_start_internal( + DltContext* handle, DltContextData* log, DltLogLevelType loglevel, uint32_t messageid, bool is_verbose) { int ret = DLT_RETURN_TRUE; @@ -2545,22 +2402,17 @@ DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, ret = dlt_user_log_write_start_init(handle, log, loglevel, is_verbose); if (ret == DLT_RETURN_TRUE) { /* initialize values */ - if ((NULL != log->buffer)) - { + if ((NULL != log->buffer)) { free(log->buffer); log->buffer = NULL; - } - else - { + } else { log->buffer = calloc(dlt_user.log_buf_len, sizeof(unsigned char)); } if (log->buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; - } - else - { + } else { /* In non-verbose mode, insert message id */ if (!is_verbose_mode(dlt_user.verbose_mode, log)) { if ((sizeof(uint32_t)) > dlt_user.log_buf_len) @@ -2571,7 +2423,7 @@ DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, log->size = sizeof(uint32_t); /* as the message id is part of each message in non-verbose mode, - * it doesn't increment the argument counter in extended header (if used) */ + * it doesn't increment the argument counter in extended header (if used) */ log->msid = messageid; /* TODO: For non verbose mode in Version 2, following should be uncommented @@ -2584,12 +2436,8 @@ DltReturnValue dlt_user_log_write_start_internal(DltContext *handle, return ret; } -DltReturnValue dlt_user_log_write_start_w_given_buffer(DltContext *handle, - DltContextData *log, - DltLogLevelType loglevel, - char *buffer, - size_t size, - int32_t args_num) +DltReturnValue dlt_user_log_write_start_w_given_buffer( + DltContext* handle, DltContextData* log, DltLogLevelType loglevel, char* buffer, size_t size, int32_t args_num) { int ret = DLT_RETURN_TRUE; @@ -2611,15 +2459,15 @@ DltReturnValue dlt_user_log_write_start_w_given_buffer(DltContext *handle, ret = dlt_user_log_write_start_init(handle, log, loglevel, true); if (ret == DLT_RETURN_TRUE) { - log->buffer = (unsigned char *)buffer; + log->buffer = (unsigned char*)buffer; log->size = (int32_t)size; log->args_num = args_num; } return ret; - } +} -DltReturnValue dlt_user_log_write_finish(DltContextData *log) +DltReturnValue dlt_user_log_write_finish(DltContextData* log) { int ret = DLT_RETURN_ERROR; @@ -2633,7 +2481,7 @@ DltReturnValue dlt_user_log_write_finish(DltContextData *log) return ret; } -DltReturnValue dlt_user_log_write_finish_v2(DltContextData *log) +DltReturnValue dlt_user_log_write_finish_v2(DltContextData* log) { int ret = DLT_RETURN_ERROR; @@ -2646,7 +2494,7 @@ DltReturnValue dlt_user_log_write_finish_v2(DltContextData *log) return ret; } -DltReturnValue dlt_user_log_write_finish_w_given_buffer(DltContextData *log) +DltReturnValue dlt_user_log_write_finish_w_given_buffer(DltContextData* log) { int ret = DLT_RETURN_ERROR; @@ -2658,7 +2506,7 @@ DltReturnValue dlt_user_log_write_finish_w_given_buffer(DltContextData *log) return ret; } -DltReturnValue dlt_user_log_write_finish_w_given_buffer_v2(DltContextData *log) +DltReturnValue dlt_user_log_write_finish_w_given_buffer_v2(DltContextData* log) { int ret = DLT_RETURN_ERROR; @@ -2670,24 +2518,28 @@ DltReturnValue dlt_user_log_write_finish_w_given_buffer_v2(DltContextData *log) return ret; } -static DltReturnValue dlt_user_log_write_raw_internal(DltContextData *log, const void *data, uint16_t length, DltFormatType type, const char *name, bool with_var_info) +static DltReturnValue dlt_user_log_write_raw_internal( + DltContextData* log, const void* data, uint16_t length, DltFormatType type, const char* name, bool with_var_info) { /* check nullpointer */ if ((log == NULL) || ((data == NULL) && (length != 0))) return DLT_RETURN_WRONG_PARAMETER; - /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning + */ if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %u is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } if (!DLT_USER_INITIALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } - const uint16_t name_size = (name != NULL) ? (uint16_t)(strlen(name)+1) : 0; + const uint16_t name_size = (name != NULL) ? (uint16_t)(strlen(name) + 1) : 0; size_t needed_size = length + sizeof(uint16_t); if ((size_t)log->size + needed_size > dlt_user.log_buf_len) @@ -2699,7 +2551,7 @@ static DltReturnValue dlt_user_log_write_raw_internal(DltContextData *log, const needed_size += sizeof(uint32_t); // Type Info field if (with_var_info) { needed_size += sizeof(uint16_t); // length of name - needed_size += name_size; // the name itself + needed_size += name_size; // the name itself type_info |= DLT_TYPE_INFO_VARI; } @@ -2711,9 +2563,7 @@ static DltReturnValue dlt_user_log_write_raw_internal(DltContextData *log, const if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) { type_info |= DLT_SCOD_HEX; type_info += type; - } - else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) - { + } else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) { type_info |= DLT_SCOD_BIN; type_info += type - DLT_FORMAT_BIN8 + 1; } @@ -2751,34 +2601,38 @@ static DltReturnValue dlt_user_log_write_raw_internal(DltContextData *log, const return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length) +DltReturnValue dlt_user_log_write_raw(DltContextData* log, void* data, uint16_t length) { return dlt_user_log_write_raw_internal(log, data, length, DLT_FORMAT_DEFAULT, NULL, false); } -DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type) +DltReturnValue dlt_user_log_write_raw_formatted(DltContextData* log, void* data, uint16_t length, DltFormatType type) { return dlt_user_log_write_raw_internal(log, data, length, type, NULL, false); } -DltReturnValue dlt_user_log_write_raw_attr(DltContextData *log, const void *data, uint16_t length, const char *name) +DltReturnValue dlt_user_log_write_raw_attr(DltContextData* log, const void* data, uint16_t length, const char* name) { return dlt_user_log_write_raw_internal(log, data, length, DLT_FORMAT_DEFAULT, name, true); } -DltReturnValue dlt_user_log_write_raw_formatted_attr(DltContextData *log, const void *data, uint16_t length, DltFormatType type, const char *name) +DltReturnValue dlt_user_log_write_raw_formatted_attr( + DltContextData* log, const void* data, uint16_t length, DltFormatType type, const char* name) { return dlt_user_log_write_raw_internal(log, data, length, type, name, true); } // Generic implementation for all "simple" types, possibly with attributes -static DltReturnValue dlt_user_log_write_generic_attr(DltContextData *log, const void *datap, size_t datalen, uint32_t type_info, const VarInfo *varinfo) +static DltReturnValue dlt_user_log_write_generic_attr( + DltContextData* log, const void* datap, size_t datalen, uint32_t type_info, const VarInfo* varinfo) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; if (!DLT_USER_INITIALIZED_NOT_FREEING) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } @@ -2794,11 +2648,11 @@ static DltReturnValue dlt_user_log_write_generic_attr(DltContextData *log, const needed_size += sizeof(uint32_t); // Type Info field if (with_var_info) { - name_size = (varinfo->name != NULL) ? (uint16_t)(strlen(varinfo->name)+1) : 0; - unit_size = (varinfo->unit != NULL) ? (uint16_t)(strlen(varinfo->unit)+1) : 0; + name_size = (varinfo->name != NULL) ? (uint16_t)(strlen(varinfo->name) + 1) : 0; + unit_size = (varinfo->unit != NULL) ? (uint16_t)(strlen(varinfo->unit) + 1) : 0; - needed_size += sizeof(uint16_t); // length of name - needed_size += name_size; // the name itself + needed_size += sizeof(uint16_t); // length of name + needed_size += name_size; // the name itself if (varinfo->with_unit) { needed_size += sizeof(uint16_t); // length of unit needed_size += unit_size; // the unit itself @@ -2846,19 +2700,23 @@ static DltReturnValue dlt_user_log_write_generic_attr(DltContextData *log, const } // Generic implementation for all "simple" types -static DltReturnValue dlt_user_log_write_generic_formatted(DltContextData *log, const void *datap, size_t datalen, uint32_t type_info, DltFormatType type) +static DltReturnValue dlt_user_log_write_generic_formatted( + DltContextData* log, const void* datap, size_t datalen, uint32_t type_info, DltFormatType type) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning + */ if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } if (!DLT_USER_INITIALIZED) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } @@ -2889,7 +2747,7 @@ static DltReturnValue dlt_user_log_write_generic_formatted(DltContextData *log, return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data) +DltReturnValue dlt_user_log_write_float32(DltContextData* log, float32_t data) { if (sizeof(float32_t) != 4) return DLT_RETURN_ERROR; @@ -2898,7 +2756,7 @@ DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data) return dlt_user_log_write_generic_attr(log, &data, sizeof(float32_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_float64(DltContextData *log, float64_t data) +DltReturnValue dlt_user_log_write_float64(DltContextData* log, float64_t data) { if (sizeof(float64_t) != 8) return DLT_RETURN_ERROR; @@ -2907,59 +2765,56 @@ DltReturnValue dlt_user_log_write_float64(DltContextData *log, float64_t data) return dlt_user_log_write_generic_attr(log, &data, sizeof(float64_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_float32_attr(DltContextData* log, float32_t data, const char* name, const char* unit) { if (sizeof(float32_t) != 4) return DLT_RETURN_ERROR; uint32_t type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(float32_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_float64_attr(DltContextData *log, float64_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_float64_attr(DltContextData* log, float64_t data, const char* name, const char* unit) { if (sizeof(float64_t) != 8) return DLT_RETURN_ERROR; uint32_t type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(float64_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data) +DltReturnValue dlt_user_log_write_uint(DltContextData* log, unsigned int data) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; if (!DLT_USER_INITIALIZED_NOT_FREEING) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } switch (sizeof(unsigned int)) { - case 1: - { + case 1: { return dlt_user_log_write_uint8(log, (uint8_t)data); break; } - case 2: - { + case 2: { return dlt_user_log_write_uint16(log, (uint16_t)data); break; } - case 4: - { + case 4: { return dlt_user_log_write_uint32(log, (uint32_t)data); break; } - case 8: - { + case 8: { return dlt_user_log_write_uint64(log, (uint64_t)data); break; } - default: - { + default: { return DLT_RETURN_ERROR; break; } @@ -2968,31 +2823,31 @@ DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data) return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data) +DltReturnValue dlt_user_log_write_uint8(DltContextData* log, uint8_t data) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data) +DltReturnValue dlt_user_log_write_uint16(DltContextData* log, uint16_t data) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint16_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data) +DltReturnValue dlt_user_log_write_uint32(DltContextData* log, uint32_t data) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint32_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data) +DltReturnValue dlt_user_log_write_uint64(DltContextData* log, uint64_t data) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint64_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_uint_attr(DltContextData* log, unsigned int data, const char* name, const char* unit) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3003,28 +2858,23 @@ DltReturnValue dlt_user_log_write_uint_attr(DltContextData *log, unsigned int da } switch (sizeof(unsigned int)) { - case 1: - { + case 1: { return dlt_user_log_write_uint8_attr(log, (uint8_t)data, name, unit); break; } - case 2: - { + case 2: { return dlt_user_log_write_uint16_attr(log, (uint16_t)data, name, unit); break; } - case 4: - { + case 4: { return dlt_user_log_write_uint32_attr(log, (uint32_t)data, name, unit); break; } - case 8: - { + case 8: { return dlt_user_log_write_uint64_attr(log, (uint64_t)data, name, unit); break; } - default: - { + default: { return DLT_RETURN_ERROR; break; } @@ -3033,59 +2883,59 @@ DltReturnValue dlt_user_log_write_uint_attr(DltContextData *log, unsigned int da return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_uint8_attr(DltContextData* log, uint8_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_uint16_attr(DltContextData* log, uint16_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint16_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_uint32_attr(DltContextData* log, uint32_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint32_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_uint64_attr(DltContextData* log, uint64_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint64_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type) +DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData* log, uint8_t data, DltFormatType type) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint8_t), type_info, type); } -DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type) +DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData* log, uint16_t data, DltFormatType type) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint16_t), type_info, type); } -DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type) +DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData* log, uint32_t data, DltFormatType type) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint32_t), type_info, type); } -DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type) +DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData* log, uint64_t data, DltFormatType type) { uint32_t type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; return dlt_user_log_write_generic_formatted(log, &data, sizeof(uint64_t), type_info, type); } -DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data) +DltReturnValue dlt_user_log_write_ptr(DltContextData* log, void* data) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3095,57 +2945,49 @@ DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data) return DLT_RETURN_ERROR; } - switch (sizeof(void *)) { + switch (sizeof(void*)) { case 4: - return dlt_user_log_write_uint32_formatted(log, - (uint32_t)(uintptr_t)data, - DLT_FORMAT_HEX32); + return dlt_user_log_write_uint32_formatted(log, (uint32_t)(uintptr_t)data, DLT_FORMAT_HEX32); break; case 8: - return dlt_user_log_write_uint64_formatted(log, - (uintptr_t) data, - DLT_FORMAT_HEX64); + return dlt_user_log_write_uint64_formatted(log, (uintptr_t)data, DLT_FORMAT_HEX64); break; - default: - ; /* skip */ + default:; /* skip */ } return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_int(DltContextData *log, int data) +DltReturnValue dlt_user_log_write_int(DltContextData* log, int data) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; if (!DLT_USER_INITIALIZED_NOT_FREEING) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } switch (sizeof(int)) { - case 1: - { + case 1: { return dlt_user_log_write_int8(log, (int8_t)data); break; } - case 2: - { + case 2: { return dlt_user_log_write_int16(log, (int16_t)data); break; } - case 4: - { + case 4: { return dlt_user_log_write_int32(log, (int32_t)data); break; } - case 8: - { + case 8: { return dlt_user_log_write_int64(log, (int64_t)data); break; } - default: - { + default: { return DLT_RETURN_ERROR; break; } @@ -3154,31 +2996,31 @@ DltReturnValue dlt_user_log_write_int(DltContextData *log, int data) return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data) +DltReturnValue dlt_user_log_write_int8(DltContextData* log, int8_t data) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(int8_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data) +DltReturnValue dlt_user_log_write_int16(DltContextData* log, int16_t data) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(int16_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data) +DltReturnValue dlt_user_log_write_int32(DltContextData* log, int32_t data) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(int32_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data) +DltReturnValue dlt_user_log_write_int64(DltContextData* log, int64_t data) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(int64_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_int_attr(DltContextData *log, int data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int_attr(DltContextData* log, int data, const char* name, const char* unit) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3189,28 +3031,23 @@ DltReturnValue dlt_user_log_write_int_attr(DltContextData *log, int data, const } switch (sizeof(int)) { - case 1: - { + case 1: { return dlt_user_log_write_int8_attr(log, (int8_t)data, name, unit); break; } - case 2: - { + case 2: { return dlt_user_log_write_int16_attr(log, (int16_t)data, name, unit); break; } - case 4: - { + case 4: { return dlt_user_log_write_int32_attr(log, (int32_t)data, name, unit); break; } - case 8: - { + case 8: { return dlt_user_log_write_int64_attr(log, (int64_t)data, name, unit); break; } - default: - { + default: { return DLT_RETURN_ERROR; break; } @@ -3219,148 +3056,163 @@ DltReturnValue dlt_user_log_write_int_attr(DltContextData *log, int data, const return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_int8_attr(DltContextData *log, int8_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int8_attr(DltContextData* log, int8_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(int8_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_int16_attr(DltContextData *log, int16_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int16_attr(DltContextData* log, int16_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(int16_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_int32_attr(DltContextData *log, int32_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int32_attr(DltContextData* log, int32_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(int32_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_int64_attr(DltContextData *log, int64_t data, const char *name, const char *unit) +DltReturnValue dlt_user_log_write_int64_attr(DltContextData* log, int64_t data, const char* name, const char* unit) { uint32_t type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; - const VarInfo var_info = { name, unit, true }; + const VarInfo var_info = {name, unit, true}; return dlt_user_log_write_generic_attr(log, &data, sizeof(int64_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data) +DltReturnValue dlt_user_log_write_bool(DltContextData* log, uint8_t data) { uint32_t type_info = DLT_TYPE_INFO_BOOL | DLT_TYLE_8BIT; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, NULL); } -DltReturnValue dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name) +DltReturnValue dlt_user_log_write_bool_attr(DltContextData* log, uint8_t data, const char* name) { uint32_t type_info = DLT_TYPE_INFO_BOOL | DLT_TYLE_8BIT; - const VarInfo var_info = { name, NULL, false }; + const VarInfo var_info = {name, NULL, false}; return dlt_user_log_write_generic_attr(log, &data, sizeof(uint8_t), type_info, &var_info); } -DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text) +DltReturnValue dlt_user_log_write_string(DltContextData* log, const char* text) { return dlt_user_log_write_string_utils_attr(log, text, ASCII_STRING, NULL, false); } -DltReturnValue dlt_user_log_write_string_attr(DltContextData *log, const char *text, const char *name) +DltReturnValue dlt_user_log_write_string_attr(DltContextData* log, const char* text, const char* name) { return dlt_user_log_write_string_utils_attr(log, text, ASCII_STRING, name, true); } -DltReturnValue dlt_user_log_write_sized_string(DltContextData *log, const char *text, uint16_t length) +DltReturnValue dlt_user_log_write_sized_string(DltContextData* log, const char* text, uint16_t length) { return dlt_user_log_write_sized_string_utils_attr(log, text, length, ASCII_STRING, NULL, false); } -DltReturnValue dlt_user_log_write_sized_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) +DltReturnValue dlt_user_log_write_sized_string_attr( + DltContextData* log, const char* text, uint16_t length, const char* name) { return dlt_user_log_write_sized_string_utils_attr(log, text, length, ASCII_STRING, name, true); } -DltReturnValue dlt_user_log_write_constant_string(DltContextData *log, const char *text) +DltReturnValue dlt_user_log_write_constant_string(DltContextData* log, const char* text) { /* Send parameter only in verbose mode */ return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_string(log, text) : DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name) +DltReturnValue dlt_user_log_write_constant_string_attr(DltContextData* log, const char* text, const char* name) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_string_attr(log, text, name) : DLT_RETURN_OK; + return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_string_attr(log, text, name) : + DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_sized_constant_string(DltContextData *log, const char *text, uint16_t length) +DltReturnValue dlt_user_log_write_sized_constant_string(DltContextData* log, const char* text, uint16_t length) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_string(log, text, length) : DLT_RETURN_OK; + return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_string(log, text, length) : + DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) +DltReturnValue dlt_user_log_write_sized_constant_string_attr( + DltContextData* log, const char* text, uint16_t length, const char* name) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_string_attr(log, text, length, name) : DLT_RETURN_OK; + return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_string_attr(log, text, length, name) : + DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *text) +DltReturnValue dlt_user_log_write_utf8_string(DltContextData* log, const char* text) { return dlt_user_log_write_string_utils_attr(log, text, UTF8_STRING, NULL, false); } -DltReturnValue dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name) +DltReturnValue dlt_user_log_write_utf8_string_attr(DltContextData* log, const char* text, const char* name) { return dlt_user_log_write_string_utils_attr(log, text, UTF8_STRING, name, true); } -DltReturnValue dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length) +DltReturnValue dlt_user_log_write_sized_utf8_string(DltContextData* log, const char* text, uint16_t length) { return dlt_user_log_write_sized_string_utils_attr(log, text, length, UTF8_STRING, NULL, false); } -DltReturnValue dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) +DltReturnValue dlt_user_log_write_sized_utf8_string_attr( + DltContextData* log, const char* text, uint16_t length, const char* name) { return dlt_user_log_write_sized_string_utils_attr(log, text, length, UTF8_STRING, name, true); } -DltReturnValue dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text) +DltReturnValue dlt_user_log_write_constant_utf8_string(DltContextData* log, const char* text) { /* Send parameter only in verbose mode */ return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_utf8_string(log, text) : DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name) +DltReturnValue dlt_user_log_write_constant_utf8_string_attr(DltContextData* log, const char* text, const char* name) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_utf8_string_attr(log, text, name) : DLT_RETURN_OK; + return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_utf8_string_attr(log, text, name) : + DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text, uint16_t length) +DltReturnValue dlt_user_log_write_sized_constant_utf8_string(DltContextData* log, const char* text, uint16_t length) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_utf8_string(log, text, length) : DLT_RETURN_OK; + return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_utf8_string(log, text, length) : + DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_sized_constant_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name) +DltReturnValue dlt_user_log_write_sized_constant_utf8_string_attr( + DltContextData* log, const char* text, uint16_t length, const char* name) { /* Send parameter only in verbose mode */ - return is_verbose_mode(dlt_user.verbose_mode, log) ? dlt_user_log_write_sized_utf8_string_attr(log, text, length, name) : DLT_RETURN_OK; + return is_verbose_mode(dlt_user.verbose_mode, log) ? + dlt_user_log_write_sized_utf8_string_attr(log, text, length, name) : + DLT_RETURN_OK; } -static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData *log, const char *text, size_t length, const enum StringType type, const char *name, bool with_var_info) +static DltReturnValue dlt_user_log_write_sized_string_utils_attr( + DltContextData* log, const char* text, size_t length, const enum StringType type, const char* name, + bool with_var_info) { if ((log == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; if (!DLT_USER_INITIALIZED_NOT_FREEING) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } - const uint16_t name_size = (name != NULL) ? (uint16_t)(strlen(name)+1) : 0; + const uint16_t name_size = (name != NULL) ? (uint16_t)(strlen(name) + 1) : 0; - size_t arg_size = (size_t) (length + 1); + size_t arg_size = (size_t)(length + 1); size_t new_log_size = (size_t)log->size + arg_size + sizeof(uint16_t); @@ -3370,7 +3222,7 @@ static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData new_log_size += sizeof(uint32_t); if (with_var_info) { new_log_size += sizeof(uint16_t); // length of "name" attribute - new_log_size += name_size; // the "name" attribute itself + new_log_size += name_size; // the "name" attribute itself type_info |= DLT_TYPE_INFO_VARI; } @@ -3385,13 +3237,13 @@ static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData ret = DLT_RETURN_USER_BUFFER_FULL; /* Re-calculate arg_size */ - arg_size = (size_t) (dlt_user.log_buf_len - (size_t)log->size - sizeof(uint16_t)); + arg_size = (size_t)(dlt_user.log_buf_len - (size_t)log->size - sizeof(uint16_t)); size_t min_payload_str_truncate_msg = (size_t)log->size + str_truncate_message_length + sizeof(uint16_t); if (is_verbose_mode(dlt_user.verbose_mode, log)) { min_payload_str_truncate_msg += sizeof(uint32_t); - arg_size -= (size_t) sizeof(uint32_t); + arg_size -= (size_t)sizeof(uint32_t); if (with_var_info) { min_payload_str_truncate_msg += sizeof(uint16_t) + name_size; arg_size -= sizeof(uint16_t) + name_size; @@ -3413,7 +3265,7 @@ static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData * refer: https://en.wikipedia.org/wiki/UTF-8 * one utf8 character will have maximum 4 bytes then maximum bytes will be truncate additional is 3 */ - const char *tmp = (text + max_payload_str_msg - 3); + const char* tmp = (text + max_payload_str_msg - 3); uint16_t reduce_size = 0; if (tmp[2] & 0x80) { @@ -3429,7 +3281,7 @@ static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData } max_payload_str_msg -= reduce_size; - arg_size -= (size_t) reduce_size; + arg_size -= (size_t)reduce_size; } } @@ -3471,26 +3323,24 @@ static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData } switch (ret) { - case DLT_RETURN_OK: - { - /* Whole string will be copied */ - memcpy(log->buffer + log->size, text, length); - /* The input string might not be null-terminated, so we're doing that by ourselves */ - log->buffer[(size_t)log->size + length] = '\0'; - log->size += (int32_t)arg_size; - break; - } - case DLT_RETURN_USER_BUFFER_FULL: - { - /* Only copy partial string */ - memcpy(log->buffer + log->size, text, max_payload_str_msg); - log->size += (int32_t)max_payload_str_msg; + case DLT_RETURN_OK: { + /* Whole string will be copied */ + memcpy(log->buffer + log->size, text, length); + /* The input string might not be null-terminated, so we're doing that by ourselves */ + log->buffer[(size_t)log->size + length] = '\0'; + log->size += (int32_t)arg_size; + break; + } + case DLT_RETURN_USER_BUFFER_FULL: { + /* Only copy partial string */ + memcpy(log->buffer + log->size, text, max_payload_str_msg); + log->size += (int32_t)max_payload_str_msg; - /* Append string truncate the input string */ - memcpy(log->buffer + log->size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); - log->size += (int32_t)str_truncate_message_length; - break; - } + /* Append string truncate the input string */ + memcpy(log->buffer + log->size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); + log->size += (int32_t)str_truncate_message_length; + break; + } default: /* Do nothing */ break; @@ -3501,7 +3351,8 @@ static DltReturnValue dlt_user_log_write_sized_string_utils_attr(DltContextData return ret; } -static DltReturnValue dlt_user_log_write_string_utils_attr(DltContextData *log, const char *text, const enum StringType type, const char *name, bool with_var_info) +static DltReturnValue dlt_user_log_write_string_utils_attr( + DltContextData* log, const char* text, const enum StringType type, const char* name, bool with_var_info) { if ((log == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -3510,14 +3361,14 @@ static DltReturnValue dlt_user_log_write_string_utils_attr(DltContextData *log, return dlt_user_log_write_sized_string_utils_attr(log, text, length, type, name, with_var_info); } -DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint32_t service_id, - dlt_injection_callback_id dlt_injection_cbk, void *priv) +DltReturnValue dlt_register_injection_callback_with_id( + DltContext* handle, uint32_t service_id, dlt_injection_callback_id dlt_injection_cbk, void* priv) { DltContextData log; uint32_t i, j, k; int found = 0; - DltUserInjectionCallback *old; + DltUserInjectionCallback* old; if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; @@ -3538,36 +3389,33 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3 } /* Insert callback in corresponding table */ - i = (uint32_t) handle->log_level_pos; + i = (uint32_t)handle->log_level_pos; /* Insert each service_id only once */ for (k = 0; k < dlt_user.dlt_ll_ts[i].nrcallbacks; k++) - if ((dlt_user.dlt_ll_ts[i].injection_table) && - (dlt_user.dlt_ll_ts[i].injection_table[k].service_id == service_id)) { + if ((dlt_user.dlt_ll_ts[i].injection_table) + && (dlt_user.dlt_ll_ts[i].injection_table[k].service_id == service_id)) { found = 1; break; } if (found) { j = k; - } - else { + } else { j = dlt_user.dlt_ll_ts[i].nrcallbacks; /* Allocate or expand injection table */ if (dlt_user.dlt_ll_ts[i].injection_table == NULL) { - dlt_user.dlt_ll_ts[i].injection_table = - (DltUserInjectionCallback *)malloc(sizeof(DltUserInjectionCallback)); + dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback*)malloc(sizeof(DltUserInjectionCallback)); if (dlt_user.dlt_ll_ts[i].injection_table == NULL) { dlt_mutex_unlock(); return DLT_RETURN_ERROR; } - } - else { + } else { old = dlt_user.dlt_ll_ts[i].injection_table; - dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback *)malloc( - sizeof(DltUserInjectionCallback) * (j + 1)); + dlt_user.dlt_ll_ts[i].injection_table = + (DltUserInjectionCallback*)malloc(sizeof(DltUserInjectionCallback) * (j + 1)); if (dlt_user.dlt_ll_ts[i].injection_table == NULL) { dlt_user.dlt_ll_ts[i].injection_table = old; @@ -3592,8 +3440,7 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3 dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = callback_internal.without_id; dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback_with_id = NULL; dlt_user.dlt_ll_ts[i].injection_table[j].data = NULL; - } - else { + } else { dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = NULL; dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback_with_id = dlt_injection_cbk; dlt_user.dlt_ll_ts[i].injection_table[j].data = priv; @@ -3604,25 +3451,19 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3 return DLT_RETURN_OK; } -DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t service_id, - int (*dlt_injection_callback_fn)(uint32_t service_id, - void *data, - uint32_t length)) +DltReturnValue dlt_register_injection_callback( + DltContext* handle, uint32_t service_id, + int (*dlt_injection_callback_fn)(uint32_t service_id, void* data, uint32_t length)) { /* Convert dlt_injection_callback to dlt_injection_callback_id using union */ dlt_injection_callback_internal callback_internal; callback_internal.without_id = dlt_injection_callback_fn; - return dlt_register_injection_callback_with_id(handle, - service_id, - callback_internal.with_id, - NULL); + return dlt_register_injection_callback_with_id(handle, service_id, callback_internal.with_id, NULL); } -DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, - void (*dlt_log_level_changed_callback)( - char context_id[DLT_ID_SIZE], - uint8_t log_level, - uint8_t trace_status)) +DltReturnValue dlt_register_log_level_changed_callback( + DltContext* handle, + void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status)) { DltContextData log; uint32_t i; @@ -3643,7 +3484,7 @@ DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, } /* Insert callback in corresponding table */ - i = (uint32_t) handle->log_level_pos; + i = (uint32_t)handle->log_level_pos; /* Store new callback function */ dlt_user.dlt_ll_ts[i].log_level_changed_callback = dlt_log_level_changed_callback; @@ -3653,11 +3494,9 @@ DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, return DLT_RETURN_OK; } -DltReturnValue dlt_register_log_level_changed_callback_v2(DltContext *handle, - void (*dlt_log_level_changed_callback_v2)( - char *context_id, - uint8_t log_level, - uint8_t trace_status)) +DltReturnValue dlt_register_log_level_changed_callback_v2( + DltContext* handle, + void (*dlt_log_level_changed_callback_v2)(char* context_id, uint8_t log_level, uint8_t trace_status)) { DltContextData log; uint32_t i; @@ -3678,7 +3517,7 @@ DltReturnValue dlt_register_log_level_changed_callback_v2(DltContext *handle, } /* Insert callback in corresponding table */ - i = (uint32_t) handle->log_level_pos; + i = (uint32_t)handle->log_level_pos; /* Store new callback function */ dlt_user.dlt_ll_ts[i].log_level_changed_callback_v2 = dlt_log_level_changed_callback_v2; @@ -3705,14 +3544,11 @@ int check_buffer(void) * Send the start of a segment chain. * Returns DLT_RETURN_ERROR on failure */ -DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, - DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len) -{ - DltContextData log = { 0 }; +DltReturnValue dlt_user_trace_network_segmented_start( + uint32_t* id, DltContext* handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void* header, + uint16_t payload_len) +{ + DltContextData log = {0}; struct timeval tv; int ret = DLT_RETURN_ERROR; @@ -3747,7 +3583,7 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, log.size = 0; gettimeofday(&tv, NULL); - *id = (uint32_t) tv.tv_usec; + *id = (uint32_t)tv.tv_usec; /* Write identifier */ if (dlt_user_log_write_string(&log, DLT_TRACE_NW_START) < 0) { @@ -3774,7 +3610,7 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, } /* Write expected segment count */ - uint16_t segment_count = (uint16_t) (payload_len / DLT_MAX_TRACE_SEGMENT_SIZE + 1); + uint16_t segment_count = (uint16_t)(payload_len / DLT_MAX_TRACE_SEGMENT_SIZE + 1); /* If segments align perfectly with segment size, avoid sending empty segment */ if ((payload_len % DLT_MAX_TRACE_SEGMENT_SIZE) == 0) @@ -3802,12 +3638,9 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, return DLT_RETURN_OK; } -DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, - DltContext *handle, - DltNetworkTraceType nw_trace_type, - int sequence, - uint16_t payload_len, - void *payload) +DltReturnValue dlt_user_trace_network_segmented_segment( + uint32_t id, DltContext* handle, DltNetworkTraceType nw_trace_type, int sequence, uint16_t payload_len, + void* payload) { int ret = DLT_RETURN_ERROR; struct timespec ts; @@ -3829,7 +3662,7 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, return DLT_RETURN_ERROR; if (handle->trace_status_ptr && (*(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)) { - DltContextData log = { 0 }; + DltContextData log = {0}; if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; @@ -3861,7 +3694,7 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, } /* Write segment sequence number */ - if (dlt_user_log_write_uint16(&log, (uint16_t) sequence) < DLT_RETURN_OK) { + if (dlt_user_log_write_uint16(&log, (uint16_t)sequence) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } @@ -3885,9 +3718,9 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, return DLT_RETURN_OK; } -DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *handle, DltNetworkTraceType nw_trace_type) +DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext* handle, DltNetworkTraceType nw_trace_type) { - DltContextData log = { 0 }; + DltContextData log = {0}; int ret = DLT_RETURN_ERROR; if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { @@ -3935,13 +3768,12 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han dlt_user_free_buffer(&(log.buffer)); return ret; - } return DLT_RETURN_OK; } -void *dlt_user_trace_network_segmented_thread(void *unused) +void* dlt_user_trace_network_segmented_thread(void* unused) { /* Unused on purpose. */ (void)unused; @@ -3954,21 +3786,20 @@ void *dlt_user_trace_network_segmented_thread(void *unused) #endif pthread_cleanup_push(dlt_user_cleanup_handler, NULL); - s_segmented_data *data; + s_segmented_data* data; while (1) { /* Wait until message queue is initialized */ dlt_lock_mutex(&mq_mutex); - while (dlt_user.dlt_segmented_queue_read_handle < 0) - { + while (dlt_user.dlt_segmented_queue_read_handle < 0) { pthread_cond_wait(&mq_init_condition, &mq_mutex); } dlt_unlock_mutex(&mq_mutex); - ssize_t read = mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char *)&data, - sizeof(s_segmented_data *), NULL); + ssize_t read = + mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char*)&data, sizeof(s_segmented_data*), NULL); if (read < 0) { if (errno != EINTR) { @@ -3983,7 +3814,7 @@ void *dlt_user_trace_network_segmented_thread(void *unused) continue; } - if (read != sizeof(s_segmented_data *)) { + if (read != sizeof(s_segmented_data*)) { /* This case will not happen. */ /* When this thread is interrupted by signal, mq_receive() will not return */ /* partial read length and will return -1. And also no data is removed from mq. */ @@ -4009,10 +3840,10 @@ void *dlt_user_trace_network_segmented_thread(void *unused) return NULL; } -void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data) +void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data* data) { /* Segment the data and send the chunks */ - void *ptr = NULL; + void* ptr = NULL; uint32_t offset = 0; uint16_t sequence = 0; @@ -4020,7 +3851,7 @@ void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data) uint16_t len = 0; if (offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len) - len = (uint16_t) (data->payload_len - offset); + len = (uint16_t)(data->payload_len - offset); else len = DLT_MAX_TRACE_SEGMENT_SIZE; @@ -4028,30 +3859,23 @@ void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data) if (len == 0) break; - ptr = (void *)((uintptr_t)data->payload + offset); - DltReturnValue err = dlt_user_trace_network_segmented_segment(data->id, - data->handle, - data->nw_trace_type, - sequence++, - len, - ptr); + ptr = (void*)((uintptr_t)data->payload + offset); + DltReturnValue err = + dlt_user_trace_network_segmented_segment(data->id, data->handle, data->nw_trace_type, sequence++, len, ptr); if ((err == DLT_RETURN_BUFFER_FULL) || (err == DLT_RETURN_ERROR)) { dlt_log(LOG_ERR, "NWTSegmented: Could not send segment. Aborting.\n"); - break; /* loop */ + break; /* loop */ } offset += len; - } while (offset < (uint32_t )((uintptr_t)data->payload + data->payload_len)); + } while (offset < (uint32_t)((uintptr_t)data->payload + data->payload_len)); } -DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload) +DltReturnValue dlt_user_trace_network_segmented( + DltContext* handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void* header, uint16_t payload_len, + void* payload) { /* forbid dlt usage in child after fork */ if (g_dlt_is_child) @@ -4062,7 +3886,7 @@ DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, return dlt_user_trace_network(handle, nw_trace_type, header_len, header, payload_len, payload); /* Allocate Memory */ - s_segmented_data *thread_data = malloc(sizeof(s_segmented_data)); + s_segmented_data* thread_data = malloc(sizeof(s_segmented_data)); if (thread_data == NULL) return DLT_RETURN_ERROR; @@ -4091,12 +3915,9 @@ DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, memcpy(thread_data->payload, payload, payload_len); /* Send start message */ - DltReturnValue err = dlt_user_trace_network_segmented_start(&(thread_data->id), - thread_data->handle, - thread_data->nw_trace_type, - (uint16_t) thread_data->header_len, - thread_data->header, - (uint16_t) thread_data->payload_len); + DltReturnValue err = dlt_user_trace_network_segmented_start( + &(thread_data->id), thread_data->handle, thread_data->nw_trace_type, (uint16_t)thread_data->header_len, + thread_data->header, (uint16_t)thread_data->payload_len); if ((err == DLT_RETURN_BUFFER_FULL) || (err == DLT_RETURN_ERROR)) { dlt_log(LOG_ERR, "NWTSegmented: Could not send start segment. Aborting.\n"); @@ -4117,8 +3938,7 @@ DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, } /* Add to queue */ - if (mq_send(dlt_user.dlt_segmented_queue_write_handle, - (char *)&thread_data, sizeof(s_segmented_data *), 1) < 0) { + if (mq_send(dlt_user.dlt_segmented_queue_write_handle, (char*)&thread_data, sizeof(s_segmented_data*), 1) < 0) { if (errno == EAGAIN) dlt_log(LOG_WARNING, "NWTSegmented: Queue full. Message discarded.\n"); @@ -4134,26 +3954,19 @@ DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, return DLT_RETURN_OK; } -DltReturnValue dlt_user_trace_network(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload) +DltReturnValue dlt_user_trace_network( + DltContext* handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void* header, uint16_t payload_len, + void* payload) { return dlt_user_trace_network_truncated(handle, nw_trace_type, header_len, header, payload_len, payload, 1); } -DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload, - int allow_truncate) +DltReturnValue dlt_user_trace_network_truncated( + DltContext* handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void* header, uint16_t payload_len, + void* payload, int allow_truncate) { int ret = DLT_RETURN_ERROR; - DltContextData log = { 0 }; + DltContextData log = {0}; if ((payload == NULL) && (payload_len > 0)) return DLT_RETURN_WRONG_PARAMETER; @@ -4188,7 +4001,8 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, header_len = 0; /* If truncation is allowed, check if we must do it */ - if ((allow_truncate > 0) && ((size_t)header_len + (size_t)payload_len + sizeof(uint16_t) > dlt_user.log_buf_len)) { + if ((allow_truncate > 0) + && ((size_t)header_len + (size_t)payload_len + sizeof(uint16_t) > dlt_user.log_buf_len)) { /* Identify as truncated */ if (dlt_user_log_write_string(&log, DLT_TRACE_NW_TRUNCATED) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); @@ -4211,14 +4025,14 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, * Calculate maximum available space in sending buffer after headers. */ - uint16_t truncated_payload_len = (uint16_t) ((size_t)dlt_user.log_buf_len - (size_t)log.size - sizeof(uint16_t) - sizeof(uint32_t)); + uint16_t truncated_payload_len = + (uint16_t)((size_t)dlt_user.log_buf_len - (size_t)log.size - sizeof(uint16_t) - sizeof(uint32_t)); /* Write truncated payload */ if (dlt_user_log_write_raw(&log, payload, truncated_payload_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - } - else { /* Truncation not allowed or data short enough */ + } else { /* Truncation not allowed or data short enough */ /* Write header and its length */ if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK) { @@ -4246,13 +4060,10 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, return DLT_RETURN_OK; } -#else /* DLT_NETWORK_TRACE_ENABLE not set */ -DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload) +#else /* DLT_NETWORK_TRACE_ENABLE not set */ +DltReturnValue dlt_user_trace_network_segmented( + DltContext* handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void* header, uint16_t payload_len, + void* payload) { /** * vsomeip uses the DLT_TRACE_NETWORK_SEGMENTED macro that calls this function. @@ -4269,13 +4080,9 @@ DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, return DLT_RETURN_LOGGING_DISABLED; } -DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, - DltNetworkTraceType nw_trace_type, - uint16_t header_len, - void *header, - uint16_t payload_len, - void *payload, - int allow_truncate) +DltReturnValue dlt_user_trace_network_truncated( + DltContext* handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void* header, uint16_t payload_len, + void* payload, int allow_truncate) { /** * vsomeip uses the DLT_TRACE_NETWORK_TRUNCATED macro that calls this function. @@ -4295,7 +4102,7 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, #endif /* DLT_NETWORK_TRACE_ENABLE */ -DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text) +DltReturnValue dlt_log_string(DltContext* handle, DltLogLevelType loglevel, const char* text) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4316,7 +4123,7 @@ DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, cons return ret; } -DltReturnValue dlt_log_string_v2(DltContext *handle, DltLogLevelType loglevel, const char *text) +DltReturnValue dlt_log_string_v2(DltContext* handle, DltLogLevelType loglevel, const char* text) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4337,7 +4144,7 @@ DltReturnValue dlt_log_string_v2(DltContext *handle, DltLogLevelType loglevel, c return ret; } -DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, const char *text, int data) +DltReturnValue dlt_log_string_int(DltContext* handle, DltLogLevelType loglevel, const char* text, int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4359,7 +4166,7 @@ DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, return ret; } -DltReturnValue dlt_log_string_int_v2(DltContext *handle, DltLogLevelType loglevel, const char *text, int data) +DltReturnValue dlt_log_string_int_v2(DltContext* handle, DltLogLevelType loglevel, const char* text, int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4381,7 +4188,7 @@ DltReturnValue dlt_log_string_int_v2(DltContext *handle, DltLogLevelType logleve return ret; } -DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data) +DltReturnValue dlt_log_string_uint(DltContext* handle, DltLogLevelType loglevel, const char* text, unsigned int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4403,7 +4210,7 @@ DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, return ret; } -DltReturnValue dlt_log_string_uint_v2(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data) +DltReturnValue dlt_log_string_uint_v2(DltContext* handle, DltLogLevelType loglevel, const char* text, unsigned int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4425,7 +4232,7 @@ DltReturnValue dlt_log_string_uint_v2(DltContext *handle, DltLogLevelType loglev return ret; } -DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int data) +DltReturnValue dlt_log_int(DltContext* handle, DltLogLevelType loglevel, int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4445,7 +4252,7 @@ DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int dat return DLT_RETURN_OK; } -DltReturnValue dlt_log_int_v2(DltContext *handle, DltLogLevelType loglevel, int data) +DltReturnValue dlt_log_int_v2(DltContext* handle, DltLogLevelType loglevel, int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4465,7 +4272,7 @@ DltReturnValue dlt_log_int_v2(DltContext *handle, DltLogLevelType loglevel, int return DLT_RETURN_OK; } -DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsigned int data) +DltReturnValue dlt_log_uint(DltContext* handle, DltLogLevelType loglevel, unsigned int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4485,7 +4292,7 @@ DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsign return DLT_RETURN_OK; } -DltReturnValue dlt_log_uint_v2(DltContext *handle, DltLogLevelType loglevel, unsigned int data) +DltReturnValue dlt_log_uint_v2(DltContext* handle, DltLogLevelType loglevel, unsigned int data) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4505,7 +4312,7 @@ DltReturnValue dlt_log_uint_v2(DltContext *handle, DltLogLevelType loglevel, uns return DLT_RETURN_OK; } -DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *data, uint16_t length) +DltReturnValue dlt_log_raw(DltContext* handle, DltLogLevelType loglevel, void* data, uint16_t length) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4529,7 +4336,7 @@ DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *d return DLT_RETURN_OK; } -DltReturnValue dlt_log_raw_v2(DltContext *handle, DltLogLevelType loglevel, void *data, uint16_t length) +DltReturnValue dlt_log_raw_v2(DltContext* handle, DltLogLevelType loglevel, void* data, uint16_t length) { if (!is_verbose_mode(dlt_user.verbose_mode, NULL)) return DLT_RETURN_ERROR; @@ -4655,11 +4462,11 @@ DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id) return DLT_RETURN_OK; } -DltReturnValue dlt_with_filename_and_line_number(const char *fina, const int linr) +DltReturnValue dlt_with_filename_and_line_number(const char* fina, const int linr) { - if (fina == NULL){ - dlt_vlog(LOG_ERR, "%s Wrong parameter", __func__); - return DLT_RETURN_ERROR; + if (fina == NULL) { + dlt_vlog(LOG_ERR, "%s Wrong parameter", __func__); + return DLT_RETURN_ERROR; } if (!DLT_USER_INITIALIZED) { if (dlt_init() < DLT_RETURN_OK) { @@ -4677,7 +4484,7 @@ DltReturnValue dlt_with_filename_and_line_number(const char *fina, const int lin } dlt_user.filename = (char*)malloc((size_t)dlt_user.filenamelen + 1); - if (dlt_user.filename == NULL){ + if (dlt_user.filename == NULL) { dlt_vlog(LOG_ERR, "%s Could not allocate memory for filename", __func__); return DLT_RETURN_ERROR; } @@ -4703,10 +4510,11 @@ DltReturnValue dlt_with_prlv(uint8_t prlv) return DLT_RETURN_OK; } -DltReturnValue dlt_with_tags(const char *firstTag, ...) { - if (firstTag == NULL){ - dlt_vlog(LOG_ERR, "%s Wrong parameter", __func__); - return DLT_RETURN_ERROR; +DltReturnValue dlt_with_tags(const char* firstTag, ...) +{ + if (firstTag == NULL) { + dlt_vlog(LOG_ERR, "%s Wrong parameter", __func__); + return DLT_RETURN_ERROR; } if (!DLT_USER_INITIALIZED) { if (dlt_init() < DLT_RETURN_OK) { @@ -4716,14 +4524,14 @@ DltReturnValue dlt_with_tags(const char *firstTag, ...) { } va_list args; - const char *currentTag = firstTag; + const char* currentTag = firstTag; uint8_t count = 0; // Initial pass: Count the number of tags to allocate memory accurately va_start(args, firstTag); while (currentTag != NULL) { count++; - currentTag = va_arg(args, const char *); + currentTag = va_arg(args, const char*); } va_end(args); @@ -4735,7 +4543,7 @@ DltReturnValue dlt_with_tags(const char *firstTag, ...) { * necessary to fit `DLT_V2_ID_SIZE - 1` characters plus NUL. */ int i = 0; - dlt_user.tag = (DltTag *)malloc((size_t)count * sizeof(DltTag)); + dlt_user.tag = (DltTag*)malloc((size_t)count * sizeof(DltTag)); if (dlt_user.tag == NULL) { return DLT_RETURN_ERROR; } @@ -4758,7 +4566,7 @@ DltReturnValue dlt_with_tags(const char *firstTag, ...) { total_size += (int)len + 1; } i++; - currentTag = va_arg(args, const char *); + currentTag = va_arg(args, const char*); } va_end(args); @@ -4796,7 +4604,7 @@ DltReturnValue dlt_disable_local_print(void) } /* Cleanup on thread cancellation, thread may hold lock release it here */ -static void dlt_user_cleanup_handler(void *arg) +static void dlt_user_cleanup_handler(void* arg) { DLT_UNUSED(arg); /* Satisfy compiler */ @@ -4808,7 +4616,7 @@ static void dlt_user_cleanup_handler(void *arg) dlt_mutex_unlock(); } -void *dlt_user_housekeeperthread_function(void *ptr) +void* dlt_user_housekeeperthread_function(void* ptr) { struct timespec ts; bool in_loop = true; @@ -4825,18 +4633,17 @@ void *dlt_user_housekeeperthread_function(void *ptr) sigemptyset(&set); sigaddset(&set, SIGUSR1); if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) { - dlt_vlog(LOG_ERR, "Failed to block signal with error [%s]\n", - strerror(errno)); + dlt_vlog(LOG_ERR, "Failed to block signal with error [%s]\n", strerror(errno)); in_loop = false; } #endif #ifdef DLT_USE_PTHREAD_SETNAME_NP -# if defined(__APPLE__) +#if defined(__APPLE__) if (pthread_setname_np("dlt_housekeeper")) -# else +#else if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper")) -# endif +#endif dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n"); #elif defined(linux) if (prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0) < 0) @@ -4895,7 +4702,7 @@ void *dlt_user_housekeeperthread_function(void *ptr) /* Private functions of user library */ -DltReturnValue dlt_user_log_init(DltContext *handle, DltContextData *log) +DltReturnValue dlt_user_log_init(DltContext* handle, DltContextData* log) { int ret = DLT_RETURN_OK; @@ -4918,7 +4725,7 @@ DltReturnValue dlt_user_log_init(DltContext *handle, DltContextData *log) return ret; } -DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int *const sent_size) +DltReturnValue dlt_user_log_send_log(DltContextData* log, const int mtype, int* const sent_size) { DltMessage msg; DltUserHeader userheader; @@ -4933,16 +4740,15 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * DltReturnValue ret = DLT_RETURN_OK; if (!DLT_USER_INITIALIZED_NOT_FREEING) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } dlt_mutex_lock(); - if ((log == NULL) || - (log->handle == NULL) || - (log->handle->contextID[0] == '\0') || - (mtype < DLT_TYPE_LOG) || (mtype > DLT_TYPE_CONTROL) - ) { + if ((log == NULL) || (log->handle == NULL) || (log->handle->contextID[0] == '\0') || (mtype < DLT_TYPE_LOG) + || (mtype > DLT_TYPE_CONTROL)) { dlt_mutex_unlock(); return DLT_RETURN_WRONG_PARAMETER; } @@ -4958,14 +4764,14 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * return DLT_RETURN_ERROR; } - msg.storageheader = (DltStorageHeader *)msg.headerbuffer; + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; if (dlt_set_storageheader(msg.storageheader, dlt_user.ecuID) == DLT_RETURN_ERROR) { dlt_mutex_unlock(); return DLT_RETURN_ERROR; } - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1; /* send ecu id */ @@ -4982,7 +4788,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * if (__builtin_expect(!!(dlt_user.local_pid == -1), false)) { dlt_user.local_pid = getpid(); } - msg.headerextra.seid = (uint32_t) dlt_user.local_pid; + msg.headerextra.seid = (uint32_t)dlt_user.local_pid; } if (is_verbose_mode(dlt_user.verbose_mode, log)) @@ -5005,8 +4811,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * /*msg.headerextra.seid = 0; */ if (log->use_timestamp == DLT_AUTO_TIMESTAMP) { msg.headerextra.tmsp = dlt_uptime(); - } - else { + } else { msg.headerextra.tmsp = log->user_timestamp; } @@ -5023,24 +4828,21 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * if (DLT_IS_HTYP_UEH(msg.standardheader->htyp)) { /* with extended header */ msg.extendedheader = - (DltExtendedHeader *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); switch (mtype) { - case DLT_TYPE_LOG: - { - msg.extendedheader->msin = (uint8_t) (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT | - ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + case DLT_TYPE_LOG: { + msg.extendedheader->msin = (uint8_t)(DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT + | ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); break; } - case DLT_TYPE_NW_TRACE: - { - msg.extendedheader->msin = (uint8_t) (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT | - ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + case DLT_TYPE_NW_TRACE: { + msg.extendedheader->msin = (uint8_t)(DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT + | ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); break; } - default: - { + default: { /* This case should not occur */ dlt_mutex_unlock(); return DLT_RETURN_ERROR; @@ -5052,20 +4854,16 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * if (is_verbose_mode(dlt_user.verbose_mode, log)) msg.extendedheader->msin |= DLT_MSIN_VERB; - msg.extendedheader->noar = (uint8_t) log->args_num; /* number of arguments */ - dlt_set_id(msg.extendedheader->apid, dlt_user.appID); /* application id */ - dlt_set_id(msg.extendedheader->ctid, log->handle->contextID); /* context id */ + msg.extendedheader->noar = (uint8_t)log->args_num; /* number of arguments */ + dlt_set_id(msg.extendedheader->apid, dlt_user.appID); /* application id */ + dlt_set_id(msg.extendedheader->ctid, log->handle->contextID); /* context id */ - msg.headersize = (int32_t) (sizeof(DltStorageHeader) - + sizeof(DltStandardHeader) - + sizeof(DltExtendedHeader) - + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); - } - else { + msg.headersize = (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + } else { /* without extended header */ - msg.headersize = (int32_t) (sizeof(DltStorageHeader) - + sizeof(DltStandardHeader) - + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.headersize = (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); } int32_t tmplen = (int32_t)msg.headersize - (int32_t)sizeof(DltStorageHeader) + (int32_t)log->size; @@ -5083,8 +4881,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * msg.standardheader->len = DLT_HTOBE_16((uint16_t)len); /* print to std out, if enabled */ - if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) && - (dlt_user.local_print_mode != DLT_PM_AUTOMATIC)) { + if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) && (dlt_user.local_print_mode != DLT_PM_AUTOMATIC)) { if ((dlt_user.enable_local_print) || (dlt_user.local_print_mode == DLT_PM_FORCE_ON)) if (dlt_user_print_msg(&msg, log) == DLT_RETURN_ERROR) { dlt_mutex_unlock(); @@ -5096,36 +4893,30 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * if (dlt_user_file_reach_max) { dlt_mutex_unlock(); return DLT_RETURN_FILESZERR; - } - else { + } else { /* Get file size */ struct stat st; - if(fstat(dlt_user.dlt_log_handle, &st) != 0) { - dlt_vlog(LOG_WARNING, - "%s: Cannot get file information (errno=%d)\n", __func__, errno); + if (fstat(dlt_user.dlt_log_handle, &st) != 0) { + dlt_vlog(LOG_WARNING, "%s: Cannot get file information (errno=%d)\n", __func__, errno); dlt_mutex_unlock(); return DLT_RETURN_ERROR; } - dlt_vlog(LOG_DEBUG, "%s: Current file size=[%lld]\n", __func__, - (long long)st.st_size); + dlt_vlog(LOG_DEBUG, "%s: Current file size=[%lld]\n", __func__, (long long)st.st_size); /* Check filesize */ /* Return error if the file size has reached to maximum */ - unsigned int msg_size = (unsigned int)st.st_size + (unsigned int)msg.headersize + - (unsigned int)log->size; + unsigned int msg_size = (unsigned int)st.st_size + (unsigned int)msg.headersize + (unsigned int)log->size; if (msg_size > dlt_user.filesize_max) { dlt_user_file_reach_max = true; - dlt_vlog(LOG_ERR, - "%s: File size (%lld bytes) reached to defined maximum size (%d bytes)\n", - __func__, (long long)st.st_size, dlt_user.filesize_max); + dlt_vlog( + LOG_ERR, "%s: File size (%lld bytes) reached to defined maximum size (%d bytes)\n", __func__, + (long long)st.st_size, dlt_user.filesize_max); dlt_mutex_unlock(); return DLT_RETURN_FILESZERR; - } - else { + } else { /* log to file */ - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - msg.headerbuffer, (size_t)msg.headersize, - log->buffer, (size_t)log->size); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, msg.headerbuffer, (size_t)msg.headersize, log->buffer, (size_t)log->size); dlt_mutex_unlock(); return ret; } @@ -5152,39 +4943,36 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * #ifdef DLT_SHM_ENABLE if (dlt_user.dlt_log_handle != -1) - dlt_shm_push(&dlt_user.dlt_shm, msg.headerbuffer + sizeof(DltStorageHeader), - msg.headersize - sizeof(DltStorageHeader), - log->buffer, log->size, 0, 0); - - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - 0, 0, - 0, 0); + dlt_shm_push( + &dlt_user.dlt_shm, msg.headerbuffer + sizeof(DltStorageHeader), + msg.headersize - sizeof(DltStorageHeader), log->buffer, log->size, 0, 0); + + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), 0, 0, 0, 0); #else -# ifdef DLT_TEST_ENABLE +#ifdef DLT_TEST_ENABLE if (dlt_user.corrupt_user_header) { - userheader.pattern[0] = (char) 0xff; - userheader.pattern[1] = (char) 0xff; - userheader.pattern[2] = (char) 0xff; - userheader.pattern[3] = (char) 0xff; + userheader.pattern[0] = (char)0xff; + userheader.pattern[1] = (char)0xff; + userheader.pattern[2] = (char)0xff; + userheader.pattern[3] = (char)0xff; } if (dlt_user.corrupt_message_size) msg.standardheader->len = DLT_HTOBE_16(dlt_user.corrupt_message_size_size); -# endif +#endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE /* Check trace load before output */ - if (!sent_size) - { + if (!sent_size) { int pos = log->handle->log_level_pos; char ctxid[DLT_ID_SIZE]; memcpy(ctxid, log->handle->contextID, DLT_ID_SIZE); if ((uint32_t)pos > dlt_user.dlt_ll_ts_num_entries) { char msg_buffer[255]; - sprintf(msg_buffer, "log handle has invalid log level pos %d, current entries: %u, dropping message\n", + sprintf( + msg_buffer, "log handle has invalid log level pos %d, current entries: %u, dropping message\n", log->handle->log_level_pos, dlt_user.dlt_ll_ts_num_entries); dlt_mutex_unlock(); dlt_user_output_internal_msg(LOG_ERR, msg_buffer, NULL); @@ -5193,7 +4981,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * dlt_mutex_unlock(); pthread_rwlock_rdlock(&trace_load_rw_lock); - DltTraceLoadSettings *computed_settings = dlt_find_runtime_trace_load_settings( + DltTraceLoadSettings* computed_settings = dlt_find_runtime_trace_load_settings( trace_load_settings, trace_load_settings_count, dlt_user.appID, ctxid); pthread_rwlock_unlock(&trace_load_rw_lock); @@ -5205,55 +4993,44 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * } } dlt_mutex_unlock(); - size_t trace_load_size = (size_t)sizeof(DltUserHeader) - + (size_t)msg.headersize - - (size_t)sizeof(DltStorageHeader) - + (size_t)log->size; + size_t trace_load_size = (size_t)sizeof(DltUserHeader) + (size_t)msg.headersize + - (size_t)sizeof(DltStorageHeader) + (size_t)log->size; int32_t trace_load_size_i32 = safe_size_to_int32(trace_load_size); const bool trace_load_in_limits = dlt_check_trace_load( - computed_settings, - log->log_level, - time_stamp, - trace_load_size_i32, - dlt_user_output_internal_msg, - NULL); - - if (!trace_load_in_limits){ + computed_settings, log->log_level, time_stamp, trace_load_size_i32, dlt_user_output_internal_msg, + NULL); + + if (!trace_load_in_limits) { return DLT_RETURN_LOAD_EXCEEDED; } dlt_mutex_lock(); - } - else - { + } else { { - size_t total_size = (size_t)sizeof(DltUserHeader) + (size_t)msg.headersize - (size_t)sizeof(DltStorageHeader) + (size_t)log->size; + size_t total_size = (size_t)sizeof(DltUserHeader) + (size_t)msg.headersize + - (size_t)sizeof(DltStorageHeader) + (size_t)log->size; *sent_size = safe_size_to_int32(total_size); } } #endif - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (size_t)msg.headersize - (size_t)sizeof(DltStorageHeader), - log->buffer, (size_t)log->size); + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), + msg.headerbuffer + sizeof(DltStorageHeader), (size_t)msg.headersize - (size_t)sizeof(DltStorageHeader), + log->buffer, (size_t)log->size); #endif } DltReturnValue process_error_ret = DLT_RETURN_OK; /* store message in ringbuffer, if an error has occurred */ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - if (((ret!=DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) && !sent_size) + if (((ret != DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) && !sent_size) #else if ((ret != DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) #endif - process_error_ret = dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (size_t)msg.headersize - (size_t)sizeof(DltStorageHeader), - log->buffer, - (size_t)log->size); + process_error_ret = dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), msg.headerbuffer + sizeof(DltStorageHeader), + (size_t)msg.headersize - (size_t)sizeof(DltStorageHeader), log->buffer, (size_t)log->size); if (process_error_ret == DLT_RETURN_OK) { dlt_mutex_unlock(); @@ -5268,25 +5045,23 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * /* handle return value of function dlt_user_log_out3() when process_error_ret < 0*/ switch (ret) { - case DLT_RETURN_PIPE_FULL: - { - /* data could not be written */ - dlt_mutex_unlock(); - return DLT_RETURN_PIPE_FULL; - } - case DLT_RETURN_PIPE_ERROR: - { - /* handle not open or pipe error */ - close(dlt_user.dlt_log_handle); - dlt_user.dlt_log_handle = -1; + case DLT_RETURN_PIPE_FULL: { + /* data could not be written */ + dlt_mutex_unlock(); + return DLT_RETURN_PIPE_FULL; + } + case DLT_RETURN_PIPE_ERROR: { + /* handle not open or pipe error */ + close(dlt_user.dlt_log_handle); + dlt_user.dlt_log_handle = -1; #if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC dlt_user.connection_state = DLT_USER_RETRY_CONNECT; #endif - #ifdef DLT_SHM_ENABLE +#ifdef DLT_SHM_ENABLE /* free shared memory */ dlt_shm_free_client(&dlt_user.dlt_shm); - #endif +#endif if (dlt_user.local_print_mode == DLT_PM_AUTOMATIC) dlt_user_print_msg(&msg, log); @@ -5294,19 +5069,16 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * dlt_mutex_unlock(); return DLT_RETURN_PIPE_ERROR; } - case DLT_RETURN_ERROR: - { + case DLT_RETURN_ERROR: { /* other error condition */ dlt_mutex_unlock(); return DLT_RETURN_ERROR; } - case DLT_RETURN_OK: - { + case DLT_RETURN_OK: { dlt_mutex_unlock(); return DLT_RETURN_OK; } - default: - { + default: { /* This case should never occur. */ dlt_mutex_unlock(); return DLT_RETURN_ERROR; @@ -5318,7 +5090,8 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, DltHtyp2ContentType msgcontent, int *const sent_size) +DltReturnValue dlt_user_log_send_log_v2( + DltContextData* log, const int mtype, DltHtyp2ContentType msgcontent, int* const sent_size) { DltMessageV2 msg = {0}; DltUserHeader userheader; @@ -5333,16 +5106,14 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl DltReturnValue ret = DLT_RETURN_OK; if (!DLT_USER_INITIALIZED_NOT_FREEING) { - dlt_vlog(LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, dlt_user_init_state, dlt_user_freeing); + dlt_vlog( + LOG_WARNING, "%s dlt_user_init_state=%i (expected INIT_DONE), dlt_user_freeing=%i\n", __func__, + dlt_user_init_state, dlt_user_freeing); return DLT_RETURN_ERROR; } - if ((log == NULL) || - (log->handle == NULL) || - (log->handle->contextID2 == NULL) || - (mtype < DLT_TYPE_LOG) || (mtype > DLT_TYPE_CONTROL) || - (msgcontent < DLT_VERBOSE_DATA_MSG) || (msgcontent > DLT_CONTROL_MSG) - ) + if ((log == NULL) || (log->handle == NULL) || (log->handle->contextID2 == NULL) || (mtype < DLT_TYPE_LOG) + || (mtype > DLT_TYPE_CONTROL) || (msgcontent < DLT_VERBOSE_DATA_MSG) || (msgcontent > DLT_CONTROL_MSG)) return DLT_RETURN_WRONG_PARAMETER; /* also for Trace messages */ @@ -5356,8 +5127,8 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl msg.baseheaderextrasizev2 = (uint32_t)dlt_message_get_extraparameters_size_v2(msgcontent); msg.extendedheadersizev2 = (uint32_t)dlt_get_extendedheadersize_v2(dlt_user, log->handle->contextID2len); - msg.headersizev2 = (int32_t)(msg.storageheadersizev2 + msg.baseheadersizev2 + - msg.baseheaderextrasizev2 + msg.extendedheadersizev2); + msg.headersizev2 = (int32_t)(msg.storageheadersizev2 + msg.baseheadersizev2 + msg.baseheaderextrasizev2 + + msg.extendedheadersizev2); if (msg.headerbufferv2 != NULL) { free(msg.headerbufferv2); @@ -5372,7 +5143,7 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl if (dlt_message_set_storageparameters_v2(&msg, 0) != DLT_RETURN_OK) return DLT_RETURN_ERROR; - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + msg.storageheadersizev2); + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + msg.storageheadersizev2); msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2; msg.baseheaderv2->htyp2 |= msgcontent; @@ -5410,23 +5181,20 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl /* Fill base header conditional parameters */ - if (msgcontent==DLT_VERBOSE_DATA_MSG) { + if (msgcontent == DLT_VERBOSE_DATA_MSG) { /* To Update Handle all mtypes*/ switch (mtype) { - case DLT_TYPE_LOG: - { - msg.headerextrav2.msin = (uint8_t) (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT | - ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + case DLT_TYPE_LOG: { + msg.headerextrav2.msin = (uint8_t)(DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT + | ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); break; } - case DLT_TYPE_NW_TRACE: - { - msg.headerextrav2.msin = (uint8_t) (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT | - ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); + case DLT_TYPE_NW_TRACE: { + msg.headerextrav2.msin = (uint8_t)(DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT + | ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN)); break; } - default: - { + default: { /* This case should not occur */ return DLT_RETURN_ERROR; break; @@ -5435,68 +5203,68 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl /* If in verbose mode, set flag in header for verbose mode */ if (is_verbose_mode(dlt_user.verbose_mode, log)) msg.headerextrav2.msin |= DLT_MSIN_VERB; - msg.headerextrav2.noar = (uint8_t) log->args_num; /* number of arguments */ + msg.headerextrav2.noar = (uint8_t)log->args_num; /* number of arguments */ } - if ((msgcontent==DLT_VERBOSE_DATA_MSG)||(msgcontent==DLT_NON_VERBOSE_DATA_MSG)) { + if ((msgcontent == DLT_VERBOSE_DATA_MSG) || (msgcontent == DLT_NON_VERBOSE_DATA_MSG)) { memset(msg.headerextrav2.seconds, 0, 5); msg.headerextrav2.nanoseconds = 0; - #if defined (__WIN32__) || defined(_MSC_VER) +#if defined(__WIN32__) || defined(_MSC_VER) time_t t = time(NULL); - if (t==-1){ + if (t == -1) { uint32_t tcnt = (uint32_t)(GetTickCount()); /* GetTickCount() in 10 ms resolution */ tcnt_seconds = tcnt / 100; - tcnt_ns = (tcnt - (tcnt*100)) * 10000; - msg.headerextrav2.seconds[0]=(tcnt_seconds >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(tcnt_seconds >> 24) & 0xFF; - msg.headerextrav2.seconds[2]=(tcnt_seconds >> 16) & 0xFF; - msg.headerextrav2.seconds[3]=(tcnt_seconds >> 8) & 0xFF; - msg.headerextrav2.seconds[4]= tcnt_seconds & 0xFF; + tcnt_ns = (tcnt - (tcnt * 100)) * 10000; + msg.headerextrav2.seconds[0] = (tcnt_seconds >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (tcnt_seconds >> 24) & 0xFF; + msg.headerextrav2.seconds[2] = (tcnt_seconds >> 16) & 0xFF; + msg.headerextrav2.seconds[3] = (tcnt_seconds >> 8) & 0xFF; + msg.headerextrav2.seconds[4] = tcnt_seconds & 0xFF; if (ts.tv_nsec < 0x3B9ACA00) { msg.headerextrav2.nanoseconds = tcnt_ns; } - }else{ - msg.headerextrav2.seconds[0]=(t >> 32) & 0xFF; - msg.headerextrav2.seconds[1]=(t >> 24) & 0xFF; - msg.headerextrav2.seconds[2]=(t >> 16) & 0xFF; - msg.headerextrav2.seconds[3]=(t >> 8) & 0xFF; - msg.headerextrav2.seconds[4]= t & 0xFF; + } else { + msg.headerextrav2.seconds[0] = (t >> 32) & 0xFF; + msg.headerextrav2.seconds[1] = (t >> 24) & 0xFF; + msg.headerextrav2.seconds[2] = (t >> 16) & 0xFF; + msg.headerextrav2.seconds[3] = (t >> 8) & 0xFF; + msg.headerextrav2.seconds[4] = t & 0xFF; msg.headerextrav2.nanoseconds |= 0x80000000; } - #else +#else struct timespec ts; - if(clock_gettime(CLOCK_REALTIME, &ts) == 0) { - msg.headerextrav2.seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - msg.headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - msg.headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - msg.headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - msg.headerextrav2.seconds[4]=(uint8_t)(ts.tv_sec & 0xFF); + if (clock_gettime(CLOCK_REALTIME, &ts) == 0) { + msg.headerextrav2.seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + msg.headerextrav2.seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + msg.headerextrav2.seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + msg.headerextrav2.seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + msg.headerextrav2.seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { - msg.headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } - }else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - msg.headerextrav2.seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - msg.headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - msg.headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - msg.headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - msg.headerextrav2.seconds[4]=(uint8_t)(ts.tv_sec & 0xFF); + } else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + msg.headerextrav2.seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + msg.headerextrav2.seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + msg.headerextrav2.seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + msg.headerextrav2.seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + msg.headerextrav2.seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); if (ts.tv_nsec < 0x3B9ACA00) { - msg.headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */ + msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */ } msg.headerextrav2.nanoseconds |= 0x80000000; } - #endif +#endif } - if (msgcontent==DLT_NON_VERBOSE_DATA_MSG) { + if (msgcontent == DLT_NON_VERBOSE_DATA_MSG) { msg.headerextrav2.msid = log->msid; } -/* TODO: -#ifdef DLT_TRACE_LOAD_CTRL_ENABLE - time_stamp = msg.headerextra.tmsp; -#endif -*/ + /* TODO: + #ifdef DLT_TRACE_LOAD_CTRL_ENABLE + time_stamp = msg.headerextra.tmsp; + #endif + */ if (dlt_message_set_extraparameters_v2(&msg, 0) != DLT_RETURN_OK) return DLT_RETURN_ERROR; @@ -5531,7 +5299,7 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl if (__builtin_expect(!!(dlt_user.local_pid == -1), false)) { dlt_user.local_pid = getpid(); } - msg.extendedheaderv2.seid = (uint32_t) dlt_user.local_pid; + msg.extendedheaderv2.seid = (uint32_t)dlt_user.local_pid; } if (DLT_IS_HTYP2_WSFLN(msg.baseheaderv2->htyp2)) { @@ -5549,7 +5317,7 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl if (msg.extendedheaderv2.notg == 0) { msg.extendedheaderv2.tag = NULL; } else { - msg.extendedheaderv2.tag = (DltTag *)malloc((msg.extendedheaderv2.notg) * sizeof(DltTag)); + msg.extendedheaderv2.tag = (DltTag*)malloc((msg.extendedheaderv2.notg) * sizeof(DltTag)); if (msg.extendedheaderv2.tag == NULL) { return DLT_RETURN_ERROR; } @@ -5590,11 +5358,10 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl } len = (uint32_t)tmplen; - msg.baseheaderv2->len = DLT_HTOBE_16((uint16_t) len); + msg.baseheaderv2->len = DLT_HTOBE_16((uint16_t)len); /* print to std out, if enabled */ - if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) && - (dlt_user.local_print_mode != DLT_PM_AUTOMATIC)) { + if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) && (dlt_user.local_print_mode != DLT_PM_AUTOMATIC)) { if ((dlt_user.enable_local_print) || (dlt_user.local_print_mode == DLT_PM_FORCE_ON)) if (dlt_user_print_msg_v2(&msg, log) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; @@ -5603,34 +5370,32 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl if (dlt_user.dlt_is_file) { if (dlt_user_file_reach_max) { return DLT_RETURN_FILESZERR; - } - else { + } else { /* Get file size */ struct stat st; - if(fstat(dlt_user.dlt_log_handle, &st) != 0) { - dlt_vlog(LOG_WARNING, - "%s: Cannot get file information (errno=%d)\n", __func__, errno); + if (fstat(dlt_user.dlt_log_handle, &st) != 0) { + dlt_vlog(LOG_WARNING, "%s: Cannot get file information (errno=%d)\n", __func__, errno); return DLT_RETURN_ERROR; } - dlt_vlog(LOG_DEBUG, "%s: Current file size=[%lld]\n", __func__, - (long long)st.st_size); + dlt_vlog(LOG_DEBUG, "%s: Current file size=[%lld]\n", __func__, (long long)st.st_size); /* Check filesize */ /* Return error if the file size has reached to maximum */ unsigned int msg_size = 0; if (st.st_size < 0 || st.st_size > UINT_MAX) { - dlt_vlog(LOG_ERR, "%s: File size (%lld bytes) is invalid or too large for unsigned int\n", __func__, (long long)st.st_size); + dlt_vlog( + LOG_ERR, "%s: File size (%lld bytes) is invalid or too large for unsigned int\n", __func__, + (long long)st.st_size); return DLT_RETURN_FILESZERR; } - msg_size = (unsigned int)st.st_size + (unsigned int) msg.headersizev2 + (unsigned int) log->size; + msg_size = (unsigned int)st.st_size + (unsigned int)msg.headersizev2 + (unsigned int)log->size; if (msg_size > dlt_user.filesize_max) { dlt_user_file_reach_max = true; - dlt_vlog(LOG_ERR, - "%s: File size (%lld bytes) reached to defined maximum size (%d bytes)\n", - __func__, (long long)st.st_size, dlt_user.filesize_max); + dlt_vlog( + LOG_ERR, "%s: File size (%lld bytes) reached to defined maximum size (%d bytes)\n", __func__, + (long long)st.st_size, dlt_user.filesize_max); return DLT_RETURN_FILESZERR; - } - else { + } else { /* log to file */ int32_t headersizev2 = msg.headersizev2; int32_t logsize = log->size; @@ -5638,9 +5403,8 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl dlt_log(LOG_WARNING, "Negative header or log size!\n"); return DLT_RETURN_ERROR; } - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - msg.headerbufferv2, (size_t)headersizev2, - log->buffer, (size_t)logsize); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, msg.headerbufferv2, (size_t)headersizev2, log->buffer, (size_t)logsize); return ret; } } @@ -5664,51 +5428,40 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl #ifdef DLT_SHM_ENABLE if (dlt_user.dlt_log_handle != -1) - dlt_shm_push(&dlt_user.dlt_shm, msg.headerbufferv2 + msg.storageheadersizev2, - msg.headersizev2 - msg.storageheadersizev2, - log->buffer, log->size, 0, 0); - - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - 0, 0, - 0, 0); + dlt_shm_push( + &dlt_user.dlt_shm, msg.headerbufferv2 + msg.storageheadersizev2, + msg.headersizev2 - msg.storageheadersizev2, log->buffer, log->size, 0, 0); + + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), 0, 0, 0, 0); #else -# ifdef DLT_TEST_ENABLE +#ifdef DLT_TEST_ENABLE if (dlt_user.corrupt_user_header) { - userheader.pattern[0] = (char) 0xff; - userheader.pattern[1] = (char) 0xff; - userheader.pattern[2] = (char) 0xff; - userheader.pattern[3] = (char) 0xff; + userheader.pattern[0] = (char)0xff; + userheader.pattern[1] = (char)0xff; + userheader.pattern[2] = (char)0xff; + userheader.pattern[3] = (char)0xff; } if (dlt_user.corrupt_message_size) msg.baseheaderv2->len = DLT_HTOBE_16(dlt_user.corrupt_message_size_size); -# endif +#endif #ifdef DLT_TRACE_LOAD_CTRL_ENABLE /* check trace load before output */ - if (!sent_size) - { + if (!sent_size) { pthread_rwlock_wrlock(&trace_load_rw_lock); - DltTraceLoadSettings* settings = - dlt_find_runtime_trace_load_settings( - trace_load_settings, trace_load_settings_count, dlt_user.appID2, log->handle->contextID2); + DltTraceLoadSettings* settings = dlt_find_runtime_trace_load_settings( + trace_load_settings, trace_load_settings_count, dlt_user.appID2, log->handle->contextID2); const bool trace_load_in_limits = dlt_check_trace_load( - settings, - log->log_level, time_stamp, - sizeof(DltUserHeader) - + msg.headersizev2 - msg.storageheadersizev2 - + log->size, - dlt_user_output_internal_msg, - NULL); + settings, log->log_level, time_stamp, + sizeof(DltUserHeader) + msg.headersizev2 - msg.storageheadersizev2 + log->size, + dlt_user_output_internal_msg, NULL); pthread_rwlock_unlock(&trace_load_rw_lock); - if (!trace_load_in_limits){ + if (!trace_load_in_limits) { return DLT_RETURN_LOAD_EXCEEDED; } - } - else - { + } else { *sent_size = (sizeof(DltUserHeader) + msg.headersizev2 - msg.storageheadersizev2 + log->size); } #endif @@ -5719,11 +5472,9 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl dlt_log(LOG_WARNING, "Negative header or log size!\n"); return DLT_RETURN_ERROR; } - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - msg.headerbufferv2 + msg.storageheadersizev2, - (uint32_t)header_size, - log->buffer, (size_t)logsize); + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), + msg.headerbufferv2 + msg.storageheadersizev2, (uint32_t)header_size, log->buffer, (size_t)logsize); #endif } @@ -5731,28 +5482,25 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl DltReturnValue process_error_ret = DLT_RETURN_OK; /* store message in ringbuffer, if an error has occurred */ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - if (((ret!=DLT_RETURN_OK) || (dlt_user.appID2len == 0)) && !sent_size) + if (((ret != DLT_RETURN_OK) || (dlt_user.appID2len == 0)) && !sent_size) #else if ((ret != DLT_RETURN_OK) || (dlt_user.appID2len == 0)) #endif - { - int32_t header_size2 = (int32_t)msg.headersizev2 - (int32_t)msg.storageheadersizev2; - int32_t logsize2 = log->size; - if (header_size2 < 0 || logsize2 < 0) { - dlt_log(LOG_WARNING, "Negative header or log size!\n"); - return DLT_RETURN_ERROR; + { + int32_t header_size2 = (int32_t)msg.headersizev2 - (int32_t)msg.storageheadersizev2; + int32_t logsize2 = log->size; + if (header_size2 < 0 || logsize2 < 0) { + dlt_log(LOG_WARNING, "Negative header or log size!\n"); + return DLT_RETURN_ERROR; + } + process_error_ret = dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), msg.headerbufferv2 + msg.storageheadersizev2, + (uint32_t)header_size2, log->buffer, (size_t)logsize2); } - process_error_ret = dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - msg.headerbufferv2 + msg.storageheadersizev2, - (uint32_t)header_size2, - log->buffer, - (size_t)logsize2); - } if (process_error_ret == DLT_RETURN_OK) { { - unsigned char *headerbufferv2_ptr = msg.headerbufferv2; + unsigned char* headerbufferv2_ptr = msg.headerbufferv2; dlt_user_free_buffer(&headerbufferv2_ptr); } return DLT_RETURN_OK; @@ -5766,54 +5514,49 @@ DltReturnValue dlt_user_log_send_log_v2(DltContextData *log, const int mtype, Dl /* handle return value of function dlt_user_log_out3() when process_error_ret < 0*/ switch (ret) { - case DLT_RETURN_PIPE_FULL: - { - /* data could not be written */ - return DLT_RETURN_PIPE_FULL; - } - case DLT_RETURN_PIPE_ERROR: - { - /* handle not open or pipe error */ - dlt_mutex_lock(); - close(dlt_user.dlt_log_handle); - dlt_user.dlt_log_handle = -1; - dlt_mutex_unlock(); + case DLT_RETURN_PIPE_FULL: { + /* data could not be written */ + return DLT_RETURN_PIPE_FULL; + } + case DLT_RETURN_PIPE_ERROR: { + /* handle not open or pipe error */ + dlt_mutex_lock(); + close(dlt_user.dlt_log_handle); + dlt_user.dlt_log_handle = -1; + dlt_mutex_unlock(); #if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC dlt_user.connection_state = DLT_USER_RETRY_CONNECT; #endif - #ifdef DLT_SHM_ENABLE +#ifdef DLT_SHM_ENABLE /* free shared memory */ dlt_shm_free_client(&dlt_user.dlt_shm); - #endif +#endif if (dlt_user.local_print_mode == DLT_PM_AUTOMATIC) dlt_user_print_msg_v2(&msg, log); return DLT_RETURN_PIPE_ERROR; } - case DLT_RETURN_ERROR: - { + case DLT_RETURN_ERROR: { /* other error condition */ return DLT_RETURN_ERROR; } - case DLT_RETURN_OK: - { + case DLT_RETURN_OK: { { - unsigned char *headerbufferv2_ptr = msg.headerbufferv2; + unsigned char* headerbufferv2_ptr = msg.headerbufferv2; dlt_user_free_buffer(&headerbufferv2_ptr); } return DLT_RETURN_OK; } - default: - { + default: { /* This case should never occur. */ return DLT_RETURN_ERROR; } } } - unsigned char *headerbufferv2_ptr = msg.headerbufferv2; + unsigned char* headerbufferv2_ptr = msg.headerbufferv2; dlt_user_free_buffer(&headerbufferv2_ptr); return DLT_RETURN_OK; } @@ -5833,30 +5576,26 @@ DltReturnValue dlt_user_log_send_register_application(void) return DLT_RETURN_ERROR; /* set usercontext */ - dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ usercontext.pid = getpid(); if (dlt_user.application_description != NULL) - usercontext.description_length = (uint32_t) strlen(dlt_user.application_description); + usercontext.description_length = (uint32_t)strlen(dlt_user.application_description); else usercontext.description_length = 0; if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgRegisterApplication), - dlt_user.application_description, usercontext.description_length); + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgRegisterApplication), dlt_user.application_description, usercontext.description_length); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgRegisterApplication), - dlt_user.application_description, - usercontext.description_length); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterApplication), + dlt_user.application_description, usercontext.description_length); return DLT_RETURN_OK; } @@ -5867,7 +5606,7 @@ DltReturnValue dlt_user_log_send_register_application_v2(void) DltUserControlMsgRegisterApplicationV2 usercontext; char apid_local[DLT_V2_ID_SIZE]; usercontext.apid = apid_local; - uint8_t *buffer; + uint8_t* buffer; DltReturnValue ret; int usercontextSize; @@ -5884,7 +5623,7 @@ DltReturnValue dlt_user_log_send_register_application_v2(void) usercontext.pid = getpid(); if (dlt_user.application_description != NULL) - usercontext.description_length = (uint32_t) strlen(dlt_user.application_description); + usercontext.description_length = (uint32_t)strlen(dlt_user.application_description); else usercontext.description_length = 0; @@ -5905,19 +5644,15 @@ DltReturnValue dlt_user_log_send_register_application_v2(void) memcpy((buffer + 1 + usercontext.apidlen), &(usercontext.pid), sizeof(pid_t)); memcpy((buffer + 1 + usercontext.apidlen + sizeof(pid_t)), &(usercontext.description_length), sizeof(uint32_t)); - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - buffer, (size_t)usercontextSize, - dlt_user.application_description, usercontext.description_length); + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize, + dlt_user.application_description, usercontext.description_length); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - ret = dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)usercontextSize, - dlt_user.application_description, - usercontext.description_length); + ret = dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize, dlt_user.application_description, + usercontext.description_length); free(buffer); @@ -5938,24 +5673,21 @@ DltReturnValue dlt_user_log_send_unregister_application(void) return DLT_RETURN_ERROR; /* set usercontext */ - dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ usercontext.pid = getpid(); if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgUnregisterApplication)); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgUnregisterApplication)); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgUnregisterApplication), - NULL, - 0); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgUnregisterApplication), NULL, + 0); return DLT_RETURN_OK; } @@ -5966,7 +5698,7 @@ DltReturnValue dlt_user_log_send_unregister_application_v2(void) DltUserControlMsgUnregisterApplicationV2 usercontext; char apid_local[DLT_V2_ID_SIZE]; usercontext.apid = apid_local; - uint8_t *buffer; + uint8_t* buffer; DltReturnValue ret; int usercontextSize; @@ -5994,23 +5726,18 @@ DltReturnValue dlt_user_log_send_unregister_application_v2(void) memcpy(buffer + 1, usercontext.apid, usercontext.apidlen); memcpy((buffer + 1 + usercontext.apidlen), &(usercontext.pid), sizeof(pid_t)); - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - buffer, (size_t)usercontextSize); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - ret = dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)usercontextSize, - NULL, - 0); + ret = dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize, NULL, 0); free(buffer); return ret; } -DltReturnValue dlt_user_log_send_register_context(DltContextData *log) +DltReturnValue dlt_user_log_send_register_context(DltContextData* log) { DltUserHeader userheader; DltUserControlMsgRegisterContext usercontext; @@ -6030,16 +5757,16 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log) return DLT_RETURN_ERROR; /* set usercontext */ - dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ - dlt_set_id(usercontext.ctid, log->handle->contextID); /* context id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ + dlt_set_id(usercontext.ctid, log->handle->contextID); /* context id */ usercontext.log_level_pos = log->handle->log_level_pos; usercontext.pid = getpid(); - usercontext.log_level = (int8_t) log->log_level; - usercontext.trace_status = (int8_t) log->trace_status; + usercontext.log_level = (int8_t)log->log_level; + usercontext.trace_status = (int8_t)log->trace_status; if (log->context_description != NULL) - usercontext.description_length = (uint32_t) strlen(log->context_description); + usercontext.description_length = (uint32_t)strlen(log->context_description); else usercontext.description_length = 0; @@ -6047,34 +5774,25 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log) return DLT_RETURN_OK; if (dlt_user.appID[0] != '\0') - ret = - dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgRegisterContext), - log->context_description, - usercontext.description_length); + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgRegisterContext), log->context_description, usercontext.description_length); /* store message in ringbuffer, if an error has occured */ if ((ret != DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgRegisterContext), - log->context_description, - usercontext.description_length); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext), + log->context_description, usercontext.description_length); return DLT_RETURN_OK; - } -DltReturnValue dlt_user_log_send_register_context_v2(DltContextData *log) +DltReturnValue dlt_user_log_send_register_context_v2(DltContextData* log) { DltUserHeader userheader; DltUserControlMsgRegisterContextV2 usercontext; DltReturnValue ret = DLT_RETURN_ERROR; - uint8_t *buffer; + uint8_t* buffer; int usercontextSize; int offset = 0; char apid_local[DLT_V2_ID_SIZE]; @@ -6102,19 +5820,19 @@ DltReturnValue dlt_user_log_send_register_context_v2(DltContextData *log) usercontext.log_level_pos = log->handle->log_level_pos; usercontext.pid = getpid(); - usercontext.log_level = (int8_t) log->log_level; - usercontext.trace_status = (int8_t) log->trace_status; + usercontext.log_level = (int8_t)log->log_level; + usercontext.trace_status = (int8_t)log->trace_status; if (log->context_description != NULL) - usercontext.description_length = (uint32_t) strlen(log->context_description); + usercontext.description_length = (uint32_t)strlen(log->context_description); else usercontext.description_length = 0; if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - usercontextSize = (int)sizeof(uint8_t) + usercontext.apidlen + - (int)sizeof(uint8_t) + usercontext.ctidlen + 10 + (int)sizeof(pid_t); + usercontextSize = (int)sizeof(uint8_t) + usercontext.apidlen + (int)sizeof(uint8_t) + usercontext.ctidlen + 10 + + (int)sizeof(pid_t); buffer = (uint8_t*)malloc((size_t)usercontextSize); if (!buffer) return DLT_RETURN_ERROR; @@ -6139,29 +5857,21 @@ DltReturnValue dlt_user_log_send_register_context_v2(DltContextData *log) offset = offset + 4; if (dlt_user.appID2len != 0) - ret = - dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)usercontextSize, - log->context_description, - usercontext.description_length); + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize, + log->context_description, usercontext.description_length); /* store message in ringbuffer, if an error has occured */ if ((ret != DLT_RETURN_OK) || (dlt_user.appID2len == 0)) - ret = dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)usercontextSize, - log->context_description, - usercontext.description_length); + ret = dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize, log->context_description, + usercontext.description_length); free(buffer); return ret; } -DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log) +DltReturnValue dlt_user_log_send_unregister_context(DltContextData* log) { DltUserHeader userheader; DltUserControlMsgUnregisterContext usercontext; @@ -6181,37 +5891,31 @@ DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log) return DLT_RETURN_ERROR; /* set usercontext */ - dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ - dlt_set_id(usercontext.ctid, log->handle->contextID); /* context id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ + dlt_set_id(usercontext.ctid, log->handle->contextID); /* context id */ usercontext.pid = getpid(); if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgUnregisterContext)); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgUnregisterContext)); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgUnregisterContext), - NULL, - 0); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgUnregisterContext), NULL, 0); return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_send_unregister_context_v2(DltContextData *log) +DltReturnValue dlt_user_log_send_unregister_context_v2(DltContextData* log) { DltUserHeader userheader; DltUserControlMsgUnregisterContextV2 usercontext; DltReturnValue ret; - uint8_t *buffer; + uint8_t* buffer; int usercontextSize; int offset = 0; char apid_local[DLT_V2_ID_SIZE]; @@ -6242,8 +5946,8 @@ DltReturnValue dlt_user_log_send_unregister_context_v2(DltContextData *log) if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - usercontextSize = (int)sizeof(uint8_t) + usercontext.apidlen + - (int)sizeof(uint8_t) + usercontext.ctidlen + (int)sizeof(pid_t); + usercontextSize = + (int)sizeof(uint8_t) + usercontext.apidlen + (int)sizeof(uint8_t) + usercontext.ctidlen + (int)sizeof(pid_t); buffer = (uint8_t*)malloc((size_t)usercontextSize); if (!buffer) return DLT_RETURN_ERROR; @@ -6259,25 +5963,18 @@ DltReturnValue dlt_user_log_send_unregister_context_v2(DltContextData *log) memcpy(buffer + offset, &(usercontext.pid), sizeof(pid_t)); offset = offset + (int)sizeof(pid_t); - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)usercontextSize); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - ret = dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)usercontextSize, - NULL, - 0); + ret = dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), buffer, (size_t)usercontextSize, NULL, 0); free(buffer); return DLT_RETURN_OK; } -DltReturnValue dlt_send_app_ll_ts_limit(const char *apid, DltLogLevelType loglevel, DltTraceStatusType tracestatus) +DltReturnValue dlt_send_app_ll_ts_limit(const char* apid, DltLogLevelType loglevel, DltTraceStatusType tracestatus) { DltUserHeader userheader; DltUserControlMsgAppLogLevelTraceStatus usercontext; @@ -6301,30 +5998,27 @@ DltReturnValue dlt_send_app_ll_ts_limit(const char *apid, DltLogLevelType loglev return DLT_RETURN_ERROR; /* set usercontext */ - dlt_set_id(usercontext.apid, apid); /* application id */ + dlt_set_id(usercontext.apid, apid); /* application id */ usercontext.log_level = loglevel; usercontext.trace_status = tracestatus; if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgAppLogLevelTraceStatus)); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), + sizeof(DltUserControlMsgAppLogLevelTraceStatus)); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - &(usercontext), - sizeof(DltUserControlMsgAppLogLevelTraceStatus), - NULL, - 0); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgAppLogLevelTraceStatus), NULL, + 0); return DLT_RETURN_OK; } -DltReturnValue dlt_send_app_ll_ts_limit_v2(const char *apid, DltLogLevelType loglevel, DltTraceStatusType tracestatus) +DltReturnValue dlt_send_app_ll_ts_limit_v2(const char* apid, DltLogLevelType loglevel, DltTraceStatusType tracestatus) { DltUserHeader userheader; DltUserControlMsgAppLogLevelTraceStatusV2 usercontext; @@ -6376,18 +6070,12 @@ DltReturnValue dlt_send_app_ll_ts_limit_v2(const char *apid, DltLogLevelType log if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - buffer, (size_t)buffersize); + ret = dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), buffer, (size_t)buffersize); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - buffer, - (size_t)buffersize, - NULL, - 0); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), buffer, (size_t)buffersize, NULL, 0); return DLT_RETURN_OK; } @@ -6407,12 +6095,10 @@ DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode, uint8_t version) if (version == DLTProtocolV1) { if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_MODE) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - } - else if (version == DLTProtocolV2) { + } else if (version == DLTProtocolV2) { if (dlt_user_set_userheader_v2(&userheader, DLT_USER_MESSAGE_LOG_MODE) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - } - else { + } else { return DLT_RETURN_ERROR; } @@ -6422,18 +6108,13 @@ DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode, uint8_t version) if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(logmode), sizeof(DltUserControlMsgLogMode)); + ret = dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(logmode), sizeof(DltUserControlMsgLogMode)); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - &(logmode), - sizeof(DltUserControlMsgLogMode), - NULL, - 0); + return dlt_user_log_out_error_handling( + &(userheader), sizeof(DltUserHeader), &(logmode), sizeof(DltUserControlMsgLogMode), NULL, 0); return DLT_RETURN_OK; } @@ -6444,13 +6125,13 @@ DltReturnValue dlt_user_log_send_marker() DltReturnValue ret; /* set userheader */ - if(dlt_user.appID[0] != '\0'){ + if (dlt_user.appID[0] != '\0') { if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_MARKER) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - }else if (dlt_user.appID2len != 0){ + } else if (dlt_user.appID2len != 0) { if (dlt_user_set_userheader_v2(&userheader, DLT_USER_MESSAGE_MARKER) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - }else { + } else { return DLT_RETURN_ERROR; } @@ -6458,24 +6139,18 @@ DltReturnValue dlt_user_log_send_marker() return DLT_RETURN_OK; /* log to FIFO */ - ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), 0, 0); + ret = dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), 0, 0); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - return dlt_user_log_out_error_handling(&(userheader), - sizeof(DltUserHeader), - NULL, - 0, - NULL, - 0); + return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), NULL, 0, NULL, 0); return DLT_RETURN_OK; } -DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log) +DltReturnValue dlt_user_print_msg(DltMessage* msg, DltContextData* log) { - uint8_t *databuffer_tmp; + uint8_t* databuffer_tmp; uint32_t datasize_tmp; uint32_t databuffersize_tmp; static char text[DLT_USER_TEXT_LENGTH]; @@ -6510,9 +6185,9 @@ DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log) return DLT_RETURN_OK; } -DltReturnValue dlt_user_print_msg_v2(DltMessageV2 *msg, DltContextData *log) +DltReturnValue dlt_user_print_msg_v2(DltMessageV2* msg, DltContextData* log) { - uint8_t *databuffer_tmp; + uint8_t* databuffer_tmp; int32_t datasize_tmp; int32_t databuffersize_tmp; static char text[DLT_USER_TEXT_LENGTH]; @@ -6526,8 +6201,8 @@ DltReturnValue dlt_user_print_msg_v2(DltMessageV2 *msg, DltContextData *log) /* Act like a receiver, convert header back to host format */ msg->baseheaderv2->len = DLT_BETOH_16(msg->baseheaderv2->len); - //dlt_message_get_storageparameters_v2(msg, 0); - //dlt_message_get_extraparameters_v2(msg, 0); + // dlt_message_get_storageparameters_v2(msg, 0); + // dlt_message_get_extraparameters_v2(msg, 0); msg->databuffer = log->buffer; if (log->size < 0) { @@ -6549,17 +6224,19 @@ DltReturnValue dlt_user_print_msg_v2(DltMessageV2 *msg, DltContextData *log) return DLT_RETURN_OK; } -int dlt_get_extendedheadersize_v2(DltUser dlt_user_param, int contextIDSize) { +int dlt_get_extendedheadersize_v2(DltUser dlt_user_param, int contextIDSize) +{ int size = 0; /* Each variable-length field is: 1 byte length + N bytes data (NO null terminator) */ - size += (1 + ((int)dlt_user_param.ecuID2len))*((int)dlt_user_param.with_ecu_id); - size += (int)(sizeof(uint32_t))*((int)dlt_user_param.with_session_id); - size += (1 + ((int)dlt_user_param.appID2len) + 1 + (contextIDSize))*((int)dlt_user_param.with_app_and_context_id); - size += (1 + ((int)dlt_user_param.filenamelen) + (int)sizeof(dlt_user_param.linenumber))*((int)dlt_user_param.with_filename_and_line_number); - size += (1 + ((int)dlt_user_param.tagbuffersize))*((int)dlt_user_param.with_tags); - size += (int)(sizeof(dlt_user_param.prlv))*((int)dlt_user_param.with_privacy_level); - //To Update: 8 with segmentation data size depending on type of frame (8, 4 or 0) - size += ((int)(sizeof(uint8_t))+(int)(sizeof(uint8_t))+8)*((int)dlt_user_param.with_segmentation); + size += (1 + ((int)dlt_user_param.ecuID2len)) * ((int)dlt_user_param.with_ecu_id); + size += (int)(sizeof(uint32_t)) * ((int)dlt_user_param.with_session_id); + size += (1 + ((int)dlt_user_param.appID2len) + 1 + (contextIDSize)) * ((int)dlt_user_param.with_app_and_context_id); + size += (1 + ((int)dlt_user_param.filenamelen) + (int)sizeof(dlt_user_param.linenumber)) + * ((int)dlt_user_param.with_filename_and_line_number); + size += (1 + ((int)dlt_user_param.tagbuffersize)) * ((int)dlt_user_param.with_tags); + size += (int)(sizeof(dlt_user_param.prlv)) * ((int)dlt_user_param.with_privacy_level); + // To Update: 8 with segmentation data size depending on type of frame (8, 4 or 0) + size += ((int)(sizeof(uint8_t)) + (int)(sizeof(uint8_t)) + 8) * ((int)dlt_user_param.with_segmentation); return size; } @@ -6575,16 +6252,16 @@ DltReturnValue dlt_user_log_check_user_message(void) int fd; struct pollfd nfd[1]; - DltUserHeader *userheader; - DltReceiver *receiver = &(dlt_user.receiver); + DltUserHeader* userheader; + DltReceiver* receiver = &(dlt_user.receiver); - DltUserControlMsgLogLevel *usercontextll; - DltUserControlMsgInjection *usercontextinj; - DltUserControlMsgLogState *userlogstate; - unsigned char *userbuffer; + DltUserControlMsgLogLevel* usercontextll; + DltUserControlMsgInjection* usercontextinj; + DltUserControlMsgLogState* userlogstate; + unsigned char* userbuffer; #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - DltUserControlMsgTraceSettingMsg *trace_load_settings_user_messages; + DltUserControlMsgTraceSettingMsg* trace_load_settings_user_messages; uint32_t trace_load_settings_user_messages_count = 0; uint32_t trace_load_settings_user_message_bytes_required = 0; unsigned long trace_load_settings_alloc_size = 0; @@ -6593,7 +6270,7 @@ DltReturnValue dlt_user_log_check_user_message(void) /* For delayed calling of injection callback, to avoid deadlock */ DltUserInjectionCallback delayed_injection_callback; DltUserLogLevelChangedCallback delayed_log_level_changed_callback; - unsigned char *delayed_inject_buffer = 0; + unsigned char* delayed_inject_buffer = 0; uint32_t delayed_inject_data_length = 0; /* Ensure that callback is null before searching for it */ @@ -6626,14 +6303,14 @@ DltReturnValue dlt_user_log_check_user_message(void) /* look through buffer as long as data is in there */ while (1) { - if (receiver->bytesRcvd < (int32_t) sizeof(DltUserHeader)) + if (receiver->bytesRcvd < (int32_t)sizeof(DltUserHeader)) break; /* resync if necessary */ offset = 0; do { - userheader = (DltUserHeader *)(receiver->buf + offset); + userheader = (DltUserHeader*)(receiver->buf + offset); /* Check for user header pattern */ if (dlt_user_check_userheader(userheader)) @@ -6641,11 +6318,10 @@ DltReturnValue dlt_user_log_check_user_message(void) offset++; - } while (((int32_t) (sizeof(DltUserHeader)) + offset) <= receiver->bytesRcvd); + } while (((int32_t)(sizeof(DltUserHeader)) + offset) <= receiver->bytesRcvd); /* Check for user header pattern */ - if ((dlt_user_check_userheader(userheader) < 0) || - (dlt_user_check_userheader(userheader) == 0)) + if ((dlt_user_check_userheader(userheader) < 0) || (dlt_user_check_userheader(userheader) == 0)) break; /* Set new start offset */ @@ -6657,55 +6333,60 @@ DltReturnValue dlt_user_log_check_user_message(void) version = dlt_get_version_from_userheader(userheader); switch (userheader->message) { - case DLT_USER_MESSAGE_LOG_LEVEL: - { - if (receiver->bytesRcvd < (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel))) { + case DLT_USER_MESSAGE_LOG_LEVEL: { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel))) { leave_while = 1; break; } - usercontextll = (DltUserControlMsgLogLevel *)(receiver->buf + sizeof(DltUserHeader)); + usercontextll = (DltUserControlMsgLogLevel*)(receiver->buf + sizeof(DltUserHeader)); /* Update log level and trace status */ if (usercontextll != NULL) { dlt_mutex_lock(); - if ((usercontextll->log_level_pos >= 0) && - (usercontextll->log_level_pos < (int32_t)dlt_user.dlt_ll_ts_num_entries)) { + if ((usercontextll->log_level_pos >= 0) + && (usercontextll->log_level_pos < (int32_t)dlt_user.dlt_ll_ts_num_entries)) { if (dlt_user.dlt_ll_ts) { - dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = (int8_t) usercontextll->log_level; + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = + (int8_t)usercontextll->log_level; dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = - (int8_t) usercontextll->trace_status; + (int8_t)usercontextll->trace_status; if (dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = - (int8_t) usercontextll->log_level; + (int8_t)usercontextll->log_level; if (dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = - (int8_t) usercontextll->trace_status; + (int8_t)usercontextll->trace_status; if (version == DLTProtocolV1) { delayed_log_level_changed_callback.log_level_changed_callback = dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_changed_callback; - dlt_set_id(delayed_log_level_changed_callback.contextID, - dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID); + dlt_set_id( + delayed_log_level_changed_callback.contextID, + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID); - delayed_log_level_changed_callback.log_level = (int8_t) usercontextll->log_level; - delayed_log_level_changed_callback.trace_status = (int8_t) usercontextll->trace_status; - }else if (version == DLTProtocolV2) { + delayed_log_level_changed_callback.log_level = (int8_t)usercontextll->log_level; + delayed_log_level_changed_callback.trace_status = + (int8_t)usercontextll->trace_status; + } else if (version == DLTProtocolV2) { delayed_log_level_changed_callback.log_level_changed_callback_v2 = dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_changed_callback_v2; - delayed_log_level_changed_callback.contextID2len = dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID2len; + delayed_log_level_changed_callback.contextID2len = + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID2len; - dlt_set_id_v2(delayed_log_level_changed_callback.contextID2, - dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID2, - dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID2len); + dlt_set_id_v2( + delayed_log_level_changed_callback.contextID2, + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID2, + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID2len); - delayed_log_level_changed_callback.log_level = (int8_t) usercontextll->log_level; - delayed_log_level_changed_callback.trace_status = (int8_t) usercontextll->trace_status; + delayed_log_level_changed_callback.log_level = (int8_t)usercontextll->log_level; + delayed_log_level_changed_callback.trace_status = + (int8_t)usercontextll->trace_status; } } } @@ -6718,46 +6399,41 @@ DltReturnValue dlt_user_log_check_user_message(void) if (delayed_log_level_changed_callback.log_level_changed_callback != 0) delayed_log_level_changed_callback.log_level_changed_callback( delayed_log_level_changed_callback.contextID, - (uint8_t) delayed_log_level_changed_callback.log_level, - (uint8_t) delayed_log_level_changed_callback.trace_status); + (uint8_t)delayed_log_level_changed_callback.log_level, + (uint8_t)delayed_log_level_changed_callback.trace_status); /* keep not read data in buffer */ - if (dlt_receiver_remove(receiver, - sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel)) == - DLT_RETURN_ERROR) + if (dlt_receiver_remove(receiver, sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel)) + == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - }else if (version == DLTProtocolV2) { + } else if (version == DLTProtocolV2) { if (delayed_log_level_changed_callback.log_level_changed_callback_v2 != 0) delayed_log_level_changed_callback.log_level_changed_callback_v2( delayed_log_level_changed_callback.contextID2, - (uint8_t) delayed_log_level_changed_callback.log_level, - (uint8_t) delayed_log_level_changed_callback.trace_status); + (uint8_t)delayed_log_level_changed_callback.log_level, + (uint8_t)delayed_log_level_changed_callback.trace_status); /* keep not read data in buffer */ - if (dlt_receiver_remove(receiver, - sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel)) == - DLT_RETURN_ERROR) + if (dlt_receiver_remove(receiver, sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel)) + == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; } - } - break; - case DLT_USER_MESSAGE_INJECTION: - { - /* At least, user header, user context, and service id and data_length of injected message is available */ - if (receiver->bytesRcvd < (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection))) { + } break; + case DLT_USER_MESSAGE_INJECTION: { + /* At least, user header, user context, and service id and data_length of injected message is + * available */ + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection))) { leave_while = 1; break; } - usercontextinj = (DltUserControlMsgInjection *)(receiver->buf + sizeof(DltUserHeader)); + usercontextinj = (DltUserControlMsgInjection*)(receiver->buf + sizeof(DltUserHeader)); userbuffer = - (unsigned char *)(receiver->buf + sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection)); + (unsigned char*)(receiver->buf + sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection)); if (userbuffer != NULL) { - - if (receiver->bytesRcvd < - (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + - usercontextinj->data_length_inject)) { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + + usercontextinj->data_length_inject)) { leave_while = 1; break; } @@ -6767,22 +6443,27 @@ DltReturnValue dlt_user_log_check_user_message(void) if ((usercontextinj->data_length_inject > 0) && (dlt_user.dlt_ll_ts)) /* Check if injection callback is registered for this context */ for (i = 0; i < dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].nrcallbacks; i++) - if ((dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table) && - (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].service_id == - usercontextinj->service_id)) { + if ((dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table) + && (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].service_id + == usercontextinj->service_id)) { /* Prepare delayed injection callback call */ - if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. - injection_callback != NULL) { + if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos] + .injection_table[i] + .injection_callback + != NULL) { delayed_injection_callback.injection_callback = - dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. - injection_callback; - } - else if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. - injection_callback_with_id != NULL) - { + dlt_user.dlt_ll_ts[usercontextinj->log_level_pos] + .injection_table[i] + .injection_callback; + } else if ( + dlt_user.dlt_ll_ts[usercontextinj->log_level_pos] + .injection_table[i] + .injection_callback_with_id + != NULL) { delayed_injection_callback.injection_callback_with_id = - dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. - injection_callback_with_id; + dlt_user.dlt_ll_ts[usercontextinj->log_level_pos] + .injection_table[i] + .injection_callback_with_id; delayed_injection_callback.data = dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].data; } @@ -6793,8 +6474,7 @@ DltReturnValue dlt_user_log_check_user_message(void) if (delayed_inject_buffer != NULL) { memcpy(delayed_inject_buffer, userbuffer, delayed_inject_data_length); - } - else { + } else { dlt_mutex_unlock(); dlt_log(LOG_WARNING, "malloc failed!\n"); return DLT_RETURN_ERROR; @@ -6806,20 +6486,18 @@ DltReturnValue dlt_user_log_check_user_message(void) dlt_mutex_unlock(); /* Delayed injection callback call */ - if ((delayed_inject_buffer != NULL) && - (delayed_injection_callback.injection_callback != NULL)) { - delayed_injection_callback.injection_callback(delayed_injection_callback.service_id, - delayed_inject_buffer, - delayed_inject_data_length); + if ((delayed_inject_buffer != NULL) + && (delayed_injection_callback.injection_callback != NULL)) { + delayed_injection_callback.injection_callback( + delayed_injection_callback.service_id, delayed_inject_buffer, + delayed_inject_data_length); delayed_injection_callback.injection_callback = NULL; - } - else if ((delayed_inject_buffer != NULL) && - (delayed_injection_callback.injection_callback_with_id != NULL)) - { - delayed_injection_callback.injection_callback_with_id(delayed_injection_callback.service_id, - delayed_inject_buffer, - delayed_inject_data_length, - delayed_injection_callback.data); + } else if ( + (delayed_inject_buffer != NULL) + && (delayed_injection_callback.injection_callback_with_id != NULL)) { + delayed_injection_callback.injection_callback_with_id( + delayed_injection_callback.service_id, delayed_inject_buffer, + delayed_inject_data_length, delayed_injection_callback.data); delayed_injection_callback.injection_callback_with_id = NULL; } @@ -6827,41 +6505,37 @@ DltReturnValue dlt_user_log_check_user_message(void) delayed_inject_buffer = NULL; /* keep not read data in buffer */ - if (dlt_receiver_remove(receiver, - (int) (sizeof(DltUserHeader) + - sizeof(DltUserControlMsgInjection) + - usercontextinj->data_length_inject)) != DLT_RETURN_OK) + if (dlt_receiver_remove( + receiver, (int)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + + usercontextinj->data_length_inject)) + != DLT_RETURN_OK) return DLT_RETURN_ERROR; } - } - break; - case DLT_USER_MESSAGE_LOG_STATE: - { - /* At least, user header, user context, and service id and data_length of injected message is available */ - if (receiver->bytesRcvd < (int32_t) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) { + } break; + case DLT_USER_MESSAGE_LOG_STATE: { + /* At least, user header, user context, and service id and data_length of injected message is + * available */ + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) { leave_while = 1; break; } - userlogstate = (DltUserControlMsgLogState *)(receiver->buf + sizeof(DltUserHeader)); + userlogstate = (DltUserControlMsgLogState*)(receiver->buf + sizeof(DltUserHeader)); dlt_user.log_state = userlogstate->log_state; /* keep not read data in buffer */ - if (dlt_receiver_remove(receiver, - (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) == - DLT_RETURN_ERROR) + if (dlt_receiver_remove(receiver, (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) + == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } - break; + } break; #ifdef DLT_TRACE_LOAD_CTRL_ENABLE - case DLT_USER_MESSAGE_TRACE_LOAD: - { + case DLT_USER_MESSAGE_TRACE_LOAD: { /* TODO: Need update for version 2 */ /* * at least user header and message length is available */ trace_load_settings_user_message_bytes_required = - (int32_t) (sizeof(DltUserHeader) + sizeof(uint32_t )); + (int32_t)(sizeof(DltUserHeader) + sizeof(uint32_t)); if (receiver->bytesRcvd < (int32_t)trace_load_settings_user_message_bytes_required) { // Not enough data to read the message length leave_while = 1; @@ -6871,7 +6545,8 @@ DltReturnValue dlt_user_log_check_user_message(void) // Read trace settings count from buffer. trace_load_settings_user_messages_count = (uint32_t)(*(receiver->buf + sizeof(DltUserHeader))); trace_load_settings_user_message_bytes_required += - (uint32_t)trace_load_settings_user_messages_count * (uint32_t)sizeof(DltUserControlMsgTraceSettingMsg); + (uint32_t)trace_load_settings_user_messages_count + * (uint32_t)sizeof(DltUserControlMsgTraceSettingMsg); if (receiver->bytesRcvd < (int32_t)trace_load_settings_user_message_bytes_required) { // Not enough data to read trace settings leave_while = 1; @@ -6879,7 +6554,7 @@ DltReturnValue dlt_user_log_check_user_message(void) } trace_load_settings_user_messages = - (DltUserControlMsgTraceSettingMsg *)(receiver->buf + sizeof(DltUserHeader) + sizeof(uint32_t)); + (DltUserControlMsgTraceSettingMsg*)(receiver->buf + sizeof(DltUserHeader) + sizeof(uint32_t)); pthread_rwlock_wrlock(&trace_load_rw_lock); @@ -6890,12 +6565,15 @@ DltReturnValue dlt_user_log_check_user_message(void) trace_load_settings = NULL; } - trace_load_settings_alloc_size = sizeof(DltTraceLoadSettings) * trace_load_settings_user_messages_count; + trace_load_settings_alloc_size = + sizeof(DltTraceLoadSettings) * trace_load_settings_user_messages_count; trace_load_settings = malloc(trace_load_settings_alloc_size); - if (trace_load_settings == NULL) { + if (trace_load_settings == NULL) { pthread_rwlock_unlock(&trace_load_rw_lock); - dlt_vlog(LOG_EMERG, "Unable to allocate memory for trace load settings, no logging will be possible\n"); - } else { + dlt_vlog( + LOG_EMERG, + "Unable to allocate memory for trace load settings, no logging will be possible\n"); + } else { memset(trace_load_settings, 0, trace_load_settings_alloc_size); for (i = 0; i < trace_load_settings_user_messages_count; i++) { memcpy(trace_load_settings[i].apid, dlt_user.appID, DLT_ID_SIZE); @@ -6905,9 +6583,9 @@ DltReturnValue dlt_user_log_check_user_message(void) } /* Publish the newly installed trace_load_settings (protected by rwlock) - * and then update the per-context pointer while holding the DLT mutex to - * avoid races with concurrent context registration/unregistration. - */ + * and then update the per-context pointer while holding the DLT mutex to + * avoid races with concurrent context registration/unregistration. + */ trace_load_settings_count = trace_load_settings_user_messages_count; pthread_rwlock_unlock(&trace_load_rw_lock); @@ -6919,7 +6597,7 @@ DltReturnValue dlt_user_log_check_user_message(void) } dlt_mutex_unlock(); - char **messages = malloc(trace_load_settings_count * sizeof(char *)); + char** messages = malloc(trace_load_settings_count * sizeof(char*)); if (messages == NULL) { pthread_rwlock_unlock(&trace_load_rw_lock); dlt_vlog(LOG_ERR, "unable to allocate memory for trace load message buffer\n"); @@ -6928,16 +6606,21 @@ DltReturnValue dlt_user_log_check_user_message(void) for (i = 0U; i < trace_load_settings_count; i++) { messages[i] = malloc(255 * sizeof(char)); if (messages[i] == NULL) { - dlt_vlog(LOG_ERR, "unable to allocate memory for trace load message buffer, index: %u, skipping remaining entries\n", i); + dlt_vlog( + LOG_ERR, + "unable to allocate memory for trace load message buffer, index: %u, skipping " + "remaining entries\n", + i); break; } ++msg_count; - snprintf(messages[i], 255, "Received trace load settings: apid=%.4s%s%.4s, soft_limit=%u, hard_limit=%u\n", - trace_load_settings[i].apid, - trace_load_settings[i].ctid[0] == '\0' ? "" : ", ctid=", - trace_load_settings[i].ctid[0] == '\0' ? "" : trace_load_settings[i].ctid, - trace_load_settings[i].soft_limit, - trace_load_settings[i].hard_limit); + snprintf( + messages[i], 255, + "Received trace load settings: apid=%.4s%s%.4s, soft_limit=%u, hard_limit=%u\n", + trace_load_settings[i].apid, + trace_load_settings[i].ctid[0] == '\0' ? "" : ", ctid=", + trace_load_settings[i].ctid[0] == '\0' ? "" : trace_load_settings[i].ctid, + trace_load_settings[i].soft_limit, trace_load_settings[i].hard_limit); } /* Messages are emitted outside of both the rwlock and the DLT mutex */ for (i = 0U; i < msg_count; i++) { @@ -6954,18 +6637,15 @@ DltReturnValue dlt_user_log_check_user_message(void) == DLT_RETURN_ERROR) { return DLT_RETURN_ERROR; } - } - break; + } break; #endif - default: - { + default: { dlt_log(LOG_WARNING, "Invalid user message type received!\n"); /* Ignore result */ if (dlt_receiver_remove(receiver, sizeof(DltUserHeader)) == -1) dlt_log(LOG_WARNING, "Can't remove bytes from receiver\n"); /* In next invocation of while loop, a resync will be triggered if additional data was received */ - } - break; + } break; } /* switch() */ if (leave_while == 1) { @@ -7000,64 +6680,57 @@ DltReturnValue dlt_user_log_resend_buffer(void) count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); dlt_mutex_unlock(); - if(dlt_user.appID[0] == '\0') { + if (dlt_user.appID[0] == '\0') { for (num = 0; num < count; num++) { dlt_mutex_lock(); size = dlt_buffer_copy(&(dlt_user.startup_buffer), dlt_user.resend_buffer, dlt_user.log_buf_len); if (size > 0) { - DltUserHeader *userheader = (DltUserHeader *)(dlt_user.resend_buffer); + DltUserHeader* userheader = (DltUserHeader*)(dlt_user.resend_buffer); /* Add application id to the messages of needed*/ if (dlt_user_check_userheader(userheader)) { switch (userheader->message) { - case DLT_USER_MESSAGE_REGISTER_CONTEXT: - { - DltUserControlMsgRegisterContext *usercontext = - (DltUserControlMsgRegisterContext *)(dlt_user.resend_buffer + sizeof(DltUserHeader)); + case DLT_USER_MESSAGE_REGISTER_CONTEXT: { + DltUserControlMsgRegisterContext* usercontext = + (DltUserControlMsgRegisterContext*)(dlt_user.resend_buffer + sizeof(DltUserHeader)); if ((usercontext != 0) && (usercontext->apid[0] == '\0')) dlt_set_id(usercontext->apid, dlt_user.appID); break; } - case DLT_USER_MESSAGE_LOG: - { - DltExtendedHeader *extendedHeader = - (DltExtendedHeader *)(dlt_user.resend_buffer + sizeof(DltUserHeader) + - sizeof(DltStandardHeader) + - sizeof(DltStandardHeaderExtra)); - - if (((extendedHeader) != 0) && (extendedHeader->apid[0] == '\0')) /* if application id is empty, add it */ + case DLT_USER_MESSAGE_LOG: { + DltExtendedHeader* extendedHeader = + (DltExtendedHeader*)(dlt_user.resend_buffer + sizeof(DltUserHeader) + + sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra)); + + if (((extendedHeader) != 0) + && (extendedHeader->apid[0] == '\0')) /* if application id is empty, add it */ dlt_set_id(extendedHeader->apid, dlt_user.appID); break; } - default: - { + default: { break; } } } #ifdef DLT_SHM_ENABLE - dlt_shm_push(&dlt_user.dlt_shm, - dlt_user.resend_buffer + sizeof(DltUserHeader), - size - sizeof(DltUserHeader), - 0, - 0, - 0, - 0); - - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, sizeof(DltUserHeader), 0, 0, 0, 0); -#else /* DLT_SHM_ENABLE */ - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, (size_t) size, 0, 0, 0, 0); + dlt_shm_push( + &dlt_user.dlt_shm, dlt_user.resend_buffer + sizeof(DltUserHeader), size - sizeof(DltUserHeader), 0, + 0, 0, 0); + + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, dlt_user.resend_buffer, sizeof(DltUserHeader), 0, 0, 0, 0); +#else /* DLT_SHM_ENABLE */ + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, (size_t)size, 0, 0, 0, 0); #endif /* DLT_SHM_ENABLE */ /* in case of error, keep message in ringbuffer */ if (ret == DLT_RETURN_OK) { dlt_buffer_remove(&(dlt_user.startup_buffer)); - } - else { + } else { if (ret == DLT_RETURN_PIPE_ERROR) { /* handle not open or pipe error */ close(dlt_user.dlt_log_handle); @@ -7071,7 +6744,7 @@ DltReturnValue dlt_user_log_resend_buffer(void) } dlt_mutex_unlock(); } - }else if (dlt_user.appID2len != 0) { + } else if (dlt_user.appID2len != 0) { /* Initialize resend buffer for version 2*/ DltHtyp2ContentType msgcontent; if (dlt_user.verbose_mode == 1) { @@ -7085,31 +6758,27 @@ DltReturnValue dlt_user_log_resend_buffer(void) size = dlt_buffer_copy(&(dlt_user.startup_buffer), dlt_user.resend_buffer, dlt_user.log_buf_len); if (size > 0) { - DltUserHeader *userheader = (DltUserHeader *)(dlt_user.resend_buffer); + DltUserHeader* userheader = (DltUserHeader*)(dlt_user.resend_buffer); /* Add application id to the messages of needed*/ if (dlt_user_check_userheader(userheader)) { switch (userheader->message) { - case DLT_USER_MESSAGE_REGISTER_CONTEXT: - { + case DLT_USER_MESSAGE_REGISTER_CONTEXT: { DltUserControlMsgRegisterContextV2 usercontextv2; char resend_apid[DLT_V2_ID_SIZE]; usercontextv2.apid = resend_apid; usercontextv2.apidlen = dlt_user.appID2len; dlt_set_id_v2(usercontextv2.apid, dlt_user.appID2, dlt_user.appID2len); - memcpy(dlt_user.resend_buffer + sizeof(DltUserHeader), - &(usercontextv2.apidlen), - 1); + memcpy(dlt_user.resend_buffer + sizeof(DltUserHeader), &(usercontextv2.apidlen), 1); if (usercontextv2.apid != NULL && usercontextv2.apidlen > 0) { - memcpy(dlt_user.resend_buffer + sizeof(DltUserHeader) + 1, - usercontextv2.apid, + memcpy( + dlt_user.resend_buffer + sizeof(DltUserHeader) + 1, usercontextv2.apid, usercontextv2.apidlen); - } + } break; } - case DLT_USER_MESSAGE_LOG: - { + case DLT_USER_MESSAGE_LOG: { int offset = 0; DltExtendedHeaderV2 extendedheaderv2; char resend_apid2[DLT_V2_ID_SIZE]; @@ -7119,45 +6788,40 @@ DltReturnValue dlt_user_log_resend_buffer(void) if (dlt_user.with_ecu_id) { offset = dlt_user.ecuID2len + 1; }; - memcpy(dlt_user.resend_buffer + sizeof(DltUserHeader) + BASE_HEADER_V2_FIXED_SIZE + - dlt_message_get_extraparameters_size_v2(msgcontent) + offset, - &(extendedheaderv2.apidlen), - 1); + memcpy( + dlt_user.resend_buffer + sizeof(DltUserHeader) + BASE_HEADER_V2_FIXED_SIZE + + dlt_message_get_extraparameters_size_v2(msgcontent) + offset, + &(extendedheaderv2.apidlen), 1); if (extendedheaderv2.apid != NULL && extendedheaderv2.apidlen > 0) { - memcpy(dlt_user.resend_buffer + sizeof(DltUserHeader) + BASE_HEADER_V2_FIXED_SIZE + - dlt_message_get_extraparameters_size_v2(msgcontent) + offset + 1, - extendedheaderv2.apid, - extendedheaderv2.apidlen); - } + memcpy( + dlt_user.resend_buffer + sizeof(DltUserHeader) + BASE_HEADER_V2_FIXED_SIZE + + dlt_message_get_extraparameters_size_v2(msgcontent) + offset + 1, + extendedheaderv2.apid, extendedheaderv2.apidlen); + } break; } - default: - { + default: { break; } } } - #ifdef DLT_SHM_ENABLE - dlt_shm_push(&dlt_user.dlt_shm, - dlt_user.resend_buffer + sizeof(DltUserHeader), - size - sizeof(DltUserHeader), - 0, - 0, - 0, - 0); - - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, sizeof(DltUserHeader), 0, 0, 0, 0); - #else - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, (size_t) size, 0, 0, 0, 0); - #endif +#ifdef DLT_SHM_ENABLE + dlt_shm_push( + &dlt_user.dlt_shm, dlt_user.resend_buffer + sizeof(DltUserHeader), size - sizeof(DltUserHeader), 0, + 0, 0, 0); + + ret = dlt_user_log_out3( + dlt_user.dlt_log_handle, dlt_user.resend_buffer, sizeof(DltUserHeader), 0, 0, 0, 0); +#else + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, (size_t)size, 0, 0, 0, 0); +#endif /* in case of error, keep message in ringbuffer */ if (ret == DLT_RETURN_OK) { dlt_buffer_remove(&(dlt_user.startup_buffer)); - } - else { + } else { if (ret == DLT_RETURN_PIPE_ERROR) { /* handle not open or pipe error */ close(dlt_user.dlt_log_handle); @@ -7222,8 +6886,11 @@ void dlt_user_log_reattach_to_daemon(void) /* init shared memory */ if (dlt_shm_init_client(&dlt_user.dlt_shm, dltShmName) < DLT_RETURN_OK) - dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Logging disabled," - " Shared memory %s cannot be created!\n", dltShmName); + dlt_vnlog( + LOG_WARNING, DLT_USER_BUFFER_LENGTH, + "Logging disabled," + " Shared memory %s cannot be created!\n", + dltShmName); #endif @@ -7245,7 +6912,7 @@ void dlt_user_log_reattach_to_daemon(void) /* Re-register stored context */ if ((dlt_user.appID[0] != '\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0] != '\0')) { dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID); - handle.log_level_pos = (int32_t) num; + handle.log_level_pos = (int32_t)num; log_new.context_description = dlt_user.dlt_ll_ts[num].context_description; dlt_mutex_unlock(); log_new.log_level = DLT_USER_LOG_LEVEL_NOT_SET; @@ -7253,12 +6920,13 @@ void dlt_user_log_reattach_to_daemon(void) if (dlt_user_log_send_register_context(&log_new) < DLT_RETURN_ERROR) return; dlt_mutex_lock(); - } else if ((dlt_user.appID2len != 0) && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID2[0] != 0)) { + } else if ( + (dlt_user.appID2len != 0) && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID2[0] != 0)) { handle.contextID2len = dlt_user.dlt_ll_ts[num].contextID2len; /* Ensure handle.contextID2 points to a valid buffer before copying */ handle.contextID2 = dlt_user.dlt_ll_ts[num].contextID2; dlt_set_id_v2(handle.contextID2, dlt_user.dlt_ll_ts[num].contextID2, handle.contextID2len); - handle.log_level_pos = (int32_t) num; + handle.log_level_pos = (int32_t)num; log_new.context_description = dlt_user.dlt_ll_ts[num].context_description; dlt_mutex_unlock(); log_new.log_level = DLT_USER_LOG_LEVEL_NOT_SET; @@ -7282,7 +6950,7 @@ DltReturnValue dlt_user_log_send_overflow(void) if (dlt_user.dlt_is_file) return DLT_RETURN_OK; - if (dlt_user.appID[0] != '\0'){ + if (dlt_user.appID[0] != '\0') { /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_OVERFLOW) < DLT_RETURN_OK) return DLT_RETURN_ERROR; @@ -7291,9 +6959,9 @@ DltReturnValue dlt_user_log_send_overflow(void) userpayload2.overflow_counter = dlt_user.overflow_counter; userpayload2.apidlen = dlt_user.appID2len; dlt_set_id_v2(userpayload2.apid, dlt_user.appID2, dlt_user.appID2len); - return dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(userpayload), sizeof(DltUserControlMsgBufferOverflow)); + return dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(userpayload), + sizeof(DltUserControlMsgBufferOverflow)); } else if (dlt_user.appID2len != 0) { /* set userheader */ if (dlt_user_set_userheader_v2(&userheader, DLT_USER_MESSAGE_OVERFLOW) < DLT_RETURN_OK) @@ -7312,15 +6980,14 @@ DltReturnValue dlt_user_log_send_overflow(void) memcpy(buffer + sizeof(uint32_t) + sizeof(uint8_t), userpayload2.apid, userpayload2.apidlen); } - return dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - buffer, (size_t)buffersize); + return dlt_user_log_out2( + dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), buffer, (size_t)buffersize); } else { return DLT_RETURN_ERROR; } } -DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size) +DltReturnValue dlt_user_check_buffer(int* total_size, int* used_size) { if ((total_size == NULL) || (used_size == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -7331,7 +6998,7 @@ DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size) *total_size = dlt_shm_get_total_size(&(dlt_user.dlt_shm)); *used_size = dlt_shm_get_used_size(&(dlt_user.dlt_shm)); #else - *total_size = (int) dlt_buffer_get_total_size(&(dlt_user.startup_buffer)); + *total_size = (int)dlt_buffer_get_total_size(&(dlt_user.startup_buffer)); *used_size = dlt_buffer_get_used_size(&(dlt_user.startup_buffer)); #endif @@ -7360,8 +7027,8 @@ int dlt_start_threads() atomic_bool dlt_housekeeper_running = false; /* - * Configure the condition varibale to use CLOCK_MONOTONIC. - * This makes sure we're protected against changes in the system clock + * Configure the condition varibale to use CLOCK_MONOTONIC. + * This makes sure we're protected against changes in the system clock */ pthread_condattr_t attr; pthread_condattr_init(&attr); @@ -7370,10 +7037,9 @@ int dlt_start_threads() #endif pthread_cond_init(&dlt_housekeeper_running_cond, &attr); - if (pthread_create(&(dlt_housekeeperthread_handle), - 0, - dlt_user_housekeeperthread_function, - &dlt_housekeeper_running) != 0) { + if (pthread_create( + &(dlt_housekeeperthread_handle), 0, dlt_user_housekeeperthread_function, &dlt_housekeeper_running) + != 0) { dlt_log(LOG_CRIT, "Can't create housekeeper thread!\n"); return -1; } @@ -7384,25 +7050,23 @@ int dlt_start_threads() time_to_wait.tv_nsec = now.tv_nsec; /* - * wait until the house keeper is up and running - * Even though the condition variable and the while are - * using the same time out the while loop is not a no op. - * This is due to the fact that the pthread_cond_timedwait - * can be woken before time is up and dlt_housekeeper_running is not true yet. - * (spurious wakeup) - * To protect against this, a while loop with a timeout is added - * */ + * wait until the house keeper is up and running + * Even though the condition variable and the while are + * using the same time out the while loop is not a no op. + * This is due to the fact that the pthread_cond_timedwait + * can be woken before time is up and dlt_housekeeper_running is not true yet. + * (spurious wakeup) + * To protect against this, a while loop with a timeout is added + * */ // pthread_cond_timedwait has to be called on a locked mutex pthread_mutex_lock(&dlt_housekeeper_running_mutex); - while (!dlt_housekeeper_running - && now.tv_sec <= time_to_wait.tv_sec) { - + while (!dlt_housekeeper_running && now.tv_sec <= time_to_wait.tv_sec) { /* - * wait 500ms at a time - * this makes sure we don't block too long - * even if we missed the signal + * wait 500ms at a time + * this makes sure we don't block too long + * even if we missed the signal */ clock_gettime(CLOCK_MONOTONIC, &now); if (now.tv_nsec >= 500000000) { @@ -7413,29 +7077,26 @@ int dlt_start_threads() single_wait.tv_nsec = now.tv_nsec + 500000000; } - signal_status = pthread_cond_timedwait( - &dlt_housekeeper_running_cond, - &dlt_housekeeper_running_mutex, - &single_wait); + signal_status = + pthread_cond_timedwait(&dlt_housekeeper_running_cond, &dlt_housekeeper_running_mutex, &single_wait); /* otherwise it might be a spurious wakeup, try again until the time is over */ if (signal_status == 0) { break; } - } + } pthread_mutex_unlock(&dlt_housekeeper_running_mutex); - if (signal_status != 0 && !dlt_housekeeper_running) { - dlt_log(LOG_CRIT, "Failed to wait for house keeper thread!\n"); - dlt_stop_threads(); - return -1; - } + if (signal_status != 0 && !dlt_housekeeper_running) { + dlt_log(LOG_CRIT, "Failed to wait for house keeper thread!\n"); + dlt_stop_threads(); + return -1; + } #ifdef DLT_NETWORK_TRACE_ENABLE /* Start the segmented thread */ - if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL, - dlt_user_trace_network_segmented_thread, NULL)) { + if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL, dlt_user_trace_network_segmented_thread, NULL)) { dlt_log(LOG_CRIT, "Can't start segmented thread!\n"); return -1; } @@ -7463,14 +7124,14 @@ void dlt_stop_threads() if (dlt_housekeeperthread_result != 0) - dlt_vlog(LOG_ERR, - "ERROR %s(dlt_housekeeperthread_handle): %s\n", + dlt_vlog( + LOG_ERR, "ERROR %s(dlt_housekeeperthread_handle): %s\n", #ifndef __ANDROID_API__ - "pthread_cancel", + "pthread_cancel", #else - "pthread_kill", + "pthread_kill", #endif - strerror(dlt_housekeeperthread_result)); + strerror(dlt_housekeeperthread_result)); } #ifdef DLT_NETWORK_TRACE_ENABLE @@ -7484,9 +7145,9 @@ void dlt_stop_threads() dlt_segmented_nwt_result = pthread_cancel(dlt_user.dlt_segmented_nwt_handle); if (dlt_segmented_nwt_result != 0) - dlt_vlog(LOG_ERR, - "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", - strerror(dlt_segmented_nwt_result)); + dlt_vlog( + LOG_ERR, "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", + strerror(dlt_segmented_nwt_result)); } #endif /* DLT_NETWORK_TRACE_ENABLE */ /* make sure that the threads really finished working */ @@ -7494,9 +7155,7 @@ void dlt_stop_threads() joined = pthread_join(dlt_housekeeperthread_handle, NULL); if (joined != 0) - dlt_vlog(LOG_ERR, - "ERROR pthread_join(dlt_housekeeperthread_handle, NULL): %s\n", - strerror(joined)); + dlt_vlog(LOG_ERR, "ERROR pthread_join(dlt_housekeeperthread_handle, NULL): %s\n", strerror(joined)); dlt_housekeeperthread_handle = 0; /* set to invalid */ } @@ -7506,9 +7165,7 @@ void dlt_stop_threads() joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); if (joined != 0) - dlt_vlog(LOG_ERR, - "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", - strerror(joined)); + dlt_vlog(LOG_ERR, "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", strerror(joined)); dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */ } @@ -7529,37 +7186,32 @@ static void dlt_fork_child_fork_handler() #if defined(DLT_TRACE_LOAD_CTRL_ENABLE) static DltReturnValue dlt_user_output_internal_msg( - const DltLogLevelType loglevel, const char *const text, void* const params) + const DltLogLevelType loglevel, const char* const text, void* const params) { - (void)params; // parameter is not needed + (void)params; // parameter is not needed static DltContext handle; DltContextData log; int ret; int sent_size = 0; - if (!handle.contextID[0]) - { + if (!handle.contextID[0]) { // Register Special Context ID for output DLT library internal message ret = dlt_register_context(&handle, DLT_TRACE_LOAD_CONTEXT_ID, "DLT user library internal context"); - if (ret < DLT_RETURN_OK) - { + if (ret < DLT_RETURN_OK) { return ret; } } - if (dlt_user.verbose_mode == 0) - { + if (dlt_user.verbose_mode == 0) { return DLT_RETURN_ERROR; } - if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX) - { + if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX) { dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel); return DLT_RETURN_WRONG_PARAMETER; } - if (text == NULL) - { + if (text == NULL) { return DLT_RETURN_WRONG_PARAMETER; } @@ -7567,25 +7219,21 @@ static DltReturnValue dlt_user_output_internal_msg( // Ok means below threshold // see src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp::sloggerinfo_callback for reference - if (ret == DLT_RETURN_OK) - { + if (ret == DLT_RETURN_OK) { return ret; } - if (ret != DLT_RETURN_TRUE) - { + if (ret != DLT_RETURN_TRUE) { dlt_vlog(LOG_ERR, "Loglevel %d is disabled", loglevel); } - if (log.buffer == NULL) - { + if (log.buffer == NULL) { return DLT_RETURN_LOGGING_DISABLED; } ret = dlt_user_log_write_string(&log, text); - if (ret < DLT_RETURN_OK) - { + if (ret < DLT_RETURN_OK) { return ret; } @@ -7596,8 +7244,8 @@ static DltReturnValue dlt_user_output_internal_msg( } #endif -DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, - size_t len3) +DltReturnValue dlt_user_log_out_error_handling( + void* ptr1, size_t len1, void* ptr2, size_t len2, void* ptr3, size_t len3) { DltReturnValue ret = DLT_RETURN_ERROR; size_t msg_size = len1 + len2 + len3; @@ -7609,10 +7257,9 @@ DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void *pt dlt_mutex_lock(); - if (dlt_buffer_push3(&(dlt_user.startup_buffer), - ptr1, (unsigned int)len1, - ptr2, (unsigned int)len2, - ptr3, (unsigned int)len3) == DLT_RETURN_ERROR) { + if (dlt_buffer_push3( + &(dlt_user.startup_buffer), ptr1, (unsigned int)len1, ptr2, (unsigned int)len2, ptr3, (unsigned int)len3) + == DLT_RETURN_ERROR) { if (dlt_user.overflow_counter == 0) dlt_log(LOG_WARNING, "Buffer full! Messages will be discarded.\n"); @@ -7623,23 +7270,23 @@ DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void *pt return ret; } -DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle, DltLogLevelType loglevel) +DltReturnValue dlt_user_is_logLevel_enabled(DltContext* handle, DltLogLevelType loglevel) { - if ((loglevel < DLT_LOG_DEFAULT) || (loglevel >= DLT_LOG_MAX)) { - return DLT_RETURN_WRONG_PARAMETER; - } + if ((loglevel < DLT_LOG_DEFAULT) || (loglevel >= DLT_LOG_MAX)) { + return DLT_RETURN_WRONG_PARAMETER; + } - dlt_mutex_lock(); - if ((handle == NULL) || (handle->log_level_ptr == NULL)) { - dlt_mutex_unlock(); - return DLT_RETURN_WRONG_PARAMETER; - } + dlt_mutex_lock(); + if ((handle == NULL) || (handle->log_level_ptr == NULL)) { + dlt_mutex_unlock(); + return DLT_RETURN_WRONG_PARAMETER; + } - if ((loglevel <= (DltLogLevelType)(*(handle->log_level_ptr))) && (loglevel != DLT_LOG_OFF)) { - dlt_mutex_unlock(); - return DLT_RETURN_TRUE; - } + if ((loglevel <= (DltLogLevelType)(*(handle->log_level_ptr))) && (loglevel != DLT_LOG_OFF)) { + dlt_mutex_unlock(); + return DLT_RETURN_TRUE; + } - dlt_mutex_unlock(); - return DLT_RETURN_LOGGING_DISABLED; + dlt_mutex_unlock(); + return DLT_RETURN_LOGGING_DISABLED; } diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h index 65e5df546..7386994bb 100644 --- a/src/lib/dlt_user_cfg.h +++ b/src/lib/dlt_user_cfg.h @@ -74,30 +74,30 @@ #define DLT_USER_RCVBUF_MAX_SIZE 10024 /* Size of ring buffer */ -#define DLT_USER_RINGBUFFER_MIN_SIZE 50000 -#define DLT_USER_RINGBUFFER_MAX_SIZE 500000 -#define DLT_USER_RINGBUFFER_STEP_SIZE 50000 +#define DLT_USER_RINGBUFFER_MIN_SIZE 50000 +#define DLT_USER_RINGBUFFER_MAX_SIZE 500000 +#define DLT_USER_RINGBUFFER_STEP_SIZE 50000 /* Name of environment variable for ringbuffer configuration */ -#define DLT_USER_ENV_BUFFER_MIN_SIZE "DLT_USER_BUFFER_MIN" -#define DLT_USER_ENV_BUFFER_MAX_SIZE "DLT_USER_BUFFER_MAX" +#define DLT_USER_ENV_BUFFER_MIN_SIZE "DLT_USER_BUFFER_MIN" +#define DLT_USER_ENV_BUFFER_MAX_SIZE "DLT_USER_BUFFER_MAX" #define DLT_USER_ENV_BUFFER_STEP_SIZE "DLT_USER_BUFFER_STEP" /* Temporary buffer length */ -#define DLT_USER_BUFFER_LENGTH 255 +#define DLT_USER_BUFFER_LENGTH 255 /* Number of context entries, which will be allocated, * if no more context entries are available */ -#define DLT_USER_CONTEXT_ALLOC_SIZE 500 +#define DLT_USER_CONTEXT_ALLOC_SIZE 500 /* Maximu length of a filename string */ -#define DLT_USER_MAX_FILENAME_LENGTH 255 +#define DLT_USER_MAX_FILENAME_LENGTH 255 /* Maximum length of a single version number */ -#define DLT_USER_MAX_LIB_VERSION_LENGTH 3 +#define DLT_USER_MAX_LIB_VERSION_LENGTH 3 /* Length of buffer for constructing text output */ -#define DLT_USER_TEXT_LENGTH 10024 +#define DLT_USER_TEXT_LENGTH 10024 /* Stack size of receiver thread */ #define DLT_USER_RECEIVERTHREAD_STACKSIZE 100000 @@ -106,7 +106,7 @@ #define DLT_USER_DEFAULT_ECU_ID "ECU1" /* Initial log level */ -#define DLT_USER_INITIAL_LOG_LEVEL DLT_LOG_INFO +#define DLT_USER_INITIAL_LOG_LEVEL DLT_LOG_INFO /* Initial trace status */ #define DLT_USER_INITIAL_TRACE_STATUS DLT_TRACE_STATUS_OFF @@ -154,11 +154,9 @@ #define DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP 100000000 /* Name of environment variable to disable extended header in non verbose mode */ -#define DLT_USER_ENV_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE \ - "DLT_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE" +#define DLT_USER_ENV_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE "DLT_DISABLE_EXTENDED_HEADER_FOR_NONVERBOSE" -typedef enum -{ +typedef enum { DLT_USER_NO_USE_EXTENDED_HEADER_FOR_NONVERBOSE = 0, DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE } DltExtHeaderNonVer; @@ -181,12 +179,12 @@ typedef enum /************************/ /* Minimum valid ID of an injection message */ -#define DLT_USER_INJECTION_MIN 0xFFF +#define DLT_USER_INJECTION_MIN 0xFFF /* Defines of the different local print modes */ -#define DLT_PM_UNSET 0 +#define DLT_PM_UNSET 0 #define DLT_PM_AUTOMATIC 1 -#define DLT_PM_FORCE_ON 2 -#define DLT_PM_FORCE_OFF 3 +#define DLT_PM_FORCE_ON 2 +#define DLT_PM_FORCE_OFF 3 #endif /* DLT_USER_CFG_H */ diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 151c10b9a..a8b507c71 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -40,10 +40,10 @@ #define GENERAL_BASE_NAME "General" -DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *data) +DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig* data) { - DltLogStorageFileList *n = NULL; - DltLogStorageFileList *n1 = NULL; + DltLogStorageFileList* n = NULL; + DltLogStorageFileList* n1 = NULL; if (data->apids) { free(data->apids); @@ -119,18 +119,15 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat * @param reason Reason for the destroying of Filter configurations list * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, - DltLogStorageUserConfig *uconfig, - char *dev_path, - int reason) +DLT_STATIC int dlt_logstorage_list_destroy( + DltLogStorageFilterList** list, DltLogStorageUserConfig* uconfig, char* dev_path, int reason) { - DltLogStorageFilterList *tmp = NULL; + DltLogStorageFilterList* tmp = NULL; while (*(list) != NULL) { tmp = *list; *list = (*list)->next; - if (tmp->key_list != NULL) - { + if (tmp->key_list != NULL) { free(tmp->key_list); tmp->key_list = NULL; } @@ -138,10 +135,7 @@ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, if (tmp->data != NULL) { /* sync data if necessary */ /* ignore return value */ - tmp->data->dlt_logstorage_sync(tmp->data, - uconfig, - dev_path, - reason); + tmp->data->dlt_logstorage_sync(tmp->data, uconfig, dev_path, reason); dlt_logstorage_filter_config_free(tmp->data); @@ -156,8 +150,7 @@ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, return 0; } -DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data, - DltLogStorageFilterConfig **listdata) +DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig* data, DltLogStorageFilterConfig** listdata) { if (*(listdata) == NULL) return -1; @@ -197,25 +190,22 @@ DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data, * @param list List of the filter configurations * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_list_add(char *keys, - int num_keys, - DltLogStorageFilterConfig *data, - DltLogStorageFilterList **list) +DLT_STATIC int dlt_logstorage_list_add( + char* keys, int num_keys, DltLogStorageFilterConfig* data, DltLogStorageFilterList** list) { - DltLogStorageFilterList *tmp = NULL; + DltLogStorageFilterList* tmp = NULL; while (*(list) != NULL) { list = &(*list)->next; } - tmp = (DltLogStorageFilterList *)calloc(1, sizeof(DltLogStorageFilterList)); + tmp = (DltLogStorageFilterList*)calloc(1, sizeof(DltLogStorageFilterList)); if (tmp == NULL) return -1; - tmp->key_list = (char *)calloc((size_t)num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); - if (tmp->key_list == NULL) - { + tmp->key_list = (char*)calloc((size_t)num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); + if (tmp->key_list == NULL) { free(tmp); tmp = NULL; return -1; @@ -224,7 +214,7 @@ DLT_STATIC int dlt_logstorage_list_add(char *keys, memcpy(tmp->key_list, keys, (size_t)num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); tmp->num_keys = num_keys; tmp->next = NULL; - tmp->data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + tmp->data = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if (tmp->data == NULL) { free(tmp->key_list); @@ -259,20 +249,17 @@ DLT_STATIC int dlt_logstorage_list_add(char *keys, * @param config Filter configurations corresponding with the key. * @return Number of the filter configuration found. */ -DLT_STATIC int dlt_logstorage_list_find(char *key, - DltLogStorageFilterList **list, - DltLogStorageFilterConfig **config) +DLT_STATIC int dlt_logstorage_list_find(char* key, DltLogStorageFilterList** list, DltLogStorageFilterConfig** config) { int i = 0; int num = 0; while (*(list) != NULL) { - for (i = 0; i < (*list)->num_keys; i++) - { - if (strncmp(((*list)->key_list - + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), - key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0) - { + for (i = 0; i < (*list)->num_keys; i++) { + if (strncmp( + ((*list)->key_list + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), key, + DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) + == 0) { config[num] = (*list)->data; num++; break; @@ -286,14 +273,13 @@ DLT_STATIC int dlt_logstorage_list_find(char *key, /* Configuration file parsing helper functions */ -DLT_STATIC int dlt_logstorage_count_ids(const char *str) +DLT_STATIC int dlt_logstorage_count_ids(const char* str) { - if (str == NULL) return -1; /* delimiter is: "," */ - const char *p = str; + const char* p = str; int i = 0; int num = 1; @@ -316,15 +302,14 @@ DLT_STATIC int dlt_logstorage_count_ids(const char *str) * @param reason Reason for freeing the device * */ -void dlt_logstorage_free(DltLogStorage *handle, int reason) +void dlt_logstorage_free(DltLogStorage* handle, int reason) { if (handle == NULL) { dlt_vlog(LOG_ERR, "%s failed: handle is NULL\n", __func__); return; } - dlt_logstorage_list_destroy(&(handle->config_list), &handle->uconfig, - handle->device_mount_point, reason); + dlt_logstorage_list_destroy(&(handle->config_list), &handle->uconfig, handle->device_mount_point, reason); } @@ -343,12 +328,12 @@ void dlt_logstorage_free(DltLogStorage *handle, int reason) * @param value string given in config file * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, const char *value) +DLT_STATIC int dlt_logstorage_read_list_of_names(char** names, const char* value) { int i = 0; int y = 0; size_t len = 0; - char *tok; + char* tok; int num = 1; if ((names == NULL) || (value == NULL)) { @@ -365,8 +350,7 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, const char *value len = strlen(value); if (len == 0) { - dlt_vlog(LOG_ERR, "%s: Length of string given in config file is 0\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Length of string given in config file is 0\n", __func__); return -1; } @@ -374,7 +358,7 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, const char *value num = dlt_logstorage_count_ids(value); /* need to alloc space for 5 chars, 4 for the name and "," and "\0" */ - *names = (char *)calloc((size_t)num * 5, sizeof(char)); + *names = (char*)calloc((size_t)num * 5, sizeof(char)); if (*names == NULL) { dlt_vlog(LOG_ERR, "%s: Cannot allocate memory\n", __func__); @@ -382,8 +366,8 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, const char *value } - char *tok_buf = strdup(value); - char *tok_ptr = tok_buf; + char* tok_buf = strdup(value); + char* tok_ptr = tok_buf; tok = strtok(tok_ptr, ","); i = 1; @@ -413,7 +397,7 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, const char *value return 0; } -DLT_STATIC int dlt_logstorage_set_number(unsigned int *number, unsigned int value) +DLT_STATIC int dlt_logstorage_set_number(unsigned int* number, unsigned int value) { if (value == 0) { dlt_log(LOG_ERR, "Invalid value of 0\n"); @@ -438,7 +422,7 @@ DLT_STATIC int dlt_logstorage_set_number(unsigned int *number, unsigned int valu * @param value string given in config file * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value) +DLT_STATIC int dlt_logstorage_read_number(unsigned int* number, char* value) { size_t i = 0; size_t len = 0; @@ -477,12 +461,11 @@ DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value) * @param numids Number of keys in the list is stored here * @return: 0 on success, error on failure* */ -DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list, - int *numids) +DLT_STATIC int dlt_logstorage_get_keys_list(char* ids, char* sep, char** list, int* numids) { - char *token = NULL; - char *tmp_token = NULL; - char *ids_local = NULL; + char* token = NULL; + char* tmp_token = NULL; + char* ids_local = NULL; *numids = 0; @@ -499,7 +482,7 @@ DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list, return -1; } - *list = (char *)calloc((size_t)DLT_OFFLINE_LOGSTORAGE_MAXIDS * (DLT_ID_SIZE + 1), sizeof(char)); + *list = (char*)calloc((size_t)DLT_OFFLINE_LOGSTORAGE_MAXIDS * (DLT_ID_SIZE + 1), sizeof(char)); if (*(list) == NULL) { free(ids_local); @@ -523,11 +506,11 @@ DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list, return 0; } -DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *excluded_ids) +DLT_STATIC bool dlt_logstorage_check_excluded_ids(char* id, char* delim, char* excluded_ids) { - char *token = NULL; - char *tmp_token = NULL; - char *ids_local = NULL; + char* token = NULL; + char* tmp_token = NULL; + char* ids_local = NULL; if ((id == NULL) || (delim == NULL) || (excluded_ids == NULL)) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -550,7 +533,7 @@ DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *e } while (token != NULL) { - if(strncmp(id, token, DLT_ID_SIZE) == 0) { + if (strncmp(id, token, DLT_ID_SIZE) == 0) { free(ids_local); return true; } @@ -573,11 +556,10 @@ DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *e * @param key Prepared key stored here * @return None */ -DLT_STATIC void dlt_logstorage_create_keys_only_ctid(char *ecuid, char *ctid, - char *key) +DLT_STATIC void dlt_logstorage_create_keys_only_ctid(char* ecuid, char* ctid, char* key) { - char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - const char *delimiter = "::"; + char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {0}; + const char* delimiter = "::"; if (ecuid != NULL) { snprintf(curr_str, sizeof(curr_str), "%.*s%s", DLT_ID_SIZE, ecuid, delimiter); @@ -601,11 +583,10 @@ DLT_STATIC void dlt_logstorage_create_keys_only_ctid(char *ecuid, char *ctid, * @param key Prepared key stored here * @return None */ -DLT_STATIC void dlt_logstorage_create_keys_only_apid(char *ecuid, char *apid, - char *key) +DLT_STATIC void dlt_logstorage_create_keys_only_apid(char* ecuid, char* apid, char* key) { - char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - const char *colon = ":"; + char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {0}; + const char* colon = ":"; if (ecuid != NULL) { snprintf(curr_str, sizeof(curr_str), "%.*s%s", DLT_ID_SIZE, ecuid, colon); @@ -631,11 +612,10 @@ DLT_STATIC void dlt_logstorage_create_keys_only_apid(char *ecuid, char *apid, * @param key Prepared key stored here * @return None */ -DLT_STATIC void dlt_logstorage_create_keys_multi(char *ecuid, char *apid, - char *ctid, char *key) +DLT_STATIC void dlt_logstorage_create_keys_multi(char* ecuid, char* apid, char* ctid, char* key) { - char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - const char *colon = ":"; + char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {0}; + const char* colon = ":"; if (ecuid != NULL) { snprintf(curr_str, sizeof(curr_str), "%.*s%s", DLT_ID_SIZE, ecuid, colon); @@ -661,9 +641,9 @@ DLT_STATIC void dlt_logstorage_create_keys_multi(char *ecuid, char *apid, * @param key Prepared key stored here * @return None */ -DLT_STATIC void dlt_logstorage_create_keys_only_ecu(char *ecuid, char *key) +DLT_STATIC void dlt_logstorage_create_keys_only_ecu(char* ecuid, char* key) { - char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; + char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {0}; snprintf(curr_str, sizeof(curr_str), "%.*s::", DLT_ID_SIZE, ecuid); snprintf(key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1, "%s", curr_str); @@ -697,29 +677,25 @@ DLT_STATIC void dlt_logstorage_create_keys_only_ecu(char *ecuid, char *key) * @param[out] num_keys number of keys * @return: 0 on success, error on failure* */ -DLT_STATIC int dlt_logstorage_create_keys(char *apids, - char *ctids, - char *ecuid, - char **keys, - int *num_keys) +DLT_STATIC int dlt_logstorage_create_keys(char* apids, char* ctids, char* ecuid, char** keys, int* num_keys) { int i, j; int num_apids = 0; int num_ctids = 0; - char *apid_list = NULL; - char *ctid_list = NULL; - char *curr_apid = NULL; - char *curr_ctid = NULL; - char curr_key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; + char* apid_list = NULL; + char* ctid_list = NULL; + char* curr_apid = NULL; + char* curr_ctid = NULL; + char curr_key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = {0}; int num_currkey = 0; /* Handle ecuid alone case here */ - if (((apids == NULL) && (ctids == NULL) && (ecuid != NULL)) || - ((apids != NULL) && (strncmp(apids, ".*", 2) == 0) && - (ctids != NULL) && (strncmp(ctids, ".*", 2) == 0) && (ecuid != NULL)) ) { + if (((apids == NULL) && (ctids == NULL) && (ecuid != NULL)) + || ((apids != NULL) && (strncmp(apids, ".*", 2) == 0) && (ctids != NULL) && (strncmp(ctids, ".*", 2) == 0) + && (ecuid != NULL))) { dlt_logstorage_create_keys_only_ecu(ecuid, curr_key); *(num_keys) = 1; - *(keys) = (char *)calloc((size_t)(*num_keys) * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); + *(keys) = (char*)calloc((size_t)(*num_keys) * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); if (*(keys) == NULL) return -1; @@ -750,7 +726,7 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids, *(num_keys) = num_apids * num_ctids; /* allocate memory for needed number of keys */ - *(keys) = (char *)calloc((size_t)(*num_keys) * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); + *(keys) = (char*)calloc((size_t)(*num_keys) * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); if (*(keys) == NULL) { free(apid_list); @@ -772,8 +748,9 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids, else /* key is combination of all */ dlt_logstorage_create_keys_multi(ecuid, curr_apid, curr_ctid, curr_key); - memcpy((*keys + (num_currkey * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), - curr_key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + memcpy( + (*keys + (num_currkey * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), curr_key, + DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); (*keys + (num_currkey * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN))[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN - 1] = '\0'; num_currkey += 1; memset(&curr_key[0], 0, sizeof(curr_key)); @@ -795,27 +772,22 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids, * @param data Holds all other configuration values * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, - DltLogStorageFilterConfig *data) +DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage* handle, DltLogStorageFilterConfig* data) { int ret = 0; int num_keys = 0; int found = 0; - char *keys = NULL; - DltNewestFileName *tmp = NULL; - DltNewestFileName *prev_tmp = NULL; - DltNewestFileName *new_tmp = NULL; + char* keys = NULL; + DltNewestFileName* tmp = NULL; + DltNewestFileName* prev_tmp = NULL; + DltNewestFileName* new_tmp = NULL; if ((handle == NULL) || (data == NULL)) { dlt_vlog(LOG_ERR, "Invalid parameters in %s\n", __func__); return -1; } - ret = dlt_logstorage_create_keys(data->apids, - data->ctids, - data->ecuid, - &keys, - &num_keys); + ret = dlt_logstorage_create_keys(data->apids, data->ctids, data->ecuid, &keys, &num_keys); if (ret != 0) { dlt_log(LOG_ERR, "Not able to create keys for hash table\n"); @@ -823,11 +795,7 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, } /* hash_add */ - if (dlt_logstorage_list_add(keys, - num_keys, - data, - &(handle->config_list)) != 0) - { + if (dlt_logstorage_list_add(keys, num_keys, data, &(handle->config_list)) != 0) { dlt_log(LOG_ERR, "Adding to hash table failed, returning failure\n"); dlt_logstorage_free(handle, DLT_LOGSTORAGE_SYNC_ON_ERROR); free(keys); @@ -842,8 +810,7 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, if (strcmp(tmp->file_name, data->file_name) == 0) { found = 1; break; - } - else { + } else { prev_tmp = tmp; tmp = tmp->next; } @@ -851,12 +818,10 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, } if (!found) { - new_tmp = (DltNewestFileName *)calloc(1, sizeof(DltNewestFileName)); + new_tmp = (DltNewestFileName*)calloc(1, sizeof(DltNewestFileName)); if (new_tmp == NULL) { /* In this case, the existing list does not need to be freed.*/ - dlt_vlog(LOG_ERR, - "Failed to allocate memory for new file name [%s]\n", - data->file_name); + dlt_vlog(LOG_ERR, "Failed to allocate memory for new file name [%s]\n", data->file_name); free(keys); keys = NULL; return -1; @@ -886,7 +851,7 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, * @return 0 on success, -1 on error * */ -DLT_STATIC int dlt_logstorage_validate_filter_name(char *name) +DLT_STATIC int dlt_logstorage_validate_filter_name(char* name) { size_t len = 0; int idx = 0; @@ -900,59 +865,44 @@ DLT_STATIC int dlt_logstorage_validate_filter_name(char *name) len = strlen(name); /* Check if section header is of format "FILTER" followed by a number */ - if (strncmp(name, - DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, - config_sec_len) == 0) { + if (strncmp(name, DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, config_sec_len) == 0) { for (idx = (int)config_sec_len; (size_t)idx < len - 1; idx++) if (!isdigit((unsigned char)name[idx])) return -1; return 0; - } - else if (strncmp(name, - DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION, - storage_sec_len) == 0) - { + } else if (strncmp(name, DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION, storage_sec_len) == 0) { for (idx = (int)storage_sec_len; (size_t)idx < len - 1; idx++) if (!isdigit((unsigned char)name[idx])) return -1; return 0; - } - else if (strncmp(name, - DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION, - control_sec_len) == 0) - { + } else if (strncmp(name, DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION, control_sec_len) == 0) { for (idx = (int)control_sec_len; (size_t)idx < len - 1; idx++) if (!isdigit((unsigned char)name[idx])) return -1; return 0; - } - else { + } else { return -1; } } -DLT_STATIC void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig *config, - int strategy) +DLT_STATIC void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig* config, int strategy) { if (config == NULL) return; /* file based */ - if ((strategy == DLT_LOGSTORAGE_SYNC_ON_MSG) || - (strategy == DLT_LOGSTORAGE_SYNC_UNSET)) { + if ((strategy == DLT_LOGSTORAGE_SYNC_ON_MSG) || (strategy == DLT_LOGSTORAGE_SYNC_UNSET)) { config->dlt_logstorage_prepare = &dlt_logstorage_prepare_on_msg; config->dlt_logstorage_write = &dlt_logstorage_write_on_msg; config->dlt_logstorage_sync = &dlt_logstorage_sync_on_msg; - } - else { /* cache based */ + } else { /* cache based */ config->dlt_logstorage_prepare = &dlt_logstorage_prepare_msg_cache; config->dlt_logstorage_write = &dlt_logstorage_write_msg_cache; config->dlt_logstorage_sync = &dlt_logstorage_sync_msg_cache; } } -DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) { dlt_log(LOG_ERR, "Not able to create keys for hash table\n"); @@ -962,8 +912,7 @@ DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, return dlt_logstorage_read_list_of_names(&config->apids, value); } -DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -971,8 +920,7 @@ DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, return dlt_logstorage_read_list_of_names(&config->ctids, (const char*)value); } -DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -982,8 +930,7 @@ DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterCon return dlt_logstorage_read_list_of_names(&config->excluded_apids, value); } -DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); @@ -993,8 +940,7 @@ DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterCon return dlt_logstorage_read_list_of_names(&config->excluded_ctids, (const char*)value); } -DLT_STATIC int dlt_logstorage_set_loglevel(int *log_level, - int value) +DLT_STATIC int dlt_logstorage_set_loglevel(int* log_level, int value) { *log_level = value; if ((value <= DLT_LOG_DEFAULT) || (value >= DLT_LOG_MAX)) { @@ -1005,8 +951,7 @@ DLT_STATIC int dlt_logstorage_set_loglevel(int *log_level, return 0; } -DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig* config, char* value) { int ll = -1; @@ -1019,33 +964,22 @@ DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, if (strcmp(value, "DLT_LOG_FATAL") == 0) { ll = 1; - } - else if (strcmp(value, "DLT_LOG_ERROR") == 0) - { + } else if (strcmp(value, "DLT_LOG_ERROR") == 0) { ll = 2; - } - else if (strcmp(value, "DLT_LOG_WARN") == 0) - { + } else if (strcmp(value, "DLT_LOG_WARN") == 0) { ll = 3; - } - else if (strcmp(value, "DLT_LOG_INFO") == 0) - { + } else if (strcmp(value, "DLT_LOG_INFO") == 0) { ll = 4; - } - else if (strcmp(value, "DLT_LOG_DEBUG") == 0) - { + } else if (strcmp(value, "DLT_LOG_DEBUG") == 0) { ll = 5; - } - else if (strcmp(value, "DLT_LOG_VERBOSE") == 0) - { + } else if (strcmp(value, "DLT_LOG_VERBOSE") == 0) { ll = 6; } return dlt_logstorage_set_loglevel(&config->log_level, ll); } -DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig* config, char* value) { if (config == NULL) return -1; @@ -1057,32 +991,19 @@ DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *co if (strcmp(value, "DLT_LOG_OFF") == 0) { config->reset_log_level = DLT_LOG_OFF; - } - else if (strcmp(value, "DLT_LOG_FATAL") == 0) - { + } else if (strcmp(value, "DLT_LOG_FATAL") == 0) { config->reset_log_level = DLT_LOG_FATAL; - } - else if (strcmp(value, "DLT_LOG_ERROR") == 0) - { + } else if (strcmp(value, "DLT_LOG_ERROR") == 0) { config->reset_log_level = DLT_LOG_ERROR; - } - else if (strcmp(value, "DLT_LOG_WARN") == 0) - { + } else if (strcmp(value, "DLT_LOG_WARN") == 0) { config->reset_log_level = DLT_LOG_WARN; - } - else if (strcmp(value, "DLT_LOG_INFO") == 0) - { + } else if (strcmp(value, "DLT_LOG_INFO") == 0) { config->reset_log_level = DLT_LOG_INFO; - } - else if (strcmp(value, "DLT_LOG_DEBUG") == 0) - { + } else if (strcmp(value, "DLT_LOG_DEBUG") == 0) { config->reset_log_level = DLT_LOG_DEBUG; - } - else if (strcmp(value, "DLT_LOG_VERBOSE") == 0) - { + } else if (strcmp(value, "DLT_LOG_VERBOSE") == 0) { config->reset_log_level = DLT_LOG_VERBOSE; - } - else { + } else { config->reset_log_level = -1; dlt_log(LOG_ERR, "Invalid log level \n"); return -1; @@ -1091,8 +1012,7 @@ DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *co return 0; } -DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig* config, char* value) { size_t len; @@ -1107,35 +1027,30 @@ DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, len = strlen(value); if (len == 0) { - dlt_vlog(LOG_ERR, "%s: Length of string given in config file is 0\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Length of string given in config file is 0\n", __func__); return -1; } /* do not allow the user to change directory by adding a relative path */ if (strstr(value, "..") == NULL) { - config->file_name = (char *)calloc(len + 1, sizeof(char)); + config->file_name = (char*)calloc(len + 1, sizeof(char)); if (config->file_name == NULL) { - dlt_log(LOG_ERR, - "Cannot allocate memory for filename\n"); + dlt_log(LOG_ERR, "Cannot allocate memory for filename\n"); return -1; } memcpy(config->file_name, value, len); config->file_name[len] = '\0'; - } - else { - dlt_log(LOG_ERR, - "Invalid filename, paths not accepted due to security issues\n"); + } else { + dlt_log(LOG_ERR, "Invalid filename, paths not accepted due to security issues\n"); return -1; } return 0; } -DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1143,8 +1058,7 @@ DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config, return dlt_logstorage_read_number(&config->file_size, value); } -DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1152,8 +1066,7 @@ DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config, return dlt_logstorage_read_number(&config->num_files, value); } -DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1173,8 +1086,7 @@ DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig *conf * @param value string given in config file * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1182,8 +1094,7 @@ DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *con if (strcasestr(value, "ON_MSG") != NULL) { config->sync = DLT_LOGSTORAGE_SYNC_ON_MSG; dlt_log(LOG_DEBUG, "ON_MSG found, ignore other if added\n"); - } - else { /* ON_MSG not set, combination of cache based strategies possible */ + } else { /* ON_MSG not set, combination of cache based strategies possible */ if (strcasestr(value, "ON_DAEMON_EXIT") != NULL) config->sync |= DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT; @@ -1201,8 +1112,7 @@ DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *con config->sync |= DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE; if (config->sync == 0) { - dlt_log(LOG_WARNING, - "Unknown sync strategies. Set default ON_MSG\n"); + dlt_log(LOG_WARNING, "Unknown sync strategies. Set default ON_MSG\n"); config->sync = DLT_LOGSTORAGE_SYNC_ON_MSG; return 1; } @@ -1223,8 +1133,7 @@ DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *con * @param[in] value string given in config file * @return 0 on success, 1 on unknown value, -1 on error */ -DLT_STATIC int dlt_logstorage_check_overwrite_strategy(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_overwrite_strategy(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1234,8 +1143,7 @@ DLT_STATIC int dlt_logstorage_check_overwrite_strategy(DltLogStorageFilterConfig } else if (strcasestr(value, "DISCARD_NEW") != NULL) { config->overwrite = DLT_LOGSTORAGE_OVERWRITE_DISCARD_NEW; } else { - dlt_log(LOG_WARNING, - "Unknown overwrite strategy. Set default DISCARD_OLD\n"); + dlt_log(LOG_WARNING, "Unknown overwrite strategy. Set default DISCARD_OLD\n"); config->overwrite = DLT_LOGSTORAGE_OVERWRITE_DISCARD_OLD; return 1; } @@ -1255,8 +1163,7 @@ DLT_STATIC int dlt_logstorage_check_overwrite_strategy(DltLogStorageFilterConfig * @param[in] value string given in config file * @return 0 on success, 1 on unknown value, -1 on error */ -DLT_STATIC int dlt_logstorage_check_disable_network(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_disable_network(DltLogStorageFilterConfig* config, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1266,8 +1173,7 @@ DLT_STATIC int dlt_logstorage_check_disable_network(DltLogStorageFilterConfig *c } else if (strcasestr(value, "OFF") != NULL) { config->disable_network_routing = DLT_LOGSTORAGE_DISABLE_NW_OFF; } else { - dlt_log(LOG_WARNING, - "Unknown disable network flag. Set default OFF\n"); + dlt_log(LOG_WARNING, "Unknown disable network flag. Set default OFF\n"); config->disable_network_routing = DLT_LOGSTORAGE_DISABLE_NW_OFF; return 1; } @@ -1287,8 +1193,7 @@ DLT_STATIC int dlt_logstorage_check_disable_network(DltLogStorageFilterConfig *c * @param[in] value string given in config file * @return 0 on success, 1 on unknown value, -1 on error */ -DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig* config, char* value) { #ifdef DLT_LOGSTORAGE_USE_GZIP if ((config == NULL) || (value == NULL)) @@ -1320,8 +1225,7 @@ DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig * * @param value string given in config file * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, - char *value) +DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig* config, char* value) { size_t len; @@ -1334,7 +1238,7 @@ DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, } len = strlen(value); - config->ecuid = (char *)calloc(len + 1, sizeof(char)); + config->ecuid = (char*)calloc(len + 1, sizeof(char)); if (config->ecuid == NULL) return -1; @@ -1345,243 +1249,76 @@ DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, return 0; } -DLT_STATIC DltLogstorageFilterConf - filter_cfg_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = { - [DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = { - .key = "LogAppName", - .func = dlt_logstorage_check_apids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME] = { - .key = "ContextName", - .func = dlt_logstorage_check_ctids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = { - .key = "ExcludedLogAppName", - .func = dlt_logstorage_store_config_excluded_apids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = { - .key = "ExcludedContextName", - .func = dlt_logstorage_store_config_excluded_ctids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = { - .key = "LogLevel", - .func = dlt_logstorage_check_loglevel, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL] = { - .key = NULL, - .func = dlt_logstorage_check_reset_loglevel, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_FILE] = { - .key = "File", - .func = dlt_logstorage_check_filename, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_FILESIZE] = { - .key = "FileSize", - .func = dlt_logstorage_check_filesize, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_NOFILES] = { - .key = "NOFiles", - .func = dlt_logstorage_check_nofiles, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR] = { - .key = "SyncBehavior", - .func = dlt_logstorage_check_sync_strategy, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_OVERWRITEBEHAVIOR] = { - .key = "OverwriteBehavior", - .func = dlt_logstorage_check_overwrite_strategy, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_ECUID] = { - .key = "EcuID", - .func = dlt_logstorage_check_ecuid, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = { - .key = "SpecificSize", - .func = dlt_logstorage_check_specificsize, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = { - .key = "GzipCompression", - .func = dlt_logstorage_check_gzip_compression, - .is_opt = 1 - }, +DLT_STATIC DltLogstorageFilterConf filter_cfg_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = { + [DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = {.key = "LogAppName", .func = dlt_logstorage_check_apids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME] = {.key = "ContextName", .func = dlt_logstorage_check_ctids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = + {.key = "ExcludedLogAppName", .func = dlt_logstorage_store_config_excluded_apids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = + {.key = "ExcludedContextName", .func = dlt_logstorage_store_config_excluded_ctids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = {.key = "LogLevel", .func = dlt_logstorage_check_loglevel, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL] = + {.key = NULL, .func = dlt_logstorage_check_reset_loglevel, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_FILE] = {.key = "File", .func = dlt_logstorage_check_filename, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_FILESIZE] = {.key = "FileSize", .func = dlt_logstorage_check_filesize, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_NOFILES] = {.key = "NOFiles", .func = dlt_logstorage_check_nofiles, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR] = + {.key = "SyncBehavior", .func = dlt_logstorage_check_sync_strategy, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_OVERWRITEBEHAVIOR] = + {.key = "OverwriteBehavior", .func = dlt_logstorage_check_overwrite_strategy, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_ECUID] = {.key = "EcuID", .func = dlt_logstorage_check_ecuid, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = + {.key = "SpecificSize", .func = dlt_logstorage_check_specificsize, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = + {.key = "GzipCompression", .func = dlt_logstorage_check_gzip_compression, .is_opt = 1}, [DLT_LOGSTORAGE_FILTER_CONF_DISABLE_NETWORK] = { - .key = "DisableNetwork", - .func = dlt_logstorage_check_disable_network, - .is_opt = 1 - } -}; + .key = "DisableNetwork", .func = dlt_logstorage_check_disable_network, .is_opt = 1}}; /* */ -DLT_STATIC DltLogstorageFilterConf - filter_nonverbose_storage_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = { - [DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = { - .key = NULL, - .func = dlt_logstorage_check_apids, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME] = { - .key = NULL, - .func = dlt_logstorage_check_ctids, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = { - .key = NULL, - .func = dlt_logstorage_store_config_excluded_apids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = { - .key = NULL, - .func = dlt_logstorage_store_config_excluded_ctids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = { - .key = NULL, - .func = dlt_logstorage_check_loglevel, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL] = { - .key = NULL, - .func = NULL, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_FILE] = { - .key = "File", - .func = dlt_logstorage_check_filename, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_FILESIZE] = { - .key = "FileSize", - .func = dlt_logstorage_check_filesize, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_NOFILES] = { - .key = "NOFiles", - .func = dlt_logstorage_check_nofiles, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR] = { - .key = NULL, - .func = dlt_logstorage_check_sync_strategy, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_OVERWRITEBEHAVIOR] = { - .key = NULL, - .func = dlt_logstorage_check_overwrite_strategy, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_ECUID] = { - .key = "EcuID", - .func = dlt_logstorage_check_ecuid, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = { - .key = NULL, - .func = dlt_logstorage_check_specificsize, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = { - .key = "GzipCompression", - .func = dlt_logstorage_check_gzip_compression, - .is_opt = 1 - }, +DLT_STATIC DltLogstorageFilterConf filter_nonverbose_storage_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = { + [DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = {.key = NULL, .func = dlt_logstorage_check_apids, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME] = {.key = NULL, .func = dlt_logstorage_check_ctids, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = + {.key = NULL, .func = dlt_logstorage_store_config_excluded_apids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = + {.key = NULL, .func = dlt_logstorage_store_config_excluded_ctids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = {.key = NULL, .func = dlt_logstorage_check_loglevel, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL] = {.key = NULL, .func = NULL, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_FILE] = {.key = "File", .func = dlt_logstorage_check_filename, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_FILESIZE] = {.key = "FileSize", .func = dlt_logstorage_check_filesize, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_NOFILES] = {.key = "NOFiles", .func = dlt_logstorage_check_nofiles, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR] = {.key = NULL, .func = dlt_logstorage_check_sync_strategy, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_OVERWRITEBEHAVIOR] = + {.key = NULL, .func = dlt_logstorage_check_overwrite_strategy, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_ECUID] = {.key = "EcuID", .func = dlt_logstorage_check_ecuid, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = {.key = NULL, .func = dlt_logstorage_check_specificsize, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = + {.key = "GzipCompression", .func = dlt_logstorage_check_gzip_compression, .is_opt = 1}, [DLT_LOGSTORAGE_FILTER_CONF_DISABLE_NETWORK] = { - .key = NULL, - .func = dlt_logstorage_check_disable_network, - .is_opt = 1 - } -}; - -DLT_STATIC DltLogstorageFilterConf - filter_nonverbose_control_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = { - [DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = { - .key = "LogAppName", - .func = dlt_logstorage_check_apids, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME] = { - .key = "ContextName", - .func = dlt_logstorage_check_ctids, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = { - .key = NULL, - .func = dlt_logstorage_store_config_excluded_apids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = { - .key = NULL, - .func = dlt_logstorage_store_config_excluded_ctids, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = { - .key = "LogLevel", - .func = dlt_logstorage_check_loglevel, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL] = { - .key = "ResetLogLevel", - .func = dlt_logstorage_check_reset_loglevel, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_FILE] = { - .key = NULL, - .func = dlt_logstorage_check_filename, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_FILESIZE] = { - .key = NULL, - .func = dlt_logstorage_check_filesize, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_NOFILES] = { - .key = NULL, - .func = dlt_logstorage_check_nofiles, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR] = { - .key = NULL, - .func = dlt_logstorage_check_sync_strategy, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_OVERWRITEBEHAVIOR] = { - .key = NULL, - .func = dlt_logstorage_check_overwrite_strategy, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_ECUID] = { - .key = "EcuID", - .func = dlt_logstorage_check_ecuid, - .is_opt = 0 - }, - [DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = { - .key = NULL, - .func = dlt_logstorage_check_specificsize, - .is_opt = 1 - }, - [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = { - .key = "GzipCompression", - .func = dlt_logstorage_check_gzip_compression, - .is_opt = 1 - }, + .key = NULL, .func = dlt_logstorage_check_disable_network, .is_opt = 1}}; + +DLT_STATIC DltLogstorageFilterConf filter_nonverbose_control_entries[DLT_LOGSTORAGE_FILTER_CONF_COUNT] = { + [DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME] = {.key = "LogAppName", .func = dlt_logstorage_check_apids, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME] = {.key = "ContextName", .func = dlt_logstorage_check_ctids, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = + {.key = NULL, .func = dlt_logstorage_store_config_excluded_apids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = + {.key = NULL, .func = dlt_logstorage_store_config_excluded_ctids, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = {.key = "LogLevel", .func = dlt_logstorage_check_loglevel, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL] = + {.key = "ResetLogLevel", .func = dlt_logstorage_check_reset_loglevel, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_FILE] = {.key = NULL, .func = dlt_logstorage_check_filename, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_FILESIZE] = {.key = NULL, .func = dlt_logstorage_check_filesize, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_NOFILES] = {.key = NULL, .func = dlt_logstorage_check_nofiles, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR] = {.key = NULL, .func = dlt_logstorage_check_sync_strategy, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_OVERWRITEBEHAVIOR] = + {.key = NULL, .func = dlt_logstorage_check_overwrite_strategy, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_ECUID] = {.key = "EcuID", .func = dlt_logstorage_check_ecuid, .is_opt = 0}, + [DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE] = {.key = NULL, .func = dlt_logstorage_check_specificsize, .is_opt = 1}, + [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = + {.key = "GzipCompression", .func = dlt_logstorage_check_gzip_compression, .is_opt = 1}, [DLT_LOGSTORAGE_FILTER_CONF_DISABLE_NETWORK] = { - .key = NULL, - .func = dlt_logstorage_check_disable_network, - .is_opt = 1 - } -}; + .key = NULL, .func = dlt_logstorage_check_disable_network, .is_opt = 1}}; /** * Check filter configuration parameter is valid. @@ -1591,9 +1328,8 @@ DLT_STATIC DltLogstorageFilterConf * @param value specified property value from configuration file * @return 0 on success, -1 otherwise */ -DLT_STATIC int dlt_logstorage_check_param(DltLogStorageFilterConfig *config, - DltLogstorageFilterConfType ctype, - char *value) +DLT_STATIC int dlt_logstorage_check_param( + DltLogStorageFilterConfig* config, DltLogstorageFilterConfType ctype, char* value) { if ((config == NULL) || (value == NULL)) return -1; @@ -1604,10 +1340,8 @@ DLT_STATIC int dlt_logstorage_check_param(DltLogStorageFilterConfig *config, return -1; } -DLT_STATIC int dlt_logstorage_get_filter_section_value(DltConfigFile *config_file, - char *sec_name, - DltLogstorageFilterConf entry, - char *value) +DLT_STATIC int dlt_logstorage_get_filter_section_value( + DltConfigFile* config_file, char* sec_name, DltLogstorageFilterConf entry, char* value) { int ret = 0; @@ -1615,34 +1349,25 @@ DLT_STATIC int dlt_logstorage_get_filter_section_value(DltConfigFile *config_fil return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; if (entry.key != NULL) { - ret = dlt_config_file_get_value(config_file, sec_name, - entry.key, - value); + ret = dlt_config_file_get_value(config_file, sec_name, entry.key, value); if ((ret != 0) && (entry.is_opt == 0)) { - dlt_vlog(LOG_WARNING, - "Invalid configuration in section: %s -> %s : %s\n", - sec_name, entry.key, value); + dlt_vlog(LOG_WARNING, "Invalid configuration in section: %s -> %s : %s\n", sec_name, entry.key, value); return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; } if ((ret != 0) && (entry.is_opt == 1)) { - dlt_vlog(LOG_DEBUG, "Optional parameter %s not specified\n", - entry.key); + dlt_vlog(LOG_DEBUG, "Optional parameter %s not specified\n", entry.key); return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; } - } - else { + } else { return DLT_OFFLINE_LOGSTORAGE_FILTER_CONTINUE; } return 0; } -DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file, - char *sec_name, - int index, - char *value) +DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile* config_file, char* sec_name, int index, char* value) { int ret = 0; size_t config_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION); @@ -1653,28 +1378,15 @@ DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file, return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; /* Branch based on section name, no complete string compare needed */ - if (strncmp(sec_name, - DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, - config_sec_len) == 0) { - ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, - filter_cfg_entries[index], - value); - } - else if (strncmp(sec_name, - DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION, - storage_sec_len) == 0) { - ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, - filter_nonverbose_storage_entries[index], - value); - } - else if ((strncmp(sec_name, - DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION, - control_sec_len) == 0)) { - ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, - filter_nonverbose_control_entries[index], - value); - } - else { + if (strncmp(sec_name, DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, config_sec_len) == 0) { + ret = dlt_logstorage_get_filter_section_value(config_file, sec_name, filter_cfg_entries[index], value); + } else if (strncmp(sec_name, DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION, storage_sec_len) == 0) { + ret = dlt_logstorage_get_filter_section_value( + config_file, sec_name, filter_nonverbose_storage_entries[index], value); + } else if ((strncmp(sec_name, DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION, control_sec_len) == 0)) { + ret = dlt_logstorage_get_filter_section_value( + config_file, sec_name, filter_nonverbose_control_entries[index], value); + } else { dlt_log(LOG_ERR, "Error: Section name not valid \n"); ret = DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; } @@ -1682,8 +1394,7 @@ DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file, return ret; } -DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage *handle, - DltLogStorageFilterConfig *tmp_data) +DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage* handle, DltLogStorageFilterConfig* tmp_data) { int ret = 0; @@ -1705,12 +1416,11 @@ DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage *handle, * DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR - On error while storing in hash table */ -DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, - DltConfigFile *config_file, - char *sec_name) +DLT_STATIC int dlt_daemon_offline_setup_filter_properties( + DltLogStorage* handle, DltConfigFile* config_file, char* sec_name) { DltLogStorageFilterConfig tmp_data; - char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN + 1] = { '\0' }; + char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN + 1] = {'\0'}; int i = 0; int ret = 0; @@ -1774,8 +1484,11 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, } } - if(dlt_logstorage_count_ids(tmp_data.excluded_apids) > 1 && dlt_logstorage_count_ids(tmp_data.excluded_ctids) > 1) { - dlt_vlog(LOG_WARNING, "%s: Logstorage does not support both multiple excluded applications and contexts\n", __func__); + if (dlt_logstorage_count_ids(tmp_data.excluded_apids) > 1 + && dlt_logstorage_count_ids(tmp_data.excluded_ctids) > 1) { + dlt_vlog( + LOG_WARNING, "%s: Logstorage does not support both multiple excluded applications and contexts\n", + __func__); return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; } @@ -1785,8 +1498,7 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, if (ret != 0) { dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n", __func__); ret = DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR; - } - else { /* move to next free filter configuration, if no error occurred */ + } else { /* move to next free filter configuration, if no error occurred */ handle->num_configs += 1; } @@ -1808,26 +1520,18 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, * @param value string given in config file * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_check_maintain_logstorage_loglevel(DltLogStorage *handle, - char *value) +DLT_STATIC int dlt_logstorage_check_maintain_logstorage_loglevel(DltLogStorage* handle, char* value) { - if ((handle == NULL) || (value == NULL)) - { + if ((handle == NULL) || (value == NULL)) { return -1; } - if ((strncmp(value, "OFF", 3) == 0) || (strncmp(value, "0", 1) == 0)) - { + if ((strncmp(value, "OFF", 3) == 0) || (strncmp(value, "0", 1) == 0)) { handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF; - } - else if ((strncmp(value, "ON", 2) == 0) || (strncmp(value, "1", 1) == 0)) - { + } else if ((strncmp(value, "ON", 2) == 0) || (strncmp(value, "1", 1) == 0)) { handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; - } - else - { - dlt_vlog(LOG_ERR, - "Wrong value for Maintain logstorage loglevel section name: %s\n", value); + } else { + dlt_vlog(LOG_ERR, "Wrong value for Maintain logstorage loglevel section name: %s\n", value); handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; return -1; } @@ -1835,14 +1539,9 @@ DLT_STATIC int dlt_logstorage_check_maintain_logstorage_loglevel(DltLogStorage * return 0; } -DLT_STATIC DltLogstorageGeneralConf - general_cfg_entries[DLT_LOGSTORAGE_GENERAL_CONF_COUNT] = { +DLT_STATIC DltLogstorageGeneralConf general_cfg_entries[DLT_LOGSTORAGE_GENERAL_CONF_COUNT] = { [DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL] = { - .key = "MaintainLogstorageLogLevel", - .func = dlt_logstorage_check_maintain_logstorage_loglevel, - .is_opt = 1 - } -}; + .key = "MaintainLogstorageLogLevel", .func = dlt_logstorage_check_maintain_logstorage_loglevel, .is_opt = 1}}; /** * Check if DltLogstorage General configuration parameter is valid. @@ -1852,62 +1551,39 @@ DLT_STATIC DltLogstorageGeneralConf * @param value specified property value from configuration file * @return 0 on success, -1 otherwise */ -DLT_STATIC int dlt_logstorage_check_general_param(DltLogStorage *handle, - DltLogstorageGeneralConfType ctype, - char *value) +DLT_STATIC int dlt_logstorage_check_general_param( + DltLogStorage* handle, DltLogstorageGeneralConfType ctype, char* value) { - if ((handle == NULL) || (value == NULL)) - { + if ((handle == NULL) || (value == NULL)) { return -1; } - if (ctype < DLT_LOGSTORAGE_GENERAL_CONF_COUNT) - { + if (ctype < DLT_LOGSTORAGE_GENERAL_CONF_COUNT) { return general_cfg_entries[ctype].func(handle, value); } return -1; } -DLT_STATIC int dlt_daemon_setup_general_properties(DltLogStorage *handle, - DltConfigFile *config_file, - char *sec_name) +DLT_STATIC int dlt_daemon_setup_general_properties(DltLogStorage* handle, DltConfigFile* config_file, char* sec_name) { DltLogstorageGeneralConfType type = DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {0}; - if ((handle == NULL) || (config_file == NULL) || (sec_name == NULL)) - { + if ((handle == NULL) || (config_file == NULL) || (sec_name == NULL)) { return -1; } - for ( ; type < DLT_LOGSTORAGE_GENERAL_CONF_COUNT ; type++) - { - if (dlt_config_file_get_value(config_file, - sec_name, - general_cfg_entries[type].key, - value) == 0) - { - if (dlt_logstorage_check_general_param(handle, type, value) != 0) - { - dlt_vlog(LOG_WARNING, - "General parameter %s [%s] is invalid\n", - general_cfg_entries[type].key, value); - } - } - else - { - if (general_cfg_entries[type].is_opt == 1) - { - dlt_vlog(LOG_DEBUG, - "Optional General parameter %s not given\n", - general_cfg_entries[type].key); + for (; type < DLT_LOGSTORAGE_GENERAL_CONF_COUNT; type++) { + if (dlt_config_file_get_value(config_file, sec_name, general_cfg_entries[type].key, value) == 0) { + if (dlt_logstorage_check_general_param(handle, type, value) != 0) { + dlt_vlog(LOG_WARNING, "General parameter %s [%s] is invalid\n", general_cfg_entries[type].key, value); } - else - { - dlt_vlog(LOG_ERR, - "General parameter %s not given\n", - general_cfg_entries[type].key); + } else { + if (general_cfg_entries[type].is_opt == 1) { + dlt_vlog(LOG_DEBUG, "Optional General parameter %s not given\n", general_cfg_entries[type].key); + } else { + dlt_vlog(LOG_ERR, "General parameter %s not given\n", general_cfg_entries[type].key); return -1; } } @@ -1927,10 +1603,9 @@ DLT_STATIC int dlt_daemon_setup_general_properties(DltLogStorage *handle, * @return 0 on success, -1 on error, 1 on warning * */ -DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle, - char *config_file_name) +DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage* handle, char* config_file_name) { - DltConfigFile *config = NULL; + DltConfigFile* config = NULL; int sec = 0; int num_sec = 0; int ret = 0; @@ -1963,34 +1638,25 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle, } if (strstr(sec_name, GENERAL_BASE_NAME) != NULL) { - if (dlt_daemon_setup_general_properties(handle, config, sec_name) == -1) - { + if (dlt_daemon_setup_general_properties(handle, config, sec_name) == -1) { dlt_log(LOG_CRIT, "General configuration is invalid\n"); continue; } - } - else if (dlt_logstorage_validate_filter_name(sec_name) == 0) - { + } else if (dlt_logstorage_validate_filter_name(sec_name) == 0) { ret = dlt_daemon_offline_setup_filter_properties(handle, config, sec_name); if (ret == DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR) { break; - } - else if (ret == DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR) - { + } else if (ret == DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR) { valid = 1; - dlt_vlog(LOG_WARNING, - "%s filter configuration is invalid \n", - sec_name); + dlt_vlog(LOG_WARNING, "%s filter configuration is invalid \n", sec_name); /* Continue reading next filter section */ continue; - } - else - /* Filter properties read and stored successfuly */ - if (valid != 1) - valid = 0; - } - else { /* unknown section */ + } else + /* Filter properties read and stored successfuly */ + if (valid != 1) + valid = 0; + } else { /* unknown section */ dlt_vlog(LOG_WARNING, "Unknown section: %s", sec_name); } } @@ -2014,31 +1680,25 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle, * @param handle DLT Logstorage handle * @return 0 on success, -1 on error, 1 on warning */ -DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle) +DLT_STATIC int dlt_logstorage_load_config(DltLogStorage* handle) { char config_file_name[PATH_MAX] = {0}; int ret = 0; /* Check if handle is NULL or already initialized or already configured */ - if ((handle == NULL) || - (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)) + if ((handle == NULL) || (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)) return -1; /* Check if this device config was already setup */ if (handle->config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) { - dlt_vlog(LOG_ERR, - "%s: Device already configured. Send disconnect first.\n", - __func__); + dlt_vlog(LOG_ERR, "%s: Device already configured. Send disconnect first.\n", __func__); return -1; } - if (snprintf(config_file_name, - PATH_MAX, - "%s/%s", - handle->device_mount_point, - DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME) < 0) { - dlt_log(LOG_ERR, - "Creating configuration file path string failed\n"); + if (snprintf( + config_file_name, PATH_MAX, "%s/%s", handle->device_mount_point, DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME) + < 0) { + dlt_log(LOG_ERR, "Creating configuration file path string failed\n"); return -1; } config_file_name[PATH_MAX - 1] = 0; @@ -2047,11 +1707,8 @@ DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle) if (ret == 1) { handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; return 1; - } - else if (ret != 0) - { - dlt_log(LOG_ERR, - "dlt_logstorage_load_config Error : Storing filters failed\n"); + } else if (ret != 0) { + dlt_log(LOG_ERR, "dlt_logstorage_load_config Error : Storing filters failed\n"); return -1; } @@ -2069,7 +1726,7 @@ DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle) * @param mount_point Device mount path * @return 0 on success, -1 on error, 1 on warning */ -int dlt_logstorage_device_connected(DltLogStorage *handle, const char *mount_point) +int dlt_logstorage_device_connected(DltLogStorage* handle, const char* mount_point) { if ((handle == NULL) || (mount_point == NULL)) { dlt_log(LOG_ERR, "Handle error \n"); @@ -2077,12 +1734,9 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, const char *mount_poi } if (handle->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { - dlt_log(LOG_WARNING, - "Device already connected. Send disconnect, connect request\n"); + dlt_log(LOG_WARNING, "Device already connected. Send disconnect, connect request\n"); - dlt_logstorage_device_disconnected( - handle, - DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); + dlt_logstorage_device_disconnected(handle, DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); } strncpy(handle->device_mount_point, mount_point, DLT_MOUNT_PATH_MAX); @@ -2094,10 +1748,10 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, const char *mount_poi handle->newest_file_list = NULL; switch (handle->config_mode) { - case DLT_LOGSTORAGE_CONFIG_FILE: + case DLT_LOGSTORAGE_CONFIG_FILE: /* Setup logstorage with config file settings */ return dlt_logstorage_load_config(handle); - default: + default: return -1; } } @@ -2112,9 +1766,9 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, const char *mount_poi * @return 0 on success, -1 on error * */ -int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason) +int dlt_logstorage_device_disconnected(DltLogStorage* handle, int reason) { - DltNewestFileName *tmp = NULL; + DltNewestFileName* tmp = NULL; if (handle == NULL) return -1; @@ -2158,47 +1812,40 @@ int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason) * @param key key to search for in Hash MAP * @return log level on success:, -1 on error */ -int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key) +int dlt_logstorage_get_loglevel_by_key(DltLogStorage* handle, char* key) { - DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + DltLogStorageFilterConfig* config[DLT_CONFIG_FILE_SECTIONS_MAX] = {0}; int num_configs = 0; int i = 0; int log_level = 0; /* Check if handle is NULL,already initialized or already configured */ - if ((handle == NULL) || - (key == NULL) || - (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || - (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + if ((handle == NULL) || (key == NULL) || (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return -1; num_configs = dlt_logstorage_list_find(key, &(handle->config_list), config); - if (num_configs == 0) - { + if (num_configs == 0) { dlt_vlog(LOG_WARNING, "Configuration for key [%s] not found!\n", key); return -1; - } - else if (num_configs == 1) - { - if (config[0] != NULL) - { + } else if (num_configs == 1) { + if (config[0] != NULL) { log_level = config[0]->log_level; } - } - else - { + } else { /** * Multiple configurations found, raise a warning to the user and go * for the more verbose one. */ - dlt_vlog(LOG_WARNING, "Multiple configuration for key [%s] found," - " return the highest log level!\n", key); - - for (i = 0; i < num_configs; i++) - { - if ((config[i] != NULL) && (config[i]->log_level > log_level)) - { + dlt_vlog( + LOG_WARNING, + "Multiple configuration for key [%s] found," + " return the highest log level!\n", + key); + + for (i = 0; i < num_configs; i++) { + if ((config[i] != NULL) && (config[i]->log_level > log_level)) { log_level = config[i]->log_level; } } @@ -2219,14 +1866,11 @@ int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key) * @param ecuid ecu id * @return number of configurations found */ -int dlt_logstorage_get_config(DltLogStorage *handle, - DltLogStorageFilterConfig **config, - char *apid, - char *ctid, - char *ecuid) +int dlt_logstorage_get_config( + DltLogStorage* handle, DltLogStorageFilterConfig** config, char* apid, char* ctid, char* ecuid) { - DltLogStorageFilterConfig **cur_config_ptr = NULL; - char key[DLT_CONFIG_FILE_SECTIONS_MAX][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = { { '\0' }, { '\0' }, { '\0' } }; + DltLogStorageFilterConfig** cur_config_ptr = NULL; + char key[DLT_CONFIG_FILE_SECTIONS_MAX][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = {{'\0'}, {'\0'}, {'\0'}}; int i = 0; size_t apid_len = 0; size_t ctid_len = 0; @@ -2235,10 +1879,8 @@ int dlt_logstorage_get_config(DltLogStorage *handle, int num = 0; /* Check if handle is NULL,already initialized or already configured */ - if ((handle == NULL) || (config == NULL) || - (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || - (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) || - (ecuid == NULL)) + if ((handle == NULL) || (config == NULL) || (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) || (ecuid == NULL)) return 0; /* Prepare possible keys with @@ -2259,17 +1901,16 @@ int dlt_logstorage_get_config(DltLogStorage *handle, /* ecu:: */ snprintf(key[0], sizeof(key[0]), "%.*s::", (int)ecuid_len, ecuid); - num_configs = dlt_logstorage_list_find(key[0], &(handle->config_list), - config); + num_configs = dlt_logstorage_list_find(key[0], &(handle->config_list), config); return num_configs; } - if (apid != NULL){ + if (apid != NULL) { apid_len = strlen(apid); if (apid_len > DLT_ID_SIZE) apid_len = DLT_ID_SIZE; } - if (ctid != NULL){ + if (ctid != NULL) { ctid_len = strlen(ctid); if (ctid_len > DLT_ID_SIZE) ctid_len = DLT_ID_SIZE; @@ -2285,34 +1926,25 @@ int dlt_logstorage_get_config(DltLogStorage *handle, snprintf(key[2], sizeof(key[2]), ":%.*s:%.*s", (int)apid_len, apid ? apid : "", (int)ctid_len, ctid ? ctid : ""); /* ecu:apid:ctid */ - snprintf(key[3], sizeof(key[3]), "%.*s:%.*s:%.*s", - (int)ecuid_len, ecuid, - (int)apid_len, apid ? apid : "", - (int)ctid_len, ctid ? ctid : ""); + snprintf( + key[3], sizeof(key[3]), "%.*s:%.*s:%.*s", (int)ecuid_len, ecuid, (int)apid_len, apid ? apid : "", (int)ctid_len, + ctid ? ctid : ""); /* ecu:apid: */ - snprintf(key[4], sizeof(key[4]), "%.*s:%.*s:", - (int)ecuid_len, ecuid, - (int)apid_len, apid ? apid : ""); + snprintf(key[4], sizeof(key[4]), "%.*s:%.*s:", (int)ecuid_len, ecuid, (int)apid_len, apid ? apid : ""); /* ecu::ctid */ - snprintf(key[5], sizeof(key[5]), "%.*s::%.*s", - (int)ecuid_len, ecuid, - (int)ctid_len, ctid ? ctid : ""); + snprintf(key[5], sizeof(key[5]), "%.*s::%.*s", (int)ecuid_len, ecuid, (int)ctid_len, ctid ? ctid : ""); /* ecu:: */ - snprintf(key[6], sizeof(key[6]), "%.*s::", - (int)ecuid_len, ecuid); + snprintf(key[6], sizeof(key[6]), "%.*s::", (int)ecuid_len, ecuid); - for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS; i++) - { + for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS; i++) { cur_config_ptr = &config[num_configs]; - num = dlt_logstorage_list_find(key[i], &(handle->config_list), - cur_config_ptr); + num = dlt_logstorage_list_find(key[i], &(handle->config_list), cur_config_ptr); num_configs += num; /* If all filter configurations matched, stop and return */ - if (num_configs == handle->num_configs) - { + if (num_configs == handle->num_configs) { break; } } @@ -2337,12 +1969,8 @@ int dlt_logstorage_get_config(DltLogStorage *handle, * @param ecuid EcuID given in the message * @return number of found configurations */ -DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle, - DltLogStorageFilterConfig **config, - char *apid, - char *ctid, - char *ecuid, - int log_level) +DLT_STATIC int dlt_logstorage_filter( + DltLogStorage* handle, DltLogStorageFilterConfig** config, char* apid, char* ctid, char* ecuid, int log_level) { int i = 0; int num = 0; @@ -2354,65 +1982,69 @@ DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle, num = dlt_logstorage_get_config(handle, config, apid, ctid, ecuid); if (num == 0) { - dlt_vlog(LOG_DEBUG, - "%s: No valid filter configuration found for apid=[%.4s] ctid=[%.4s] ecuid=[%.4s]\n", - __func__, apid, ctid, ecuid); + dlt_vlog( + LOG_DEBUG, "%s: No valid filter configuration found for apid=[%.4s] ctid=[%.4s] ecuid=[%.4s]\n", __func__, + apid, ctid, ecuid); return 0; } - for (i = 0 ; i < num ; i++) - { - if (config[i] == NULL) - { - dlt_vlog(LOG_DEBUG, - "%s: config[%d] is NULL, continue the filter loop\n", - __func__, i); + for (i = 0; i < num; i++) { + if (config[i] == NULL) { + dlt_vlog(LOG_DEBUG, "%s: config[%d] is NULL, continue the filter loop\n", __func__, i); continue; } /* filter on log level */ if (log_level > config[i]->log_level) { - dlt_vlog(LOG_DEBUG, - "%s: Requested log level (%d) is higher than config[%d]->log_level (%d). Set the config to NULL and continue the filter loop\n", - __func__, log_level, i, config[i]->log_level); + dlt_vlog( + LOG_DEBUG, + "%s: Requested log level (%d) is higher than config[%d]->log_level (%d). Set the config to NULL and " + "continue the filter loop\n", + __func__, log_level, i, config[i]->log_level); config[i] = NULL; continue; } /* filter on ECU id only if EcuID is set */ if (config[i]->ecuid != NULL) { - if (strncmp(ecuid, config[i]->ecuid, DLT_ID_SIZE) != 0) - { - dlt_vlog(LOG_DEBUG, - "%s: ECUID does not match (Requested=%s, config[%d]=%s). Set the config to NULL and continue the filter loop\n", - __func__, ecuid, i, config[i]->ecuid); + if (strncmp(ecuid, config[i]->ecuid, DLT_ID_SIZE) != 0) { + dlt_vlog( + LOG_DEBUG, + "%s: ECUID does not match (Requested=%s, config[%d]=%s). Set the config to NULL and continue the " + "filter loop\n", + __func__, ecuid, i, config[i]->ecuid); config[i] = NULL; continue; } } - if(config[i]->excluded_apids != NULL && config[i]->excluded_ctids != NULL) { + if (config[i]->excluded_apids != NULL && config[i]->excluded_ctids != NULL) { /* Filter on excluded application and context */ - if(apid != NULL && ctid != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids) - && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) { - dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s] and %s matches with [%s]. Set the config to NULL and continue the filter loop\n", - __func__, apid, config[i]->excluded_apids, ctid, config[i]->excluded_ctids); + if (apid != NULL && ctid != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids) + && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) { + dlt_vlog( + LOG_DEBUG, + "%s: %s matches with [%s] and %s matches with [%s]. Set the config to NULL and continue the filter " + "loop\n", + __func__, apid, config[i]->excluded_apids, ctid, config[i]->excluded_ctids); config[i] = NULL; } - } - else if(config[i]->excluded_apids == NULL) { + } else if (config[i]->excluded_apids == NULL) { /* Only filter on excluded contexts */ - if(ctid != NULL && config[i]->excluded_ctids != NULL && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) { - dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n", - __func__, ctid, config[i]->excluded_ctids); + if (ctid != NULL && config[i]->excluded_ctids != NULL + && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) { + dlt_vlog( + LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n", + __func__, ctid, config[i]->excluded_ctids); config[i] = NULL; } - } - else if(config[i]->excluded_ctids == NULL) { + } else if (config[i]->excluded_ctids == NULL) { /* Only filter on excluded applications */ - if(apid != NULL && config[i]->excluded_apids != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids)) { - dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n", - __func__, apid, config[i]->excluded_apids); + if (apid != NULL && config[i]->excluded_apids != NULL + && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids)) { + dlt_vlog( + LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n", + __func__, apid, config[i]->excluded_apids); config[i] = NULL; } } @@ -2438,17 +2070,11 @@ DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle, * @param disable_nw Flag to disable network routing * @return 0 on success or write errors < max write errors, -1 on error */ -int dlt_logstorage_write(DltLogStorage *handle, - DltLogStorageUserConfig *uconfig, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3, - int *disable_nw) +int dlt_logstorage_write( + DltLogStorage* handle, DltLogStorageUserConfig* uconfig, unsigned char* data1, int size1, unsigned char* data2, + int size2, unsigned char* data3, int size3, int* disable_nw) { - DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + DltLogStorageFilterConfig* config[DLT_CONFIG_FILE_SECTIONS_MAX] = {0}; int i = 0; int ret = 0; @@ -2456,24 +2082,23 @@ int dlt_logstorage_write(DltLogStorage *handle, int err = 0; /* data2 contains DltStandardHeader, DltStandardHeaderExtra and * DltExtendedHeader. We are interested in ecuid, apid, ctid and loglevel */ - DltExtendedHeader *extendedHeader = NULL; - DltStandardHeaderExtra *extraHeader = NULL; - DltStandardHeader *standardHeader = NULL; + DltExtendedHeader* extendedHeader = NULL; + DltStandardHeaderExtra* extraHeader = NULL; + DltStandardHeader* standardHeader = NULL; size_t standardHeaderExtraLen = sizeof(DltStandardHeaderExtra); size_t header_len = 0; - DltNewestFileName *tmp = NULL; + DltNewestFileName* tmp = NULL; int found = 0; int log_level = -1; - if ((handle == NULL) || (uconfig == NULL) || - (data1 == NULL) || (data2 == NULL) || (data3 == NULL) || - (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) || - (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) + if ((handle == NULL) || (uconfig == NULL) || (data1 == NULL) || (data2 == NULL) || (data3 == NULL) + || (handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return 0; /* Calculate real length of DltStandardHeaderExtra */ - standardHeader = (DltStandardHeader *)data2; + standardHeader = (DltStandardHeader*)data2; if (!DLT_IS_HTYP_WEID(standardHeader->htyp)) standardHeaderExtraLen -= (size_t)DLT_ID_SIZE; @@ -2484,8 +2109,7 @@ int dlt_logstorage_write(DltLogStorage *handle, if (!DLT_IS_HTYP_WTMS(standardHeader->htyp)) standardHeaderExtraLen -= (size_t)DLT_SIZE_WTMS; - extraHeader = (DltStandardHeaderExtra *)(data2 - + sizeof(DltStandardHeader)); + extraHeader = (DltStandardHeaderExtra*)(data2 + sizeof(DltStandardHeader)); if (DLT_IS_HTYP_UEH(standardHeader->htyp)) { header_len = sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + standardHeaderExtraLen; @@ -2496,24 +2120,22 @@ int dlt_logstorage_write(DltLogStorage *handle, return 0; } - extendedHeader = (DltExtendedHeader *)(data2 - + sizeof(DltStandardHeader) + standardHeaderExtraLen); + extendedHeader = (DltExtendedHeader*)(data2 + sizeof(DltStandardHeader) + standardHeaderExtraLen); log_level = DLT_GET_MSIN_MTIN(extendedHeader->msin); /* check if log message need to be stored in a certain device based on * filter configuration */ - num = dlt_logstorage_filter(handle, config, extendedHeader->apid, - extendedHeader->ctid, extraHeader->ecu, log_level); + num = dlt_logstorage_filter( + handle, config, extendedHeader->apid, extendedHeader->ctid, extraHeader->ecu, log_level); if ((num == 0) || (num == -1)) { - dlt_vlog(LOG_DEBUG, - "%s: No valid filter configuration found for apid=[%.4s] ctid=[%.4s] ecuid=[%.4s]!\n", - __func__, extendedHeader->apid, extendedHeader->ctid, extraHeader->ecu); + dlt_vlog( + LOG_DEBUG, "%s: No valid filter configuration found for apid=[%.4s] ctid=[%.4s] ecuid=[%.4s]!\n", + __func__, extendedHeader->apid, extendedHeader->ctid, extraHeader->ecu); return 0; } - } - else { + } else { header_len = sizeof(DltStandardHeader) + standardHeaderExtraLen; /* check if size2 is big enough to contain expected DLT message header */ @@ -2526,8 +2148,7 @@ int dlt_logstorage_write(DltLogStorage *handle, /* check if log message need to be stored in a certain device based on * filter configuration */ - num = dlt_logstorage_filter(handle, config, NULL, - NULL, extraHeader->ecu, log_level); + num = dlt_logstorage_filter(handle, config, NULL, NULL, extraHeader->ecu, log_level); if ((num == 0) || (num == -1)) { dlt_log(LOG_DEBUG, "No valid filter configuration found!\n"); @@ -2536,23 +2157,20 @@ int dlt_logstorage_write(DltLogStorage *handle, } /* store log message in every found filter */ - for (i = 0; i < num; i++) - { - if (config[i] == NULL) - { - dlt_vlog(LOG_DEBUG, - "%s: config[%d] is NULL. Continue the filter loop\n", - __func__, i); + for (i = 0; i < num; i++) { + if (config[i] == NULL) { + dlt_vlog(LOG_DEBUG, "%s: config[%d] is NULL. Continue the filter loop\n", __func__, i); continue; } /* If file name is not present, the filter is non verbose control filter * hence skip storing */ - if (config[i]->file_name == NULL) - { - dlt_vlog(LOG_DEBUG, - "%s: config[%d]->file_name is NULL, which equals to non verbose control filter. Continue the filter loop\n", - __func__, i); + if (config[i]->file_name == NULL) { + dlt_vlog( + LOG_DEBUG, + "%s: config[%d]->file_name is NULL, which equals to non verbose control filter. Continue the filter " + "loop\n", + __func__, i); continue; } @@ -2560,18 +2178,19 @@ int dlt_logstorage_write(DltLogStorage *handle, if ((config[i]->disable_network_routing & DLT_LOGSTORAGE_DISABLE_NW_ON) > 0) { *disable_nw = 1; if (config[i]->ecuid == NULL) - dlt_vlog(LOG_DEBUG, "%s: Disable routing to network for ApId-CtId-EcuId [%s]-[%s]-[]\n", __func__, - config[i]->apids, config[i]->ctids); + dlt_vlog( + LOG_DEBUG, "%s: Disable routing to network for ApId-CtId-EcuId [%s]-[%s]-[]\n", __func__, + config[i]->apids, config[i]->ctids); else - dlt_vlog(LOG_DEBUG, "%s: Disable routing to network for ApId-CtId-EcuId [%s]-[%s]-[%s]\n", __func__, - config[i]->apids, config[i]->ctids, config[i]->ecuid); + dlt_vlog( + LOG_DEBUG, "%s: Disable routing to network for ApId-CtId-EcuId [%s]-[%s]-[%s]\n", __func__, + config[i]->apids, config[i]->ctids, config[i]->ecuid); } - if (config[i]->skip == 1) - { - dlt_vlog(LOG_DEBUG, - "%s: config[%d] (filename=%s) is skipped. Continue the filter loop\n", - __func__, i, config[i]->file_name); + if (config[i]->skip == 1) { + dlt_vlog( + LOG_DEBUG, "%s: config[%d] (filename=%s) is skipped. Continue the filter loop\n", __func__, i, + config[i]->file_name); continue; } @@ -2580,47 +2199,39 @@ int dlt_logstorage_write(DltLogStorage *handle, if (strcmp(tmp->file_name, config[i]->file_name) == 0) { found = 1; break; - } - else { + } else { tmp = tmp->next; } } if (!found) { - dlt_vlog(LOG_ERR, "Cannot find out record for filename [%s]\n", - config[i]->file_name); + dlt_vlog(LOG_ERR, "Cannot find out record for filename [%s]\n", config[i]->file_name); return -1; } /* prepare log file (create and/or open)*/ if (config[i]->ecuid == NULL) - dlt_vlog(LOG_DEBUG, "%s: ApId-CtId-EcuId [%s]-[%s]-[]\n", __func__, - config[i]->apids, config[i]->ctids); + dlt_vlog(LOG_DEBUG, "%s: ApId-CtId-EcuId [%s]-[%s]-[]\n", __func__, config[i]->apids, config[i]->ctids); else - dlt_vlog(LOG_DEBUG, "%s: ApId-CtId-EcuId [%s]-[%s]-[%s]\n", __func__, - config[i]->apids, config[i]->ctids, config[i]->ecuid); + dlt_vlog( + LOG_DEBUG, "%s: ApId-CtId-EcuId [%s]-[%s]-[%s]\n", __func__, config[i]->apids, config[i]->ctids, + config[i]->ecuid); if (tmp != NULL) { - ret = config[i]->dlt_logstorage_prepare(config[i], - uconfig, - handle->device_mount_point, - size1 + size2 + size3, - tmp); + ret = config[i]->dlt_logstorage_prepare( + config[i], uconfig, handle->device_mount_point, size1 + size2 + size3, tmp); } if (ret == 0 && config[i]->skip == 1) { continue; } - if ((ret == 0) && - (config[i]->sync == DLT_LOGSTORAGE_SYNC_UNSET || - config[i]->sync == DLT_LOGSTORAGE_SYNC_ON_MSG)) { + if ((ret == 0) + && (config[i]->sync == DLT_LOGSTORAGE_SYNC_UNSET || config[i]->sync == DLT_LOGSTORAGE_SYNC_ON_MSG)) { /* It is abnormal if working file is still NULL after preparation. */ if (!config[i]->working_file_name) { - dlt_vlog(LOG_ERR, "Failed to prepare working file for %s\n", - config[i]->file_name); + dlt_vlog(LOG_ERR, "Failed to prepare working file for %s\n", config[i]->file_name); return -1; - } - else { + } else { /* After preparation phase, update newest file info * it means there is new file created, newest file info must be updated. */ @@ -2634,15 +2245,8 @@ int dlt_logstorage_write(DltLogStorage *handle, } if (ret == 0) { /* log data (write) */ - ret = config[i]->dlt_logstorage_write(config[i], - uconfig, - handle->device_mount_point, - data1, - size1, - data2, - size2, - data3, - size3); + ret = config[i]->dlt_logstorage_write( + config[i], uconfig, handle->device_mount_point, data1, size1, data2, size2, data3, size3); if (ret == 0) { /* In case of behavior CACHED_BASED, the newest file info @@ -2652,8 +2256,7 @@ int dlt_logstorage_write(DltLogStorage *handle, * If both working file name and newest file name are unavailable, * it means the sync to file is not performed yet, wait for next times. */ - if (config[i]->sync != DLT_LOGSTORAGE_SYNC_ON_MSG && - config[i]->sync != DLT_LOGSTORAGE_SYNC_UNSET) { + if (config[i]->sync != DLT_LOGSTORAGE_SYNC_ON_MSG && config[i]->sync != DLT_LOGSTORAGE_SYNC_UNSET) { if (config[i]->working_file_name) { if (tmp->newest_file) { free(tmp->newest_file); @@ -2665,38 +2268,29 @@ int dlt_logstorage_write(DltLogStorage *handle, } /* flush to be sure log is stored on device */ - ret = config[i]->dlt_logstorage_sync(config[i], - uconfig, - handle->device_mount_point, - DLT_LOGSTORAGE_SYNC_ON_MSG); + ret = config[i]->dlt_logstorage_sync( + config[i], uconfig, handle->device_mount_point, DLT_LOGSTORAGE_SYNC_ON_MSG); if (ret != 0) - dlt_log(LOG_ERR, - "dlt_logstorage_write: Unable to sync.\n"); - } - else { + dlt_log(LOG_ERR, "dlt_logstorage_write: Unable to sync.\n"); + } else { handle->write_errors += 1; - if (handle->write_errors >= - DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS) + if (handle->write_errors >= DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS) err = -1; - dlt_log(LOG_ERR, - "dlt_logstorage_write: Unable to write.\n"); + dlt_log(LOG_ERR, "dlt_logstorage_write: Unable to write.\n"); } - } - else { + } else { handle->prepare_errors += 1; - if (handle->prepare_errors >= - DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS) { + if (handle->prepare_errors >= DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS) { config[i]->skip = 1; - dlt_vlog(LOG_WARNING, - "%s: Unable to prepare. Skip filename [%s] because maxmimum trial has been reached.\n", - __func__, config[i]->file_name); + dlt_vlog( + LOG_WARNING, "%s: Unable to prepare. Skip filename [%s] because maxmimum trial has been reached.\n", + __func__, config[i]->file_name); } else { - dlt_vlog(LOG_ERR, - "%s: Unable to prepare.\n", __func__); + dlt_vlog(LOG_ERR, "%s: Unable to prepare.\n", __func__); } } } @@ -2712,9 +2306,9 @@ int dlt_logstorage_write(DltLogStorage *handle, * @param handle DltLogStorage handle * @return 0 on success, -1 on error */ -int dlt_logstorage_sync_caches(DltLogStorage *handle) +int dlt_logstorage_sync_caches(DltLogStorage* handle) { - DltLogStorageFilterList **tmp = NULL; + DltLogStorageFilterList** tmp = NULL; if (handle == NULL) return -1; @@ -2723,17 +2317,13 @@ int dlt_logstorage_sync_caches(DltLogStorage *handle) while (*(tmp) != NULL) { if ((*tmp)->data != NULL) { - if ((*tmp)->data->dlt_logstorage_sync((*tmp)->data, - &handle->uconfig, - handle->device_mount_point, - DLT_LOGSTORAGE_SYNC_ON_DEMAND) != 0) - dlt_vlog(LOG_ERR, - "%s: Sync failed. Continue with next cache.\n", - __func__); + if ((*tmp)->data->dlt_logstorage_sync( + (*tmp)->data, &handle->uconfig, handle->device_mount_point, DLT_LOGSTORAGE_SYNC_ON_DEMAND) + != 0) + dlt_vlog(LOG_ERR, "%s: Sync failed. Continue with next cache.\n", __func__); } tmp = &(*tmp)->next; - } return 0; diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h index cfb70f33b..136b5c509 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.h +++ b/src/offlinelogstorage/dlt_offline_logstorage.h @@ -60,41 +60,40 @@ #include "dlt-daemon_cfg.h" #include "dlt_config_file_parser.h" -#define DLT_OFFLINE_LOGSTORAGE_MAXIDS 100 /* Maximum entries for each apids and ctids */ -#define DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS 7 /* Max number of possible keys when searching for */ +#define DLT_OFFLINE_LOGSTORAGE_MAXIDS 100 /* Maximum entries for each apids and ctids */ +#define DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS 7 /* Max number of possible keys when searching for */ -#define DLT_OFFLINE_LOGSTORAGE_INIT_DONE 1 /* For device configuration status */ -#define DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED 1 -#define DLT_OFFLINE_LOGSTORAGE_FREE 0 -#define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED 0 -#define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE 1 +#define DLT_OFFLINE_LOGSTORAGE_INIT_DONE 1 /* For device configuration status */ +#define DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED 1 +#define DLT_OFFLINE_LOGSTORAGE_FREE 0 +#define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED 0 +#define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE 1 -#define DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES 2 /* sync logstorage caches */ +#define DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES 2 /* sync logstorage caches */ -#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN 15 /* Maximum size for key */ -#define DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN 100 /* Maximum file name length of the log file including path under mount point */ +#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN 15 /* Maximum size for key */ +#define DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN \ + 100 /* Maximum file name length of the log file including path under mount point */ -#define DLT_OFFLINE_LOGSTORAGE_GZ_FILE_EXTENSION_LEN 7 -#define DLT_OFFLINE_LOGSTORAGE_INDEX_LEN 3 -#define DLT_OFFLINE_LOGSTORAGE_MAX_INDEX 999 -#define DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN 16 -#define DLT_OFFLINE_LOGSTORAGE_INDEX_OFFSET (DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + \ - DLT_OFFLINE_LOGSTORAGE_INDEX_LEN) -#define DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN (DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + \ - DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + \ - DLT_OFFLINE_LOGSTORAGE_INDEX_LEN + 1) +#define DLT_OFFLINE_LOGSTORAGE_GZ_FILE_EXTENSION_LEN 7 +#define DLT_OFFLINE_LOGSTORAGE_INDEX_LEN 3 +#define DLT_OFFLINE_LOGSTORAGE_MAX_INDEX 999 +#define DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN 16 +#define DLT_OFFLINE_LOGSTORAGE_INDEX_OFFSET (DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + DLT_OFFLINE_LOGSTORAGE_INDEX_LEN) +#define DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN \ + (DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN \ + + DLT_OFFLINE_LOGSTORAGE_INDEX_LEN + 1) -#define DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME "dlt_logstorage.conf" +#define DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME "dlt_logstorage.conf" /* +3 because of device number and \0 */ -#define DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN (DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + \ - DLT_MOUNT_PATH_MAX + 3) +#define DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN (DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + DLT_MOUNT_PATH_MAX + 3) -#define DLT_OFFLINE_LOGSTORAGE_MAX(A, B) ((A) > (B) ? (A) : (B)) -#define DLT_OFFLINE_LOGSTORAGE_MIN(A, B) ((A) < (B) ? (A) : (B)) +#define DLT_OFFLINE_LOGSTORAGE_MAX(A, B) ((A) > (B) ? (A) : (B)) +#define DLT_OFFLINE_LOGSTORAGE_MIN(A, B) ((A) < (B) ? (A) : (B)) -#define DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS 5 -#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM 8 +#define DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS 5 +#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM 8 #define DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION "FILTER" #define DLT_OFFLINE_LOGSTORAGE_GENERAL_CONFIG_SECTION "GENERAL" @@ -102,50 +101,48 @@ #define DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION "NON-VERBOSE-LOGLEVEL-CTRL" /* Offline Logstorage sync strategies */ -#define DLT_LOGSTORAGE_SYNC_ON_ERROR -1 /* error case */ -#define DLT_LOGSTORAGE_SYNC_UNSET 0 /* strategy not set */ -#define DLT_LOGSTORAGE_SYNC_ON_MSG 1 /* default, on message sync */ -#define DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT (1 << 1) /* sync on daemon exit */ -#define DLT_LOGSTORAGE_SYNC_ON_DEMAND (1 << 2) /* sync on demand */ -#define DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT (1 << 3) /* sync on device disconnect*/ -#define DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE (1 << 4) /* sync on after specific size */ -#define DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE (1 << 5) /* sync on file size reached */ +#define DLT_LOGSTORAGE_SYNC_ON_ERROR -1 /* error case */ +#define DLT_LOGSTORAGE_SYNC_UNSET 0 /* strategy not set */ +#define DLT_LOGSTORAGE_SYNC_ON_MSG 1 /* default, on message sync */ +#define DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT (1 << 1) /* sync on daemon exit */ +#define DLT_LOGSTORAGE_SYNC_ON_DEMAND (1 << 2) /* sync on demand */ +#define DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT (1 << 3) /* sync on device disconnect*/ +#define DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE (1 << 4) /* sync on after specific size */ +#define DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE (1 << 5) /* sync on file size reached */ -#define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S)&(s)) +#define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S) & (s)) /* Offline Logstorage overwrite strategies */ -#define DLT_LOGSTORAGE_OVERWRITE_ERROR -1 /* error case */ -#define DLT_LOGSTORAGE_OVERWRITE_UNSET 0 /* strategy not set */ -#define DLT_LOGSTORAGE_OVERWRITE_DISCARD_OLD 1 /* default, discard old */ -#define DLT_LOGSTORAGE_OVERWRITE_DISCARD_NEW (1 << 1) /* discard new */ +#define DLT_LOGSTORAGE_OVERWRITE_ERROR -1 /* error case */ +#define DLT_LOGSTORAGE_OVERWRITE_UNSET 0 /* strategy not set */ +#define DLT_LOGSTORAGE_OVERWRITE_DISCARD_OLD 1 /* default, discard old */ +#define DLT_LOGSTORAGE_OVERWRITE_DISCARD_NEW (1 << 1) /* discard new */ /* Offline Logstorage disable network routing */ -#define DLT_LOGSTORAGE_DISABLE_NW_ERROR -1 /* error case */ -#define DLT_LOGSTORAGE_DISABLE_NW_UNSET 0 /* not set */ -#define DLT_LOGSTORAGE_DISABLE_NW_OFF 1 /* default, enable network routing */ -#define DLT_LOGSTORAGE_DISABLE_NW_ON (1 << 1) /* disable network routing */ +#define DLT_LOGSTORAGE_DISABLE_NW_ERROR -1 /* error case */ +#define DLT_LOGSTORAGE_DISABLE_NW_UNSET 0 /* not set */ +#define DLT_LOGSTORAGE_DISABLE_NW_OFF 1 /* default, enable network routing */ +#define DLT_LOGSTORAGE_DISABLE_NW_ON (1 << 1) /* disable network routing */ /* Offline Logstorage disable network routing */ -#define DLT_LOGSTORAGE_GZIP_ERROR -1 /* error case */ -#define DLT_LOGSTORAGE_GZIP_UNSET 0 /* not set */ -#define DLT_LOGSTORAGE_GZIP_OFF 1 /* default, no compression */ -#define DLT_LOGSTORAGE_GZIP_ON (1 << 1) /* enable gzip compression */ +#define DLT_LOGSTORAGE_GZIP_ERROR -1 /* error case */ +#define DLT_LOGSTORAGE_GZIP_UNSET 0 /* not set */ +#define DLT_LOGSTORAGE_GZIP_OFF 1 /* default, no compression */ +#define DLT_LOGSTORAGE_GZIP_ON (1 << 1) /* enable gzip compression */ /* logstorage max cache */ extern unsigned int g_logstorage_cache_max; /* current logstorage cache size */ extern unsigned int g_logstorage_cache_size; -typedef struct -{ - unsigned int offset; /* current write offset */ - unsigned int wrap_around_cnt; /* wrap around counter */ +typedef struct { + unsigned int offset; /* current write offset */ + unsigned int wrap_around_cnt; /* wrap around counter */ unsigned int last_sync_offset; /* last sync position */ - unsigned int end_sync_offset; /* end position of previous round */ + unsigned int end_sync_offset; /* end position of previous round */ } DltLogStorageCacheFooter; -typedef struct -{ +typedef struct { /* File name user configurations */ int logfile_timestamp; /* Timestamp set/reset */ char logfile_delimiter; /* Choice of delimiter */ @@ -154,111 +151,96 @@ typedef struct int logfile_optional_counter; /* Don't append counter for num_files=1 */ } DltLogStorageUserConfig; -typedef struct DltLogStorageFileList -{ +typedef struct DltLogStorageFileList { /* List for filenames */ - char *name; /* Filename */ + char* name; /* Filename */ unsigned int idx; /* File index */ - struct DltLogStorageFileList *next; /* Pointer to next */ + struct DltLogStorageFileList* next; /* Pointer to next */ } DltLogStorageFileList; typedef struct DltNewestFileName DltNewestFileName; -struct DltNewestFileName -{ - char *file_name; /* The unique name of file in whole a dlt_logstorage.conf */ - char *newest_file; /* The real newest name of file which is associated with filename.*/ - unsigned int wrap_id; /* Identifier of wrap around happened for this file_name */ - DltNewestFileName *next; /* Pointer to next */ +struct DltNewestFileName { + char* file_name; /* The unique name of file in whole a dlt_logstorage.conf */ + char* newest_file; /* The real newest name of file which is associated with filename.*/ + unsigned int wrap_id; /* Identifier of wrap around happened for this file_name */ + DltNewestFileName* next; /* Pointer to next */ }; typedef struct DltLogStorageFilterConfig DltLogStorageFilterConfig; -struct DltLogStorageFilterConfig -{ +struct DltLogStorageFilterConfig { /* filter section */ - char *apids; /* Application IDs configured for filter */ - char *ctids; /* Context IDs configured for filter */ - char *excluded_apids; /* Excluded Application IDs configured for filter */ - char *excluded_ctids; /* Excluded Context IDs configured for filter */ - int log_level; /* Log level number configured for filter */ - int reset_log_level; /* reset Log level to be sent on disconnect */ - char *file_name; /* File name for log storage configured for filter */ - char *working_file_name; /* Current open log file name */ - unsigned int wrap_id; /* Identifier of wrap around happened for this filter */ - unsigned int file_size; /* MAX File size of storage file configured for filter */ - unsigned int num_files; /* MAX number of storage files configured for filters */ - int sync; /* Sync strategy */ - int overwrite; /* Overwrite strategy */ - int skip; /* Flag to skip file logging if DISCARD_NEW */ - char *ecuid; /* ECU identifier */ - int gzip_compression; /* Toggle if log files should be gzip compressed */ + char* apids; /* Application IDs configured for filter */ + char* ctids; /* Context IDs configured for filter */ + char* excluded_apids; /* Excluded Application IDs configured for filter */ + char* excluded_ctids; /* Excluded Context IDs configured for filter */ + int log_level; /* Log level number configured for filter */ + int reset_log_level; /* reset Log level to be sent on disconnect */ + char* file_name; /* File name for log storage configured for filter */ + char* working_file_name; /* Current open log file name */ + unsigned int wrap_id; /* Identifier of wrap around happened for this filter */ + unsigned int file_size; /* MAX File size of storage file configured for filter */ + unsigned int num_files; /* MAX number of storage files configured for filters */ + int sync; /* Sync strategy */ + int overwrite; /* Overwrite strategy */ + int skip; /* Flag to skip file logging if DISCARD_NEW */ + char* ecuid; /* ECU identifier */ + int gzip_compression; /* Toggle if log files should be gzip compressed */ /* callback function for filter configurations */ - int (*dlt_logstorage_prepare)(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info); - int (*dlt_logstorage_write)(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3); + int (*dlt_logstorage_prepare)( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int log_msg_size, + DltNewestFileName* newest_file_info); + int (*dlt_logstorage_write)( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, unsigned char* data1, + int size1, unsigned char* data2, int size2, unsigned char* data3, int size3); /* status is strategy, e.g. DLT_LOGSTORAGE_SYNC_ON_MSG is used when callback * is called on message received */ - int (*dlt_logstorage_sync)(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *uconfig, - char *dev_path, - int status); - FILE *log; /* current open log file */ - int fd; /* The file descriptor for the active log file */ + int (*dlt_logstorage_sync)( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* uconfig, char* dev_path, int status); + FILE* log; /* current open log file */ + int fd; /* The file descriptor for the active log file */ #ifdef DLT_LOGSTORAGE_USE_GZIP - gzFile gzlog; /* current open gz log file */ + gzFile gzlog; /* current open gz log file */ #endif - void *cache; /* log data cache */ - unsigned int specific_size; /* cache size used for specific_size sync strategy */ - unsigned int current_write_file_offset; /* file offset for specific_size sync strategy */ - DltLogStorageFileList *records; /* File name list */ - int disable_network_routing; /* Flag to disable routing to network client */ + void* cache; /* log data cache */ + unsigned int specific_size; /* cache size used for specific_size sync strategy */ + unsigned int current_write_file_offset; /* file offset for specific_size sync strategy */ + DltLogStorageFileList* records; /* File name list */ + int disable_network_routing; /* Flag to disable routing to network client */ }; typedef struct DltLogStorageFilterList DltLogStorageFilterList; -struct DltLogStorageFilterList -{ - char *key_list; /* List of key */ - int num_keys; /* Number of keys */ - DltLogStorageFilterConfig *data; /* Filter data */ - DltLogStorageFilterList *next; /* Pointer to next */ +struct DltLogStorageFilterList { + char* key_list; /* List of key */ + int num_keys; /* Number of keys */ + DltLogStorageFilterConfig* data; /* Filter data */ + DltLogStorageFilterList* next; /* Pointer to next */ }; typedef enum { - DLT_LOGSTORAGE_CONFIG_FILE = 0, /* Use dlt-logstorage.conf file from device */ + DLT_LOGSTORAGE_CONFIG_FILE = 0, /* Use dlt-logstorage.conf file from device */ } DltLogStorageConfigMode; -typedef struct -{ - DltLogStorageFilterList *config_list; /* List of all filters */ - DltLogStorageUserConfig uconfig; /* User configurations for file name*/ - int num_configs; /* Number of configs */ +typedef struct { + DltLogStorageFilterList* config_list; /* List of all filters */ + DltLogStorageUserConfig uconfig; /* User configurations for file name*/ + int num_configs; /* Number of configs */ char device_mount_point[DLT_MOUNT_PATH_MAX + 1]; /* Device mount path */ - unsigned int connection_type; /* Type of connection */ - unsigned int config_status; /* Status of configuration */ - int prepare_errors; /* number of prepare errors */ - int write_errors; /* number of write errors */ - DltNewestFileName *newest_file_list; /* List of newest file name */ - int maintain_logstorage_loglevel; /* Permission to maintain the logstorage loglevel*/ - DltLogStorageConfigMode config_mode; /* Configuration Mechanism */ + unsigned int connection_type; /* Type of connection */ + unsigned int config_status; /* Status of configuration */ + int prepare_errors; /* number of prepare errors */ + int write_errors; /* number of write errors */ + DltNewestFileName* newest_file_list; /* List of newest file name */ + int maintain_logstorage_loglevel; /* Permission to maintain the logstorage loglevel*/ + DltLogStorageConfigMode config_mode; /* Configuration Mechanism */ } DltLogStorage; typedef struct { - char *key; /* The configuration key */ - int (*func)(DltLogStorage *handle, char *value); /* conf handler */ - int is_opt; /* If configuration is optional or not */ + char* key; /* The configuration key */ + int (*func)(DltLogStorage* handle, char* value); /* conf handler */ + int is_opt; /* If configuration is optional or not */ } DltLogstorageGeneralConf; typedef enum { @@ -267,9 +249,9 @@ typedef enum { } DltLogstorageGeneralConfType; typedef struct { - char *key; /* Configuration key */ - int (*func)(DltLogStorageFilterConfig *config, char *value); /* conf handler */ - int is_opt; /* If configuration is optional or not */ + char* key; /* Configuration key */ + int (*func)(DltLogStorageFilterConfig* config, char* value); /* conf handler */ + int is_opt; /* If configuration is optional or not */ } DltLogstorageFilterConf; typedef enum { @@ -301,8 +283,7 @@ typedef enum { * @param mount_point Device mount path * @return 0 on success, -1 on error */ -int dlt_logstorage_device_connected(DltLogStorage *handle, - const char *mount_point); +int dlt_logstorage_device_connected(DltLogStorage* handle, const char* mount_point); /** * dlt_logstorage_device_disconnected @@ -312,8 +293,7 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, * @param reason Reason for device disconnection * @return 0 on success, -1 on error */ -int dlt_logstorage_device_disconnected(DltLogStorage *handle, - int reason); +int dlt_logstorage_device_disconnected(DltLogStorage* handle, int reason); /** * dlt_logstorage_get_config * @@ -329,11 +309,8 @@ int dlt_logstorage_device_disconnected(DltLogStorage *handle, * @param ecuid ecu id * @return number of found configurations */ -int dlt_logstorage_get_config(DltLogStorage *handle, - DltLogStorageFilterConfig **config, - char *apid, - char *ctid, - char *ecuid); +int dlt_logstorage_get_config( + DltLogStorage* handle, DltLogStorageFilterConfig** config, char* apid, char* ctid, char* ecuid); /** * dlt_logstorage_get_loglevel_by_key @@ -346,7 +323,7 @@ int dlt_logstorage_get_config(DltLogStorage *handle, * @param key key to search for in Hash MAP * @return log level on success:, -1 on error */ -int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key); +int dlt_logstorage_get_loglevel_by_key(DltLogStorage* handle, char* key); /** * dlt_logstorage_write @@ -365,15 +342,9 @@ int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key); * @param disable_nw Flag to disable network routing * @return 0 on success or write errors < max write errors, -1 on error */ -int dlt_logstorage_write(DltLogStorage *handle, - DltLogStorageUserConfig *uconfig, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3, - int *disable_nw); +int dlt_logstorage_write( + DltLogStorage* handle, DltLogStorageUserConfig* uconfig, unsigned char* data1, int size1, unsigned char* data2, + int size2, unsigned char* data3, int size3, int* disable_nw); /** * dlt_logstorage_sync_caches @@ -383,6 +354,6 @@ int dlt_logstorage_write(DltLogStorage *handle, * @param handle DltLogStorage handle * @return 0 on success, -1 otherwise */ -int dlt_logstorage_sync_caches(DltLogStorage *handle); +int dlt_logstorage_sync_caches(DltLogStorage* handle); #endif /* DLT_OFFLINE_LOGSTORAGE_H */ diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c index ae8f4442f..bc304993d 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c @@ -44,7 +44,7 @@ unsigned int g_logstorage_cache_size; * @param dst The destination string * @param src The source string to concat */ -DLT_STATIC void dlt_logstorage_concat_logfile_name(char *log_file_name, const char *append) +DLT_STATIC void dlt_logstorage_concat_logfile_name(char* log_file_name, const char* append) { size_t dst_len = strnlen(log_file_name, DLT_MOUNT_PATH_MAX); size_t src_len = strlen(append); @@ -82,12 +82,9 @@ DLT_STATIC void dlt_logstorage_concat_logfile_name(char *log_file_name, const ch * @param[in] idx continous index of log files * @ return None */ -void dlt_logstorage_log_file_name(char *log_file_name, - DltLogStorageUserConfig *file_config, - const DltLogStorageFilterConfig *filter_config, - const char *name, - const int num_files, - const int idx) +void dlt_logstorage_log_file_name( + char* log_file_name, DltLogStorageUserConfig* file_config, const DltLogStorageFilterConfig* filter_config, + const char* name, const int num_files, const int idx) { if ((log_file_name == NULL) || (file_config == NULL) || (filter_config == NULL)) return; @@ -99,9 +96,7 @@ void dlt_logstorage_log_file_name(char *log_file_name, index_width = 0; } - const char *suffix = - filter_config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON ? ".dlt.gz" - : ".dlt"; + const char* suffix = filter_config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON ? ".dlt.gz" : ".dlt"; const size_t smax = (size_t)DLT_MOUNT_PATH_MAX - strlen(suffix) - 1; size_t spos = 0; log_file_name[spos] = '\0'; @@ -120,7 +115,7 @@ void dlt_logstorage_log_file_name(char *log_file_name, spos = smax; } else if (rt < 0) { dlt_vlog(LOG_ERR, "%s: snprintf error rt=%d\n", __func__, rt); - const char *fmt_err = "fmt_err"; + const char* fmt_err = "fmt_err"; memcpy(log_file_name, fmt_err, strlen(fmt_err) + 1); spos = strlen(fmt_err) + 1; } else { @@ -130,25 +125,18 @@ void dlt_logstorage_log_file_name(char *log_file_name, /* Add time stamp if user has configured */ if (file_config->logfile_timestamp) { - char stamp[DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1] = { 0 }; + char stamp[DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1] = {0}; time_t t = time(NULL); struct tm tm_info; ssize_t n = 0; tzset(); localtime_r(&t, &tm_info); - n = snprintf(stamp, - DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1, - "%c%04d%02d%02d-%02d%02d%02d", - delim, - 1900 + tm_info.tm_year, - 1 + tm_info.tm_mon, - tm_info.tm_mday, - tm_info.tm_hour, - tm_info.tm_min, - tm_info.tm_sec); + n = snprintf( + stamp, DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1, "%c%04d%02d%02d-%02d%02d%02d", delim, + 1900 + tm_info.tm_year, 1 + tm_info.tm_mon, tm_info.tm_mday, tm_info.tm_hour, tm_info.tm_min, + tm_info.tm_sec); if (n < 0 || (size_t)n > (DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1)) { - dlt_vlog(LOG_WARNING, "%s: snprintf truncation %s\n", __func__, - stamp); + dlt_vlog(LOG_WARNING, "%s: snprintf truncation %s\n", __func__, stamp); } dlt_logstorage_concat_logfile_name(log_file_name, stamp); } @@ -167,7 +155,7 @@ void dlt_logstorage_log_file_name(char *log_file_name, * @param head Log filename list * @ return The last (biggest) index */ -unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList **head) +unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList** head) { int done = 0; unsigned int max_idx = 0; @@ -177,9 +165,9 @@ unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList **head) while (!done) { /* "source" of the pointer to the current node in the list struct */ - DltLogStorageFileList **pv = head; - DltLogStorageFileList *nd = *head; /* local iterator pointer */ - DltLogStorageFileList *nx = (*head)->next; /* local next pointer */ + DltLogStorageFileList** pv = head; + DltLogStorageFileList* nd = *head; /* local iterator pointer */ + DltLogStorageFileList* nx = (*head)->next; /* local next pointer */ done = 1; @@ -211,19 +199,18 @@ unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList **head) * @param head Log filename list * @ return None */ -void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head) +void dlt_logstorage_rearrange_file_name(DltLogStorageFileList** head) { - DltLogStorageFileList *n_prev = NULL; - DltLogStorageFileList *tail = NULL; - DltLogStorageFileList *wrap_pre = NULL; - DltLogStorageFileList *wrap_post = NULL; - DltLogStorageFileList *n = NULL; + DltLogStorageFileList* n_prev = NULL; + DltLogStorageFileList* tail = NULL; + DltLogStorageFileList* wrap_pre = NULL; + DltLogStorageFileList* wrap_post = NULL; + DltLogStorageFileList* n = NULL; if ((head == NULL) || (*head == NULL) || ((*head)->next == NULL)) return; - if ((*head)->idx != 1) - { + if ((*head)->idx != 1) { /* Do not sort */ return; } @@ -261,9 +248,8 @@ void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head) * @param file file name to extract the index from * @return index on success, -1 if no index is found */ -unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_config, - DltLogStorageFilterConfig *config, - char *file) +unsigned int dlt_logstorage_get_idx_of_log_file( + DltLogStorageUserConfig* file_config, DltLogStorageFilterConfig* config, char* file) { if (file_config == NULL || config == NULL || file == NULL) return (unsigned int)-1; @@ -284,8 +270,7 @@ unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_co idx = strtol(sptr, &eptr, 10); if (idx == 0) - dlt_log(LOG_ERR, - "Unable to calculate index from log file name. Reset to 001.\n"); + dlt_log(LOG_ERR, "Unable to calculate index from log file name. Reset to 001.\n"); return (unsigned int)idx; } @@ -301,43 +286,37 @@ unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_co * @param config DltLogStorageFilterConfig * @return 0 on success, -1 on error */ -int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, - char *path, - DltLogStorageFilterConfig *config) +int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig* file_config, char* path, DltLogStorageFilterConfig* config) { int check = 0; int i = 0; int cnt = 0; int ret = 0; unsigned int max_idx = 0; - struct dirent **files = { 0 }; + struct dirent** files = {0}; unsigned int current_idx = 0; - DltLogStorageFileList *n = NULL; - DltLogStorageFileList *n1 = NULL; - char storage_path[DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN + 1] = { '\0' }; - char file_name[DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + 1] = { '\0' }; + DltLogStorageFileList* n = NULL; + DltLogStorageFileList* n1 = NULL; + char storage_path[DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN + 1] = {'\0'}; + char file_name[DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + 1] = {'\0'}; char* dir = NULL; - if ((config == NULL) || - (file_config == NULL) || - (path == NULL) || - (config->file_name == NULL)) + if ((config == NULL) || (file_config == NULL) || (path == NULL) || (config->file_name == NULL)) return -1; strncpy(storage_path, path, DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN); if (strstr(config->file_name, "/") != NULL) { /* Append directory path */ - char tmpdir[DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + 1] = { '\0' }; - char tmpfile[DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + 1] = { '\0' }; - char *file; + char tmpdir[DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + 1] = {'\0'}; + char tmpfile[DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + 1] = {'\0'}; + char* file; strncpy(tmpdir, config->file_name, DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN); strncpy(tmpfile, config->file_name, DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN); dir = dirname(tmpdir); file = basename(tmpfile); if ((strlen(path) + strlen(dir)) > DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN) { - dlt_vlog(LOG_ERR, "%s: Directory name [%s] is too long to store (file name [%s])\n", - __func__, dir, file); + dlt_vlog(LOG_ERR, "%s: Directory name [%s] is too long to store (file name [%s])\n", __func__, dir, file); return -1; } strncat(storage_path, dir, DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN - strlen(storage_path)); @@ -349,8 +328,7 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, cnt = scandir(storage_path, &files, 0, alphasort); if (cnt < 0) { - dlt_vlog(LOG_ERR, "%s: Failed to scan directory [%s] for file name [%s]\n", - __func__, storage_path, file_name); + dlt_vlog(LOG_ERR, "%s: Failed to scan directory [%s] for file name [%s]\n", __func__, storage_path, file_name); return -1; } @@ -372,20 +350,18 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, config->records = NULL; } - char *suffix = config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON ? ".dlt.gz" : ".dlt"; + char* suffix = config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON ? ".dlt.gz" : ".dlt"; for (i = 0; i < cnt; i++) { size_t len = strlen(file_name); - dlt_vlog(LOG_DEBUG, - "%s: Scanned file name=[%s], filter file name=[%s]\n", - __func__, files[i]->d_name, file_name); + dlt_vlog( + LOG_DEBUG, "%s: Scanned file name=[%s], filter file name=[%s]\n", __func__, files[i]->d_name, file_name); if (strncmp(files[i]->d_name, file_name, len) == 0) { if (config->num_files == 1 && file_config->logfile_optional_counter) { /* .dlt or _.dlt */ - if ((files[i]->d_name[len] == suffix[0]) || - (file_config->logfile_timestamp && - (files[i]->d_name[len] == file_config->logfile_delimiter))) { + if ((files[i]->d_name[len] == suffix[0]) + || (file_config->logfile_timestamp && (files[i]->d_name[len] == file_config->logfile_delimiter))) { current_idx = 1; } else { continue; @@ -393,14 +369,13 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, } else { /* _idx.dlt or _idx_.dlt */ if (files[i]->d_name[len] == file_config->logfile_delimiter) { - current_idx = dlt_logstorage_get_idx_of_log_file(file_config, config, - files[i]->d_name); + current_idx = dlt_logstorage_get_idx_of_log_file(file_config, config, files[i]->d_name); } else { continue; } } - DltLogStorageFileList **tmp = NULL; + DltLogStorageFileList** tmp = NULL; if (config->records == NULL) { config->records = malloc(sizeof(DltLogStorageFileList)); @@ -412,8 +387,7 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, } tmp = &config->records; - } - else { + } else { tmp = &config->records; while (*(tmp) != NULL) @@ -428,7 +402,7 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, } } - char tmpfile[DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + 1] = { '\0' }; + char tmpfile[DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + 1] = {'\0'}; if (dir != NULL) { /* Append directory path */ strcat(tmpfile, dir); @@ -442,8 +416,7 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, } } - dlt_vlog(LOG_DEBUG, "%s: After dir scan: [%d] files of [%s]\n", __func__, - check, file_name); + dlt_vlog(LOG_DEBUG, "%s: After dir scan: [%d] files of [%s]\n", __func__, check, file_name); if (ret == 0) { max_idx = dlt_logstorage_sort_file_name(&config->records); @@ -477,11 +450,10 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, * @param fpath The file path * @param mode The mode to open the file with */ -DLT_STATIC void dlt_logstorage_open_log_output_file(DltLogStorageFilterConfig *config, - const char *fpath, - const char *mode) +DLT_STATIC void dlt_logstorage_open_log_output_file( + DltLogStorageFilterConfig* config, const char* fpath, const char* mode) { - FILE *file = fopen(fpath, mode); + FILE* file = fopen(fpath, mode); if (file == NULL) { dlt_vlog(LOG_DEBUG, "%s: could not open configuration file\n", __func__); return; @@ -492,8 +464,7 @@ DLT_STATIC void dlt_logstorage_open_log_output_file(DltLogStorageFilterConfig *c dlt_vlog(LOG_DEBUG, "%s: Opening GZIP log file\n", __func__); config->gzlog = gzdopen(config->fd, mode); #endif - } - else { + } else { dlt_vlog(LOG_DEBUG, "%s: Opening log file\n", __func__); config->log = file; } @@ -514,22 +485,19 @@ DLT_STATIC void dlt_logstorage_open_log_output_file(DltLogStorageFilterConfig *c * @param is_update_required The file list needs to be updated * @return 0 on succes, -1 on error */ -int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int msg_size, - bool is_update_required, - bool is_sync) +int dlt_logstorage_open_log_file( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int msg_size, + bool is_update_required, bool is_sync) { int ret = 0; - char absolute_file_path[DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN + 1] = { '\0' }; - char storage_path[DLT_MOUNT_PATH_MAX + 1] = { '\0' }; - char file_name[DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + 1] = { '\0' }; + char absolute_file_path[DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN + 1] = {'\0'}; + char storage_path[DLT_MOUNT_PATH_MAX + 1] = {'\0'}; + char file_name[DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + 1] = {'\0'}; unsigned int num_log_files = 0; struct stat s; memset(&s, 0, sizeof(struct stat)); - DltLogStorageFileList **tmp = NULL; - DltLogStorageFileList **newest = NULL; + DltLogStorageFileList** tmp = NULL; + DltLogStorageFileList** newest = NULL; if (config == NULL) return -1; @@ -570,12 +538,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, /* need new file*/ if (num_log_files == 0) { - dlt_logstorage_log_file_name(file_name, - file_config, - config, - config->file_name, - (int)config->num_files, - 1); + dlt_logstorage_log_file_name(file_name, file_config, config, config->file_name, (int)config->num_files, 1); /* concatenate path and file and open absolute path */ strcat(absolute_file_path, storage_path); @@ -594,8 +557,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, (*tmp)->name = strdup(file_name); (*tmp)->idx = 1; (*tmp)->next = NULL; - } - else { + } else { strcat(absolute_file_path, storage_path); /* newest file available @@ -617,23 +579,21 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, } snprintf(absolute_file_path + abs_len, sizeof(absolute_file_path) - abs_len, "%s", config->working_file_name); - dlt_vlog(LOG_DEBUG, - "%s: Number of log files-newest file-wrap_id [%u]-[%s]-[%u]\n", - __func__, num_log_files, config->working_file_name, - config->wrap_id); + dlt_vlog( + LOG_DEBUG, "%s: Number of log files-newest file-wrap_id [%u]-[%s]-[%u]\n", __func__, num_log_files, + config->working_file_name, config->wrap_id); ret = stat(absolute_file_path, &s); /* if file stats is read and, either * is_sync is true and (other than ON_MSG sync behavior and current size is less than configured size) or * msg_size fit into the size (ON_MSG or par of cache needs to be written into new file), open it */ - if ((ret == 0) && - ((is_sync && (s.st_size < (long)config->file_size)) || - (!is_sync && (s.st_size + msg_size <= (long)config->file_size)))) { + if ((ret == 0) + && ((is_sync && (s.st_size < (long)config->file_size)) + || (!is_sync && (s.st_size + msg_size <= (long)config->file_size)))) { dlt_logstorage_open_log_output_file(config, absolute_file_path, "a"); config->current_write_file_offset = (unsigned int)s.st_size; - } - else { + } else { /* no space in file or file stats cannot be read */ unsigned int idx = 0; @@ -641,21 +601,19 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, if (config->num_files == 1 && file_config->logfile_optional_counter) { idx = 1; } else { - idx = dlt_logstorage_get_idx_of_log_file(file_config, config, - config->working_file_name); + idx = dlt_logstorage_get_idx_of_log_file(file_config, config, config->working_file_name); } /* Check if file logging shall be stopped */ if (config->overwrite == DLT_LOGSTORAGE_OVERWRITE_DISCARD_NEW) { - dlt_vlog(LOG_DEBUG, - "%s: num_files=%d, current_idx=%d (filename=%s)\n", - __func__, config->num_files, idx, - config->file_name); + dlt_vlog( + LOG_DEBUG, "%s: num_files=%d, current_idx=%d (filename=%s)\n", __func__, config->num_files, idx, + config->file_name); if (config->num_files == idx) { - dlt_vlog(LOG_INFO, - "%s: logstorage limit reached, stopping capture for filter: %s\n", - __func__, config->file_name); + dlt_vlog( + LOG_INFO, "%s: logstorage limit reached, stopping capture for filter: %s\n", __func__, + config->file_name); config->skip = 1; return 0; } @@ -670,21 +628,15 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, config->wrap_id += 1; } - dlt_logstorage_log_file_name(file_name, - file_config, - config, - config->file_name, - (int)config->num_files, - (int)idx); + dlt_logstorage_log_file_name( + file_name, file_config, config, config->file_name, (int)config->num_files, (int)idx); /* concatenate path and file and open absolute path */ - memset(absolute_file_path, - 0, - sizeof(absolute_file_path) / sizeof(char)); + memset(absolute_file_path, 0, sizeof(absolute_file_path) / sizeof(char)); strcat(absolute_file_path, storage_path); strcat(absolute_file_path, file_name); - if(config->working_file_name) { + if (config->working_file_name) { free(config->working_file_name); config->working_file_name = strdup(file_name); } @@ -695,16 +647,14 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, if (config->wrap_id && stat(absolute_file_path, &s) == 0) { remove(absolute_file_path); num_log_files -= 1; - dlt_vlog(LOG_DEBUG, - "%s: Remove '%s' (num_log_files: %u, config->num_files:%u)\n", - __func__, absolute_file_path, num_log_files, config->num_files); + dlt_vlog( + LOG_DEBUG, "%s: Remove '%s' (num_log_files: %u, config->num_files:%u)\n", __func__, + absolute_file_path, num_log_files, config->num_files); } config->log = fopen(absolute_file_path, "w+"); - dlt_vlog(LOG_DEBUG, - "%s: Filename and Index after updating [%s]-[%u]\n", - __func__, file_name, idx); + dlt_vlog(LOG_DEBUG, "%s: Filename and Index after updating [%s]-[%u]\n", __func__, file_name, idx); /* Add file to file list */ *tmp = malloc(sizeof(DltLogStorageFileList)); @@ -724,11 +674,9 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, if (num_log_files > config->num_files) { if (!(config->num_files == 1 && file_config->logfile_optional_counter)) { /* delete oldest */ - DltLogStorageFileList **head = &config->records; - DltLogStorageFileList *n = *head; - memset(absolute_file_path, - 0, - sizeof(absolute_file_path) / sizeof(char)); + DltLogStorageFileList** head = &config->records; + DltLogStorageFileList* n = *head; + memset(absolute_file_path, 0, sizeof(absolute_file_path) / sizeof(char)); strcat(absolute_file_path, storage_path); size_t abs_len2 = strnlen(absolute_file_path, sizeof(absolute_file_path)); size_t head_name_len = strnlen((*head)->name, sizeof(absolute_file_path) - abs_len2 - 1); @@ -737,10 +685,9 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, return -1; } snprintf(absolute_file_path + abs_len2, sizeof(absolute_file_path) - abs_len2, "%s", (*head)->name); - dlt_vlog(LOG_DEBUG, - "%s: Remove '%s' (num_log_files: %d, config->num_files:%d, file_name:%s)\n", - __func__, absolute_file_path, num_log_files, - config->num_files, config->file_name); + dlt_vlog( + LOG_DEBUG, "%s: Remove '%s' (num_log_files: %d, config->num_files:%d, file_name:%s)\n", + __func__, absolute_file_path, num_log_files, config->num_files, config->file_name); if (remove(absolute_file_path) != 0) dlt_log(LOG_ERR, "Could not remove file\n"); @@ -751,7 +698,6 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, free(n); } } - } } @@ -791,17 +737,15 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, * @param cnt count * @return index on success, -1 on error */ -DLT_STATIC int dlt_logstorage_find_dlt_header(void *ptr, - unsigned int offset, - unsigned int cnt) +DLT_STATIC int dlt_logstorage_find_dlt_header(void* ptr, unsigned int offset, unsigned int cnt) { - const char magic[] = { 'D', 'L', 'T', 0x01 }; - const char *cache = (char*)ptr + offset; + const char magic[] = {'D', 'L', 'T', 0x01}; + const char* cache = (char*)ptr + offset; unsigned int i; for (i = 0; i < cnt; i++) { if ((cache[i] == 'D') && (strncmp(&cache[i], magic, 4) == 0)) - return (int)i; + return (int)i; } return -1; @@ -817,15 +761,13 @@ DLT_STATIC int dlt_logstorage_find_dlt_header(void *ptr, * @param cnt count * @return index on success, -1 on error */ -DLT_STATIC int dlt_logstorage_find_last_dlt_header(void *ptr, - unsigned int offset, - unsigned int cnt) +DLT_STATIC int dlt_logstorage_find_last_dlt_header(void* ptr, unsigned int offset, unsigned int cnt) { const char magic[] = {'D', 'L', 'T', 0x01}; - const char *cache = (char*)ptr + offset; + const char* cache = (char*)ptr + offset; int i; - for (i = (int)cnt - (DLT_ID_SIZE - 1) ; i > 0; i--) { + for (i = (int)cnt - (DLT_ID_SIZE - 1); i > 0; i--) { if ((cache[i] == 'D') && (strncmp(&cache[i], magic, 4) == 0)) return i; } @@ -843,14 +785,12 @@ DLT_STATIC int dlt_logstorage_find_last_dlt_header(void *ptr, * @param nmemb The number of blocks to write * @param config A pointer to DltLogStorageFilterConfig */ -DLT_STATIC int dlt_logstorage_write_to_log(void *ptr, size_t size, size_t nmemb, - DltLogStorageFilterConfig *config) +DLT_STATIC int dlt_logstorage_write_to_log(void* ptr, size_t size, size_t nmemb, DltLogStorageFilterConfig* config) { #ifdef DLT_LOGSTORAGE_USE_GZIP if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) { return (int)gzfwrite(ptr, size, nmemb, config->gzlog); - } - else { + } else { return (int)fwrite(ptr, size, nmemb, config->log); } #else @@ -866,8 +806,7 @@ DLT_STATIC int dlt_logstorage_write_to_log(void *ptr, size_t size, size_t nmemb, * @param config DltLogStorageFilterConfig * @param ret return value of fwrite/gzfwrite call */ -DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config, - int ret) +DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig* config, int ret) { if (config == NULL) { dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__); @@ -877,26 +816,23 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config if (ret <= 0) { if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) { #ifdef DLT_LOGSTORAGE_USE_GZIP - const char *msg = gzerror(config->gzlog, &ret); + const char* msg = gzerror(config->gzlog, &ret); if (msg != NULL) { dlt_vlog(LOG_ERR, "%s: failed to write cache into log file: %s\n", __func__, msg); } #endif - } - else { + } else { if (ferror(config->log) != 0) dlt_vlog(LOG_ERR, "%s: failed to write cache into log file\n", __func__); } - } - else { + } else { /* force sync */ if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) { #ifdef DLT_LOGSTORAGE_USE_GZIP if (gzflush(config->gzlog, Z_SYNC_FLUSH) != 0) dlt_vlog(LOG_ERR, "%s: failed to gzflush log file\n", __func__); #endif - } - else { + } else { if (fflush(config->log) != 0) dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__); } @@ -904,8 +840,7 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config if (fsync(config->fd) != 0) { /* some filesystem doesn't support fsync() */ if (errno != ENOSYS) { - dlt_vlog(LOG_ERR, "%s: failed to sync log file\n", - __func__); + dlt_vlog(LOG_ERR, "%s: failed to sync log file\n", __func__); } } } @@ -919,9 +854,8 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config * * @param config The DltLogStorageFilterConfig to operate on */ -DLT_STATIC void dlt_logstorage_close_file(DltLogStorageFilterConfig *config) +DLT_STATIC void dlt_logstorage_close_file(DltLogStorageFilterConfig* config) { - #ifdef DLT_LOGSTORAGE_USE_GZIP if (config->gzlog) { gzclose(config->gzlog); @@ -947,12 +881,9 @@ DLT_STATIC void dlt_logstorage_close_file(DltLogStorageFilterConfig *config) * @param end_offset End offset of the cache * @return 0 on success, -1 on error */ -DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - DltLogStorageCacheFooter *footer, - unsigned int start_offset, - unsigned int end_offset) +DLT_STATIC int dlt_logstorage_sync_to_file( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, + DltLogStorageCacheFooter* footer, unsigned int start_offset, unsigned int end_offset) { int ret = 0; int start_index = 0; @@ -960,9 +891,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, int count = 0; unsigned int remain_file_size = 0; - if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || - (footer == NULL)) - { + if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || (footer == NULL)) { dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__); return -1; } @@ -975,8 +904,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, dlt_logstorage_close_file(config); config->current_write_file_offset = 0; - if (dlt_logstorage_open_log_file(config, file_config, - dev_path, count, true, true) != 0) { + if (dlt_logstorage_open_log_file(config, file_config, dev_path, count, true, true) != 0) { dlt_vlog(LOG_ERR, "%s: failed to open log file\n", __func__); return -1; } @@ -988,20 +916,18 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, remain_file_size = (unsigned int)(config->file_size - config->current_write_file_offset); - if ((unsigned int)count > remain_file_size) - { + if ((unsigned int)count > remain_file_size) { /* Check if more than one message can fit into the remaining file */ - start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, - remain_file_size); - end_index = dlt_logstorage_find_last_dlt_header(config->cache, - (unsigned int)start_offset + (unsigned int)start_index, - remain_file_size - (unsigned int)start_index); + start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, remain_file_size); + end_index = dlt_logstorage_find_last_dlt_header( + config->cache, (unsigned int)start_offset + (unsigned int)start_index, + remain_file_size - (unsigned int)start_index); count = (int)(end_index - start_index); - if ((start_index >= 0) && (end_index > start_index) && - (count > 0) && ((unsigned int)count <= remain_file_size)) - { - ret = dlt_logstorage_write_to_log((uint8_t*)config->cache + start_offset + start_index, (size_t)count, 1, config); + if ((start_index >= 0) && (end_index > start_index) && (count > 0) + && ((unsigned int)count <= remain_file_size)) { + ret = dlt_logstorage_write_to_log( + (uint8_t*)config->cache + start_offset + start_index, (size_t)count, 1, config); dlt_logstorage_check_write_ret(config, ret); /* Close log file */ @@ -1010,9 +936,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, footer->last_sync_offset = (unsigned int)start_offset + (unsigned int)count; start_offset = footer->last_sync_offset; - } - else - { + } else { /* Close log file */ dlt_logstorage_close_file(config); config->current_write_file_offset = 0; @@ -1022,8 +946,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, (unsigned int)count); count = (int)(end_offset - start_offset - (unsigned int)start_index); - if ((start_index >= 0) && (count > 0)) - { + if ((start_index >= 0) && (count > 0)) { /* Prepare log file */ #ifdef DLT_LOGSTORAGE_USE_GZIP if (config->log == NULL && config->gzlog == NULL) @@ -1031,22 +954,20 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, if (config->log == NULL) #endif { - if (dlt_logstorage_open_log_file(config, file_config, dev_path, - count, true, false) != 0) - { + if (dlt_logstorage_open_log_file(config, file_config, dev_path, count, true, false) != 0) { dlt_vlog(LOG_ERR, "%s: failed to open log file\n", __func__); dlt_logstorage_close_file(config); return -1; } - if (config->skip == 1) - { + if (config->skip == 1) { dlt_logstorage_close_file(config); return 0; } } - ret = dlt_logstorage_write_to_log((uint8_t *)config->cache + start_offset + start_index, (size_t)count, 1, config); + ret = + dlt_logstorage_write_to_log((uint8_t*)config->cache + start_offset + start_index, (size_t)count, 1, config); dlt_logstorage_check_write_ret(config, ret); config->current_write_file_offset += (unsigned int)count; @@ -1071,17 +992,14 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, * @param newest_file_info Info of newest file for corresponding filename * @return 0 on success, -1 on error */ -int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info) +int dlt_logstorage_prepare_on_msg( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int log_msg_size, + DltNewestFileName* newest_file_info) { int ret = 0; struct stat s; - if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || - (newest_file_info == NULL)) { + if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || (newest_file_info == NULL)) { dlt_vlog(LOG_INFO, "%s: Wrong paratemters\n", __func__); return -1; } @@ -1104,14 +1022,8 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, } /* open a new log file */ - ret = dlt_logstorage_open_log_file(config, - file_config, - dev_path, - log_msg_size, - true, - false); - } - else { /* already open, check size and create a new file if needed */ + ret = dlt_logstorage_open_log_file(config, file_config, dev_path, log_msg_size, true, false); + } else { /* already open, check size and create a new file if needed */ ret = fstat(config->fd, &s); if (ret == 0) { @@ -1121,13 +1033,11 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, * messages aren't gigantic it should be negligeble * * Also check if wrap id needs to be updated */ - if ((s.st_size + log_msg_size > (int)config->file_size) || - (strcmp(config->working_file_name, newest_file_info->newest_file) != 0) || - (config->wrap_id < newest_file_info->wrap_id)) { - + if ((s.st_size + log_msg_size > (int)config->file_size) + || (strcmp(config->working_file_name, newest_file_info->newest_file) != 0) + || (config->wrap_id < newest_file_info->wrap_id)) { /* Sync only if on_msg */ - if ((config->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) || - (config->sync == DLT_LOGSTORAGE_SYNC_UNSET)) { + if ((config->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) || (config->sync == DLT_LOGSTORAGE_SYNC_UNSET)) { #ifdef DLT_LOGSTORAGE_USE_GZIP if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) { if (fsync(config->fd) != 0) { @@ -1158,18 +1068,11 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, config->working_file_name = strdup(newest_file_info->newest_file); } - ret = dlt_logstorage_open_log_file(config, - file_config, - dev_path, - log_msg_size, - true, - false); - } - else { /*everything is prepared */ + ret = dlt_logstorage_open_log_file(config, file_config, dev_path, log_msg_size, true, false); + } else { /*everything is prepared */ ret = 0; } - } - else { + } else { dlt_vlog(LOG_ERR, "%s: stat() failed.\n", __func__); ret = -1; } @@ -1194,21 +1097,14 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, * @param size3 payload size * @return 0 on success, -1 on error */ -int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3) +int dlt_logstorage_write_on_msg( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, unsigned char* data1, + int size1, unsigned char* data2, int size2, unsigned char* data3, int size3) { int ret; - if ((config == NULL) || (data1 == NULL) || (data2 == NULL) || (data3 == NULL) || - (file_config == NULL) || (dev_path == NULL)) - { + if ((config == NULL) || (data1 == NULL) || (data2 == NULL) || (data3 == NULL) || (file_config == NULL) + || (dev_path == NULL)) { return -1; } @@ -1229,8 +1125,7 @@ int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config, if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) { gzerror(config->gzlog, &ret); return ret; - } - else { + } else { return ferror(config->log); } #else @@ -1249,12 +1144,10 @@ int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config, * @param status Strategy flag * @return 0 on success, -1 on error */ -int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int status) +int dlt_logstorage_sync_on_msg( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int status) { - (void)file_config; /* satisfy compiler */ + (void)file_config; /* satisfy compiler */ (void)dev_path; if (config == NULL) @@ -1266,8 +1159,7 @@ int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config, if (gzflush(config->gzlog, Z_SYNC_FLUSH) != 0) dlt_vlog(LOG_ERR, "%s: failed to gzflush log file\n", __func__); #endif - } - else { + } else { if (fflush(config->log) != 0) dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__); } @@ -1290,14 +1182,11 @@ int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config, * @param newest_file_info Info of newest files for corresponding filename * @return 0 on success, -1 on error */ -int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info ) +int dlt_logstorage_prepare_msg_cache( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int log_msg_size, + DltNewestFileName* newest_file_info) { - if ((config == NULL) || (file_config == NULL) || - (dev_path == NULL) || (newest_file_info == NULL)) + if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || (newest_file_info == NULL)) return -1; /* check if newest file info is available @@ -1307,9 +1196,9 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, * ++ newest file name <> working file name */ if (newest_file_info->newest_file) { - if (config->working_file_name && - ((config->wrap_id != newest_file_info->wrap_id) || - (strcmp(newest_file_info->newest_file, config->working_file_name) != 0))) { + if (config->working_file_name + && ((config->wrap_id != newest_file_info->wrap_id) + || (strcmp(newest_file_info->newest_file, config->working_file_name) != 0))) { free(config->working_file_name); config->working_file_name = NULL; } @@ -1324,8 +1213,8 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, * Combination not allowed : File_Size with Specific_Size */ /* check for combinations of specific_size and file_size strategy */ - if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) && - ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)) > 0)) { + if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) + && ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)) > 0)) { dlt_log(LOG_WARNING, "wrong combination of sync strategies \n"); return -1; } @@ -1333,57 +1222,44 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, (void)log_msg_size; /* satisfy compiler */ /* check specific size is smaller than file size */ - if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) && - (config->specific_size > config->file_size)) - { - dlt_log(LOG_ERR, - "Cache size is larger than file size. " - "Cannot prepare log file for ON_SPECIFIC_SIZE sync\n"); + if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) + && (config->specific_size > config->file_size)) { + dlt_log( + LOG_ERR, + "Cache size is larger than file size. " + "Cannot prepare log file for ON_SPECIFIC_SIZE sync\n"); return -1; } - if (config->cache == NULL) - { + if (config->cache == NULL) { unsigned int cache_size = 0; /* check for sync_specific_size strategy */ - if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) - { + if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) { cache_size = config->specific_size; - } - else /* other cache strategies */ + } else /* other cache strategies */ { cache_size = config->file_size; } /* check total logstorage cache size */ - if ((g_logstorage_cache_size + cache_size + - sizeof(DltLogStorageCacheFooter)) > - g_logstorage_cache_max) - { - dlt_vlog(LOG_ERR, - "%s: Max size of Logstorage Cache already used. (ApId=[%s] CtId=[%s]) \n", - __func__, config->apids, config->ctids); + if ((g_logstorage_cache_size + cache_size + sizeof(DltLogStorageCacheFooter)) > g_logstorage_cache_max) { + dlt_vlog( + LOG_ERR, "%s: Max size of Logstorage Cache already used. (ApId=[%s] CtId=[%s]) \n", __func__, + config->apids, config->ctids); return -1; } else { - dlt_vlog(LOG_DEBUG, - "%s: Logstorage total: %d , requested cache size: %d, max: %d (ApId=[%s] CtId=[%s])\n", - __func__, g_logstorage_cache_size, cache_size, - g_logstorage_cache_max, config->apids, config->ctids); + dlt_vlog( + LOG_DEBUG, "%s: Logstorage total: %d , requested cache size: %d, max: %d (ApId=[%s] CtId=[%s])\n", + __func__, g_logstorage_cache_size, cache_size, g_logstorage_cache_max, config->apids, config->ctids); } /* create cache */ config->cache = calloc(1, cache_size + sizeof(DltLogStorageCacheFooter)); - if (config->cache == NULL) - { - dlt_log(LOG_CRIT, - "Cannot allocate memory for filter ring buffer\n"); - } - else - { + if (config->cache == NULL) { + dlt_log(LOG_CRIT, "Cannot allocate memory for filter ring buffer\n"); + } else { /* update current used cache size */ g_logstorage_cache_size += (unsigned int)(cache_size + sizeof(DltLogStorageCacheFooter)); } @@ -1408,41 +1284,29 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, * @param size3 payload size * @return 0 on success, -1 on error */ -int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3) +int dlt_logstorage_write_msg_cache( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, unsigned char* data1, + int size1, unsigned char* data2, int size2, unsigned char* data3, int size3) { - DltLogStorageCacheFooter *footer = NULL; + DltLogStorageCacheFooter* footer = NULL; int msg_size; int remain_cache_size; - uint8_t *curr_write_addr = NULL; + uint8_t* curr_write_addr = NULL; int ret = 0; unsigned int cache_size; - if ((config == NULL) || (data1 == NULL) || (size1 < 0) || (data2 == NULL) || - (size2 < 0) || (data3 == NULL) || (size3 < 0) || (config->cache == NULL) || - (file_config == NULL) || (dev_path == NULL)) - { + if ((config == NULL) || (data1 == NULL) || (size1 < 0) || (data2 == NULL) || (size2 < 0) || (data3 == NULL) + || (size3 < 0) || (config->cache == NULL) || (file_config == NULL) || (dev_path == NULL)) { return -1; } - if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) - { + if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) { cache_size = config->specific_size; - } - else - { + } else { cache_size = config->file_size; } - footer = (DltLogStorageCacheFooter *)((uint8_t*)config->cache + cache_size); + footer = (DltLogStorageCacheFooter*)((uint8_t*)config->cache + cache_size); msg_size = size1 + size2 + size3; remain_cache_size = (int)(cache_size - footer->offset); @@ -1467,53 +1331,33 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, * the message is still written in cache. * Then whole cache data is synchronized to file. */ - if (msg_size >= remain_cache_size) - { + if (msg_size >= remain_cache_size) { /*check for message size exceeds cache size for specific_size strategy */ - if ((unsigned int) msg_size > cache_size) - { + if ((unsigned int)msg_size > cache_size) { dlt_log(LOG_WARNING, "Message is larger than cache. Discard.\n"); return -1; } - /*sync to file for specific_size or file_size */ - if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) > 0) - { - ret = config->dlt_logstorage_sync(config, - file_config, - dev_path, - DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE); - if (ret != 0) - { - dlt_log(LOG_ERR,"dlt_logstorage_sync: Unable to sync.\n"); - return -1; - } - } - else if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) - { - - ret = config->dlt_logstorage_sync(config, - file_config, - dev_path, - DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE); - if (ret != 0) - { - dlt_log(LOG_ERR,"dlt_logstorage_sync: Unable to sync.\n"); - return -1; - } - } - else if ((DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_DEMAND) > 0) || - (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT) > 0)) - { - footer->wrap_around_cnt += 1; - } - - if (msg_size > remain_cache_size) - { + /*sync to file for specific_size or file_size */ + if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) > 0) { + ret = config->dlt_logstorage_sync(config, file_config, dev_path, DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE); + if (ret != 0) { + dlt_log(LOG_ERR, "dlt_logstorage_sync: Unable to sync.\n"); + return -1; + } + } else if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) { + ret = config->dlt_logstorage_sync(config, file_config, dev_path, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE); + if (ret != 0) { + dlt_log(LOG_ERR, "dlt_logstorage_sync: Unable to sync.\n"); + return -1; + } + } else if ( + (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_DEMAND) > 0) + || (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT) > 0)) { + footer->wrap_around_cnt += 1; + } + + if (msg_size > remain_cache_size) { /* start writing from beginning */ footer->end_sync_offset = footer->offset; curr_write_addr = config->cache; @@ -1543,83 +1387,62 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, * @param status Strategy flag * @return 0 on success, -1 on error */ -int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int status) +int dlt_logstorage_sync_msg_cache( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int status) { unsigned int cache_size; - DltLogStorageCacheFooter *footer = NULL; + DltLogStorageCacheFooter* footer = NULL; - if ((config == NULL) || (file_config == NULL) || (dev_path == NULL)) - { + if ((config == NULL) || (file_config == NULL) || (dev_path == NULL)) { return -1; } /* sync only, if given strategy is set */ - if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, status) > 0) - { - if (config->cache == NULL) - { - dlt_log(LOG_ERR, - "Cannot copy cache to file. Cache is NULL\n"); + if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, status) > 0) { + if (config->cache == NULL) { + dlt_log(LOG_ERR, "Cannot copy cache to file. Cache is NULL\n"); return -1; } - if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, - DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) - { + if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0) { cache_size = config->specific_size; - } - else - { + } else { cache_size = config->file_size; } - footer = (DltLogStorageCacheFooter *)((uint8_t*)config->cache + cache_size); + footer = (DltLogStorageCacheFooter*)((uint8_t*)config->cache + cache_size); /* sync cache data to file */ - if (footer->wrap_around_cnt < 1) - { + if (footer->wrap_around_cnt < 1) { /* Sync whole cache */ - dlt_logstorage_sync_to_file(config, file_config, dev_path, footer, - footer->last_sync_offset, footer->offset); + dlt_logstorage_sync_to_file( + config, file_config, dev_path, footer, footer->last_sync_offset, footer->offset); - } - else if ((footer->wrap_around_cnt == 1) && - (footer->offset < footer->last_sync_offset)) - { + } else if ((footer->wrap_around_cnt == 1) && (footer->offset < footer->last_sync_offset)) { /* sync (1) footer->last_sync_offset to footer->end_sync_offset, * and (2) footer->last_sync_offset (= 0) to footer->offset */ - dlt_logstorage_sync_to_file(config, file_config, dev_path, footer, - footer->last_sync_offset, footer->end_sync_offset); + dlt_logstorage_sync_to_file( + config, file_config, dev_path, footer, footer->last_sync_offset, footer->end_sync_offset); footer->last_sync_offset = 0; - dlt_logstorage_sync_to_file(config, file_config, dev_path, footer, - footer->last_sync_offset, footer->offset); - } - else - { + dlt_logstorage_sync_to_file( + config, file_config, dev_path, footer, footer->last_sync_offset, footer->offset); + } else { /* sync (1) footer->offset + index to footer->end_sync_offset, * and (2) footer->last_sync_offset (= 0) to footer->offset */ - dlt_logstorage_sync_to_file(config, file_config, dev_path, footer, - footer->offset, footer->end_sync_offset); + dlt_logstorage_sync_to_file(config, file_config, dev_path, footer, footer->offset, footer->end_sync_offset); footer->last_sync_offset = 0; - dlt_logstorage_sync_to_file(config, file_config, dev_path, footer, - footer->last_sync_offset, footer->offset); + dlt_logstorage_sync_to_file( + config, file_config, dev_path, footer, footer->last_sync_offset, footer->offset); } /* Initialize cache if needed */ - if ((status == DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) || - (status == DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)) - { + if ((status == DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) || (status == DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)) { /* clean ring buffer and reset footer information */ - memset(config->cache, 0, - cache_size + sizeof(DltLogStorageCacheFooter)); + memset(config->cache, 0, cache_size + sizeof(DltLogStorageCacheFooter)); } - if (status == DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) - { + if (status == DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE) { /* Close log file */ dlt_logstorage_close_file(config); config->current_write_file_offset = 0; diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.h b/src/offlinelogstorage/dlt_offline_logstorage_behavior.h index 08cb3d830..db54878a9 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.h +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.h @@ -51,48 +51,28 @@ #define DLT_OFFLINELOGSTORAGE_DLT_OFFLINE_LOGSTORAGE_BEHAVIOR_H_ /* ON_MSG behavior */ -int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info); -int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3); +int dlt_logstorage_prepare_on_msg( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int log_msg_size, + DltNewestFileName* newest_file_info); +int dlt_logstorage_write_on_msg( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, unsigned char* data1, + int size1, unsigned char* data2, int size2, unsigned char* data3, int size3); /* status is strategy, e.g. DLT_LOGSTORAGE_SYNC_ON_MSG is used when callback * is called on message received */ -int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int status); +int dlt_logstorage_sync_on_msg( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int status); /* Logstorage cache functionality */ -int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int log_msg_size, - DltNewestFileName *newest_file_info); +int dlt_logstorage_prepare_msg_cache( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int log_msg_size, + DltNewestFileName* newest_file_info); -int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - unsigned char *data1, - int size1, - unsigned char *data2, - int size2, - unsigned char *data3, - int size3); +int dlt_logstorage_write_msg_cache( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, unsigned char* data1, + int size1, unsigned char* data2, int size2, unsigned char* data3, int size3); -int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int status); +int dlt_logstorage_sync_msg_cache( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int status); #endif /* DLT_OFFLINELOGSTORAGE_DLT_OFFLINE_LOGSTORAGE_BEHAVIOR_H_ */ diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h b/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h index ec820d513..6dbd21298 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h @@ -49,45 +49,30 @@ #ifndef DLT_OFFLINELOGSTORAGE_BEHAVIOR_INTERNAL_H_ #define DLT_OFFLINELOGSTORAGE_BEHAVIOR_INTERNAL_H_ -void dlt_logstorage_log_file_name(char *log_file_name, - DltLogStorageUserConfig *file_config, - const DltLogStorageFilterConfig *filter_config, - const char *name, - const int num_files, - const int idx); +void dlt_logstorage_log_file_name( + char* log_file_name, DltLogStorageUserConfig* file_config, const DltLogStorageFilterConfig* filter_config, + const char* name, const int num_files, const int idx); -unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList **head); +unsigned int dlt_logstorage_sort_file_name(DltLogStorageFileList** head); -void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head); +void dlt_logstorage_rearrange_file_name(DltLogStorageFileList** head); -unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_config, - DltLogStorageFilterConfig *config, - char *file); +unsigned int dlt_logstorage_get_idx_of_log_file( + DltLogStorageUserConfig* file_config, DltLogStorageFilterConfig* config, char* file); -int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, - char *path, - DltLogStorageFilterConfig *config); +int dlt_logstorage_storage_dir_info( + DltLogStorageUserConfig* file_config, char* path, DltLogStorageFilterConfig* config); -int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int msg_size, - bool is_update_required, - bool is_sync); +int dlt_logstorage_open_log_file( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, int msg_size, + bool is_update_required, bool is_sync); -DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - DltLogStorageCacheFooter *footer, - unsigned int start_offset, - unsigned int end_offset); +DLT_STATIC int dlt_logstorage_sync_to_file( + DltLogStorageFilterConfig* config, DltLogStorageUserConfig* file_config, char* dev_path, + DltLogStorageCacheFooter* footer, unsigned int start_offset, unsigned int end_offset); -DLT_STATIC int dlt_logstorage_find_dlt_header(void *ptr, - unsigned int offset, - unsigned int cnt); +DLT_STATIC int dlt_logstorage_find_dlt_header(void* ptr, unsigned int offset, unsigned int cnt); -DLT_STATIC int dlt_logstorage_find_last_dlt_header(void *ptr, - unsigned int offset, - unsigned int cnt); +DLT_STATIC int dlt_logstorage_find_last_dlt_header(void* ptr, unsigned int offset, unsigned int cnt); #endif /* DLT_OFFLINELOGSTORAGE_BEHAVIOR_INTERNAL_H_ */ diff --git a/src/offlinelogstorage/dlt_offline_logstorage_internal.h b/src/offlinelogstorage/dlt_offline_logstorage_internal.h index f118f88d1..44eb6d471 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_internal.h +++ b/src/offlinelogstorage/dlt_offline_logstorage_internal.h @@ -48,82 +48,63 @@ #ifndef DLT_OFFLINE_LOGSTORAGE_INTERNAL_H #define DLT_OFFLINE_LOGSTORAGE_INTERNAL_H -DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, - DltLogStorageUserConfig *uconfig, - char *dev_path, - int reason); +DLT_STATIC int dlt_logstorage_list_destroy( + DltLogStorageFilterList** list, DltLogStorageUserConfig* uconfig, char* dev_path, int reason); -DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data, - DltLogStorageFilterConfig **listdata); -DLT_STATIC int dlt_logstorage_list_add(char *key, - int num_keys, - DltLogStorageFilterConfig *data, - DltLogStorageFilterList **list); +DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig* data, DltLogStorageFilterConfig** listdata); +DLT_STATIC int dlt_logstorage_list_add( + char* key, int num_keys, DltLogStorageFilterConfig* data, DltLogStorageFilterList** list); -DLT_STATIC int dlt_logstorage_list_find(char *key, - DltLogStorageFilterList **list, - DltLogStorageFilterConfig **config); +DLT_STATIC int dlt_logstorage_list_find(char* key, DltLogStorageFilterList** list, DltLogStorageFilterConfig** config); -DLT_STATIC int dlt_logstorage_count_ids(const char *str); +DLT_STATIC int dlt_logstorage_count_ids(const char* str); -DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value); +DLT_STATIC int dlt_logstorage_read_number(unsigned int* number, char* value); -DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, const char *value); +DLT_STATIC int dlt_logstorage_read_list_of_names(char** names, const char* value); -DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *excluded_ids); +DLT_STATIC bool dlt_logstorage_check_excluded_ids(char* id, char* delim, char* excluded_ids); -DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig* config, char* value); -DLT_STATIC int dlt_logstorage_check_param(DltLogStorageFilterConfig *config, - DltLogstorageFilterConfType ctype, - char *value); +DLT_STATIC int dlt_logstorage_check_param( + DltLogStorageFilterConfig* config, DltLogstorageFilterConfType ctype, char* value); -DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle, - char *config_file_name); +DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage* handle, char* config_file_name); -void dlt_logstorage_free(DltLogStorage *handle, int reason); +void dlt_logstorage_free(DltLogStorage* handle, int reason); -DLT_STATIC int dlt_logstorage_create_keys(char *apids, - char *ctids, - char *ecuid, - char **keys, - int *num_keys); +DLT_STATIC int dlt_logstorage_create_keys(char* apids, char* ctids, char* ecuid, char** keys, int* num_keys); -DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, - DltLogStorageFilterConfig *data); +DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage* handle, DltLogStorageFilterConfig* data); -DLT_STATIC int dlt_logstorage_validate_filter_name(char *name); +DLT_STATIC int dlt_logstorage_validate_filter_name(char* name); -DLT_STATIC void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig *config, - int strategy); +DLT_STATIC void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig* config, int strategy); -DLT_STATIC int dlt_logstorage_load_config(DltLogStorage *handle); +DLT_STATIC int dlt_logstorage_load_config(DltLogStorage* handle); -DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle, - DltLogStorageFilterConfig **config, - char *apid, - char *ctid, - char *ecuid, - int log_level); +DLT_STATIC int dlt_logstorage_filter( + DltLogStorage* handle, DltLogStorageFilterConfig** config, char* apid, char* ctid, char* ecuid, int log_level); #endif /* DLT_OFFLINE_LOGSTORAGE_INTERNAL_H */ diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 3763c9811..f6c1921b2 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -45,38 +45,38 @@ #include "dlt_version.h" -#if defined (__WIN32__) || defined (_MSC_VER) -# include /* for socket(), connect(), send(), and recv() */ +#if defined(__WIN32__) || defined(_MSC_VER) +#include /* for socket(), connect(), send(), and recv() */ #else -# include /* for socket(), connect(), send(), and recv() */ -# include -# include /* for clock_gettime() */ -# ifndef CLOCK_REALTIME -# define CLOCK_REALTIME 0 -# endif -# ifndef CLOCK_MONOTONIC -# define CLOCK_MONOTONIC 1 -# endif +#include /* for socket(), connect(), send(), and recv() */ +#include +#include /* for clock_gettime() */ +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 1 +#endif #endif -#if defined (_MSC_VER) -# include +#if defined(_MSC_VER) +#include #else -# include /* for read(), close() */ -# include -# include /* for gettimeofday() */ +#include /* for read(), close() */ +#include +#include /* for gettimeofday() */ #endif -#if defined (__MSDOS__) || defined (_MSC_VER) -# pragma warning(disable : 4996) /* Switch off C4996 warnings */ -# include -# include +#if defined(__MSDOS__) || defined(_MSC_VER) +#pragma warning(disable : 4996) /* Switch off C4996 warnings */ +#include +#include #endif #define MSGCONTENT_MASK 0x03 -const char dltSerialHeader[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 }; -char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D', 'L', 'S', 1 }; +const char dltSerialHeader[DLT_ID_SIZE] = {'D', 'L', 'S', 1}; +char dltSerialHeaderChar[DLT_ID_SIZE] = {'D', 'L', 'S', 1}; #if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC char dltFifoBaseDir[DLT_PATH_MAX] = "/tmp"; @@ -88,60 +88,67 @@ char dltShmName[NAME_MAX + 1] = "/dlt-shm"; static bool print_with_attributes = false; -char *message_type[] = { "log", "app_trace", "nw_trace", "control", "", "", "", "" }; -char *log_info[] = { "", "fatal", "error", "warn", "info", "debug", "verbose", "", "", "", "", "", "", "", "", "" }; -char *trace_type[] = { "", "variable", "func_in", "func_out", "state", "vfb", "", "", "", "", "", "", "", "", "", "" }; -char *nw_trace_type[] = { "", "ipc", "can", "flexray", "most", "vfb", "", "", "", "", "", "", "", "", "", "" }; -char *control_type[] = { "", "request", "response", "time", "", "", "", "", "", "", "", "", "", "", "", "" }; -static char *service_id_name[] = -{ "", "set_log_level", "set_trace_status", "get_log_info", "get_default_log_level", "store_config", - "reset_to_factory_default", - "set_com_interface_status", "set_com_interface_max_bandwidth", "set_verbose_mode", - "set_message_filtering", "set_timing_packets", - "get_local_time", "use_ecu_id", "use_session_id", "use_timestamp", "use_extended_header", - "set_default_log_level", "set_default_trace_status", - "get_software_version", "message_buffer_overflow" }; -static char *return_type[] = -{ "ok", "not_supported", "error", "perm_denied", "warning", "", "", "", "no_matching_context_id" }; +char* message_type[] = {"log", "app_trace", "nw_trace", "control", "", "", "", ""}; +char* log_info[] = {"", "fatal", "error", "warn", "info", "debug", "verbose", "", "", "", "", "", "", "", "", ""}; +char* trace_type[] = {"", "variable", "func_in", "func_out", "state", "vfb", "", "", "", "", "", "", "", "", "", ""}; +char* nw_trace_type[] = {"", "ipc", "can", "flexray", "most", "vfb", "", "", "", "", "", "", "", "", "", ""}; +char* control_type[] = {"", "request", "response", "time", "", "", "", "", "", "", "", "", "", "", "", ""}; +static char* service_id_name[] = { + "", + "set_log_level", + "set_trace_status", + "get_log_info", + "get_default_log_level", + "store_config", + "reset_to_factory_default", + "set_com_interface_status", + "set_com_interface_max_bandwidth", + "set_verbose_mode", + "set_message_filtering", + "set_timing_packets", + "get_local_time", + "use_ecu_id", + "use_session_id", + "use_timestamp", + "use_extended_header", + "set_default_log_level", + "set_default_trace_status", + "get_software_version", + "message_buffer_overflow"}; +static char* return_type[] = { + "ok", "not_supported", "error", "perm_denied", "warning", "", "", "", "no_matching_context_id"}; /* internal function definitions */ -int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete); -int dlt_buffer_reset(DltBuffer *buf); -int dlt_buffer_increase_size(DltBuffer *buf); -int dlt_buffer_minimize_size(DltBuffer *buf); -void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *data, unsigned int size); -void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsigned int size); - -static DltReturnValue dlt_message_get_extraparameters_from_recievedbuffer_v2(DltMessageV2 *msg, uint8_t* buffer, - DltHtyp2ContentType msgcontent); -DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMessageV2 *msg, uint8_t* buffer, - DltHtyp2ContentType msgcontent); +int dlt_buffer_get(DltBuffer* buf, unsigned char* data, int max_size, int delete); +int dlt_buffer_reset(DltBuffer* buf); +int dlt_buffer_increase_size(DltBuffer* buf); +int dlt_buffer_minimize_size(DltBuffer* buf); +void dlt_buffer_write_block(DltBuffer* buf, int* write, const unsigned char* data, unsigned int size); +void dlt_buffer_read_block(DltBuffer* buf, int* read, unsigned char* data, unsigned int size); + +static DltReturnValue dlt_message_get_extraparameters_from_recievedbuffer_v2( + DltMessageV2* msg, uint8_t* buffer, DltHtyp2ContentType msgcontent); +DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2( + DltMessageV2* msg, uint8_t* buffer, DltHtyp2ContentType msgcontent); #ifdef DLT_TRACE_LOAD_CTRL_ENABLE static int32_t dlt_output_soft_limit_over_warning( - DltTraceLoadSettings* tl_settings, - DltLogInternal log_internal, - void *log_params); + DltTraceLoadSettings* tl_settings, DltLogInternal log_internal, void* log_params); static int32_t dlt_output_hard_limit_warning( - DltTraceLoadSettings* tl_settings, - DltLogInternal log_internal, - void *log_params); + DltTraceLoadSettings* tl_settings, DltLogInternal log_internal, void* log_params); -static bool dlt_user_cleanup_window(DltTraceLoadStat *tl_stat); +static bool dlt_user_cleanup_window(DltTraceLoadStat* tl_stat); static int32_t dlt_switch_slot_if_needed( - DltTraceLoadSettings* tl_settings, - DltLogInternal log_internal, - void *log_internal_params, - uint32_t timestamp); + DltTraceLoadSettings* tl_settings, DltLogInternal log_internal, void* log_internal_params, uint32_t timestamp); -static void dlt_record_trace_load(DltTraceLoadStat *const tl_stat, int32_t size); +static void dlt_record_trace_load(DltTraceLoadStat* const tl_stat, int32_t size); static inline bool dlt_is_over_trace_load_soft_limit(DltTraceLoadSettings* tl_settings); static inline bool dlt_is_over_trace_load_hard_limit(DltTraceLoadSettings* tl_settings, int size); #endif -void dlt_print_hex(uint8_t *ptr, int size) +void dlt_print_hex(uint8_t* ptr, int size) { int num; @@ -152,11 +159,11 @@ void dlt_print_hex(uint8_t *ptr, int size) if (num > 0) dlt_user_printf(" "); - dlt_user_printf("%.2x", ((uint8_t *)ptr)[num]); + dlt_user_printf("%.2x", ((uint8_t*)ptr)[num]); } } -static DltReturnValue dlt_print_hex_string_delim(char *text, int textlength, uint8_t *ptr, int size, char delim) +static DltReturnValue dlt_print_hex_string_delim(char* text, int textlength, uint8_t* ptr, int size, char delim) { int num; @@ -165,9 +172,7 @@ static DltReturnValue dlt_print_hex_string_delim(char *text, int textlength, uin /* Length 3: AB_ , A is first digit of hex number, B is second digit of hex number, _ is space */ if (textlength < (size * 3)) { - dlt_vlog(LOG_WARNING, - "String does not fit hex data (available=%d, required=%d) !\n", - textlength, size * 3); + dlt_vlog(LOG_WARNING, "String does not fit hex data (available=%d, required=%d) !\n", textlength, size * 3); return DLT_RETURN_ERROR; } @@ -177,19 +182,19 @@ static DltReturnValue dlt_print_hex_string_delim(char *text, int textlength, uin text++; } - snprintf(text, 3, "%.2x", ((uint8_t *)ptr)[num]); + snprintf(text, 3, "%.2x", ((uint8_t*)ptr)[num]); text += 2; /* 2 chars */ } return DLT_RETURN_OK; } -DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size) +DltReturnValue dlt_print_hex_string(char* text, int textlength, uint8_t* ptr, int size) { return dlt_print_hex_string_delim(text, textlength, ptr, size, ' '); } -DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, int size, int html) +DltReturnValue dlt_print_mixed_string(char* text, int textlength, uint8_t* ptr, int size, int html) { int required_size = 0; int lines, rest, i; @@ -199,25 +204,22 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, /* Check maximum required size and do a length check */ if (html == 0) - required_size = - (DLT_COMMON_HEX_LINELEN + (2 * DLT_COMMON_HEX_CHARS + (DLT_COMMON_HEX_CHARS - 1)) + DLT_COMMON_CHARLEN + - DLT_COMMON_HEX_CHARS + DLT_COMMON_CHARLEN) * - ((size / DLT_COMMON_HEX_CHARS) + 1); + required_size = (DLT_COMMON_HEX_LINELEN + (2 * DLT_COMMON_HEX_CHARS + (DLT_COMMON_HEX_CHARS - 1)) + + DLT_COMMON_CHARLEN + DLT_COMMON_HEX_CHARS + DLT_COMMON_CHARLEN) + * ((size / DLT_COMMON_HEX_CHARS) + 1); /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + CR) * * ((size/16) lines + extra line for the rest) */ else - required_size = - (DLT_COMMON_HEX_LINELEN + (2 * DLT_COMMON_HEX_CHARS + (DLT_COMMON_HEX_CHARS - 1)) + DLT_COMMON_CHARLEN + - DLT_COMMON_HEX_CHARS + 4 * DLT_COMMON_CHARLEN) * - ((size / DLT_COMMON_HEX_CHARS) + 1); + required_size = (DLT_COMMON_HEX_LINELEN + (2 * DLT_COMMON_HEX_CHARS + (DLT_COMMON_HEX_CHARS - 1)) + + DLT_COMMON_CHARLEN + DLT_COMMON_HEX_CHARS + 4 * DLT_COMMON_CHARLEN) + * ((size / DLT_COMMON_HEX_CHARS) + 1); /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + 4 [HTML CR:
]) * * ((size/16) lines + extra line for the rest) */ if (textlength < required_size) { - dlt_vlog(LOG_WARNING, - "String does not fit mixed data (available=%d, required=%d) !\n", - textlength, required_size); + dlt_vlog( + LOG_WARNING, "String does not fit mixed data (available=%d, required=%d) !\n", textlength, required_size); return DLT_RETURN_ERROR; } @@ -235,9 +237,9 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, /* Hex-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_hex_string(text, textlength, - (uint8_t *)(ptr + (lines * DLT_COMMON_HEX_CHARS)), - DLT_COMMON_HEX_CHARS) < DLT_RETURN_OK) + if (dlt_print_hex_string( + text, textlength, (uint8_t*)(ptr + (lines * DLT_COMMON_HEX_CHARS)), DLT_COMMON_HEX_CHARS) + < DLT_RETURN_OK) return DLT_RETURN_ERROR; text += ((2 * DLT_COMMON_HEX_CHARS) + (DLT_COMMON_HEX_CHARS - 1)); /* 32 characters + 15 spaces */ @@ -247,16 +249,15 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, /* Char-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_char_string(&text, textlength, - (uint8_t *)(ptr + (lines * DLT_COMMON_HEX_CHARS)), - DLT_COMMON_HEX_CHARS) < DLT_RETURN_OK) + if (dlt_print_char_string( + &text, textlength, (uint8_t*)(ptr + (lines * DLT_COMMON_HEX_CHARS)), DLT_COMMON_HEX_CHARS) + < DLT_RETURN_OK) return DLT_RETURN_ERROR; if (html == 0) { snprintf(text, 2, "\n"); text += DLT_COMMON_CHARLEN; - } - else { + } else { snprintf(text, 5, "
"); text += (4 * DLT_COMMON_CHARLEN); } @@ -278,10 +279,9 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, /* Hex-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_hex_string(text, - textlength, - (uint8_t *)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), - rest) < DLT_RETURN_OK) + if (dlt_print_hex_string( + text, textlength, (uint8_t*)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), rest) + < DLT_RETURN_OK) return DLT_RETURN_ERROR; text += 2 * rest + (rest - 1); @@ -296,16 +296,16 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, /* Char-Output */ /* It is not required to decrement textlength, as it was already checked, that * there is enough space for the complete output */ - if (dlt_print_char_string(&text, textlength, - (uint8_t *)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), - rest) < DLT_RETURN_OK) + if (dlt_print_char_string( + &text, textlength, (uint8_t*)(ptr + ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)), rest) + < DLT_RETURN_OK) return DLT_RETURN_ERROR; } return DLT_RETURN_OK; } -DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, int size) +DltReturnValue dlt_print_char_string(char** text, int textlength, uint8_t* ptr, int size) { int num; @@ -313,20 +313,17 @@ DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, return DLT_RETURN_WRONG_PARAMETER; if (textlength < size) { - dlt_vlog(LOG_WARNING, - "String does not fit character data (available=%d, required=%d) !\n", - textlength, size); + dlt_vlog(LOG_WARNING, "String does not fit character data (available=%d, required=%d) !\n", textlength, size); return DLT_RETURN_WRONG_PARAMETER; } for (num = 0; num < size; num++) { - if ((((char *)ptr)[num] < DLT_COMMON_ASCII_CHAR_SPACE) || (((char *)ptr)[num] > DLT_COMMON_ASCII_CHAR_TILDE)) { + if ((((char*)ptr)[num] < DLT_COMMON_ASCII_CHAR_SPACE) || (((char*)ptr)[num] > DLT_COMMON_ASCII_CHAR_TILDE)) { snprintf(*text, 2, "."); - } - else { + } else { /* replace < with . */ - if (((char *)ptr)[num] != DLT_COMMON_ASCII_CHAR_LT) - snprintf(*text, 2, "%c", ((char *)ptr)[num]); + if (((char*)ptr)[num] != DLT_COMMON_ASCII_CHAR_LT) + snprintf(*text, 2, "%c", ((char*)ptr)[num]); else snprintf(*text, 2, "."); } @@ -349,7 +346,7 @@ size_t dlt_strnlen_s(const char* str, size_t maxsize) return maxsize; } -void dlt_print_id(char *text, const char *id) +void dlt_print_id(char* text, const char* id) { /* check nullpointer */ if ((text == NULL) || (id == NULL)) @@ -366,7 +363,7 @@ void dlt_print_id(char *text, const char *id) } /* TODO: Do memcpy instead */ -void dlt_print_id_v2(char *text, const char *id, uint8_t length) +void dlt_print_id_v2(char* text, const char* id, uint8_t length) { /* check nullpointer */ if ((text == NULL) || (id == NULL) || (length == 0)) @@ -382,7 +379,7 @@ void dlt_print_id_v2(char *text, const char *id, uint8_t length) memcpy(text, id, len); } -void dlt_set_id(char *id, const char *text) +void dlt_set_id(char* id, const char* text) { /* check nullpointer */ if ((id == NULL) || (text == NULL)) @@ -411,7 +408,7 @@ void dlt_set_id(char *id, const char *text) return; } -void dlt_set_id_v2(char *id, const char *text, uint8_t len) +void dlt_set_id_v2(char* id, const char* text, uint8_t len) { /* check nullpointer */ if ((id == NULL) || (text == NULL) || (len == 0)) @@ -430,7 +427,7 @@ void dlt_set_id_v2(char *id, const char *text, uint8_t len) memcpy(id, text, copy_len); } -void dlt_clean_string(char *text, int length) +void dlt_clean_string(char* text, int length) { int num; @@ -442,7 +439,7 @@ void dlt_clean_string(char *text, int length) text[num] = ' '; } -DltReturnValue dlt_filter_init(DltFilter *filter, int verbose) +DltReturnValue dlt_filter_init(DltFilter* filter, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -454,7 +451,7 @@ DltReturnValue dlt_filter_init(DltFilter *filter, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_filter_free(DltFilter *filter, int verbose) +DltReturnValue dlt_filter_free(DltFilter* filter, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -464,12 +461,12 @@ DltReturnValue dlt_filter_free(DltFilter *filter, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose) +DltReturnValue dlt_filter_load(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - FILE *handle; + FILE* handle; char str1[DLT_COMMON_BUFFER_LENGTH + 1]; char apid[DLT_ID_SIZE], ctid[DLT_ID_SIZE]; @@ -482,8 +479,8 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb return DLT_RETURN_ERROR; } - #define FORMAT_STRING_(x) "%" #x "s" - #define FORMAT_STRING(x) FORMAT_STRING_(x) +#define FORMAT_STRING_(x) "%" #x "s" +#define FORMAT_STRING(x) FORMAT_STRING_(x) /* Reset filters */ filter->counter = 0; @@ -522,9 +519,9 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb if (filter->counter < DLT_FILTER_MAX) dlt_filter_add(filter, apid, ctid, 0, 0, INT32_MAX, verbose); else - dlt_vlog(LOG_WARNING, - "Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", - DLT_FILTER_MAX); + dlt_vlog( + LOG_WARNING, "Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", + DLT_FILTER_MAX); } fclose(handle); @@ -532,12 +529,12 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb return DLT_RETURN_OK; } -DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int verbose) +DltReturnValue dlt_filter_load_v2(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - FILE *handle; + FILE* handle; char str1[DLT_COMMON_BUFFER_LENGTH + 1]; char apid[DLT_V2_ID_SIZE]; char ctid[DLT_V2_ID_SIZE]; @@ -552,8 +549,8 @@ DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int v return DLT_RETURN_ERROR; } - #define FORMAT_STRING_(x) "%" #x "s" - #define FORMAT_STRING(x) FORMAT_STRING_(x) +#define FORMAT_STRING_(x) "%" #x "s" +#define FORMAT_STRING(x) FORMAT_STRING_(x) /* Reset filters */ filter->counter = 0; @@ -571,8 +568,7 @@ DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int v if (strcmp(str1, "----") == 0) { apidlen = 0; - } - else { + } else { apidlen = (uint8_t)strlen(str1); dlt_set_id_v2(apid, str1, apidlen); } @@ -589,17 +585,17 @@ DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int v if (strcmp(str1, "----") == 0) { ctidlen = 0; - }else { + } else { ctidlen = (uint8_t)strlen(str1); dlt_set_id_v2(ctid, str1, ctidlen); } if (filter->counter < DLT_FILTER_MAX) { dlt_filter_add(filter, apid, ctid, 0, 0, INT32_MAX, verbose); - }else { - dlt_vlog(LOG_WARNING, - "Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", - DLT_FILTER_MAX); + } else { + dlt_vlog( + LOG_WARNING, "Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", + DLT_FILTER_MAX); } } @@ -608,12 +604,12 @@ DltReturnValue dlt_filter_load_v2(DltFilter *filter, const char *filename, int v return DLT_RETURN_OK; } -DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verbose) +DltReturnValue dlt_filter_save(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - FILE *handle; + FILE* handle; int num; char buf[DLT_COMMON_BUFFER_LENGTH]; @@ -629,16 +625,14 @@ DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verb for (num = 0; num < filter->counter; num++) { if (filter->apid[num][0] == 0) { fprintf(handle, "---- "); - } - else { + } else { dlt_print_id(buf, filter->apid[num]); fprintf(handle, "%s ", buf); } if (filter->ctid[num][0] == 0) { fprintf(handle, "---- "); - } - else { + } else { dlt_print_id(buf, filter->ctid[num]); fprintf(handle, "%s ", buf); } @@ -649,12 +643,12 @@ DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verb return DLT_RETURN_OK; } -DltReturnValue dlt_filter_save_v2(DltFilter *filter, const char *filename, int verbose) +DltReturnValue dlt_filter_save_v2(DltFilter* filter, const char* filename, int verbose) { if ((filter == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - FILE *handle; + FILE* handle; int num; char buf[DLT_COMMON_BUFFER_LENGTH]; @@ -670,8 +664,7 @@ DltReturnValue dlt_filter_save_v2(DltFilter *filter, const char *filename, int v for (num = 0; num < filter->counter; num++) { if (filter->apid2[num] == NULL) { fprintf(handle, "---- "); - } - else { + } else { memcpy(buf, filter->apid2[num], filter->apid2len[num]); memset(buf + (filter->ctid2len[num]), '\0', 1); fprintf(handle, "%s ", buf); @@ -679,8 +672,7 @@ DltReturnValue dlt_filter_save_v2(DltFilter *filter, const char *filename, int v if (filter->ctid2[num] == NULL) { fprintf(handle, "---- "); - } - else { + } else { memcpy(buf, filter->ctid2[num], filter->ctid2len[num]); memset(buf + (filter->ctid2len[num]), '\0', 1); fprintf(handle, "%s ", buf); @@ -692,8 +684,9 @@ DltReturnValue dlt_filter_save_v2(DltFilter *filter, const char *filename, int v return DLT_RETURN_OK; } -int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +int dlt_filter_find( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose) { int num; @@ -707,7 +700,8 @@ int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const /* apid matches, now check for ctid */ if (ctid == NULL) { /* check if empty ctid matches */ - /*if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)//coverity complains here about Out-of-bounds access. */ + /*if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)//coverity complains here about Out-of-bounds access. + */ char empty_ctid[DLT_ID_SIZE] = ""; if (memcmp(filter->ctid[num], empty_ctid, DLT_ID_SIZE) == 0) @@ -715,9 +709,7 @@ int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const if (filter->payload_min[num] <= payload_min) if (filter->payload_max[num] >= payload_max) return num; - } - else if (memcmp(filter->ctid[num], ctid, DLT_ID_SIZE) == 0) - { + } else if (memcmp(filter->ctid[num], ctid, DLT_ID_SIZE) == 0) { if ((filter->log_level[num] == log_level) || (filter->log_level[num] == 0)) if (filter->payload_min[num] <= payload_min) if (filter->payload_max[num] >= payload_max) @@ -728,8 +720,9 @@ int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, const return -1; /* Not found */ } -int dlt_filter_find_v2(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +int dlt_filter_find_v2( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose) { int num; @@ -749,9 +742,7 @@ int dlt_filter_find_v2(DltFilter *filter, const char *apid, const char *ctid, co if (filter->payload_min[num] <= payload_min) if (filter->payload_max[num] >= payload_max) return num; - } - else if (memcmp(filter->ctid2[num], ctid, filter->ctid2len[num]) == 0) - { + } else if (memcmp(filter->ctid2[num], ctid, filter->ctid2len[num]) == 0) { if ((filter->log_level[num] == log_level) || (filter->log_level[num] == 0)) if (filter->payload_min[num] <= payload_min) if (filter->payload_max[num] >= payload_max) @@ -762,8 +753,9 @@ int dlt_filter_find_v2(DltFilter *filter, const char *apid, const char *ctid, co return -1; /* Not found */ } -DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +DltReturnValue dlt_filter_add( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -771,9 +763,7 @@ DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *c return DLT_RETURN_WRONG_PARAMETER; if (filter->counter >= DLT_FILTER_MAX) { - dlt_vlog(LOG_WARNING, - "Maximum number (%d) of allowed filters reached, ignoring filter!\n", - DLT_FILTER_MAX); + dlt_vlog(LOG_WARNING, "Maximum number (%d) of allowed filters reached, ignoring filter!\n", DLT_FILTER_MAX); return DLT_RETURN_ERROR; } @@ -794,8 +784,9 @@ DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *c return DLT_RETURN_ERROR; } -DltReturnValue dlt_filter_add_v2(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +DltReturnValue dlt_filter_add_v2( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -803,20 +794,18 @@ DltReturnValue dlt_filter_add_v2(DltFilter *filter, const char *apid, const char return DLT_RETURN_WRONG_PARAMETER; if (filter->counter >= DLT_FILTER_MAX) { - dlt_vlog(LOG_WARNING, - "Maximum number (%d) of allowed filters reached, ignoring filter!\n", - DLT_FILTER_MAX); + dlt_vlog(LOG_WARNING, "Maximum number (%d) of allowed filters reached, ignoring filter!\n", DLT_FILTER_MAX); return DLT_RETURN_ERROR; } /* add each filter (apid, ctid, log_level, payload_min, payload_max) only once to filter array */ if (dlt_filter_find(filter, apid, ctid, log_level, payload_min, payload_max, verbose) < 0) { /* filter not found, so add it to filter array */ - filter->apid2[filter->counter] = (char *)malloc(DLT_V2_ID_SIZE * sizeof(char)); + filter->apid2[filter->counter] = (char*)malloc(DLT_V2_ID_SIZE * sizeof(char)); if (filter->apid2[filter->counter] == NULL) { return DLT_RETURN_ERROR; } - filter->ctid2[filter->counter] = (char *)malloc(DLT_V2_ID_SIZE * sizeof(char)); + filter->ctid2[filter->counter] = (char*)malloc(DLT_V2_ID_SIZE * sizeof(char)); if (filter->ctid2[filter->counter] == NULL) { free(filter->apid2[filter->counter]); filter->apid2[filter->counter] = NULL; @@ -838,8 +827,9 @@ DltReturnValue dlt_filter_add_v2(DltFilter *filter, const char *apid, const char return DLT_RETURN_ERROR; } -DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +DltReturnValue dlt_filter_delete( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose) { int j, k; int found = 0; @@ -852,12 +842,9 @@ DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char if (filter->counter > 0) { /* Get first occurence of apid and ctid in filter array */ for (j = 0; j < filter->counter; j++) - if ((memcmp(filter->apid[j], apid, DLT_ID_SIZE) == 0) && - (memcmp(filter->ctid[j], ctid, DLT_ID_SIZE) == 0) && - ((filter->log_level[j] == log_level) || (filter->log_level[j] == 0)) && - (filter->payload_min[j] == payload_min) && - (filter->payload_max[j] == payload_max) - ) { + if ((memcmp(filter->apid[j], apid, DLT_ID_SIZE) == 0) && (memcmp(filter->ctid[j], ctid, DLT_ID_SIZE) == 0) + && ((filter->log_level[j] == log_level) || (filter->log_level[j] == 0)) + && (filter->payload_min[j] == payload_min) && (filter->payload_max[j] == payload_max)) { found = 1; break; } @@ -888,8 +875,9 @@ DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char return DLT_RETURN_ERROR; } -DltReturnValue dlt_filter_delete_v2(DltFilter *filter, const char *apid, const char *ctid, const int log_level, - const int32_t payload_min, const int32_t payload_max, int verbose) +DltReturnValue dlt_filter_delete_v2( + DltFilter* filter, const char* apid, const char* ctid, const int log_level, const int32_t payload_min, + const int32_t payload_max, int verbose) { int j, k; int found = 0; @@ -902,12 +890,10 @@ DltReturnValue dlt_filter_delete_v2(DltFilter *filter, const char *apid, const c if (filter->counter > 0) { /* Get first occurence of apid and ctid in filter array */ for (j = 0; j < filter->counter; j++) - if ((memcmp(filter->apid2[j], apid, filter->apid2len[j]) == 0) && - (memcmp(filter->ctid2[j], ctid, filter->ctid2len[j]) == 0) && - ((filter->log_level[j] == log_level) || (filter->log_level[j] == 0)) && - (filter->payload_min[j] == payload_min) && - (filter->payload_max[j] == payload_max) - ) { + if ((memcmp(filter->apid2[j], apid, filter->apid2len[j]) == 0) + && (memcmp(filter->ctid2[j], ctid, filter->ctid2len[j]) == 0) + && ((filter->log_level[j] == log_level) || (filter->log_level[j] == 0)) + && (filter->payload_min[j] == payload_min) && (filter->payload_max[j] == payload_max)) { found = 1; break; } @@ -952,7 +938,7 @@ DltReturnValue dlt_filter_delete_v2(DltFilter *filter, const char *apid, const c } -DltReturnValue dlt_message_init(DltMessage *msg, int verbose) +DltReturnValue dlt_message_init(DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -975,7 +961,7 @@ DltReturnValue dlt_message_init(DltMessage *msg, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_message_init_v2(DltMessageV2 *msg, int verbose) +DltReturnValue dlt_message_init_v2(DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -997,7 +983,7 @@ DltReturnValue dlt_message_init_v2(DltMessageV2 *msg, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_message_free(DltMessage *msg, int verbose) +DltReturnValue dlt_message_free(DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -1014,7 +1000,7 @@ DltReturnValue dlt_message_free(DltMessage *msg, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_message_free_v2(DltMessageV2 *msg, int verbose) +DltReturnValue dlt_message_free_v2(DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -1051,20 +1037,20 @@ DltReturnValue dlt_message_free_v2(DltMessageV2 *msg, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_message_header(DltMessage *msg, char *text, size_t textlength, int verbose) +DltReturnValue dlt_message_header(DltMessage* msg, char* text, size_t textlength, int verbose) { return dlt_message_header_flags(msg, text, textlength, DLT_HEADER_SHOW_ALL, verbose); } -DltReturnValue dlt_message_header_v2(DltMessageV2 *msg, char *text, size_t textlength, int verbose) +DltReturnValue dlt_message_header_v2(DltMessageV2* msg, char* text, size_t textlength, int verbose) { return dlt_message_header_flags_v2(msg, text, textlength, DLT_HEADER_SHOW_ALL, verbose); } -DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t textlength, int flags, int verbose) +DltReturnValue dlt_message_header_flags(DltMessage* msg, char* text, size_t textlength, int flags, int verbose) { struct tm timeinfo; - char buffer [DLT_COMMON_BUFFER_LENGTH]; + char buffer[DLT_COMMON_BUFFER_LENGTH]; PRINT_FUNCTION_VERBOSE(verbose); @@ -1084,7 +1070,7 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t text time_t tt = (time_t)msg->storageheader->seconds; tzset(); localtime_r(&tt, &timeinfo); - strftime (buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", &timeinfo); + strftime(buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", &timeinfo); snprintf(text, textlength, "%s.%.6d ", buffer, msg->storageheader->microseconds); } @@ -1108,7 +1094,7 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t text dlt_print_id(text + strlen(text), msg->storageheader->ecu); } - /* print app id and context id if extended header available, else '----' */ # +/* print app id and context id if extended header available, else '----' */ # if ((flags & DLT_HEADER_SHOW_APID) == DLT_HEADER_SHOW_APID) { snprintf(text + strlen(text), textlength - strlen(text), " "); @@ -1133,27 +1119,32 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t text /* print info about message type and length */ if (DLT_IS_HTYP_UEH(msg->standardheader->htyp)) { if ((flags & DLT_HEADER_SHOW_MSGTYPE) == DLT_HEADER_SHOW_MSGTYPE) { - snprintf(text + strlen(text), textlength - strlen(text), "%s", - message_type[DLT_GET_MSIN_MSTP(msg->extendedheader->msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + message_type[DLT_GET_MSIN_MSTP(msg->extendedheader->msin)]); snprintf(text + strlen(text), textlength - strlen(text), " "); } if ((flags & DLT_HEADER_SHOW_MSGSUBTYPE) == DLT_HEADER_SHOW_MSGSUBTYPE) { if ((DLT_GET_MSIN_MSTP(msg->extendedheader->msin)) == DLT_TYPE_LOG) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - log_info[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + log_info[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); if ((DLT_GET_MSIN_MSTP(msg->extendedheader->msin)) == DLT_TYPE_APP_TRACE) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - trace_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + trace_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); if ((DLT_GET_MSIN_MSTP(msg->extendedheader->msin)) == DLT_TYPE_NW_TRACE) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - nw_trace_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + nw_trace_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); if ((DLT_GET_MSIN_MSTP(msg->extendedheader->msin)) == DLT_TYPE_CONTROL) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - control_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + control_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]); snprintf(text + strlen(text), textlength - strlen(text), " "); } @@ -1171,8 +1162,7 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t text if ((flags & DLT_HEADER_SHOW_NOARG) == DLT_HEADER_SHOW_NOARG) /* print number of arguments */ snprintf(text + strlen(text), textlength - strlen(text), "%d", msg->extendedheader->noar); - } - else { + } else { if ((flags & DLT_HEADER_SHOW_MSGTYPE) == DLT_HEADER_SHOW_MSGTYPE) snprintf(text + strlen(text), textlength - strlen(text), "--- "); @@ -1189,10 +1179,10 @@ DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, size_t text return DLT_RETURN_OK; } -DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t textlength, int flags, int verbose) +DltReturnValue dlt_message_header_flags_v2(DltMessageV2* msg, char* text, size_t textlength, int flags, int verbose) { struct tm timeinfo; - char buffer [DLT_COMMON_BUFFER_LENGTH]; + char buffer[DLT_COMMON_BUFFER_LENGTH]; int currtextlength = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -1210,25 +1200,26 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t if ((flags & DLT_HEADER_SHOW_TIME) == DLT_HEADER_SHOW_TIME) { /* print received time */ time_t tt = 0; - for (int i = 0; i<5; ++i){ + for (int i = 0; i < 5; ++i) { tt = (tt << 8) | msg->storageheaderv2.seconds[i]; } tzset(); localtime_r(&tt, &timeinfo); - strftime (buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", &timeinfo); + strftime(buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", &timeinfo); snprintf(text, textlength, "%s.%.9d ", buffer, msg->storageheaderv2.nanoseconds); } if ((flags & DLT_HEADER_SHOW_TMSTP) == DLT_HEADER_SHOW_TMSTP) { /* print timestamp if available */ - if ((msgcontent==DLT_VERBOSE_DATA_MSG)||(msgcontent==DLT_NON_VERBOSE_DATA_MSG)){ + if ((msgcontent == DLT_VERBOSE_DATA_MSG) || (msgcontent == DLT_NON_VERBOSE_DATA_MSG)) { time_t tt = 0; - for (int i = 0; i<5; ++i){ + for (int i = 0; i < 5; ++i) { tt = (tt << 8) | msg->headerextrav2.seconds[i]; } - snprintf(text + strlen(text), textlength - strlen(text), "%lld.%.9u ", (long long int)tt, msg->headerextrav2.nanoseconds); - } - else + snprintf( + text + strlen(text), textlength - strlen(text), "%lld.%.9u ", (long long int)tt, + msg->headerextrav2.nanoseconds); + } else snprintf(text + strlen(text), textlength - strlen(text), "---------- "); } @@ -1241,30 +1232,35 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t if ((flags & DLT_HEADER_SHOW_ECUID) == DLT_HEADER_SHOW_ECUID) { /* print ecu id, use header extra if available, else storage header value */ if (DLT_IS_HTYP2_WEID(msg->baseheaderv2->htyp2)) { - uint8_t display_len = (msg->extendedheaderv2.ecidlen > DLT_CLIENT_MAX_ID_LENGTH) ? DLT_CLIENT_MAX_ID_LENGTH : msg->extendedheaderv2.ecidlen; + uint8_t display_len = (msg->extendedheaderv2.ecidlen > DLT_CLIENT_MAX_ID_LENGTH) ? + DLT_CLIENT_MAX_ID_LENGTH : + msg->extendedheaderv2.ecidlen; memcpy(text + currtextlength, msg->extendedheaderv2.ecid, (size_t)display_len); text[currtextlength + display_len] = '\0'; currtextlength = currtextlength + display_len; - }else { - uint8_t display_len = (msg->storageheaderv2.ecidlen > DLT_CLIENT_MAX_ID_LENGTH) ? DLT_CLIENT_MAX_ID_LENGTH : msg->storageheaderv2.ecidlen; + } else { + uint8_t display_len = (msg->storageheaderv2.ecidlen > DLT_CLIENT_MAX_ID_LENGTH) ? + DLT_CLIENT_MAX_ID_LENGTH : + msg->storageheaderv2.ecidlen; memcpy(text + (size_t)currtextlength, msg->storageheaderv2.ecid, (size_t)display_len); text[currtextlength + display_len] = '\0'; currtextlength = currtextlength + display_len; } } - /* print app id and context id if extended header available, else '----' */ # +/* print app id and context id if extended header available, else '----' */ # if ((flags & DLT_HEADER_SHOW_APID) == DLT_HEADER_SHOW_APID) { snprintf(text + currtextlength, textlength - (size_t)currtextlength, " "); currtextlength++; if ((DLT_IS_HTYP2_WACID(msg->baseheaderv2->htyp2)) && (msg->extendedheaderv2.apidlen != 0)) { - uint8_t display_len = (msg->extendedheaderv2.apidlen > DLT_CLIENT_MAX_ID_LENGTH) ? DLT_CLIENT_MAX_ID_LENGTH : msg->extendedheaderv2.apidlen; + uint8_t display_len = (msg->extendedheaderv2.apidlen > DLT_CLIENT_MAX_ID_LENGTH) ? + DLT_CLIENT_MAX_ID_LENGTH : + msg->extendedheaderv2.apidlen; memcpy(text + currtextlength, msg->extendedheaderv2.apid, (size_t)display_len); text[currtextlength + display_len] = '\0'; currtextlength = currtextlength + display_len; - } - else { + } else { snprintf(text + currtextlength, textlength - (size_t)currtextlength, "----"); currtextlength = currtextlength + 4; } @@ -1274,12 +1270,13 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t if ((flags & DLT_HEADER_SHOW_CTID) == DLT_HEADER_SHOW_CTID) { if ((DLT_IS_HTYP2_WACID(msg->baseheaderv2->htyp2)) && (msg->extendedheaderv2.ctidlen != 0)) { - uint8_t display_len = (msg->extendedheaderv2.ctidlen > DLT_CLIENT_MAX_ID_LENGTH) ? DLT_CLIENT_MAX_ID_LENGTH : msg->extendedheaderv2.ctidlen; + uint8_t display_len = (msg->extendedheaderv2.ctidlen > DLT_CLIENT_MAX_ID_LENGTH) ? + DLT_CLIENT_MAX_ID_LENGTH : + msg->extendedheaderv2.ctidlen; memcpy(text + currtextlength, msg->extendedheaderv2.ctid, (size_t)display_len); text[currtextlength + display_len] = '\0'; currtextlength = currtextlength + display_len; - } - else { + } else { snprintf(text + currtextlength, textlength - (size_t)currtextlength, "----"); currtextlength = currtextlength + 4; } @@ -1314,8 +1311,10 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t if ((flags & DLT_HEADER_SHOW_TAG) == DLT_HEADER_SHOW_TAG) { if ((DLT_IS_HTYP2_WTGS(msg->baseheaderv2->htyp2)) && (msg->extendedheaderv2.notg != 0)) { - for(int i=0; iextendedheaderv2.notg; i++){ - memcpy(text + currtextlength, msg->extendedheaderv2.tag[i].tagname, (size_t)msg->extendedheaderv2.tag[i].taglen + 1); + for (int i = 0; i < msg->extendedheaderv2.notg; i++) { + memcpy( + text + currtextlength, msg->extendedheaderv2.tag[i].tagname, + (size_t)msg->extendedheaderv2.tag[i].taglen + 1); currtextlength = currtextlength + (int)msg->extendedheaderv2.tag[i].taglen; snprintf(text + currtextlength, textlength - (size_t)currtextlength, " "); currtextlength++; @@ -1324,29 +1323,34 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t } /* print info about message type and length */ - if ((msgcontent==DLT_VERBOSE_DATA_MSG)||(msgcontent==DLT_CONTROL_MSG)) { + if ((msgcontent == DLT_VERBOSE_DATA_MSG) || (msgcontent == DLT_CONTROL_MSG)) { if ((flags & DLT_HEADER_SHOW_MSGTYPE) == DLT_HEADER_SHOW_MSGTYPE) { - snprintf(text + strlen(text), textlength - strlen(text), "%s", - message_type[DLT_GET_MSIN_MSTP(msg->headerextrav2.msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + message_type[DLT_GET_MSIN_MSTP(msg->headerextrav2.msin)]); snprintf(text + strlen(text), textlength - strlen(text), " "); } if ((flags & DLT_HEADER_SHOW_MSGSUBTYPE) == DLT_HEADER_SHOW_MSGSUBTYPE) { if ((DLT_GET_MSIN_MSTP(msg->headerextrav2.msin)) == DLT_TYPE_LOG) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - log_info[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + log_info[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); if ((DLT_GET_MSIN_MSTP(msg->headerextrav2.msin)) == DLT_TYPE_APP_TRACE) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - trace_type[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + trace_type[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); if ((DLT_GET_MSIN_MSTP(msg->headerextrav2.msin)) == DLT_TYPE_NW_TRACE) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - nw_trace_type[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + nw_trace_type[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); if ((DLT_GET_MSIN_MSTP(msg->headerextrav2.msin)) == DLT_TYPE_CONTROL) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - control_type[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); + snprintf( + text + strlen(text), textlength - strlen(text), "%s", + control_type[DLT_GET_MSIN_MTIN(msg->headerextrav2.msin)]); snprintf(text + strlen(text), textlength - strlen(text), " "); } @@ -1364,8 +1368,7 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t if ((flags & DLT_HEADER_SHOW_NOARG) == DLT_HEADER_SHOW_NOARG) /* print number of arguments */ snprintf(text + strlen(text), textlength - strlen(text), "%d", msg->headerextrav2.noar); - } - else { + } else { if ((flags & DLT_HEADER_SHOW_MSGTYPE) == DLT_HEADER_SHOW_MSGTYPE) snprintf(text + strlen(text), textlength - strlen(text), "--- "); @@ -1382,17 +1385,17 @@ DltReturnValue dlt_message_header_flags_v2(DltMessageV2 *msg, char *text, size_t return DLT_RETURN_OK; } -DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlength, int type, int verbose) +DltReturnValue dlt_message_payload(DltMessage* msg, char* text, size_t textlength, int type, int verbose) { uint32_t id = 0, id_tmp = 0; uint8_t retval = 0; - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; /* Pointer to ptr and datalength */ - uint8_t **pptr; - int32_t *pdatalength; + uint8_t** pptr; + int32_t* pdatalength; int ret = 0; @@ -1402,8 +1405,8 @@ DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlengt PRINT_FUNCTION_VERBOSE(verbose); - if ((msg == NULL) || (msg->databuffer == NULL) || (text == NULL) || - (type < DLT_OUTPUT_HEX) || (type > DLT_OUTPUT_ASCII_LIMITED)) + if ((msg == NULL) || (msg->databuffer == NULL) || (text == NULL) || (type < DLT_OUTPUT_HEX) + || (type > DLT_OUTPUT_ASCII_LIMITED)) return DLT_RETURN_WRONG_PARAMETER; if (textlength <= 0) { @@ -1436,29 +1439,26 @@ DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlengt /* print payload as hex */ if (DLT_MSG_IS_NONVERBOSE(msg)) { - DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); if ((datalength < 0) || (textlength < (((unsigned int)datalength * 3) + 20))) { - dlt_vlog(LOG_WARNING, - "String does not fit binary data (available=%zu, required=%zu) !\n", - (size_t)textlength, ((size_t)datalength * 3U) + 20U); + dlt_vlog( + LOG_WARNING, "String does not fit binary data (available=%zu, required=%zu) !\n", (size_t)textlength, + ((size_t)datalength * 3U) + 20U); return DLT_RETURN_ERROR; } /* process message id / service id */ if (DLT_MSG_IS_CONTROL(msg)) { if ((id > 0) && (id < DLT_SERVICE_ID_LAST_ENTRY)) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - service_id_name[id]); /* service id */ + snprintf(text + strlen(text), textlength - strlen(text), "%s", service_id_name[id]); /* service id */ else if (!(DLT_MSG_IS_CONTROL_TIME(msg))) snprintf(text + strlen(text), textlength - strlen(text), "service(%u)", id); /* service id */ if (datalength > 0) snprintf(text + strlen(text), textlength - strlen(text), ", "); - } - else { + } else { snprintf(text + strlen(text), textlength - strlen(text), "%u, ", id); /* message id */ } @@ -1478,16 +1478,13 @@ DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlengt } if (type == DLT_OUTPUT_ASCII_LIMITED) { - ret = dlt_print_hex_string(text + strlen(text), - (int)((size_t)textlength - strlen(text)), - ptr, - (datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); + ret = dlt_print_hex_string( + text + strlen(text), (int)((size_t)textlength - strlen(text)), ptr, + (datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); - if ((datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS) && - ((textlength - strlen(text)) > 4)) + if ((datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS) && ((textlength - strlen(text)) > 4)) snprintf(text + strlen(text), textlength - strlen(text), " ..."); - } - else { + } else { ret = dlt_print_hex_string(text + strlen(text), (int)((size_t)textlength - strlen(text)), ptr, datalength); } @@ -1513,27 +1510,27 @@ DltReturnValue dlt_message_payload(DltMessage *msg, char *text, size_t textlengt /* print out argument */ text_offset = (int)strlen(text); - if (dlt_message_argument_print(msg, type_info, pptr, pdatalength, - (text + text_offset), (textlength - (size_t)text_offset), -1, - 0) == DLT_RETURN_ERROR) + if (dlt_message_argument_print( + msg, type_info, pptr, pdatalength, (text + text_offset), (textlength - (size_t)text_offset), -1, 0) + == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; } return DLT_RETURN_OK; } -DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t textlength, int type, int verbose) +DltReturnValue dlt_message_payload_v2(DltMessageV2* msg, char* text, size_t textlength, int type, int verbose) { uint32_t id = 0; uint32_t id_tmp = 0; uint8_t retval = 0; - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; /* Pointer to ptr and datalength */ - uint8_t **pptr; - int32_t *pdatalength; + uint8_t** pptr; + int32_t* pdatalength; int ret = 0; @@ -1543,8 +1540,8 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text PRINT_FUNCTION_VERBOSE(verbose); - if ((msg == NULL) || (msg->databuffer == NULL) || (text == NULL) || - (type < DLT_OUTPUT_HEX) || (type > DLT_OUTPUT_ASCII_LIMITED)) + if ((msg == NULL) || (msg->databuffer == NULL) || (text == NULL) || (type < DLT_OUTPUT_HEX) + || (type > DLT_OUTPUT_ASCII_LIMITED)) return DLT_RETURN_WRONG_PARAMETER; if (textlength <= 0) { @@ -1581,25 +1578,20 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text id = DLT_LETOH_32(msg->headerextrav2.msid); if (textlength < (((unsigned int)datalength * 3) + 20)) { - dlt_vlog(LOG_WARNING, - "String does not fit binary data (available=%d, required=%d) !\n", - (int)textlength, (datalength * 3) + 20); + dlt_vlog( + LOG_WARNING, "String does not fit binary data (available=%d, required=%d) !\n", (int)textlength, + (datalength * 3) + 20); return DLT_RETURN_ERROR; } if (type == DLT_OUTPUT_ASCII_LIMITED) { - ret = dlt_print_hex_string(text + strlen(text), - (int)(textlength - strlen( - text)), - ptr, - (datalength > - DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); - - if ((datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS) && - ((textlength - strlen(text)) > 4)) + ret = dlt_print_hex_string( + text + strlen(text), (int)(textlength - strlen(text)), ptr, + (datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); + + if ((datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS) && ((textlength - strlen(text)) > 4)) snprintf(text + strlen(text), textlength - strlen(text), " ..."); - } - else { + } else { ret = dlt_print_hex_string(text + strlen(text), (int)(textlength - strlen(text)), ptr, datalength); } return ret; @@ -1611,8 +1603,7 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text id = DLT_LETOH_32(id_tmp); if ((id > 0) && (id < DLT_SERVICE_ID_LAST_ENTRY)) - snprintf(text + strlen(text), textlength - strlen(text), "%s", - service_id_name[id]); /* service id */ + snprintf(text + strlen(text), textlength - strlen(text), "%s", service_id_name[id]); /* service id */ else if (!(DLT_MSG_IS_CONTROL_TIME_V2(msg))) snprintf(text + strlen(text), textlength - strlen(text), "service(%u)", id); /* service id */ @@ -1635,18 +1626,13 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text } if (type == DLT_OUTPUT_ASCII_LIMITED) { - ret = dlt_print_hex_string(text + strlen(text), - (int)(textlength - strlen( - text)), - ptr, - (datalength > - DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); - - if ((datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS) && - ((textlength - strlen(text)) > 4)) + ret = dlt_print_hex_string( + text + strlen(text), (int)(textlength - strlen(text)), ptr, + (datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS ? DLT_COMMON_ASCII_LIMIT_MAX_CHARS : datalength)); + + if ((datalength > DLT_COMMON_ASCII_LIMIT_MAX_CHARS) && ((textlength - strlen(text)) > 4)) snprintf(text + strlen(text), textlength - strlen(text), " ..."); - } - else { + } else { ret = dlt_print_hex_string(text + strlen(text), (int)(textlength - strlen(text)), ptr, datalength); } return ret; @@ -1669,9 +1655,9 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text /* print out argument */ text_offset = (int)strlen(text); - if (dlt_message_argument_print_v2(msg, type_info, pptr, pdatalength, - (text + text_offset), (textlength - (size_t)text_offset), -1, - 0) == DLT_RETURN_ERROR){ + if (dlt_message_argument_print_v2( + msg, type_info, pptr, pdatalength, (text + text_offset), (textlength - (size_t)text_offset), -1, 0) + == DLT_RETURN_ERROR) { return DLT_RETURN_ERROR; } } @@ -1679,7 +1665,7 @@ DltReturnValue dlt_message_payload_v2(DltMessageV2 *msg, char *text, size_t text return DLT_RETURN_OK; } -DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int verbose) +DltReturnValue dlt_message_filter_check(DltMessage* msg, DltFilter* filter, int verbose) { /* check the filters if message is used */ int num; @@ -1696,13 +1682,13 @@ DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int for (num = 0; num < filter->counter; num++) /* check each filter if it matches */ - if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) && - ((filter->apid[num][0] == 0) || (memcmp(filter->apid[num], msg->extendedheader->apid, DLT_ID_SIZE) == 0)) && - ((filter->ctid[num][0] == 0) || (memcmp(filter->ctid[num], msg->extendedheader->ctid, DLT_ID_SIZE) == 0)) && - ((filter->log_level[num] == 0) || - (filter->log_level[num] == DLT_GET_MSIN_MTIN(msg->extendedheader->msin))) && - ((filter->payload_min[num] == 0) || (filter->payload_min[num] <= msg->datasize)) && - ((filter->payload_max[num] == 0) || (filter->payload_max[num] >= msg->datasize))) { + if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) + && ((filter->apid[num][0] == 0) || (memcmp(filter->apid[num], msg->extendedheader->apid, DLT_ID_SIZE) == 0)) + && ((filter->ctid[num][0] == 0) || (memcmp(filter->ctid[num], msg->extendedheader->ctid, DLT_ID_SIZE) == 0)) + && ((filter->log_level[num] == 0) + || (filter->log_level[num] == DLT_GET_MSIN_MTIN(msg->extendedheader->msin))) + && ((filter->payload_min[num] == 0) || (filter->payload_min[num] <= msg->datasize)) + && ((filter->payload_max[num] == 0) || (filter->payload_max[num] >= msg->datasize))) { found = DLT_RETURN_TRUE; break; } @@ -1710,7 +1696,7 @@ DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int return found; } -DltReturnValue dlt_message_filter_check_v2(DltMessageV2 *msg, DltFilter *filter, int verbose) +DltReturnValue dlt_message_filter_check_v2(DltMessageV2* msg, DltFilter* filter, int verbose) { /* check the filters if message is used */ int num; @@ -1727,13 +1713,14 @@ DltReturnValue dlt_message_filter_check_v2(DltMessageV2 *msg, DltFilter *filter, for (num = 0; num < filter->counter; num++) /* check each filter if it matches */ - if ((DLT_IS_HTYP2_EH(msg->baseheaderv2->htyp2)) && - ((filter->apid2[num] == NULL) || (memcmp(filter->apid2[num], msg->extendedheaderv2.apid, msg->extendedheaderv2.apidlen) == 0)) && - ((filter->ctid2[num] == NULL) || (memcmp(filter->ctid2[num], msg->extendedheaderv2.ctid, msg->extendedheaderv2.ctidlen) == 0)) && - ((filter->log_level[num] == 0) || - (filter->log_level[num] == DLT_GET_MSIN_MTIN(msg->headerextrav2.msin))) && - ((filter->payload_min[num] == 0) || (filter->payload_min[num] <= msg->datasize)) && - ((filter->payload_max[num] == 0) || (filter->payload_max[num] >= msg->datasize))) { + if ((DLT_IS_HTYP2_EH(msg->baseheaderv2->htyp2)) + && ((filter->apid2[num] == NULL) + || (memcmp(filter->apid2[num], msg->extendedheaderv2.apid, msg->extendedheaderv2.apidlen) == 0)) + && ((filter->ctid2[num] == NULL) + || (memcmp(filter->ctid2[num], msg->extendedheaderv2.ctid, msg->extendedheaderv2.ctidlen) == 0)) + && ((filter->log_level[num] == 0) || (filter->log_level[num] == DLT_GET_MSIN_MTIN(msg->headerextrav2.msin))) + && ((filter->payload_min[num] == 0) || (filter->payload_min[num] <= msg->datasize)) + && ((filter->payload_max[num] == 0) || (filter->payload_max[num] >= msg->datasize))) { found = DLT_RETURN_TRUE; break; } @@ -1741,7 +1728,7 @@ DltReturnValue dlt_message_filter_check_v2(DltMessageV2 *msg, DltFilter *filter, return found; } -int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose) +int dlt_message_read(DltMessage* msg, uint8_t* buffer, unsigned int length, int resync, int verbose) { uint32_t extra_size = 0; @@ -1763,8 +1750,7 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int msg->found_serialheader = 1; buffer += sizeof(dltSerialHeader); length -= (unsigned int)sizeof(dltSerialHeader); - } - else { + } else { /* serial header not found */ msg->found_serialheader = 0; @@ -1801,34 +1787,32 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int memcpy(msg->headerbuffer + sizeof(DltStorageHeader), buffer, sizeof(DltStandardHeader)); /* set ptrs to structures */ - msg->storageheader = (DltStorageHeader *)msg->headerbuffer; - msg->standardheader = (DltStandardHeader *)(msg->headerbuffer + sizeof(DltStorageHeader)); + msg->storageheader = (DltStorageHeader*)msg->headerbuffer; + msg->standardheader = (DltStandardHeader*)(msg->headerbuffer + sizeof(DltStorageHeader)); /* calculate complete size of headers */ - extra_size = (uint32_t) (DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp) + - (DLT_IS_HTYP_UEH(msg->standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); - msg->headersize = (int32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + extra_size); - msg->datasize = (int32_t) ((uint32_t)DLT_BETOH_16(msg->standardheader->len) - (uint32_t)msg->headersize + (uint32_t) sizeof(DltStorageHeader)); + extra_size = (uint32_t)(DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp) + + (DLT_IS_HTYP_UEH(msg->standardheader->htyp) ? sizeof(DltExtendedHeader) : 0)); + msg->headersize = (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + extra_size); + msg->datasize = (int32_t)((uint32_t)DLT_BETOH_16(msg->standardheader->len) - (uint32_t)msg->headersize + + (uint32_t)sizeof(DltStorageHeader)); /* calculate complete size of payload */ int32_t temp_datasize; - temp_datasize = DLT_BETOH_16(msg->standardheader->len) - (int32_t) msg->headersize + (int32_t) sizeof(DltStorageHeader); + temp_datasize = + DLT_BETOH_16(msg->standardheader->len) - (int32_t)msg->headersize + (int32_t)sizeof(DltStorageHeader); /* check data size */ if (temp_datasize < 0) { - dlt_vlog(LOG_WARNING, - "Plausibility check failed. Complete message size too short (%d)!\n", - temp_datasize); + dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short (%d)!\n", temp_datasize); return DLT_MESSAGE_ERROR_CONTENT; - } - else { - msg->datasize = (int32_t) temp_datasize; + } else { + msg->datasize = (int32_t)temp_datasize; } /* check if verbose mode is on*/ if (verbose) { - dlt_vlog(LOG_DEBUG, "BufferLength=%u, HeaderSize=%u, DataSize=%u\n", - length, msg->headersize, msg->datasize); + dlt_vlog(LOG_DEBUG, "BufferLength=%u, HeaderSize=%u, DataSize=%u\n", length, msg->headersize, msg->datasize); } /* load standard header extra parameters and Extended header if used */ @@ -1836,14 +1820,15 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int if (length < (size_t)((int32_t)msg->headersize - (int32_t)sizeof(DltStorageHeader))) return DLT_MESSAGE_ERROR_SIZE; - memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), - buffer + sizeof(DltStandardHeader), (size_t)extra_size); + memcpy( + msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), + buffer + sizeof(DltStandardHeader), (size_t)extra_size); /* set extended header ptr and get standard header extra parameters */ if (DLT_IS_HTYP_UEH(msg->standardheader->htyp)) msg->extendedheader = - (DltExtendedHeader *)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); + (DltExtendedHeader*)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)); else msg->extendedheader = NULL; @@ -1859,38 +1844,38 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int if (msg->databuffer) { if (msg->datasize > msg->databuffersize) { free(msg->databuffer); - msg->databuffer = (uint8_t *)malloc((size_t)msg->datasize); + msg->databuffer = (uint8_t*)malloc((size_t)msg->datasize); msg->databuffersize = msg->datasize; } - } - else { + } else { /* get new memory for buffer */ - msg->databuffer = (uint8_t *)malloc((size_t)msg->datasize); + msg->databuffer = (uint8_t*)malloc((size_t)msg->datasize); msg->databuffersize = msg->datasize; } if (msg->databuffer == NULL) { - dlt_vlog(LOG_WARNING, - "Cannot allocate memory for payload buffer of size %u!\n", - msg->datasize); + dlt_vlog(LOG_WARNING, "Cannot allocate memory for payload buffer of size %u!\n", msg->datasize); return DLT_MESSAGE_ERROR_UNKNOWN; } /* load payload data from buffer */ - memcpy(msg->databuffer, buffer + (size_t)((int32_t)msg->headersize - (int32_t)sizeof(DltStorageHeader)), (size_t)msg->datasize); + memcpy( + msg->databuffer, buffer + (size_t)((int32_t)msg->headersize - (int32_t)sizeof(DltStorageHeader)), + (size_t)msg->datasize); return DLT_MESSAGE_ERROR_OK; } -int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, int resync, int verbose) +int dlt_message_read_v2(DltMessageV2* msg, uint8_t* buffer, unsigned int length, int resync, int verbose) { DltHtyp2ContentType msgcontent = 0x00; const char dltStorageHeaderV2Pattern[DLT_ID_SIZE] = {'D', 'L', 'T', 0x02}; PRINT_FUNCTION_VERBOSE(verbose); - if ((msg == NULL) || (buffer == NULL) || (length <= 0)){ - return DLT_MESSAGE_ERROR_UNKNOWN;} + if ((msg == NULL) || (buffer == NULL) || (length <= 0)) { + return DLT_MESSAGE_ERROR_UNKNOWN; + } /* Free any existing buffers before reinitializing */ if (msg->headerbufferv2) { @@ -1919,8 +1904,8 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, msg->resync_offset = 0; /* check if message contains storage header V2 */ - if ((length >= STORAGE_HEADER_V2_FIXED_SIZE) && - (memcmp(buffer, dltStorageHeaderV2Pattern, sizeof(dltStorageHeaderV2Pattern)) == 0)) { + if ((length >= STORAGE_HEADER_V2_FIXED_SIZE) + && (memcmp(buffer, dltStorageHeaderV2Pattern, sizeof(dltStorageHeaderV2Pattern)) == 0)) { /* Storage header V2 found - parse ECU ID length and calculate storage header size */ memcpy(&(msg->storageheaderv2.ecidlen), buffer + 13, 1); msg->storageheadersizev2 = (uint32_t)STORAGE_HEADER_V2_FIXED_SIZE + msg->storageheaderv2.ecidlen; @@ -1931,8 +1916,7 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, } buffer += msg->storageheadersizev2; length -= msg->storageheadersizev2; - } - else { + } else { msg->storageheadersizev2 = 0; } @@ -1947,8 +1931,7 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, msg->found_serialheader = 1; buffer += sizeof(dltSerialHeader); length -= (unsigned int)sizeof(dltSerialHeader); - } - else { + } else { /* serial header not found */ msg->found_serialheader = 0; @@ -1983,7 +1966,7 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, return DLT_MESSAGE_ERROR_SIZE; /* Extract Base header */ - msg->baseheaderv2 = (DltBaseHeaderV2 *)buffer; + msg->baseheaderv2 = (DltBaseHeaderV2*)buffer; msgcontent = (((uint32_t)msg->baseheaderv2->htyp2) & MSGCONTENT_MASK); msg->storageheadersizev2 = 0; @@ -1998,16 +1981,15 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, return DLT_RETURN_ERROR; /* calculate complete size of headers without storage header */ - msg->headersizev2 = (int32_t) (msg->baseheadersizev2 + - msg->baseheaderextrasizev2 + msg->extendedheadersizev2); + msg->headersizev2 = (int32_t)(msg->baseheadersizev2 + msg->baseheaderextrasizev2 + msg->extendedheadersizev2); - if(msg->headerbufferv2){ + if (msg->headerbufferv2) { free(msg->headerbufferv2); } - msg->headerbufferv2 = (uint8_t *)calloc((size_t)msg->headersizev2, 1); + msg->headerbufferv2 = (uint8_t*)calloc((size_t)msg->headersizev2, 1); - if(msg->headerbufferv2 == NULL){ + if (msg->headerbufferv2 == NULL) { return DLT_RETURN_ERROR; } memcpy(msg->headerbufferv2, buffer, (size_t)msg->headersizev2); @@ -2020,18 +2002,14 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, /* check data size */ if (temp_datasize < 0) { - dlt_vlog(LOG_WARNING, - "Plausibility check failed. Complete message size too short (%d)!\n", - temp_datasize); + dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short (%d)!\n", temp_datasize); return DLT_MESSAGE_ERROR_CONTENT; - } - else { + } else { msg->datasize = temp_datasize; } /* check if verbose mode is on*/ if (verbose) { - dlt_vlog(LOG_DEBUG, "BufferLength=%u, HeaderSize=%u, DataSize=%u\n", - length, msg->headersizev2, msg->datasize); + dlt_vlog(LOG_DEBUG, "BufferLength=%u, HeaderSize=%u, DataSize=%u\n", length, msg->headersizev2, msg->datasize); } /* check if payload fits length */ @@ -2043,89 +2021,61 @@ int dlt_message_read_v2(DltMessageV2 *msg, uint8_t *buffer, unsigned int length, if (msg->databuffer) { if (msg->datasize > msg->databuffersize) { free(msg->databuffer); - msg->databuffer = (uint8_t *)malloc((size_t)msg->datasize); + msg->databuffer = (uint8_t*)malloc((size_t)msg->datasize); msg->databuffersize = msg->datasize; } - } - else { + } else { /* get new memory for buffer */ - msg->databuffer = (uint8_t *)malloc((size_t)msg->datasize); + msg->databuffer = (uint8_t*)malloc((size_t)msg->datasize); msg->databuffersize = msg->datasize; } if (msg->databuffer == NULL) { - dlt_vlog(LOG_WARNING, - "Cannot allocate memory for payload buffer of size %u!\n", - msg->datasize); + dlt_vlog(LOG_WARNING, "Cannot allocate memory for payload buffer of size %u!\n", msg->datasize); return DLT_MESSAGE_ERROR_UNKNOWN; } /* load payload data from buffer */ memcpy(msg->databuffer, buffer + msg->headersizev2, (size_t)msg->datasize); return DLT_MESSAGE_ERROR_OK; - } -DltReturnValue dlt_message_get_storageparameters_v2(DltMessageV2 *msg, int verbose ) +DltReturnValue dlt_message_get_storageparameters_v2(DltMessageV2* msg, int verbose) { - PRINT_FUNCTION_VERBOSE(verbose); if (msg == NULL) return DLT_RETURN_WRONG_PARAMETER; - memcpy(msg->storageheaderv2.pattern, - msg->headerbufferv2, - 4); - memcpy(msg->storageheaderv2.seconds, - msg->headerbufferv2 + 4, - 5); - memcpy(&(msg->storageheaderv2.nanoseconds), - msg->headerbufferv2 + 9, - 4); + memcpy(msg->storageheaderv2.pattern, msg->headerbufferv2, 4); + memcpy(msg->storageheaderv2.seconds, msg->headerbufferv2 + 4, 5); + memcpy(&(msg->storageheaderv2.nanoseconds), msg->headerbufferv2 + 9, 4); msg->storageheaderv2.nanoseconds = (int32_t)DLT_BETOH_32((uint32_t)msg->storageheaderv2.nanoseconds); - memcpy(&(msg->storageheaderv2.ecidlen), - msg->headerbufferv2 + 13, - 1); - memcpy(msg->storageheaderv2.ecid, - msg->headerbufferv2 + 14, - msg->storageheaderv2.ecidlen); + memcpy(&(msg->storageheaderv2.ecidlen), msg->headerbufferv2 + 13, 1); + memcpy(msg->storageheaderv2.ecid, msg->headerbufferv2 + 14, msg->storageheaderv2.ecidlen); /* Add Null pointer in the end of ECUID */ - memset(msg->storageheaderv2.ecid + msg->storageheaderv2.ecidlen, - '\0', - 1); + memset(msg->storageheaderv2.ecid + msg->storageheaderv2.ecidlen, '\0', 1); return DLT_RETURN_OK; } -DltReturnValue dlt_message_set_storageparameters_v2(DltMessageV2 *msg, int verbose ) +DltReturnValue dlt_message_set_storageparameters_v2(DltMessageV2* msg, int verbose) { - PRINT_FUNCTION_VERBOSE(verbose); if (msg == NULL) return DLT_RETURN_WRONG_PARAMETER; - memcpy(msg->headerbufferv2, - msg->storageheaderv2.pattern, - 4); - memcpy(msg->headerbufferv2 + 4, - msg->storageheaderv2.seconds, - 5); - memcpy(msg->headerbufferv2 + 9, - &(msg->storageheaderv2.nanoseconds), - 4); - memcpy(msg->headerbufferv2 + 13, - &(msg->storageheaderv2.ecidlen), - 1); - memcpy(msg->headerbufferv2 + 14, - msg->storageheaderv2.ecid, - msg->storageheaderv2.ecidlen); + memcpy(msg->headerbufferv2, msg->storageheaderv2.pattern, 4); + memcpy(msg->headerbufferv2 + 4, msg->storageheaderv2.seconds, 5); + memcpy(msg->headerbufferv2 + 9, &(msg->storageheaderv2.nanoseconds), 4); + memcpy(msg->headerbufferv2 + 13, &(msg->storageheaderv2.ecidlen), 1); + memcpy(msg->headerbufferv2 + 14, msg->storageheaderv2.ecid, msg->storageheaderv2.ecidlen); return DLT_RETURN_OK; } -DltReturnValue dlt_message_get_extraparameters(DltMessage *msg, int verbose) +DltReturnValue dlt_message_get_extraparameters(DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2133,27 +2083,33 @@ DltReturnValue dlt_message_get_extraparameters(DltMessage *msg, int verbose) return DLT_RETURN_WRONG_PARAMETER; if (DLT_IS_HTYP_WEID(msg->standardheader->htyp)) - memcpy(msg->headerextra.ecu, - msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), - DLT_ID_SIZE); + memcpy( + msg->headerextra.ecu, msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), + DLT_ID_SIZE); if (DLT_IS_HTYP_WSID(msg->standardheader->htyp)) { - memcpy(&(msg->headerextra.seid), msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) - + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0), DLT_SIZE_WSID); + memcpy( + &(msg->headerextra.seid), + msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0), + DLT_SIZE_WSID); msg->headerextra.seid = DLT_BETOH_32(msg->headerextra.seid); } if (DLT_IS_HTYP_WTMS(msg->standardheader->htyp)) { - memcpy(&(msg->headerextra.tmsp), msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) - + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0) - + (DLT_IS_HTYP_WSID(msg->standardheader->htyp) ? DLT_SIZE_WSID : 0), DLT_SIZE_WTMS); + memcpy( + &(msg->headerextra.tmsp), + msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0) + + (DLT_IS_HTYP_WSID(msg->standardheader->htyp) ? DLT_SIZE_WSID : 0), + DLT_SIZE_WTMS); msg->headerextra.tmsp = DLT_BETOH_32(msg->headerextra.tmsp); } return DLT_RETURN_OK; } -DltReturnValue dlt_message_get_extraparameters_v2(DltMessageV2 *msg, int verbose) +DltReturnValue dlt_message_get_extraparameters_v2(DltMessageV2* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2164,94 +2120,68 @@ DltReturnValue dlt_message_get_extraparameters_v2(DltMessageV2 *msg, int verbose msgcontent = ((*(msg->headerbufferv2 + msg->storageheadersizev2)) & MSGCONTENT_MASK); if (msgcontent == DLT_VERBOSE_DATA_MSG) { - memcpy(&(msg->headerextrav2.msin), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, - 1); - memcpy(&(msg->headerextrav2.noar), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, - 1); - memcpy(&(msg->headerextrav2.nanoseconds), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 2, - 4); + memcpy(&(msg->headerextrav2.msin), msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, 1); + memcpy( + &(msg->headerextrav2.noar), msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, 1); + memcpy( + &(msg->headerextrav2.nanoseconds), + msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 2, 4); msg->headerextrav2.nanoseconds = DLT_BETOH_32(msg->headerextrav2.nanoseconds); - memcpy(msg->headerextrav2.seconds, - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 6, - 5); + memcpy( + msg->headerextrav2.seconds, msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 6, 5); } if (msgcontent == DLT_NON_VERBOSE_DATA_MSG) { - memcpy(&(msg->headerextrav2.nanoseconds), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, - 4); + memcpy( + &(msg->headerextrav2.nanoseconds), msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, + 4); msg->headerextrav2.nanoseconds = DLT_BETOH_32(msg->headerextrav2.nanoseconds); - memcpy(msg->headerextrav2.seconds, - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 4, - 5); - memcpy(&(msg->headerextrav2.msid), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 9, - 4); + memcpy( + msg->headerextrav2.seconds, msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 4, 5); + memcpy( + &(msg->headerextrav2.msid), msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 9, 4); msg->headerextrav2.msid = DLT_BETOH_32(msg->headerextrav2.msid); } if (msgcontent == DLT_CONTROL_MSG) { - memcpy(&(msg->headerextrav2.msin), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, - 1); - memcpy(&(msg->headerextrav2.noar), - msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, - 1); + memcpy(&(msg->headerextrav2.msin), msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, 1); + memcpy( + &(msg->headerextrav2.noar), msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, 1); } return DLT_RETURN_OK; } -static DltReturnValue dlt_message_get_extraparameters_from_recievedbuffer_v2(DltMessageV2 *msg, uint8_t* buffer, DltHtyp2ContentType msgcontent) +static DltReturnValue dlt_message_get_extraparameters_from_recievedbuffer_v2( + DltMessageV2* msg, uint8_t* buffer, DltHtyp2ContentType msgcontent) { // Buffer should be starting from Baseheader if (msg == NULL) return DLT_RETURN_WRONG_PARAMETER; if (msgcontent == DLT_VERBOSE_DATA_MSG) { - memcpy(&(msg->headerextrav2.msin), - buffer + BASE_HEADER_V2_FIXED_SIZE, - 1); - memcpy(&(msg->headerextrav2.noar), - buffer + BASE_HEADER_V2_FIXED_SIZE + 1, - 1); - memcpy(&(msg->headerextrav2.nanoseconds), - buffer + BASE_HEADER_V2_FIXED_SIZE + 2, - 4); + memcpy(&(msg->headerextrav2.msin), buffer + BASE_HEADER_V2_FIXED_SIZE, 1); + memcpy(&(msg->headerextrav2.noar), buffer + BASE_HEADER_V2_FIXED_SIZE + 1, 1); + memcpy(&(msg->headerextrav2.nanoseconds), buffer + BASE_HEADER_V2_FIXED_SIZE + 2, 4); msg->headerextrav2.nanoseconds = DLT_BETOH_32(msg->headerextrav2.nanoseconds); - memcpy(msg->headerextrav2.seconds, - buffer + BASE_HEADER_V2_FIXED_SIZE + 6, - 5); + memcpy(msg->headerextrav2.seconds, buffer + BASE_HEADER_V2_FIXED_SIZE + 6, 5); } if (msgcontent == DLT_NON_VERBOSE_DATA_MSG) { - memcpy(&(msg->headerextrav2.nanoseconds), - buffer + BASE_HEADER_V2_FIXED_SIZE, - 4); + memcpy(&(msg->headerextrav2.nanoseconds), buffer + BASE_HEADER_V2_FIXED_SIZE, 4); msg->headerextrav2.nanoseconds = DLT_BETOH_32(msg->headerextrav2.nanoseconds); - memcpy(msg->headerextrav2.seconds, - buffer + BASE_HEADER_V2_FIXED_SIZE + 4, - 5); - memcpy(&(msg->headerextrav2.msid), - buffer + BASE_HEADER_V2_FIXED_SIZE + 9, - 4); + memcpy(msg->headerextrav2.seconds, buffer + BASE_HEADER_V2_FIXED_SIZE + 4, 5); + memcpy(&(msg->headerextrav2.msid), buffer + BASE_HEADER_V2_FIXED_SIZE + 9, 4); msg->headerextrav2.msid = DLT_BETOH_32(msg->headerextrav2.msid); } if (msgcontent == DLT_CONTROL_MSG) { - memcpy(&(msg->headerextrav2.msin), - buffer + BASE_HEADER_V2_FIXED_SIZE, - 1); - memcpy(&(msg->headerextrav2.noar), - buffer + BASE_HEADER_V2_FIXED_SIZE + 1, - 1); + memcpy(&(msg->headerextrav2.msin), buffer + BASE_HEADER_V2_FIXED_SIZE, 1); + memcpy(&(msg->headerextrav2.noar), buffer + BASE_HEADER_V2_FIXED_SIZE + 1, 1); } return DLT_RETURN_OK; } -DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose) +DltReturnValue dlt_message_set_extraparameters(DltMessage* msg, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2259,33 +2189,32 @@ DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose) return DLT_RETURN_WRONG_PARAMETER; if (DLT_IS_HTYP_WEID(msg->standardheader->htyp)) - memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), - msg->headerextra.ecu, - DLT_ID_SIZE); + memcpy( + msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), msg->headerextra.ecu, + DLT_ID_SIZE); if (DLT_IS_HTYP_WSID(msg->standardheader->htyp)) { msg->headerextra.seid = DLT_HTOBE_32(msg->headerextra.seid); - memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) - + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0), - &(msg->headerextra.seid), - DLT_SIZE_WSID); + memcpy( + msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0), + &(msg->headerextra.seid), DLT_SIZE_WSID); } if (DLT_IS_HTYP_WTMS(msg->standardheader->htyp)) { msg->headerextra.tmsp = DLT_HTOBE_32(msg->headerextra.tmsp); - memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) - + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0) - + (DLT_IS_HTYP_WSID(msg->standardheader->htyp) ? DLT_SIZE_WSID : 0), - &(msg->headerextra.tmsp), - DLT_SIZE_WTMS); + memcpy( + msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0) + + (DLT_IS_HTYP_WSID(msg->standardheader->htyp) ? DLT_SIZE_WSID : 0), + &(msg->headerextra.tmsp), DLT_SIZE_WTMS); } return DLT_RETURN_OK; } -DltReturnValue dlt_message_set_extraparameters_v2(DltMessageV2 *msg, int verbose ) +DltReturnValue dlt_message_set_extraparameters_v2(DltMessageV2* msg, int verbose) { - PRINT_FUNCTION_VERBOSE(verbose); if (msg == NULL) @@ -2295,42 +2224,28 @@ DltReturnValue dlt_message_set_extraparameters_v2(DltMessageV2 *msg, int verbose msgcontent = ((msg->baseheaderv2->htyp2) & MSGCONTENT_MASK); if (msgcontent == DLT_VERBOSE_DATA_MSG) { - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, - &(msg->headerextrav2.msin), - 1); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, - &(msg->headerextrav2.noar), - 1); + memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, &(msg->headerextrav2.msin), 1); + memcpy( + msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, &(msg->headerextrav2.noar), 1); uint32_t nanoseconds_be = DLT_HTOBE_32(msg->headerextrav2.nanoseconds); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 2, - &nanoseconds_be, - 4); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 6, - msg->headerextrav2.seconds, - 5); + memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 2, &nanoseconds_be, 4); + memcpy( + msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 6, msg->headerextrav2.seconds, 5); } if (msgcontent == DLT_NON_VERBOSE_DATA_MSG) { uint32_t nanoseconds_be = DLT_HTOBE_32(msg->headerextrav2.nanoseconds); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, - &nanoseconds_be, - 4); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 4, - msg->headerextrav2.seconds, - 5); + memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, &nanoseconds_be, 4); + memcpy( + msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 4, msg->headerextrav2.seconds, 5); uint32_t msid_be = DLT_HTOBE_32(msg->headerextrav2.msid); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 9, - &msid_be, - 4); + memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 9, &msid_be, 4); } if (msgcontent == DLT_CONTROL_MSG) { - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, - &(msg->headerextrav2.msin), - 1); - memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, - &(msg->headerextrav2.noar), - 1); + memcpy(msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2, &(msg->headerextrav2.msin), 1); + memcpy( + msg->headerbufferv2 + msg->storageheadersizev2 + msg->baseheadersizev2 + 1, &(msg->headerextrav2.noar), 1); } return DLT_RETURN_OK; } @@ -2338,19 +2253,17 @@ DltReturnValue dlt_message_set_extraparameters_v2(DltMessageV2 *msg, int verbose uint8_t dlt_message_get_extraparameters_size_v2(DltHtyp2ContentType msgcontent) { uint8_t size = 0; - if (msgcontent==DLT_VERBOSE_DATA_MSG) { + if (msgcontent == DLT_VERBOSE_DATA_MSG) { size = DLT_SIZE_VERBOSE_DATA_MSG; - }else if (msgcontent==DLT_NON_VERBOSE_DATA_MSG) - { + } else if (msgcontent == DLT_NON_VERBOSE_DATA_MSG) { size = DLT_SIZE_NONVERBOSE_DATA_MSG; - }else if (msgcontent==DLT_CONTROL_MSG) - { + } else if (msgcontent == DLT_CONTROL_MSG) { size = DLT_SIZE_CONTROL_MSG; } return size; } -DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2 *msg) +DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2* msg) { if (msg == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -2358,138 +2271,106 @@ DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2 *msg) uint32_t pntroffset = msg->storageheadersizev2 + msg->baseheadersizev2 + msg->baseheaderextrasizev2; if (DLT_IS_HTYP2_WEID(msg->baseheaderv2->htyp2)) { - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.ecidlen), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.ecidlen), 1); if (msg->extendedheaderv2.ecidlen > 0) { if (msg->extendedheaderv2.ecid == NULL) { return DLT_RETURN_ERROR; } /* copy ecid into header buffer and update pointer to point into headerbufferv2 */ - memcpy(msg->headerbufferv2 + pntroffset + 1, - msg->extendedheaderv2.ecid, - msg->extendedheaderv2.ecidlen); - msg->extendedheaderv2.ecid = (char *)(msg->headerbufferv2 + pntroffset + 1); + memcpy(msg->headerbufferv2 + pntroffset + 1, msg->extendedheaderv2.ecid, msg->extendedheaderv2.ecidlen); + msg->extendedheaderv2.ecid = (char*)(msg->headerbufferv2 + pntroffset + 1); } pntroffset = pntroffset + msg->extendedheaderv2.ecidlen + 1; } if (DLT_IS_HTYP2_WACID(msg->baseheaderv2->htyp2)) { - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.apidlen), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.apidlen), 1); if (msg->extendedheaderv2.apidlen > 0) { if (msg->extendedheaderv2.apid == NULL) { return DLT_RETURN_ERROR; } /* copy apid into header buffer and update pointer to point into headerbufferv2 */ - memcpy(msg->headerbufferv2 + pntroffset + 1, - msg->extendedheaderv2.apid, - msg->extendedheaderv2.apidlen); - msg->extendedheaderv2.apid = (char *)(msg->headerbufferv2 + pntroffset + 1); + memcpy(msg->headerbufferv2 + pntroffset + 1, msg->extendedheaderv2.apid, msg->extendedheaderv2.apidlen); + msg->extendedheaderv2.apid = (char*)(msg->headerbufferv2 + pntroffset + 1); } pntroffset = pntroffset + (msg->extendedheaderv2.apidlen) + 1; - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.ctidlen), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.ctidlen), 1); if (msg->extendedheaderv2.ctidlen > 0) { if (msg->extendedheaderv2.ctid == NULL) { return DLT_RETURN_ERROR; } /* copy ctid into header buffer and update pointer to point into headerbufferv2 */ - memcpy(msg->headerbufferv2 + pntroffset + 1, - msg->extendedheaderv2.ctid, - msg->extendedheaderv2.ctidlen); - msg->extendedheaderv2.ctid = (char *)(msg->headerbufferv2 + pntroffset + 1); + memcpy(msg->headerbufferv2 + pntroffset + 1, msg->extendedheaderv2.ctid, msg->extendedheaderv2.ctidlen); + msg->extendedheaderv2.ctid = (char*)(msg->headerbufferv2 + pntroffset + 1); } pntroffset = pntroffset + msg->extendedheaderv2.ctidlen + 1; } if (DLT_IS_HTYP2_WSID(msg->baseheaderv2->htyp2)) { uint32_t seid_be = DLT_HTOBE_32(msg->extendedheaderv2.seid); - memcpy(msg->headerbufferv2 + pntroffset, - &seid_be, - 4); + memcpy(msg->headerbufferv2 + pntroffset, &seid_be, 4); pntroffset = pntroffset + 4; } if (DLT_IS_HTYP2_WSFLN(msg->baseheaderv2->htyp2)) { - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.finalen), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.finalen), 1); /* copy filename into header buffer and update pointer to point into headerbufferv2 */ if (msg->extendedheaderv2.finalen > 0 && msg->extendedheaderv2.fina != NULL) { - memcpy(msg->headerbufferv2 + pntroffset + 1, - msg->extendedheaderv2.fina, - msg->extendedheaderv2.finalen); - msg->extendedheaderv2.fina = (char *)(msg->headerbufferv2 + pntroffset + 1); + memcpy(msg->headerbufferv2 + pntroffset + 1, msg->extendedheaderv2.fina, msg->extendedheaderv2.finalen); + msg->extendedheaderv2.fina = (char*)(msg->headerbufferv2 + pntroffset + 1); } pntroffset = pntroffset + msg->extendedheaderv2.finalen + 1; uint32_t linr_be = DLT_HTOBE_32(msg->extendedheaderv2.linr); - memcpy(msg->headerbufferv2 + pntroffset, - &linr_be, - 4); + memcpy(msg->headerbufferv2 + pntroffset, &linr_be, 4); pntroffset = pntroffset + 4; } if (DLT_IS_HTYP2_WTGS(msg->baseheaderv2->htyp2)) { - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.notg), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.notg), 1); pntroffset = pntroffset + 1; - for(int j=0; jextendedheaderv2.notg; j++){ - memset(msg->headerbufferv2 + pntroffset, - msg->extendedheaderv2.tag[j].taglen, - 1); + for (int j = 0; j < msg->extendedheaderv2.notg; j++) { + memset(msg->headerbufferv2 + pntroffset, msg->extendedheaderv2.tag[j].taglen, 1); - memcpy(msg->headerbufferv2 + pntroffset + 1, - msg->extendedheaderv2.tag[j].tagname, - msg->extendedheaderv2.tag[j].taglen); - /* ensure NUL termination for tag name consumers that expect len+1 bytes */ - msg->headerbufferv2[pntroffset + 1 + msg->extendedheaderv2.tag[j].taglen] = '\0'; + memcpy( + msg->headerbufferv2 + pntroffset + 1, msg->extendedheaderv2.tag[j].tagname, + msg->extendedheaderv2.tag[j].taglen); + /* ensure NUL termination for tag name consumers that expect len+1 bytes */ + msg->headerbufferv2[pntroffset + 1 + msg->extendedheaderv2.tag[j].taglen] = '\0'; pntroffset = pntroffset + (msg->extendedheaderv2.tag[j].taglen) + 1; } } if (DLT_IS_HTYP2_WPVL(msg->baseheaderv2->htyp2)) { - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.prlv), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.prlv), 1); pntroffset = pntroffset + 1; } if (DLT_IS_HTYP2_WSGM(msg->baseheaderv2->htyp2)) { uint8_t sgmtLength = 0; - memcpy(msg->headerbufferv2 + pntroffset, - &(msg->extendedheaderv2.sgmtinfo), - 1); + memcpy(msg->headerbufferv2 + pntroffset, &(msg->extendedheaderv2.sgmtinfo), 1); - memcpy(msg->headerbufferv2 + pntroffset + 1, - &(msg->extendedheaderv2.frametype), - 1); + memcpy(msg->headerbufferv2 + pntroffset + 1, &(msg->extendedheaderv2.frametype), 1); - if (msg->extendedheaderv2.frametype == DLT_FIRST_FRAME){ + if (msg->extendedheaderv2.frametype == DLT_FIRST_FRAME) { sgmtLength = 8; - }else if (msg->extendedheaderv2.frametype == DLT_CONSECUTIVE_FRAME){ - sgmtLength = 4; - }else if (msg->extendedheaderv2.frametype == DLT_LAST_FRAME){ - sgmtLength = 0; - }else if (msg->extendedheaderv2.frametype == DLT_ABORT_FRAME){ - sgmtLength = 1; + } else if (msg->extendedheaderv2.frametype == DLT_CONSECUTIVE_FRAME) { + sgmtLength = 4; + } else if (msg->extendedheaderv2.frametype == DLT_LAST_FRAME) { + sgmtLength = 0; + } else if (msg->extendedheaderv2.frametype == DLT_ABORT_FRAME) { + sgmtLength = 1; } - memcpy(msg->headerbufferv2 + pntroffset + 2, - &(msg->extendedheaderv2.sgmtdetails), - sgmtLength); + memcpy(msg->headerbufferv2 + pntroffset + 2, &(msg->extendedheaderv2.sgmtdetails), sgmtLength); pntroffset = pntroffset + sgmtLength + 2; } @@ -2497,7 +2378,7 @@ DltReturnValue dlt_message_set_extendedparameters_v2(DltMessageV2 *msg) return DLT_RETURN_OK; } -uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2 *msg) +uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2* msg) { uint32_t size = 0; uint8_t sgmtLength = 0; @@ -2517,7 +2398,7 @@ uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2 *msg) }; if (DLT_IS_HTYP2_WTGS(msg->baseheaderv2->htyp2)) { size = size + 1; - for(int j=0; jextendedheaderv2.notg; j++){ + for (int j = 0; j < msg->extendedheaderv2.notg; j++) { size = size + (msg->extendedheaderv2.tag[j].taglen) + 1; }; }; @@ -2525,82 +2406,68 @@ uint32_t dlt_message_get_extendedparameters_size_v2(DltMessageV2 *msg) size = size + 1; }; if (DLT_IS_HTYP2_WSGM(msg->baseheaderv2->htyp2)) { - if (msg->extendedheaderv2.frametype == DLT_FIRST_FRAME){ + if (msg->extendedheaderv2.frametype == DLT_FIRST_FRAME) { sgmtLength = 8; - }else if (msg->extendedheaderv2.frametype == DLT_CONSECUTIVE_FRAME){ - sgmtLength = 4; - }else if (msg->extendedheaderv2.frametype == DLT_LAST_FRAME){ - sgmtLength = 0; - }else if (msg->extendedheaderv2.frametype == DLT_ABORT_FRAME){ - sgmtLength = 1; + } else if (msg->extendedheaderv2.frametype == DLT_CONSECUTIVE_FRAME) { + sgmtLength = 4; + } else if (msg->extendedheaderv2.frametype == DLT_LAST_FRAME) { + sgmtLength = 0; + } else if (msg->extendedheaderv2.frametype == DLT_ABORT_FRAME) { + sgmtLength = 1; } size = size + sgmtLength + 2; }; return size; } -DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMessageV2 *msg, uint8_t* buffer, DltHtyp2ContentType msgcontent) +DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2( + DltMessageV2* msg, uint8_t* buffer, DltHtyp2ContentType msgcontent) { if (msg == NULL) return DLT_RETURN_WRONG_PARAMETER; uint16_t headerExtraSize = dlt_message_get_extraparameters_size_v2(msgcontent); - msg->baseheaderv2 = (DltBaseHeaderV2 *)buffer; + msg->baseheaderv2 = (DltBaseHeaderV2*)buffer; int32_t pntroffset = BASE_HEADER_V2_FIXED_SIZE + headerExtraSize; if (DLT_IS_HTYP2_WEID(msg->baseheaderv2->htyp2)) { - memcpy(&(msg->extendedheaderv2.ecidlen), - buffer + pntroffset, - 1); - msg->extendedheaderv2.ecid = (char *)(buffer + pntroffset + 1); + memcpy(&(msg->extendedheaderv2.ecidlen), buffer + pntroffset, 1); + msg->extendedheaderv2.ecid = (char*)(buffer + pntroffset + 1); pntroffset = pntroffset + msg->extendedheaderv2.ecidlen + 1; } if (DLT_IS_HTYP2_WACID(msg->baseheaderv2->htyp2)) { - - memcpy(&(msg->extendedheaderv2.apidlen), - buffer + pntroffset, - 1); - msg->extendedheaderv2.apid = (char *)(buffer + pntroffset + 1); + memcpy(&(msg->extendedheaderv2.apidlen), buffer + pntroffset, 1); + msg->extendedheaderv2.apid = (char*)(buffer + pntroffset + 1); pntroffset = pntroffset + (msg->extendedheaderv2.apidlen) + 1; - memcpy(&(msg->extendedheaderv2.ctidlen), - buffer + pntroffset, - 1); - msg->extendedheaderv2.ctid = (char *)(buffer + pntroffset + 1); + memcpy(&(msg->extendedheaderv2.ctidlen), buffer + pntroffset, 1); + msg->extendedheaderv2.ctid = (char*)(buffer + pntroffset + 1); pntroffset = pntroffset + msg->extendedheaderv2.ctidlen + 1; } if (DLT_IS_HTYP2_WSID(msg->baseheaderv2->htyp2)) { - memcpy(&(msg->extendedheaderv2.seid), - buffer + pntroffset, - 4); + memcpy(&(msg->extendedheaderv2.seid), buffer + pntroffset, 4); msg->extendedheaderv2.seid = DLT_BETOH_32(msg->extendedheaderv2.seid); pntroffset = pntroffset + 4; } if (DLT_IS_HTYP2_WSFLN(msg->baseheaderv2->htyp2)) { - memcpy(&(msg->extendedheaderv2.finalen), - buffer + pntroffset, - 1); - msg->extendedheaderv2.fina = (char *)(buffer + pntroffset + 1); + memcpy(&(msg->extendedheaderv2.finalen), buffer + pntroffset, 1); + msg->extendedheaderv2.fina = (char*)(buffer + pntroffset + 1); pntroffset = pntroffset + msg->extendedheaderv2.finalen + 1; - memcpy(&(msg->extendedheaderv2.linr), - buffer + pntroffset, - 4); + memcpy(&(msg->extendedheaderv2.linr), buffer + pntroffset, 4); msg->extendedheaderv2.linr = DLT_BETOH_32(msg->extendedheaderv2.linr); pntroffset = pntroffset + 4; } if (DLT_IS_HTYP2_WTGS(msg->baseheaderv2->htyp2)) { - memcpy(&(msg->extendedheaderv2.notg), - buffer + pntroffset, - 1); + memcpy(&(msg->extendedheaderv2.notg), buffer + pntroffset, 1); pntroffset = pntroffset + 1; /* Free previously allocated tags before re-allocating */ @@ -2608,27 +2475,21 @@ DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMess free(msg->extendedheaderv2.tag); msg->extendedheaderv2.tag = NULL; } - msg->extendedheaderv2.tag = (DltTag *)malloc((msg->extendedheaderv2.notg) * sizeof(DltTag)); + msg->extendedheaderv2.tag = (DltTag*)malloc((msg->extendedheaderv2.notg) * sizeof(DltTag)); if (msg->extendedheaderv2.tag == NULL) { return DLT_RETURN_ERROR; } for (int j = 0; j < msg->extendedheaderv2.notg; j++) { - memcpy(&(msg->extendedheaderv2.tag[j].taglen), - buffer + pntroffset, - 1); + memcpy(&(msg->extendedheaderv2.tag[j].taglen), buffer + pntroffset, 1); /* Copy tag name into fixed-size buffer inside DltTag and NUL-terminate. */ size_t tlen = msg->extendedheaderv2.tag[j].taglen; if (tlen >= DLT_V2_ID_SIZE) { /* truncate if too long */ - memcpy(msg->extendedheaderv2.tag[j].tagname, - buffer + pntroffset + 1, - DLT_V2_ID_SIZE - 1); + memcpy(msg->extendedheaderv2.tag[j].tagname, buffer + pntroffset + 1, DLT_V2_ID_SIZE - 1); msg->extendedheaderv2.tag[j].tagname[DLT_V2_ID_SIZE - 1] = '\0'; } else { - memcpy(msg->extendedheaderv2.tag[j].tagname, - buffer + pntroffset + 1, - tlen); + memcpy(msg->extendedheaderv2.tag[j].tagname, buffer + pntroffset + 1, tlen); msg->extendedheaderv2.tag[j].tagname[tlen] = '\0'; } @@ -2637,36 +2498,28 @@ DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMess } if (DLT_IS_HTYP2_WPVL(msg->baseheaderv2->htyp2)) { - memcpy(&(msg->extendedheaderv2.prlv), - buffer + pntroffset, - 1); + memcpy(&(msg->extendedheaderv2.prlv), buffer + pntroffset, 1); pntroffset = pntroffset + 1; } if (DLT_IS_HTYP2_WSGM(msg->baseheaderv2->htyp2)) { uint8_t sgmtLength = 0; - memcpy(&(msg->extendedheaderv2.sgmtinfo), - buffer + pntroffset, - 1); + memcpy(&(msg->extendedheaderv2.sgmtinfo), buffer + pntroffset, 1); - memcpy(&(msg->extendedheaderv2.frametype), - buffer + pntroffset + 1, - 1); + memcpy(&(msg->extendedheaderv2.frametype), buffer + pntroffset + 1, 1); - if (msg->extendedheaderv2.frametype == DLT_FIRST_FRAME){ + if (msg->extendedheaderv2.frametype == DLT_FIRST_FRAME) { sgmtLength = 8; - }else if (msg->extendedheaderv2.frametype == DLT_CONSECUTIVE_FRAME){ - sgmtLength = 4; - }else if (msg->extendedheaderv2.frametype == DLT_LAST_FRAME){ - sgmtLength = 0; - }else if (msg->extendedheaderv2.frametype == DLT_ABORT_FRAME){ - sgmtLength = 1; + } else if (msg->extendedheaderv2.frametype == DLT_CONSECUTIVE_FRAME) { + sgmtLength = 4; + } else if (msg->extendedheaderv2.frametype == DLT_LAST_FRAME) { + sgmtLength = 0; + } else if (msg->extendedheaderv2.frametype == DLT_ABORT_FRAME) { + sgmtLength = 1; } - memcpy(&(msg->extendedheaderv2.sgmtdetails), - buffer + pntroffset + 2, - sgmtLength); + memcpy(&(msg->extendedheaderv2.sgmtdetails), buffer + pntroffset + 2, sgmtLength); pntroffset = pntroffset + sgmtLength + 2; } @@ -2674,7 +2527,7 @@ DltReturnValue dlt_message_get_extendedparameters_from_recievedbuffer_v2(DltMess return DLT_RETURN_OK; } -DltReturnValue dlt_file_init(DltFile *file, int verbose) +DltReturnValue dlt_file_init(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2698,7 +2551,7 @@ DltReturnValue dlt_file_init(DltFile *file, int verbose) return dlt_message_init(&(file->msg), verbose); } -DltReturnValue dlt_file_init_v2(DltFile *file, int verbose) +DltReturnValue dlt_file_init_v2(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2720,11 +2573,10 @@ DltReturnValue dlt_file_init_v2(DltFile *file, int verbose) file->error_messages = 0; return dlt_message_init_v2(&(file->msgv2), verbose); - } -DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose) +DltReturnValue dlt_file_set_filter(DltFile* file, DltFilter* filter, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2737,7 +2589,7 @@ DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose return DLT_RETURN_OK; } -DltReturnValue dlt_file_read_header(DltFile *file, int verbose) +DltReturnValue dlt_file_read_header(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2747,9 +2599,7 @@ DltReturnValue dlt_file_read_header(DltFile *file, int verbose) /* Loop until storage header is found */ while (1) { /* load header from file */ - if (fread(file->msg.headerbuffer, - sizeof(DltStorageHeader) + sizeof(DltStandardHeader), 1, - file->handle) != 1) { + if (fread(file->msg.headerbuffer, sizeof(DltStorageHeader) + sizeof(DltStandardHeader), 1, file->handle) != 1) { if (!feof(file->handle)) dlt_log(LOG_WARNING, "Cannot read header from file!\n"); else @@ -2759,41 +2609,36 @@ DltReturnValue dlt_file_read_header(DltFile *file, int verbose) } /* set ptrs to structures */ - file->msg.storageheader = (DltStorageHeader *)file->msg.headerbuffer; - file->msg.standardheader = (DltStandardHeader *)(file->msg.headerbuffer + - sizeof(DltStorageHeader)); + file->msg.storageheader = (DltStorageHeader*)file->msg.headerbuffer; + file->msg.standardheader = (DltStandardHeader*)(file->msg.headerbuffer + sizeof(DltStorageHeader)); /* check id of storage header */ if (dlt_check_storageheader(file->msg.storageheader) != DLT_RETURN_TRUE) { /* Shift the position back to the place where it stared to read + 1 */ - if (fseek(file->handle, - (long) (1 - (sizeof(DltStorageHeader) + sizeof(DltStandardHeader))), - SEEK_CUR) < 0) { + if (fseek(file->handle, (long)(1 - (sizeof(DltStorageHeader) + sizeof(DltStandardHeader))), SEEK_CUR) < 0) { dlt_log(LOG_WARNING, "DLT storage header pattern not found!\n"); return DLT_RETURN_ERROR; } - } - else { + } else { /* storage header is found */ break; } } /* calculate complete size of headers */ - file->msg.headersize = (int32_t) (sizeof(DltStorageHeader) - + sizeof(DltStandardHeader) - + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) - + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? (uint32_t)sizeof(DltExtendedHeader) : 0U)); + file->msg.headersize = + (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? (uint32_t)sizeof(DltExtendedHeader) : 0U)); /* calculate complete size of payload */ int32_t temp_datasize; - temp_datasize = DLT_BETOH_16(file->msg.standardheader->len) + (int32_t) sizeof(DltStorageHeader) - (int32_t) file->msg.headersize; + temp_datasize = + DLT_BETOH_16(file->msg.standardheader->len) + (int32_t)sizeof(DltStorageHeader) - (int32_t)file->msg.headersize; /* check data size */ if (temp_datasize < 0) { - dlt_vlog(LOG_WARNING, - "Plausibility check failed. Complete message size too short! (%d)\n", - temp_datasize); + dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short! (%d)\n", temp_datasize); return DLT_RETURN_ERROR; } else { file->msg.datasize = temp_datasize; @@ -2801,14 +2646,13 @@ DltReturnValue dlt_file_read_header(DltFile *file, int verbose) /* check if verbose mode is on */ if (verbose) { - dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n", - file->msg.headersize, file->msg.datasize); + dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n", file->msg.headersize, file->msg.datasize); } return DLT_RETURN_OK; } -DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose) +DltReturnValue dlt_file_read_header_raw(DltFile* file, int resync, int verbose) { char dltSerialHeaderBuffer[DLT_ID_SIZE]; @@ -2830,8 +2674,7 @@ DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose) /* serial header found */ /* nothing to do continue reading */ - } - else { + } else { /* serial header not found */ if (resync) { /* increase error counter */ @@ -2849,13 +2692,11 @@ DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose) /* serial header synchronised */ break; } while (1); - } - else - /* go back to last file position */ - if (0 != fseek(file->handle, (long)file->file_position, SEEK_SET)) - { - return DLT_RETURN_ERROR; - } + } else + /* go back to last file position */ + if (0 != fseek(file->handle, (long)file->file_position, SEEK_SET)) { + return DLT_RETURN_ERROR; + } } /* load header from file */ @@ -2867,8 +2708,9 @@ DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose) } /* set ptrs to structures */ - file->msg.storageheader = (DltStorageHeader *)file->msg.headerbuffer; /* this points now to a empty storage header (filled with '0') */ - file->msg.standardheader = (DltStandardHeader *)(file->msg.headerbuffer + sizeof(DltStorageHeader)); + file->msg.storageheader = + (DltStorageHeader*)file->msg.headerbuffer; /* this points now to a empty storage header (filled with '0') */ + file->msg.standardheader = (DltStandardHeader*)(file->msg.headerbuffer + sizeof(DltStorageHeader)); /* Skip storage header field, fill this field with '0' */ memset(file->msg.storageheader, 0, sizeof(DltStorageHeader)); @@ -2879,35 +2721,33 @@ DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose) /* no check for storage header id*/ /* calculate complete size of headers */ - file->msg.headersize = (int32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + - (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? (uint32_t)sizeof(DltExtendedHeader) : 0U)); + file->msg.headersize = + (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? (uint32_t)sizeof(DltExtendedHeader) : 0U)); /* calculate complete size of payload */ int32_t temp_datasize; - temp_datasize = DLT_BETOH_16(file->msg.standardheader->len) + (int32_t) sizeof(DltStorageHeader) - (int32_t) file->msg.headersize; + temp_datasize = + DLT_BETOH_16(file->msg.standardheader->len) + (int32_t)sizeof(DltStorageHeader) - (int32_t)file->msg.headersize; /* check data size */ if (temp_datasize < 0) { - dlt_vlog(LOG_WARNING, - "Plausibility check failed. Complete message size too short! (%d)\n", - temp_datasize); + dlt_vlog(LOG_WARNING, "Plausibility check failed. Complete message size too short! (%d)\n", temp_datasize); return DLT_RETURN_ERROR; - } - else { + } else { file->msg.datasize = temp_datasize; } /* check if verbose mode is on */ if (verbose) { - dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n", - file->msg.headersize, file->msg.datasize); + dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n", file->msg.headersize, file->msg.datasize); } return DLT_RETURN_OK; } -DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose) +DltReturnValue dlt_file_read_header_extended(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2916,9 +2756,10 @@ DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose) /* load standard header extra parameters if used */ if (DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp)) { - if (fread(file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), - DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp), - 1, file->handle) != 1) { + if (fread( + file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader), + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp), 1, file->handle) + != 1) { dlt_log(LOG_WARNING, "Cannot read standard header extra parameters from file!\n"); return DLT_RETURN_ERROR; } @@ -2931,10 +2772,11 @@ DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose) /* there is nothing to be loaded */ return DLT_RETURN_OK; - if (fread(file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp), - (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0), - 1, file->handle) != 1) { + if (fread( + file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp), + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0), 1, file->handle) + != 1) { dlt_log(LOG_WARNING, "Cannot read extended header from file!\n"); return DLT_RETURN_ERROR; } @@ -2942,15 +2784,15 @@ DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose) /* set extended header ptr */ if (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp)) file->msg.extendedheader = - (DltExtendedHeader *)(file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp)); + (DltExtendedHeader*)(file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp)); else file->msg.extendedheader = NULL; return DLT_RETURN_OK; } -DltReturnValue dlt_file_read_data(DltFile *file, int verbose) +DltReturnValue dlt_file_read_data(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -2965,23 +2807,19 @@ DltReturnValue dlt_file_read_data(DltFile *file, int verbose) if (file->msg.databuffer == NULL) { /* get new memory for buffer */ - file->msg.databuffer = (uint8_t *)malloc((size_t)file->msg.datasize); + file->msg.databuffer = (uint8_t*)malloc((size_t)file->msg.datasize); file->msg.databuffersize = file->msg.datasize; } if (file->msg.databuffer == NULL) { - dlt_vlog(LOG_WARNING, - "Cannot allocate memory for payload buffer of size %u!\n", - file->msg.datasize); + dlt_vlog(LOG_WARNING, "Cannot allocate memory for payload buffer of size %u!\n", file->msg.datasize); return DLT_RETURN_ERROR; } /* load payload data from file */ if (fread(file->msg.databuffer, (size_t)file->msg.datasize, 1, file->handle) != 1) { if (file->msg.datasize != 0) { - dlt_vlog(LOG_WARNING, - "Cannot read payload data from file of size %u!\n", - file->msg.datasize); + dlt_vlog(LOG_WARNING, "Cannot read payload data from file of size %u!\n", file->msg.datasize); return DLT_RETURN_ERROR; } } @@ -2989,7 +2827,7 @@ DltReturnValue dlt_file_read_data(DltFile *file, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose) +DltReturnValue dlt_file_open(DltFile* file, const char* filename, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3034,9 +2872,9 @@ DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_file_read(DltFile *file, int verbose) +DltReturnValue dlt_file_read(DltFile* file, int verbose) { - long *ptr; + long* ptr; int found = DLT_RETURN_OK; if (file == NULL) @@ -3047,7 +2885,8 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose) /* allocate new memory for index if number of messages exceeds a multiple of DLT_COMMON_INDEX_ALLOC (e.g.: 1000) */ if (file->counter % DLT_COMMON_INDEX_ALLOC == 0) { - ptr = (long *)malloc((size_t)((file->counter / DLT_COMMON_INDEX_ALLOC) + 1) * (size_t)DLT_COMMON_INDEX_ALLOC * sizeof(long)); + ptr = (long*)malloc( + (size_t)((file->counter / DLT_COMMON_INDEX_ALLOC) + 1) * (size_t)DLT_COMMON_INDEX_ALLOC * sizeof(long)); if (ptr == NULL) return DLT_RETURN_ERROR; @@ -3062,8 +2901,7 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose) /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */ if (0 != fseek(file->handle, (long)file->file_position, SEEK_SET)) { - dlt_vlog(LOG_WARNING, "Seek failed to file_position %" PRIu64 "\n", - file->file_position); + dlt_vlog(LOG_WARNING, "Seek failed to file_position %" PRIu64 "\n", file->file_position); return DLT_RETURN_ERROR; } @@ -3075,8 +2913,7 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose) if (dlt_file_read_header(file, verbose) < DLT_RETURN_OK) { /* go back to last position in file */ if (0 != fseek(file->handle, (long)file->file_position, SEEK_SET)) { - dlt_vlog(LOG_WARNING, "Seek failed to file_position %" PRIu64 " \n", - file->file_position); + dlt_vlog(LOG_WARNING, "Seek failed to file_position %" PRIu64 " \n", file->file_position); } return DLT_RETURN_ERROR; } @@ -3105,27 +2942,25 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose) /* skip payload data */ if (fseek(file->handle, (long)file->msg.datasize, SEEK_CUR) != 0) { /* go back to last position in file */ - dlt_vlog(LOG_WARNING, - "Seek failed to skip payload data of size %u!\n", - file->msg.datasize); + dlt_vlog(LOG_WARNING, "Seek failed to skip payload data of size %u!\n", file->msg.datasize); if (0 != fseek(file->handle, (long)file->file_position, SEEK_SET)) dlt_log(LOG_WARNING, "Seek back also failed!\n"); return DLT_RETURN_ERROR; } - } - else { + } else { /* filter is disabled */ /* skip additional header parameters and payload data */ - if (fseek(file->handle, - (long)((int32_t)file->msg.headersize - (int32_t)sizeof(DltStorageHeader) - (int32_t)sizeof(DltStandardHeader) + (long)file->msg.datasize), - SEEK_CUR)) { - - dlt_vlog(LOG_WARNING, - "Seek failed to skip extra header and payload data from file of size %u!\n", - file->msg.headersize - (int32_t)sizeof(DltStorageHeader) - - (int32_t)sizeof(DltStandardHeader) + file->msg.datasize); + if (fseek( + file->handle, + (long)((int32_t)file->msg.headersize - (int32_t)sizeof(DltStorageHeader) + - (int32_t)sizeof(DltStandardHeader) + (long)file->msg.datasize), + SEEK_CUR)) { + dlt_vlog( + LOG_WARNING, "Seek failed to skip extra header and payload data from file of size %u!\n", + file->msg.headersize - (int32_t)sizeof(DltStorageHeader) - (int32_t)sizeof(DltStandardHeader) + + file->msg.datasize); /* go back to last position in file */ if (fseek(file->handle, (long)file->file_position, SEEK_SET)) @@ -3151,10 +2986,10 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose) return found; } -DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose) +DltReturnValue dlt_file_read_raw(DltFile* file, int resync, int verbose) { int found = DLT_RETURN_OK; - long *ptr; + long* ptr; if (verbose) dlt_vlog(LOG_DEBUG, "%s: Message %d:\n", __func__, file->counter_total); @@ -3164,7 +2999,8 @@ DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose) /* allocate new memory for index if number of messages exceeds a multiple of DLT_COMMON_INDEX_ALLOC (e.g.: 1000) */ if (file->counter % DLT_COMMON_INDEX_ALLOC == 0) { - ptr = (long *)malloc((size_t)((file->counter / DLT_COMMON_INDEX_ALLOC) + 1) * (size_t)DLT_COMMON_INDEX_ALLOC * sizeof(long)); + ptr = (long*)malloc( + (size_t)((file->counter / DLT_COMMON_INDEX_ALLOC) + 1) * (size_t)DLT_COMMON_INDEX_ALLOC * sizeof(long)); if (ptr == NULL) return DLT_RETURN_ERROR; @@ -3227,7 +3063,7 @@ DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose) return found; } -DltReturnValue dlt_file_close(DltFile *file, int verbose) +DltReturnValue dlt_file_close(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3242,7 +3078,7 @@ DltReturnValue dlt_file_close(DltFile *file, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_file_message(DltFile *file, int index, int verbose) +DltReturnValue dlt_file_message(DltFile* file, int index, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3257,8 +3093,7 @@ DltReturnValue dlt_file_message(DltFile *file, int index, int verbose) /* seek to position in file */ if (fseek(file->handle, file->index[index], SEEK_SET) != 0) { - dlt_vlog(LOG_WARNING, "Seek to message %d to position %ld failed!\r\n", - index, file->index[index]); + dlt_vlog(LOG_WARNING, "Seek to message %d to position %ld failed!\r\n", index, file->index[index]); return DLT_RETURN_ERROR; } @@ -3278,7 +3113,7 @@ DltReturnValue dlt_file_message(DltFile *file, int index, int verbose) return DLT_RETURN_OK; } -DltReturnValue dlt_file_free(DltFile *file, int verbose) +DltReturnValue dlt_file_free(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3300,7 +3135,7 @@ DltReturnValue dlt_file_free(DltFile *file, int verbose) return dlt_message_free(&(file->msg), verbose); } -DltReturnValue dlt_file_free_v2(DltFile *file, int verbose) +DltReturnValue dlt_file_free_v2(DltFile* file, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); @@ -3323,7 +3158,7 @@ DltReturnValue dlt_file_free_v2(DltFile *file, int verbose) } #if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC -void dlt_log_set_fifo_basedir(const char *pipe_dir) +void dlt_log_set_fifo_basedir(const char* pipe_dir) { strncpy(dltFifoBaseDir, pipe_dir, DLT_PATH_MAX); dltFifoBaseDir[DLT_PATH_MAX - 1] = 0; @@ -3331,7 +3166,7 @@ void dlt_log_set_fifo_basedir(const char *pipe_dir) #endif #ifdef DLT_SHM_ENABLE -void dlt_log_set_shm_name(const char *env_shm_name) +void dlt_log_set_shm_name(const char* env_shm_name) { strncpy(dltShmName, env_shm_name, NAME_MAX); dltShmName[NAME_MAX] = 0; @@ -3343,7 +3178,7 @@ void dlt_print_with_attributes(bool state) print_with_attributes = state; } -DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, DltReceiverType type, int buffersize) +DltReturnValue dlt_receiver_init(DltReceiver* receiver, int fd, DltReceiverType type, int buffersize) { if (NULL == receiver) return DLT_RETURN_WRONG_PARAMETER; @@ -3352,11 +3187,11 @@ DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, DltReceiverType receiver->type = type; /** Reuse the receiver buffer if it exists and the buffer size - * is not changed. If not, free the old one and allocate a new buffer. - */ - if ((NULL != receiver->buffer) && ( buffersize != receiver->buffersize)) { - free(receiver->buffer); - receiver->buffer = NULL; + * is not changed. If not, free the old one and allocate a new buffer. + */ + if ((NULL != receiver->buffer) && (buffersize != receiver->buffersize)) { + free(receiver->buffer); + receiver->buffer = NULL; } if (NULL == receiver->buffer) { @@ -3365,22 +3200,21 @@ DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, DltReceiverType receiver->totalBytesRcvd = 0; receiver->buf = NULL; receiver->backup_buf = NULL; - receiver->buffer = (char *)calloc(1, (size_t)buffersize); + receiver->buffer = (char*)calloc(1, (size_t)buffersize); receiver->buffersize = (int32_t)buffersize; } if (NULL == receiver->buffer) { dlt_log(LOG_ERR, "allocate memory for receiver buffer failed.\n"); return DLT_RETURN_ERROR; - } - else { + } else { receiver->buf = receiver->buffer; } return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, DltReceiverType type, char **buffer) +DltReturnValue dlt_receiver_init_global_buffer(DltReceiver* receiver, int fd, DltReceiverType type, char** buffer) { if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3389,7 +3223,7 @@ DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, Dl /* allocating the buffer once and using it for all application receivers * by keeping allocated buffer in app_recv_buffer global handle */ - *buffer = (char *)malloc(DLT_RECEIVE_BUFSIZE); + *buffer = (char*)malloc(DLT_RECEIVE_BUFSIZE); if (*buffer == NULL) return DLT_RETURN_ERROR; @@ -3408,9 +3242,8 @@ DltReturnValue dlt_receiver_init_global_buffer(DltReceiver *receiver, int fd, Dl return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_free(DltReceiver *receiver) +DltReturnValue dlt_receiver_free(DltReceiver* receiver) { - if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3427,9 +3260,8 @@ DltReturnValue dlt_receiver_free(DltReceiver *receiver) return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_free_global_buffer(DltReceiver *receiver) +DltReturnValue dlt_receiver_free_global_buffer(DltReceiver* receiver) { - if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3443,7 +3275,7 @@ DltReturnValue dlt_receiver_free_global_buffer(DltReceiver *receiver) return DLT_RETURN_OK; } -int dlt_receiver_receive(DltReceiver *receiver) +int dlt_receiver_receive(DltReceiver* receiver) { socklen_t addrlen; @@ -3453,7 +3285,7 @@ int dlt_receiver_receive(DltReceiver *receiver) if (receiver->buffer == NULL) return -1; - receiver->buf = (char *)receiver->buffer; + receiver->buf = (char*)receiver->buffer; receiver->lastBytesRcvd = receiver->bytesRcvd; if ((receiver->lastBytesRcvd) && (receiver->backup_buf != NULL)) { @@ -3464,28 +3296,22 @@ int dlt_receiver_receive(DltReceiver *receiver) if (receiver->type == DLT_RECEIVE_SOCKET) { /* wait for data from socket */ - ssize_t bytes = recv(receiver->fd, - receiver->buf + receiver->lastBytesRcvd, - (size_t)(receiver->buffersize - receiver->lastBytesRcvd), - 0); + ssize_t bytes = recv( + receiver->fd, receiver->buf + receiver->lastBytesRcvd, + (size_t)(receiver->buffersize - receiver->lastBytesRcvd), 0); receiver->bytesRcvd = (bytes >= 0 && bytes <= INT32_MAX) ? (int32_t)bytes : 0; - } - else if (receiver->type == DLT_RECEIVE_FD) { + } else if (receiver->type == DLT_RECEIVE_FD) { /* wait for data from fd */ - ssize_t bytes = read(receiver->fd, - receiver->buf + receiver->lastBytesRcvd, - (size_t)(receiver->buffersize - receiver->lastBytesRcvd)); + ssize_t bytes = read( + receiver->fd, receiver->buf + receiver->lastBytesRcvd, + (size_t)(receiver->buffersize - receiver->lastBytesRcvd)); receiver->bytesRcvd = (bytes >= 0 && bytes <= INT32_MAX) ? (int32_t)bytes : 0; - } - else { /* receiver->type == DLT_RECEIVE_UDP_SOCKET */ + } else { /* receiver->type == DLT_RECEIVE_UDP_SOCKET */ /* wait for data from UDP socket */ addrlen = sizeof(receiver->addr); - ssize_t bytes = recvfrom(receiver->fd, - receiver->buf + receiver->lastBytesRcvd, - (size_t)(receiver->buffersize - receiver->lastBytesRcvd), - 0, - (struct sockaddr *)&(receiver->addr), - &addrlen); + ssize_t bytes = recvfrom( + receiver->fd, receiver->buf + receiver->lastBytesRcvd, + (size_t)(receiver->buffersize - receiver->lastBytesRcvd), 0, (struct sockaddr*)&(receiver->addr), &addrlen); receiver->bytesRcvd = (bytes >= 0 && bytes <= INT32_MAX) ? (int32_t)bytes : 0; } @@ -3500,7 +3326,7 @@ int dlt_receiver_receive(DltReceiver *receiver) return receiver->bytesRcvd; } -DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size) +DltReturnValue dlt_receiver_remove(DltReceiver* receiver, int size) { if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3520,7 +3346,7 @@ DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size) return DLT_RETURN_OK; } -DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver) +DltReturnValue dlt_receiver_move_to_begin(DltReceiver* receiver) { if (receiver == NULL) return DLT_RETURN_WRONG_PARAMETER; @@ -3532,9 +3358,11 @@ DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver) receiver->backup_buf = calloc((size_t)(receiver->bytesRcvd + 1), sizeof(char)); if (receiver->backup_buf == NULL) - dlt_vlog(LOG_WARNING, - "Can't allocate memory for backup buf, there will be atleast" - "one corrupted message for fd[%d] \n", receiver->fd); + dlt_vlog( + LOG_WARNING, + "Can't allocate memory for backup buf, there will be atleast" + "one corrupted message for fd[%d] \n", + receiver->fd); else memcpy(receiver->backup_buf, receiver->buf, (size_t)receiver->bytesRcvd); } @@ -3542,24 +3370,18 @@ DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver) return DLT_RETURN_OK; } -int dlt_receiver_check_and_get(DltReceiver *receiver, - void *dest, - unsigned int to_get, - unsigned int flags) +int dlt_receiver_check_and_get(DltReceiver* receiver, void* dest, unsigned int to_get, unsigned int flags) { size_t min_size = (size_t)to_get; - uint8_t *src = NULL; + uint8_t* src = NULL; if (flags & DLT_RCV_SKIP_HEADER) min_size += sizeof(DltUserHeader); - if (!receiver || - (receiver->bytesRcvd < (int32_t) min_size) || - !receiver->buf || - !dest) + if (!receiver || (receiver->bytesRcvd < (int32_t)min_size) || !receiver->buf || !dest) return DLT_RETURN_WRONG_PARAMETER; - src = (uint8_t *)receiver->buf; + src = (uint8_t*)receiver->buf; if (flags & DLT_RCV_SKIP_HEADER) src += sizeof(DltUserHeader); @@ -3576,9 +3398,8 @@ int dlt_receiver_check_and_get(DltReceiver *receiver, return (int)to_get; } -DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu) +DltReturnValue dlt_set_storageheader(DltStorageHeader* storageheader, const char* ecu) { - #if !defined(_MSC_VER) struct timeval tv; #endif @@ -3586,7 +3407,7 @@ DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char if ((storageheader == NULL) || (ecu == NULL)) return DLT_RETURN_WRONG_PARAMETER; - /* get time of day */ + /* get time of day */ #if defined(_MSC_VER) time(&(storageheader->seconds)); #else @@ -3605,16 +3426,15 @@ DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char #if defined(_MSC_VER) storageheader->microseconds = 0; #else - storageheader->seconds = (uint32_t) tv.tv_sec; /* value is long */ - storageheader->microseconds = (int32_t) tv.tv_usec; /* value is long */ + storageheader->seconds = (uint32_t)tv.tv_sec; /* value is long */ + storageheader->microseconds = (int32_t)tv.tv_usec; /* value is long */ #endif return DLT_RETURN_OK; } -DltReturnValue dlt_set_storageheader_v2(DltStorageHeaderV2 *storageheader, uint8_t ecuIDlen, const char *ecu) +DltReturnValue dlt_set_storageheader_v2(DltStorageHeaderV2* storageheader, uint8_t ecuIDlen, const char* ecu) { - #if !defined(_MSC_VER) struct timespec ts; #endif @@ -3622,14 +3442,14 @@ DltReturnValue dlt_set_storageheader_v2(DltStorageHeaderV2 *storageheader, uint8 if (ecu == NULL) return DLT_RETURN_WRONG_PARAMETER; - /* get time of day */ + /* get time of day */ #if defined(_MSC_VER) time_t t = time(NULL); - storageheader->seconds[0]=(t >> 32) & 0xFF; - storageheader->seconds[1]=(t >> 24) & 0xFF; - storageheader->seconds[2]=(t >> 16) & 0xFF; - storageheader->seconds[3]=(t >> 8) & 0xFF; - storageheader->seconds[4]= t & 0xFF; + storageheader->seconds[0] = (t >> 32) & 0xFF; + storageheader->seconds[1] = (t >> 24) & 0xFF; + storageheader->seconds[2] = (t >> 16) & 0xFF; + storageheader->seconds[3] = (t >> 8) & 0xFF; + storageheader->seconds[4] = t & 0xFF; #else /* initialize in case clock_gettime fails to avoid uninitialized reads */ memset(&ts, 0, sizeof(ts)); @@ -3649,12 +3469,12 @@ DltReturnValue dlt_set_storageheader_v2(DltStorageHeaderV2 *storageheader, uint8 #if defined(_MSC_VER) storageheader->nanoseconds = 0; #else - storageheader->seconds[0]=(uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); - storageheader->seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF); - storageheader->seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF); - storageheader->seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF); - storageheader->seconds[4]=(uint8_t)(ts.tv_sec & 0xFF); - storageheader->nanoseconds = (int32_t) ts.tv_nsec; /* value is long */ + storageheader->seconds[0] = (uint8_t)(((uint64_t)ts.tv_sec >> 32) & 0xFF); + storageheader->seconds[1] = (uint8_t)((ts.tv_sec >> 24) & 0xFF); + storageheader->seconds[2] = (uint8_t)((ts.tv_sec >> 16) & 0xFF); + storageheader->seconds[3] = (uint8_t)((ts.tv_sec >> 8) & 0xFF); + storageheader->seconds[4] = (uint8_t)(ts.tv_sec & 0xFF); + storageheader->nanoseconds = (int32_t)ts.tv_nsec; /* value is long */ #endif @@ -3678,41 +3498,39 @@ DltReturnValue dlt_check_rcv_data_size(int received, int required) return _ret; } -DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader) +DltReturnValue dlt_check_storageheader(DltStorageHeader* storageheader) { if (storageheader == NULL) return DLT_RETURN_WRONG_PARAMETER; - return ((storageheader->pattern[0] == 'D') && - (storageheader->pattern[1] == 'L') && - (storageheader->pattern[2] == 'T') && - (storageheader->pattern[3] == 1)) - ? DLT_RETURN_TRUE : DLT_RETURN_OK; + return ((storageheader->pattern[0] == 'D') && (storageheader->pattern[1] == 'L') + && (storageheader->pattern[2] == 'T') && (storageheader->pattern[3] == 1)) ? + DLT_RETURN_TRUE : + DLT_RETURN_OK; } -DltReturnValue dlt_check_storageheader_v2(DltStorageHeaderV2 *storageheader) +DltReturnValue dlt_check_storageheader_v2(DltStorageHeaderV2* storageheader) { if (storageheader == NULL) return DLT_RETURN_WRONG_PARAMETER; - return ((storageheader->pattern[0] == 'D') && - (storageheader->pattern[1] == 'L') && - (storageheader->pattern[2] == 'T') && - (storageheader->pattern[3] == 2)) - ? DLT_RETURN_TRUE : DLT_RETURN_OK; + return ((storageheader->pattern[0] == 'D') && (storageheader->pattern[1] == 'L') + && (storageheader->pattern[2] == 'T') && (storageheader->pattern[3] == 2)) ? + DLT_RETURN_TRUE : + DLT_RETURN_OK; } -DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size) +DltReturnValue dlt_buffer_init_static_server(DltBuffer* buf, const unsigned char* ptr, uint32_t size) { if ((buf == NULL) || (ptr == NULL)) return DLT_RETURN_WRONG_PARAMETER; - DltBufferHead *head; + DltBufferHead* head; /* Init parameters */ union { - const unsigned char *cp; - unsigned char *p; + const unsigned char* cp; + unsigned char* p; } shm_cast; shm_cast.cp = ptr; buf->shm = shm_cast.p; @@ -3721,32 +3539,30 @@ DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char buf->step_size = 0; /* Init pointers */ - head = (DltBufferHead *)buf->shm; + head = (DltBufferHead*)buf->shm; head->read = 0; head->write = 0; head->count = 0; - buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); - buf->size = (unsigned int) buf->min_size - (unsigned int) sizeof(DltBufferHead); + buf->mem = (unsigned char*)(buf->shm + sizeof(DltBufferHead)); + buf->size = (unsigned int)buf->min_size - (unsigned int)sizeof(DltBufferHead); /* clear memory */ memset(buf->mem, 0, buf->size); - dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size %u, Start address %lX\n", - __func__, buf->size, (unsigned long)buf->mem); + dlt_vlog(LOG_DEBUG, "%s: Buffer: Size %u, Start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); return DLT_RETURN_OK; /* OK */ } -DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size) +DltReturnValue dlt_buffer_init_static_client(DltBuffer* buf, const unsigned char* ptr, uint32_t size) { if ((buf == NULL) || (ptr == NULL)) return DLT_RETURN_WRONG_PARAMETER; /* Init parameters */ union { - const unsigned char *cp; - unsigned char *p; + const unsigned char* cp; + unsigned char* p; } shm_cast; shm_cast.cp = ptr; buf->shm = shm_cast.p; @@ -3755,20 +3571,18 @@ DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char buf->step_size = 0; /* Init pointers */ - buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); + buf->mem = (unsigned char*)(buf->shm + sizeof(DltBufferHead)); buf->size = (uint32_t)(buf->min_size - sizeof(DltBufferHead)); - dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size %u, Start address %lX\n", - __func__, buf->size, (unsigned long)buf->mem); + dlt_vlog(LOG_DEBUG, "%s: Buffer: Size %u, Start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); return DLT_RETURN_OK; /* OK */ } -DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size, uint32_t step_size) +DltReturnValue dlt_buffer_init_dynamic(DltBuffer* buf, uint32_t min_size, uint32_t max_size, uint32_t step_size) { /*Do not dlt_mutex_lock inside here! */ - DltBufferHead *head; + DltBufferHead* head; /* catch null pointer */ if (buf == NULL) @@ -3793,31 +3607,25 @@ DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32 buf->shm = malloc(buf->min_size); if (buf->shm == NULL) { - dlt_vlog(LOG_EMERG, - "%s: Buffer: Cannot allocate %u bytes\n", - __func__, buf->min_size); + dlt_vlog(LOG_EMERG, "%s: Buffer: Cannot allocate %u bytes\n", __func__, buf->min_size); return DLT_RETURN_ERROR; } /* Init pointers */ - head = (DltBufferHead *)buf->shm; + head = (DltBufferHead*)buf->shm; head->read = 0; head->write = 0; head->count = 0; - buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead)); + buf->mem = (unsigned char*)(buf->shm + sizeof(DltBufferHead)); if (buf->min_size < (uint32_t)sizeof(DltBufferHead)) { - dlt_vlog(LOG_ERR, - "%s: min_size is too small [%u]\n", - __func__, buf->min_size); + dlt_vlog(LOG_ERR, "%s: min_size is too small [%u]\n", __func__, buf->min_size); return DLT_RETURN_WRONG_PARAMETER; } - buf->size = (uint32_t) (buf->min_size - sizeof(DltBufferHead)); + buf->size = (uint32_t)(buf->min_size - sizeof(DltBufferHead)); - dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size %u, Start address %lX\n", - __func__, buf->size, (unsigned long)buf->mem); + dlt_vlog(LOG_DEBUG, "%s: Buffer: Size %u, Start address %lX\n", __func__, buf->size, (unsigned long)buf->mem); /* clear memory */ memset(buf->mem, 0, (size_t)buf->size); @@ -3825,7 +3633,7 @@ DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32 return DLT_RETURN_OK; /* OK */ } -DltReturnValue dlt_buffer_free_static(DltBuffer *buf) +DltReturnValue dlt_buffer_free_static(DltBuffer* buf) { /* catch null pointer */ if (buf == NULL) @@ -3840,7 +3648,7 @@ DltReturnValue dlt_buffer_free_static(DltBuffer *buf) return DLT_RETURN_OK; } -DltReturnValue dlt_buffer_free_dynamic(DltBuffer *buf) +DltReturnValue dlt_buffer_free_dynamic(DltBuffer* buf) { /* catch null pointer */ if (buf == NULL) @@ -3859,38 +3667,35 @@ DltReturnValue dlt_buffer_free_dynamic(DltBuffer *buf) return DLT_RETURN_OK; } -void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *data, unsigned int size) +void dlt_buffer_write_block(DltBuffer* buf, int* write, const unsigned char* data, unsigned int size) { /* catch null pointer */ if ((buf != NULL) && (write != NULL) && (data != NULL)) { - if (size <= buf->size){ - if (( (unsigned int) (*write ) + size) <= buf->size) { + if (size <= buf->size) { + if (((unsigned int)(*write) + size) <= buf->size) { /* write one block */ memcpy(buf->mem + *write, data, size); - *write += (int) size; - } - else { + *write += (int)size; + } else { /* when (*write) = buf->size, write only the second block - * and update write position correspondingly. - */ - if((unsigned int) (*write) <= buf->size) { + * and update write position correspondingly. + */ + if ((unsigned int)(*write) <= buf->size) { /* write two blocks */ - memcpy(buf->mem + *write, data, buf->size - (unsigned int) (*write)); - memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int) (*write)); - *write += (int) (size - buf->size); + memcpy(buf->mem + *write, data, buf->size - (unsigned int)(*write)); + memcpy(buf->mem, data + buf->size - *write, size - buf->size + (unsigned int)(*write)); + *write += (int)(size - buf->size); } } - } - else { - dlt_vlog(LOG_WARNING, "%s: Write error: ring buffer to small\n", __func__); - } - } - else { + } else { + dlt_vlog(LOG_WARNING, "%s: Write error: ring buffer to small\n", __func__); + } + } else { dlt_vlog(LOG_WARNING, "%s: Wrong parameter: Null pointer\n", __func__); } } -void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsigned int size) +void dlt_buffer_read_block(DltBuffer* buf, int* read, unsigned char* data, unsigned int size) { /* catch nullpointer */ if ((buf != NULL) && (read != NULL) && (data != NULL)) { @@ -3898,39 +3703,37 @@ void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsig /* read one block */ memcpy(data, buf->mem + *read, size); *read += (int)size; - } - else { + } else { /* when (*read) = buf->size, read only the second block - * and update read position correspondingly. - */ + * and update read position correspondingly. + */ if ((unsigned int)(*read) <= buf->size) { /* read two blocks */ memcpy(data, buf->mem + *read, buf->size - (unsigned int)(*read)); memcpy(data + buf->size - *read, buf->mem, size - buf->size + (unsigned int)(*read)); - *read += (int) (size - buf->size); + *read += (int)(size - buf->size); } } - } - else { + } else { dlt_vlog(LOG_WARNING, "%s: Wrong parameter: Null pointer\n", __func__); } } -DltReturnValue dlt_buffer_check_size(DltBuffer *buf, int needed) +DltReturnValue dlt_buffer_check_size(DltBuffer* buf, int needed) { if (buf == NULL) return DLT_RETURN_WRONG_PARAMETER; - if ((buf->size + sizeof(DltBufferHead) + (size_t) needed) > buf->max_size) + if ((buf->size + sizeof(DltBufferHead) + (size_t)needed) > buf->max_size) return DLT_RETURN_ERROR; return DLT_RETURN_OK; } -int dlt_buffer_increase_size(DltBuffer *buf) +int dlt_buffer_increase_size(DltBuffer* buf) { DltBufferHead *head, *new_head; - unsigned char *new_ptr; + unsigned char* new_ptr; /* catch null pointer */ if (buf == NULL) { @@ -3952,23 +3755,22 @@ int dlt_buffer_increase_size(DltBuffer *buf) new_ptr = malloc(buf->size + sizeof(DltBufferHead) + buf->step_size); if (new_ptr == NULL) { - dlt_vlog(LOG_WARNING, - "%s: Buffer: Cannot increase size because allocate %u bytes failed\n", - __func__, buf->min_size); + dlt_vlog( + LOG_WARNING, "%s: Buffer: Cannot increase size because allocate %u bytes failed\n", __func__, + buf->min_size); return DLT_RETURN_ERROR; } /* copy data */ - head = (DltBufferHead *)buf->shm; - new_head = (DltBufferHead *)new_ptr; + head = (DltBufferHead*)buf->shm; + new_head = (DltBufferHead*)new_ptr; if (head->read < head->write) { memcpy(new_ptr + sizeof(DltBufferHead), buf->mem + head->read, (size_t)(head->write - head->read)); new_head->read = 0; new_head->write = head->write - head->read; new_head->count = head->count; - } - else { + } else { memcpy(new_ptr + sizeof(DltBufferHead), buf->mem + head->read, buf->size - (uint32_t)(head->read)); memcpy(new_ptr + sizeof(DltBufferHead) + buf->size - head->read, buf->mem, (size_t)head->write); new_head->read = 0; @@ -3984,18 +3786,16 @@ int dlt_buffer_increase_size(DltBuffer *buf) buf->mem = new_ptr + sizeof(DltBufferHead); buf->size += buf->step_size; - dlt_vlog(LOG_DEBUG, - "%s: Buffer: Size increased to %u bytes with start address %lX\n", - __func__, - buf->size + (int32_t)sizeof(DltBufferHead), - (unsigned long)buf->mem); + dlt_vlog( + LOG_DEBUG, "%s: Buffer: Size increased to %u bytes with start address %lX\n", __func__, + buf->size + (int32_t)sizeof(DltBufferHead), (unsigned long)buf->mem); return DLT_RETURN_OK; /* OK */ } -int dlt_buffer_minimize_size(DltBuffer *buf) +int dlt_buffer_minimize_size(DltBuffer* buf) { - unsigned char *new_ptr; + unsigned char* new_ptr; /* catch null pointer */ if (buf == NULL) { @@ -4011,9 +3811,7 @@ int dlt_buffer_minimize_size(DltBuffer *buf) new_ptr = malloc(buf->min_size); if (new_ptr == NULL) { - dlt_vlog(LOG_WARNING, - "%s: Buffer: Cannot set to min size of %u bytes\n", - __func__, buf->min_size); + dlt_vlog(LOG_WARNING, "%s: Buffer: Cannot set to min size of %u bytes\n", __func__, buf->min_size); return DLT_RETURN_ERROR; } @@ -4026,13 +3824,13 @@ int dlt_buffer_minimize_size(DltBuffer *buf) buf->size = (uint32_t)(buf->min_size - sizeof(DltBufferHead)); /* reset pointers and counters */ - ((int *)(buf->shm))[0] = 0; /* pointer to write memory */ - ((int *)(buf->shm))[1] = 0; /* pointer to read memory */ - ((int *)(buf->shm))[2] = 0; /* number of packets */ + ((int*)(buf->shm))[0] = 0; /* pointer to write memory */ + ((int*)(buf->shm))[1] = 0; /* pointer to read memory */ + ((int*)(buf->shm))[2] = 0; /* number of packets */ - dlt_vlog(LOG_DEBUG, - "%s: Buffer: Buffer minimized to Size %u bytes with start address %lX\n", - __func__, buf->size, (unsigned long)buf->mem); + dlt_vlog( + LOG_DEBUG, "%s: Buffer: Buffer minimized to Size %u bytes with start address %lX\n", __func__, buf->size, + (unsigned long)buf->mem); /* clear memory */ memset(buf->mem, 0, buf->size); @@ -4040,7 +3838,7 @@ int dlt_buffer_minimize_size(DltBuffer *buf) return DLT_RETURN_OK; /* OK */ } -int dlt_buffer_reset(DltBuffer *buf) +int dlt_buffer_reset(DltBuffer* buf) { /* catch null pointer */ if (buf == NULL) { @@ -4048,14 +3846,14 @@ int dlt_buffer_reset(DltBuffer *buf) return DLT_RETURN_WRONG_PARAMETER; } - dlt_vlog(LOG_WARNING, - "%s: Buffer: Buffer reset triggered. Size: %u, Start address: %lX\n", - __func__, buf->size, (unsigned long)buf->mem); + dlt_vlog( + LOG_WARNING, "%s: Buffer: Buffer reset triggered. Size: %u, Start address: %lX\n", __func__, buf->size, + (unsigned long)buf->mem); /* reset pointers and counters */ - ((int *)(buf->shm))[0] = 0; /* pointer to write memory */ - ((int *)(buf->shm))[1] = 0; /* pointer to read memory */ - ((int *)(buf->shm))[2] = 0; /* number of packets */ + ((int*)(buf->shm))[0] = 0; /* pointer to write memory */ + ((int*)(buf->shm))[1] = 0; /* pointer to read memory */ + ((int*)(buf->shm))[2] = 0; /* number of packets */ /* clear memory */ memset(buf->mem, 0, buf->size); @@ -4063,18 +3861,14 @@ int dlt_buffer_reset(DltBuffer *buf) return DLT_RETURN_OK; /* OK */ } -DltReturnValue dlt_buffer_push(DltBuffer *buf, const unsigned char *data, unsigned int size) +DltReturnValue dlt_buffer_push(DltBuffer* buf, const unsigned char* data, unsigned int size) { return dlt_buffer_push3(buf, data, size, 0, 0, 0, 0); } -DltReturnValue dlt_buffer_push3(DltBuffer *buf, - const unsigned char *data1, - unsigned int size1, - const unsigned char *data2, - unsigned int size2, - const unsigned char *data3, - unsigned int size3) +DltReturnValue dlt_buffer_push3( + DltBuffer* buf, const unsigned char* data1, unsigned int size1, const unsigned char* data2, unsigned int size2, + const unsigned char* data3, unsigned int size3) { int free_size; int write, read, count; @@ -4091,15 +3885,15 @@ DltReturnValue dlt_buffer_push3(DltBuffer *buf, } /* get current write pointer */ - write = ((int *)(buf->shm))[0]; - read = ((int *)(buf->shm))[1]; - count = ((int *)(buf->shm))[2]; + write = ((int*)(buf->shm))[0]; + read = ((int*)(buf->shm))[1]; + count = ((int*)(buf->shm))[2]; /* check pointers */ if (((unsigned int)read > buf->size) || ((unsigned int)write > buf->size)) { - dlt_vlog(LOG_ERR, - "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Size: %u\n", - __func__, read, write, buf->size); + dlt_vlog( + LOG_ERR, "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Size: %u\n", __func__, read, write, + buf->size); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ } @@ -4113,7 +3907,7 @@ DltReturnValue dlt_buffer_push3(DltBuffer *buf, free_size = (int)buf->size - write + read; /* check size */ - while (free_size < (int) (sizeof(DltBufferBlockHead) + size1 + size2 + size3)) { + while (free_size < (int)(sizeof(DltBufferBlockHead) + size1 + size2 + size3)) { /* try to increase size if possible */ if (dlt_buffer_increase_size(buf)) /* increase size is not possible */ @@ -4121,10 +3915,10 @@ DltReturnValue dlt_buffer_push3(DltBuffer *buf, return DLT_RETURN_ERROR; /* ERROR */ /* update pointers */ - write = ((int *)(buf->shm))[0]; - read = ((int *)(buf->shm))[1]; + write = ((int*)(buf->shm))[0]; + read = ((int*)(buf->shm))[1]; - /* update free size */ + /* update free size */ if (read > write) free_size = read - write; else if (count && (write == read)) @@ -4140,7 +3934,7 @@ DltReturnValue dlt_buffer_push3(DltBuffer *buf, head.size = (int)(size1 + size2 + size3); /* write data */ - dlt_buffer_write_block(buf, &write, (unsigned char *)&head, sizeof(DltBufferBlockHead)); + dlt_buffer_write_block(buf, &write, (unsigned char*)&head, sizeof(DltBufferBlockHead)); if (size1) dlt_buffer_write_block(buf, &write, data1, size1); @@ -4152,14 +3946,13 @@ DltReturnValue dlt_buffer_push3(DltBuffer *buf, dlt_buffer_write_block(buf, &write, data3, size3); /* update global shm pointers */ - ((int *)(buf->shm))[0] = write; /* set new write pointer */ - ((int *)(buf->shm))[2] += 1; /* increase counter */ + ((int*)(buf->shm))[0] = write; /* set new write pointer */ + ((int*)(buf->shm))[2] += 1; /* increase counter */ return DLT_RETURN_OK; /* OK */ - } -int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete) +int dlt_buffer_get(DltBuffer* buf, unsigned char* data, int max_size, int delete) { int used_size; int write, read, count; @@ -4177,15 +3970,15 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete } /* get current write pointer */ - write = ((int *)(buf->shm))[0]; - read = ((int *)(buf->shm))[1]; - count = ((int *)(buf->shm))[2]; + write = ((int*)(buf->shm))[0]; + read = ((int*)(buf->shm))[1]; + count = ((int*)(buf->shm))[2]; /* check pointers */ if (((unsigned int)read > buf->size) || ((unsigned int)write > buf->size) || (count < 0)) { - dlt_vlog(LOG_ERR, - "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Count: %d, Size: %u\n", - __func__, read, write, count, buf->size); + dlt_vlog( + LOG_ERR, "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Count: %d, Size: %u\n", __func__, read, + write, count, buf->size); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ } @@ -4193,9 +3986,8 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete /* check if data is in there */ if (count == 0) { if (write != read) { - dlt_vlog(LOG_ERR, - "%s: Buffer: SHM should be empty, but is not. Read: %d, Write: %d\n", - __func__, read, write); + dlt_vlog( + LOG_ERR, "%s: Buffer: SHM should be empty, but is not. Read: %d, Write: %d\n", __func__, read, write); dlt_buffer_reset(buf); } @@ -4210,18 +4002,18 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete /* first check size */ if (used_size < (int)(sizeof(DltBufferBlockHead))) { - dlt_vlog(LOG_ERR, - "%s: Buffer: Used size is smaller than buffer block header size. Used size: %d\n", - __func__, used_size); + dlt_vlog( + LOG_ERR, "%s: Buffer: Used size is smaller than buffer block header size. Used size: %d\n", __func__, + used_size); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ } /* read header */ - dlt_buffer_read_block(buf, &read, (unsigned char *)&head, sizeof(DltBufferBlockHead)); + dlt_buffer_read_block(buf, &read, (unsigned char*)&head, sizeof(DltBufferBlockHead)); /* check header */ - if (memcmp((unsigned char *)(head.head), head_compare, sizeof(head_compare)) != 0) { + if (memcmp((unsigned char*)(head.head), head_compare, sizeof(head_compare)) != 0) { dlt_vlog(LOG_ERR, "%s: Buffer: Header head check failed\n", __func__); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ @@ -4235,18 +4027,18 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete /* second check size */ if (used_size < ((int)sizeof(DltBufferBlockHead) + head.size)) { - dlt_vlog(LOG_ERR, - "%s: Buffer: Used size is smaller than buffer block header size And read header size. Used size: %d\n", - __func__, used_size); + dlt_vlog( + LOG_ERR, + "%s: Buffer: Used size is smaller than buffer block header size And read header size. Used size: %d\n", + __func__, used_size); dlt_buffer_reset(buf); return DLT_RETURN_ERROR; /* ERROR */ } /* third check size */ if (max_size && (head.size > max_size)) - dlt_vlog(LOG_WARNING, - "%s: Buffer: Max size is smaller than read header size. Max size: %d\n", - __func__, max_size); + dlt_vlog( + LOG_WARNING, "%s: Buffer: Max size is smaller than read header size. Max size: %d\n", __func__, max_size); /* nothing to do but data does not fit provided buffer */ @@ -4256,22 +4048,19 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete if (delete) /* update buffer pointers */ - ((int *)(buf->shm))[1] = read; /* set new read pointer */ + ((int*)(buf->shm))[1] = read; /* set new read pointer */ - } - else if (delete) - { + } else if (delete) { if ((unsigned int)(read + head.size) <= buf->size) - ((int *)(buf->shm))[1] = read + head.size; /* set new read pointer */ + ((int*)(buf->shm))[1] = read + head.size; /* set new read pointer */ else - ((int *)(buf->shm))[1] = read + head.size - (int)buf->size; /* set new read pointer */ - + ((int*)(buf->shm))[1] = read + head.size - (int)buf->size; /* set new read pointer */ } if (delete) { - ((int *)(buf->shm))[2] -= 1; /* decrease counter */ + ((int*)(buf->shm))[2] -= 1; /* decrease counter */ - if (((int *)(buf->shm))[2] == 0) + if (((int*)(buf->shm))[2] == 0) /* try to minimize size */ dlt_buffer_minimize_size(buf); } @@ -4279,22 +4068,22 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete return head.size; /* OK */ } -int dlt_buffer_pull(DltBuffer *buf, unsigned char *data, int max_size) +int dlt_buffer_pull(DltBuffer* buf, unsigned char* data, int max_size) { return dlt_buffer_get(buf, data, max_size, 1); } -int dlt_buffer_copy(DltBuffer *buf, unsigned char *data, int max_size) +int dlt_buffer_copy(DltBuffer* buf, unsigned char* data, int max_size) { return dlt_buffer_get(buf, data, max_size, 0); } -int dlt_buffer_remove(DltBuffer *buf) +int dlt_buffer_remove(DltBuffer* buf) { return dlt_buffer_get(buf, 0, 0, 1); } -void dlt_buffer_info(DltBuffer *buf) +void dlt_buffer_info(DltBuffer* buf) { /* check nullpointer */ if (buf == NULL) { @@ -4302,12 +4091,13 @@ void dlt_buffer_info(DltBuffer *buf) return; } - dlt_vlog(LOG_DEBUG, - "Buffer: Available size: %u, Buffer: Buffer full start address: %lX, Buffer: Buffer start address: %lX\n", - buf->size, (unsigned long)buf->shm, (unsigned long)buf->mem); + dlt_vlog( + LOG_DEBUG, + "Buffer: Available size: %u, Buffer: Buffer full start address: %lX, Buffer: Buffer start address: %lX\n", + buf->size, (unsigned long)buf->shm, (unsigned long)buf->mem); } -void dlt_buffer_status(DltBuffer *buf) +void dlt_buffer_status(DltBuffer* buf) { int write, read, count; @@ -4321,16 +4111,14 @@ void dlt_buffer_status(DltBuffer *buf) if (buf->shm == NULL) return; - write = ((int *)(buf->shm))[0]; - read = ((int *)(buf->shm))[1]; - count = ((int *)(buf->shm))[2]; + write = ((int*)(buf->shm))[0]; + read = ((int*)(buf->shm))[1]; + count = ((int*)(buf->shm))[2]; - dlt_vlog(LOG_DEBUG, - "Buffer: Write: %d, Read: %d, Count: %d\n", - write, read, count); + dlt_vlog(LOG_DEBUG, "Buffer: Write: %d, Read: %d, Count: %d\n", write, read, count); } -uint32_t dlt_buffer_get_total_size(DltBuffer *buf) +uint32_t dlt_buffer_get_total_size(DltBuffer* buf) { /* catch null pointer */ if (buf == NULL) @@ -4339,7 +4127,7 @@ uint32_t dlt_buffer_get_total_size(DltBuffer *buf) return buf->max_size; } -int dlt_buffer_get_used_size(DltBuffer *buf) +int dlt_buffer_get_used_size(DltBuffer* buf) { int write, read, count; @@ -4351,9 +4139,9 @@ int dlt_buffer_get_used_size(DltBuffer *buf) if (buf->shm == NULL) return DLT_RETURN_OK; - write = ((int *)(buf->shm))[0]; - read = ((int *)(buf->shm))[1]; - count = ((int *)(buf->shm))[2]; + write = ((int*)(buf->shm))[0]; + read = ((int*)(buf->shm))[1]; + count = ((int*)(buf->shm))[2]; if (count == 0) return DLT_RETURN_OK; @@ -4364,7 +4152,7 @@ int dlt_buffer_get_used_size(DltBuffer *buf) return (int)buf->size - read + write; } -int dlt_buffer_get_message_count(DltBuffer *buf) +int dlt_buffer_get_message_count(DltBuffer* buf) { /* catch null pointer */ if (buf == NULL) @@ -4374,14 +4162,14 @@ int dlt_buffer_get_message_count(DltBuffer *buf) if (buf->shm == NULL) return DLT_RETURN_OK; - return ((int *)(buf->shm))[2]; + return ((int*)(buf->shm))[2]; } -#if !defined (__WIN32__) +#if !defined(__WIN32__) DltReturnValue dlt_setup_serial(int fd, speed_t speed) { -# if !defined (__WIN32__) && !defined(_MSC_VER) +#if !defined(__WIN32__) && !defined(_MSC_VER) struct termios config; if (isatty(fd) == 0) @@ -4396,8 +4184,7 @@ DltReturnValue dlt_setup_serial(int fd, speed_t speed) * no input parity check, don't strip high bit off, * no XON/XOFF software flow control */ - config.c_iflag &= (tcflag_t)~(IGNBRK | BRKINT | ICRNL | - INLCR | PARMRK | INPCK | ISTRIP | IXON); + config.c_iflag &= (tcflag_t) ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON); /* Output flags - Turn off output processing * no CR to NL translation, no NL to CR-NL translation, @@ -4414,13 +4201,13 @@ DltReturnValue dlt_setup_serial(int fd, speed_t speed) * echo off, echo newline off, canonical mode off, * extended input processing off, signal chars off */ - config.c_lflag &= (tcflag_t)~(ECHO | ECHONL | ICANON | IEXTEN | ISIG); + config.c_lflag &= (tcflag_t) ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG); /* Turn off character processing * clear current char size mask, no parity checking, * no output processing, force 8 bit input */ - config.c_cflag &= (tcflag_t)~(CSIZE | PARENB); + config.c_cflag &= (tcflag_t) ~(CSIZE | PARENB); config.c_cflag |= CS8; /* One input byte is enough to return from read() @@ -4441,193 +4228,162 @@ DltReturnValue dlt_setup_serial(int fd, speed_t speed) return DLT_RETURN_ERROR; return DLT_RETURN_OK; -# else +#else return DLT_RETURN_ERROR; -# endif +#endif } speed_t dlt_convert_serial_speed(int baudrate) { -# if !defined (__WIN32__) && !defined(_MSC_VER) && !defined(__CYGWIN__) +#if !defined(__WIN32__) && !defined(_MSC_VER) && !defined(__CYGWIN__) speed_t ret; switch (baudrate) { - case 50: - { + case 50: { ret = B50; break; } - case 75: - { + case 75: { ret = B75; break; } - case 110: - { + case 110: { ret = B110; break; } - case 134: - { + case 134: { ret = B134; break; } - case 150: - { + case 150: { ret = B150; break; } - case 200: - { + case 200: { ret = B200; break; } - case 300: - { + case 300: { ret = B300; break; } - case 600: - { + case 600: { ret = B600; break; } - case 1200: - { + case 1200: { ret = B1200; break; } - case 1800: - { + case 1800: { ret = B1800; break; } - case 2400: - { + case 2400: { ret = B2400; break; } - case 4800: - { + case 4800: { ret = B4800; break; } - case 9600: - { + case 9600: { ret = B9600; break; } - case 19200: - { + case 19200: { ret = B19200; break; } - case 38400: - { + case 38400: { ret = B38400; break; } - case 57600: - { + case 57600: { ret = B57600; break; } - case 115200: - { + case 115200: { ret = B115200; break; } -# ifdef __linux__ - case 230400: - { +#ifdef __linux__ + case 230400: { ret = B230400; break; } - case 460800: - { + case 460800: { ret = B460800; break; } - case 500000: - { + case 500000: { ret = B500000; break; } - case 576000: - { + case 576000: { ret = B576000; break; } - case 921600: - { + case 921600: { ret = B921600; break; } - case 1000000: - { + case 1000000: { ret = B1000000; break; } - case 1152000: - { + case 1152000: { ret = B1152000; break; } - case 1500000: - { + case 1500000: { ret = B1500000; break; } - case 2000000: - { + case 2000000: { ret = B2000000; break; } #ifdef B2500000 - case 2500000: - { + case 2500000: { ret = B2500000; break; } #endif #ifdef B3000000 - case 3000000: - { + case 3000000: { ret = B3000000; break; } #endif #ifdef B3500000 - case 3500000: - { + case 3500000: { ret = B3500000; break; } #endif #ifdef B4000000 - case 4000000: - { + case 4000000: { ret = B4000000; break; } #endif -# endif /* __linux__ */ - default: - { +#endif /* __linux__ */ + default: { ret = B115200; break; } } return ret; -# else +#else return 0; -# endif +#endif } #endif -void dlt_get_version(char *buf, size_t size) +void dlt_get_version(char* buf, size_t size) { if ((buf == NULL) && (size > 0)) { dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n"); @@ -4637,22 +4393,14 @@ void dlt_get_version(char *buf, size_t size) /* Clang does not like these macros, because they are not reproducable */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdate-time" - snprintf(buf, - size, - "DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n", - _DLT_PACKAGE_VERSION, - _DLT_PACKAGE_VERSION_STATE, - _DLT_PACKAGE_REVISION, - __DATE__, - __TIME__, - _DLT_SYSTEMD_ENABLE, - _DLT_SYSTEMD_WATCHDOG_ENABLE, - _DLT_TEST_ENABLE, - _DLT_SHM_ENABLE); + snprintf( + buf, size, "DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n", + _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE, _DLT_PACKAGE_REVISION, __DATE__, __TIME__, + _DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, _DLT_SHM_ENABLE); #pragma GCC diagnostic pop } -void dlt_get_major_version(char *buf, size_t size) +void dlt_get_major_version(char* buf, size_t size) { if ((buf == NULL) && (size > 0)) { dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n"); @@ -4662,7 +4410,7 @@ void dlt_get_major_version(char *buf, size_t size) snprintf(buf, size, "%s", _DLT_PACKAGE_MAJOR_VERSION); } -void dlt_get_minor_version(char *buf, size_t size) +void dlt_get_minor_version(char* buf, size_t size) { if ((buf == NULL) && (size > 0)) { dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n"); @@ -4675,8 +4423,7 @@ void dlt_get_minor_version(char *buf, size_t size) uint32_t dlt_uptime(void) { - -#if defined (__WIN32__) || defined(_MSC_VER) +#if defined(__WIN32__) || defined(_MSC_VER) return (uint32_t)(GetTickCount() * 10); /* GetTickCount() return DWORD */ @@ -4689,10 +4436,9 @@ uint32_t dlt_uptime(void) return 0; #endif - } -DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_header(DltMessage* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4704,7 +4450,7 @@ DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_ return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_header_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_header_v2(DltMessageV2* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4716,7 +4462,7 @@ DltReturnValue dlt_message_print_header_v2(DltMessageV2 *message, char *text, ui return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_hex(DltMessage* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4732,7 +4478,7 @@ DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t s return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_hex_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_hex_v2(DltMessageV2* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4748,7 +4494,7 @@ DltReturnValue dlt_message_print_hex_v2(DltMessageV2 *message, char *text, uint3 return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_ascii(DltMessage* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4764,13 +4510,13 @@ DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_ascii_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_ascii_v2(DltMessageV2* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; if (dlt_message_header_v2(message, text, size, verbose) < DLT_RETURN_OK) - return DLT_RETURN_ERROR; + return DLT_RETURN_ERROR; dlt_user_printf("%s ", text); if (dlt_message_payload_v2(message, text, size, DLT_OUTPUT_ASCII, verbose) < DLT_RETURN_OK) @@ -4780,7 +4526,7 @@ DltReturnValue dlt_message_print_ascii_v2(DltMessageV2 *message, char *text, uin return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_mixed_plain(DltMessage* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4796,7 +4542,7 @@ DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, ui return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_mixed_plain_v2(DltMessageV2 *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_mixed_plain_v2(DltMessageV2* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4812,7 +4558,7 @@ DltReturnValue dlt_message_print_mixed_plain_v2(DltMessageV2 *message, char *tex return DLT_RETURN_OK; } -DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose) +DltReturnValue dlt_message_print_mixed_html(DltMessage* message, char* text, uint32_t size, int verbose) { if ((message == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; @@ -4829,14 +4575,9 @@ DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uin return DLT_RETURN_OK; } -DltReturnValue dlt_message_argument_print(DltMessage *msg, - uint32_t type_info, - uint8_t **ptr, - int32_t *datalength, - char *text, - size_t textlength, - int byteLength, - int __attribute__((unused)) verbose) +DltReturnValue dlt_message_argument_print( + DltMessage* msg, uint32_t type_info, uint8_t** ptr, int32_t* datalength, char* text, size_t textlength, + int byteLength, int __attribute__((unused)) verbose) { /* check null pointers */ if ((msg == NULL) || (ptr == NULL) || (datalength == NULL) || (text == NULL)) @@ -4873,8 +4614,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, * case but never read anywhere */ quantisation_tmp += quantisation_tmp; - if ((type_info & DLT_TYPE_INFO_STRG) && - (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8))) { + if ((type_info & DLT_TYPE_INFO_STRG) + && (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) + || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8))) { /* string type or utf8-encoded string type */ if (byteLength < 0) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -4882,9 +4624,8 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); - } - else { + length = (uint16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + } else { length = (uint16_t)byteLength; } @@ -4894,7 +4635,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length2 = (uint16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; @@ -4903,8 +4644,8 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, (size_t)textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)(length2+1-1); + value_text += length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)(length2 + 1 - 1); } } @@ -4916,9 +4657,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - } - else if (type_info & DLT_TYPE_INFO_BOOL) - { + } else if (type_info & DLT_TYPE_INFO_BOOL) { /* Boolean type */ if (type_info & DLT_TYPE_INFO_VARI) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -4926,7 +4665,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length2 = (uint16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; @@ -4935,8 +4674,8 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, (size_t)textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)(length2+1-2); + value_text += length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)(length2 + 1 - 2); } } @@ -4951,16 +4690,14 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, return DLT_RETURN_ERROR; snprintf(value_text, textlength, "%d", value8u); - } - else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD))) - { + } else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD))) { if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE)) { DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ if ((*datalength) < 0) return DLT_RETURN_ERROR; - char binary[10] = { '\0' }; /* e.g.: "0b1100 0010" */ + char binary[10] = {'\0'}; /* e.g.: "0b1100 0010" */ int i; for (i = (1 << 7); i > 0; i >>= 1) { @@ -4979,7 +4716,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - char binary[20] = { '\0' }; /* e.g.: "0b1100 0010 0011 0110" */ + char binary[20] = {'\0'}; /* e.g.: "0b1100 0010 0011 0110" */ int i; for (i = (1 << 15); i > 0; i >>= 1) { @@ -4991,9 +4728,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, snprintf(value_text, textlength, "0b%s", binary); } - } - else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD))) - { + } else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD))) { if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE)) { DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ @@ -5038,9 +4773,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, snprintf(value_text + strlen(value_text), textlength - strlen(value_text), "%08x", value32u); *ptr += 4; } - } - else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT)) - { + } else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT)) { /* signed or unsigned argument received */ if (type_info & DLT_TYPE_INFO_VARI) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5048,13 +4781,13 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length2 = (uint16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length3 = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + length3 = (uint16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; @@ -5063,8 +4796,8 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, (size_t)textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":", and -1 for nul - textlength -= (size_t)(length2+1-1); + value_text += length2 + 1 - 1; // +1 for ":", and -1 for nul + textlength -= (size_t)(length2 + 1 - 1); } } @@ -5091,8 +4824,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, switch (type_info & DLT_TYPE_INFO_TYLE) { case DLT_TYLE_8BIT: case DLT_TYLE_16BIT: - case DLT_TYLE_32BIT: - { + case DLT_TYLE_32BIT: { if ((*datalength) < 4) return DLT_RETURN_ERROR; @@ -5100,8 +4832,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 4; break; } - case DLT_TYLE_64BIT: - { + case DLT_TYLE_64BIT: { if ((*datalength) < 8) return DLT_RETURN_ERROR; @@ -5109,8 +4840,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 8; break; } - case DLT_TYLE_128BIT: - { + case DLT_TYLE_128BIT: { if ((*datalength) < 16) return DLT_RETURN_ERROR; @@ -5118,28 +4848,25 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 16; break; } - default: - { + default: { return DLT_RETURN_ERROR; } } } switch (type_info & DLT_TYPE_INFO_TYLE) { - case DLT_TYLE_8BIT: - { + case DLT_TYLE_8BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value8i = 0; - DLT_MSG_READ_VALUE(value8i, *ptr, *datalength, int8_t); /* No endian conversion necessary */ + DLT_MSG_READ_VALUE(value8i, *ptr, *datalength, int8_t); /* No endian conversion necessary */ if ((*datalength) < 0) return DLT_RETURN_ERROR; snprintf(value_text, (size_t)textlength, "%d", value8i); - } - else { + } else { value8u = 0; - DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ + DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ if ((*datalength) < 0) return DLT_RETURN_ERROR; @@ -5149,8 +4876,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, break; } - case DLT_TYLE_16BIT: - { + case DLT_TYLE_16BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value16i = 0; value16i_tmp = 0; @@ -5159,10 +4885,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value16i = (int16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16i_tmp); + value16i = (int16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16i_tmp); snprintf(value_text, (size_t)textlength, "%hd", value16i); - } - else { + } else { value16u = 0; value16u_tmp = 0; DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5170,14 +4895,13 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value16u = (uint16_t) DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); + value16u = (uint16_t)DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp); snprintf(value_text, (size_t)textlength, "%hu", value16u); } break; } - case DLT_TYLE_32BIT: - { + case DLT_TYLE_32BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value32i = 0; value32i_tmp = 0; @@ -5186,10 +4910,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value32i = (int32_t) DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32i_tmp); + value32i = (int32_t)DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32i_tmp); snprintf(value_text, (size_t)textlength, "%d", value32i); - } - else { + } else { value32u = 0; value32u_tmp = 0; DLT_MSG_READ_VALUE(value32u_tmp, *ptr, *datalength, uint32_t); @@ -5203,8 +4926,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, break; } - case DLT_TYLE_64BIT: - { + case DLT_TYLE_64BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value64i = 0; value64i_tmp = 0; @@ -5213,14 +4935,13 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value64i = (int64_t) DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64i_tmp); - #if defined (__WIN32__) && !defined(_MSC_VER) + value64i = (int64_t)DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64i_tmp); +#if defined(__WIN32__) && !defined(_MSC_VER) snprintf(value_text, (size_t)textlength, "%I64d", value64i); - #else +#else snprintf(value_text, (size_t)textlength, "%" PRId64, value64i); - #endif - } - else { +#endif + } else { value64u = 0; value64u_tmp = 0; DLT_MSG_READ_VALUE(value64u_tmp, *ptr, *datalength, uint64_t); @@ -5229,19 +4950,18 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, return DLT_RETURN_ERROR; value64u = DLT_ENDIAN_GET_64(msg->standardheader->htyp, value64u_tmp); - #if defined (__WIN32__) && !defined(_MSC_VER) +#if defined(__WIN32__) && !defined(_MSC_VER) snprintf(value_text, textlength, "%I64u", value64u); - #else +#else snprintf(value_text, textlength, "%" PRIu64, value64u); - #endif +#endif } break; } - case DLT_TYLE_128BIT: - { + case DLT_TYLE_128BIT: { if (*datalength >= 16) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 16); + dlt_print_hex_string(value_text, (int)textlength, *ptr, 16); if ((*datalength) < 16) return DLT_RETURN_ERROR; @@ -5250,14 +4970,11 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 16; break; } - default: - { + default: { return DLT_RETURN_ERROR; } } - } - else if (type_info & DLT_TYPE_INFO_FLOA) - { + } else if (type_info & DLT_TYPE_INFO_FLOA) { /* float data argument */ if (type_info & DLT_TYPE_INFO_VARI) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5280,8 +4997,8 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)length2+1-1; + value_text += length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)length2 + 1 - 1; } } @@ -5300,10 +5017,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, } switch (type_info & DLT_TYPE_INFO_TYLE) { - case DLT_TYLE_8BIT: - { + case DLT_TYLE_8BIT: { if (*datalength >= 1) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 1); + dlt_print_hex_string(value_text, (int)textlength, *ptr, 1); if ((*datalength) < 1) return DLT_RETURN_ERROR; @@ -5312,10 +5028,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 1; break; } - case DLT_TYLE_16BIT: - { + case DLT_TYLE_16BIT: { if (*datalength >= 2) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 2); + dlt_print_hex_string(value_text, (int)textlength, *ptr, 2); if ((*datalength) < 2) return DLT_RETURN_ERROR; @@ -5324,8 +5039,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 2; break; } - case DLT_TYLE_32BIT: - { + case DLT_TYLE_32BIT: { if (sizeof(float32_t) == 4) { value32f = 0; value32f_tmp = 0; @@ -5338,19 +5052,17 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, memcpy(&value32f_tmp_int32i, &value32f_tmp, sizeof(float32_t)); value32f_tmp_int32i_swaped = - (int32_t) DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32f_tmp_int32i); + (int32_t)DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32f_tmp_int32i); memcpy(&value32f, &value32f_tmp_int32i_swaped, sizeof(float32_t)); snprintf(value_text, textlength, "%g", value32f); - } - else { + } else { dlt_log(LOG_ERR, "Invalid size of float32_t\n"); return DLT_RETURN_ERROR; } break; } - case DLT_TYLE_64BIT: - { + case DLT_TYLE_64BIT: { if (sizeof(float64_t) == 8) { value64f = 0; value64f_tmp = 0; @@ -5363,23 +5075,21 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, memcpy(&value64f_tmp_int64i, &value64f_tmp, sizeof(float64_t)); value64f_tmp_int64i_swaped = - (int64_t) DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64f_tmp_int64i); + (int64_t)DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64f_tmp_int64i); memcpy(&value64f, &value64f_tmp_int64i_swaped, sizeof(float64_t)); #ifdef __arm__ snprintf(value_text, textlength, "ILLEGAL"); #else snprintf(value_text, textlength, "%g", value64f); #endif - } - else { + } else { dlt_log(LOG_ERR, "Invalid size of float64_t\n"); return DLT_RETURN_ERROR; } break; } - case DLT_TYLE_128BIT: - { + case DLT_TYLE_128BIT: { if (*datalength >= 16) dlt_print_hex_string(value_text, (int)textlength, *ptr, 16); @@ -5390,14 +5100,11 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, *datalength -= 16; break; } - default: - { + default: { return DLT_RETURN_ERROR; } } - } - else if (type_info & DLT_TYPE_INFO_RAWD) - { + } else if (type_info & DLT_TYPE_INFO_RAWD) { /* raw data argument */ DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5421,8 +5128,8 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)(length2+1-1); + value_text += length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)(length2 + 1 - 1); } } @@ -5433,13 +5140,11 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < length) return DLT_RETURN_ERROR; - if (dlt_print_hex_string_delim(value_text, (int) textlength, *ptr, length, '\'') < DLT_RETURN_OK) + if (dlt_print_hex_string_delim(value_text, (int)textlength, *ptr, length, '\'') < DLT_RETURN_OK) return DLT_RETURN_ERROR; *ptr += length; *datalength -= length; - } - else if (type_info & DLT_TYPE_INFO_TRAI) - { + } else if (type_info & DLT_TYPE_INFO_TRAI) { /* trace info argument */ DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5452,8 +5157,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - } - else { + } else { return DLT_RETURN_ERROR; } if (*datalength < 0) { @@ -5476,14 +5180,9 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg, return DLT_RETURN_OK; } -DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, - uint32_t type_info, - uint8_t **ptr, - int32_t *datalength, - char *text, - size_t textlength, - int byteLength, - int __attribute__((unused)) verbose) +DltReturnValue dlt_message_argument_print_v2( + DltMessageV2* msg, uint32_t type_info, uint8_t** ptr, int32_t* datalength, char* text, size_t textlength, + int byteLength, int __attribute__((unused)) verbose) { /* check null pointers */ if ((msg == NULL) || (ptr == NULL) || (datalength == NULL) || (text == NULL)) @@ -5520,8 +5219,9 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, * case but never read anywhere */ quantisation_tmp += quantisation_tmp; - if ((type_info & DLT_TYPE_INFO_STRG) && - (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8))) { + if ((type_info & DLT_TYPE_INFO_STRG) + && (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) + || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8))) { /* string type or utf8-encoded string type */ if (byteLength < 0) { @@ -5530,9 +5230,8 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length = (uint16_t) DLT_LETOH_16(value16u_tmp); - } - else { + length = (uint16_t)DLT_LETOH_16(value16u_tmp); + } else { length = (uint16_t)byteLength; } @@ -5542,7 +5241,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_LETOH_16(value16u_tmp); + length2 = (uint16_t)DLT_LETOH_16(value16u_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; @@ -5551,8 +5250,8 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += (size_t)length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)length2+1-1; + value_text += (size_t)length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)length2 + 1 - 1; } } @@ -5564,9 +5263,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - } - else if (type_info & DLT_TYPE_INFO_BOOL) - { + } else if (type_info & DLT_TYPE_INFO_BOOL) { /* Boolean type */ if (type_info & DLT_TYPE_INFO_VARI) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5574,7 +5271,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_LETOH_16(value16u_tmp); + length2 = (uint16_t)DLT_LETOH_16(value16u_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; @@ -5583,8 +5280,8 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += (size_t)length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)length2+1-2; + value_text += (size_t)length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)length2 + 1 - 2; } } @@ -5599,16 +5296,14 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, return DLT_RETURN_ERROR; snprintf(value_text, textlength, "%d", value8u); - } - else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD))) - { + } else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD))) { if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE)) { DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ if ((*datalength) < 0) return DLT_RETURN_ERROR; - char binary[10] = { '\0' }; /* e.g.: "0b1100 0010" */ + char binary[10] = {'\0'}; /* e.g.: "0b1100 0010" */ int i; for (i = (1 << 7); i > 0; i >>= 1) { @@ -5627,7 +5322,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - char binary[20] = { '\0' }; /* e.g.: "0b1100 0010 0011 0110" */ + char binary[20] = {'\0'}; /* e.g.: "0b1100 0010 0011 0110" */ int i; for (i = (1 << 15); i > 0; i >>= 1) { @@ -5639,9 +5334,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, snprintf(value_text, textlength, "0b%s", binary); } - } - else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD))) - { + } else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD))) { if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE)) { DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ @@ -5685,9 +5378,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, snprintf(value_text + strlen(value_text), textlength - strlen(value_text), "%08x", value32u); *ptr += 4; } - } - else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT)) - { + } else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT)) { /* signed or unsigned argument received */ if (type_info & DLT_TYPE_INFO_VARI) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5695,13 +5386,13 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - length2 = (uint16_t) DLT_LETOH_16(value16u_tmp); + length2 = (uint16_t)DLT_LETOH_16(value16u_tmp); DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); if ((*datalength) < 0) return DLT_RETURN_ERROR; - length3 = (uint16_t) DLT_LETOH_16(value16u_tmp); + length3 = (uint16_t)DLT_LETOH_16(value16u_tmp); if ((*datalength) < length2) return DLT_RETURN_ERROR; @@ -5710,8 +5401,8 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += (size_t)length2+1-1; // +1 for the ":", and -1 for nul - textlength -= (size_t)length2+1-1; + value_text += (size_t)length2 + 1 - 1; // +1 for the ":", and -1 for nul + textlength -= (size_t)length2 + 1 - 1; } } @@ -5738,8 +5429,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, switch (type_info & DLT_TYPE_INFO_TYLE) { case DLT_TYLE_8BIT: case DLT_TYLE_16BIT: - case DLT_TYLE_32BIT: - { + case DLT_TYLE_32BIT: { if ((*datalength) < 4) return DLT_RETURN_ERROR; @@ -5747,8 +5437,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 4; break; } - case DLT_TYLE_64BIT: - { + case DLT_TYLE_64BIT: { if ((*datalength) < 8) return DLT_RETURN_ERROR; @@ -5756,8 +5445,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 8; break; } - case DLT_TYLE_128BIT: - { + case DLT_TYLE_128BIT: { if ((*datalength) < 16) return DLT_RETURN_ERROR; @@ -5765,28 +5453,25 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 16; break; } - default: - { + default: { return DLT_RETURN_ERROR; } } } switch (type_info & DLT_TYPE_INFO_TYLE) { - case DLT_TYLE_8BIT: - { + case DLT_TYLE_8BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value8i = 0; - DLT_MSG_READ_VALUE(value8i, *ptr, *datalength, int8_t); /* No endian conversion necessary */ + DLT_MSG_READ_VALUE(value8i, *ptr, *datalength, int8_t); /* No endian conversion necessary */ if ((*datalength) < 0) return DLT_RETURN_ERROR; snprintf(value_text, textlength, "%d", value8i); - } - else { + } else { value8u = 0; - DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ + DLT_MSG_READ_VALUE(value8u, *ptr, *datalength, uint8_t); /* No endian conversion necessary */ if ((*datalength) < 0) return DLT_RETURN_ERROR; @@ -5796,8 +5481,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, break; } - case DLT_TYLE_16BIT: - { + case DLT_TYLE_16BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value16i = 0; value16i_tmp = 0; @@ -5806,10 +5490,9 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value16i = (int16_t) DLT_LETOH_16(value16i_tmp); + value16i = (int16_t)DLT_LETOH_16(value16i_tmp); snprintf(value_text, textlength, "%hd", value16i); - } - else { + } else { value16u = 0; value16u_tmp = 0; DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5817,14 +5500,13 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value16u = (uint16_t) DLT_LETOH_16(value16u_tmp); + value16u = (uint16_t)DLT_LETOH_16(value16u_tmp); snprintf(value_text, textlength, "%hu", value16u); } break; } - case DLT_TYLE_32BIT: - { + case DLT_TYLE_32BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value32i = 0; value32i_tmp = 0; @@ -5833,10 +5515,9 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value32i = (int32_t) DLT_LETOH_32((uint32_t)value32i_tmp); + value32i = (int32_t)DLT_LETOH_32((uint32_t)value32i_tmp); snprintf(value_text, textlength, "%d", value32i); - } - else { + } else { value32u = 0; value32u_tmp = 0; DLT_MSG_READ_VALUE(value32u_tmp, *ptr, *datalength, uint32_t); @@ -5850,8 +5531,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, break; } - case DLT_TYLE_64BIT: - { + case DLT_TYLE_64BIT: { if (type_info & DLT_TYPE_INFO_SINT) { value64i = 0; value64i_tmp = 0; @@ -5860,14 +5540,13 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - value64i = (int64_t) DLT_LETOH_64((uint64_t)value64i_tmp); - #if defined (__WIN32__) && !defined(_MSC_VER) + value64i = (int64_t)DLT_LETOH_64((uint64_t)value64i_tmp); +#if defined(__WIN32__) && !defined(_MSC_VER) snprintf(value_text, textlength, "%I64d", value64i); - #else +#else snprintf(value_text, textlength, "%" PRId64, value64i); - #endif - } - else { +#endif + } else { value64u = 0; value64u_tmp = 0; DLT_MSG_READ_VALUE(value64u_tmp, *ptr, *datalength, uint64_t); @@ -5876,19 +5555,18 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, return DLT_RETURN_ERROR; value64u = DLT_LETOH_64(value64u_tmp); - #if defined (__WIN32__) && !defined(_MSC_VER) +#if defined(__WIN32__) && !defined(_MSC_VER) snprintf(value_text, textlength, "%I64u", value64u); - #else +#else snprintf(value_text, textlength, "%" PRIu64, value64u); - #endif +#endif } break; } - case DLT_TYLE_128BIT: - { + case DLT_TYLE_128BIT: { if (*datalength >= 16) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 16); + dlt_print_hex_string(value_text, (int)textlength, *ptr, 16); if ((*datalength) < 16) return DLT_RETURN_ERROR; @@ -5897,14 +5575,11 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 16; break; } - default: - { + default: { return DLT_RETURN_ERROR; } } - } - else if (type_info & DLT_TYPE_INFO_FLOA) - { + } else if (type_info & DLT_TYPE_INFO_FLOA) { /* float data argument */ if (type_info & DLT_TYPE_INFO_VARI) { DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -5927,8 +5602,8 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += (size_t)length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)length2+1-1; + value_text += (size_t)length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)length2 + 1 - 1; } } @@ -5947,10 +5622,9 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, } switch (type_info & DLT_TYPE_INFO_TYLE) { - case DLT_TYLE_8BIT: - { + case DLT_TYLE_8BIT: { if (*datalength >= 1) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 1); + dlt_print_hex_string(value_text, (int)textlength, *ptr, 1); if ((*datalength) < 1) return DLT_RETURN_ERROR; @@ -5959,10 +5633,9 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 1; break; } - case DLT_TYLE_16BIT: - { + case DLT_TYLE_16BIT: { if (*datalength >= 2) - dlt_print_hex_string(value_text, (int) textlength, *ptr, 2); + dlt_print_hex_string(value_text, (int)textlength, *ptr, 2); if ((*datalength) < 2) return DLT_RETURN_ERROR; @@ -5971,8 +5644,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 2; break; } - case DLT_TYLE_32BIT: - { + case DLT_TYLE_32BIT: { if (sizeof(float32_t) == 4) { value32f = 0; value32f_tmp = 0; @@ -5984,20 +5656,17 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, return DLT_RETURN_ERROR; memcpy(&value32f_tmp_int32i, &value32f_tmp, sizeof(float32_t)); - value32f_tmp_int32i_swaped = - (int32_t) DLT_LETOH_32((uint32_t)value32f_tmp_int32i); + value32f_tmp_int32i_swaped = (int32_t)DLT_LETOH_32((uint32_t)value32f_tmp_int32i); memcpy(&value32f, &value32f_tmp_int32i_swaped, sizeof(float32_t)); snprintf(value_text, textlength, "%g", value32f); - } - else { + } else { dlt_log(LOG_ERR, "Invalid size of float32_t\n"); return DLT_RETURN_ERROR; } break; } - case DLT_TYLE_64BIT: - { + case DLT_TYLE_64BIT: { if (sizeof(float64_t) == 8) { value64f = 0; value64f_tmp = 0; @@ -6009,24 +5678,21 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, return DLT_RETURN_ERROR; memcpy(&value64f_tmp_int64i, &value64f_tmp, sizeof(float64_t)); - value64f_tmp_int64i_swaped = - (int64_t) DLT_LETOH_64((uint64_t)value64f_tmp_int64i); + value64f_tmp_int64i_swaped = (int64_t)DLT_LETOH_64((uint64_t)value64f_tmp_int64i); memcpy(&value64f, &value64f_tmp_int64i_swaped, sizeof(float64_t)); #ifdef __arm__ snprintf(value_text, textlength, "ILLEGAL"); #else snprintf(value_text, textlength, "%g", value64f); #endif - } - else { + } else { dlt_log(LOG_ERR, "Invalid size of float64_t\n"); return DLT_RETURN_ERROR; } break; } - case DLT_TYLE_128BIT: - { + case DLT_TYLE_128BIT: { if (*datalength >= 16) dlt_print_hex_string(value_text, (int)textlength, *ptr, 16); @@ -6037,14 +5703,11 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, *datalength -= 16; break; } - default: - { + default: { return DLT_RETURN_ERROR; } } - } - else if (type_info & DLT_TYPE_INFO_RAWD) - { + } else if (type_info & DLT_TYPE_INFO_RAWD) { /* raw data argument */ DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -6068,8 +5731,8 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, // Print "name" attribute, if we have one with non-zero size. if (length2 > 1) { snprintf(text, textlength, "%s:", *ptr); - value_text += (size_t)length2+1-1; // +1 for ":" and -1 for NUL - textlength -= (size_t)length2+1-1; + value_text += (size_t)length2 + 1 - 1; // +1 for ":" and -1 for NUL + textlength -= (size_t)length2 + 1 - 1; } } @@ -6080,13 +5743,11 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < length) return DLT_RETURN_ERROR; - if (dlt_print_hex_string_delim(value_text, (int) textlength, *ptr, length, '\'') < DLT_RETURN_OK) + if (dlt_print_hex_string_delim(value_text, (int)textlength, *ptr, length, '\'') < DLT_RETURN_OK) return DLT_RETURN_ERROR; *ptr += length; *datalength -= length; - } - else if (type_info & DLT_TYPE_INFO_TRAI) - { + } else if (type_info & DLT_TYPE_INFO_TRAI) { /* trace info argument */ DLT_MSG_READ_VALUE(value16u_tmp, *ptr, *datalength, uint16_t); @@ -6099,8 +5760,7 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, if ((*datalength) < 0) return DLT_RETURN_ERROR; - } - else { + } else { return DLT_RETURN_ERROR; } @@ -6126,12 +5786,12 @@ DltReturnValue dlt_message_argument_print_v2(DltMessageV2 *msg, void dlt_check_envvar() { - char *env_log_filename = getenv("DLT_LOG_FILENAME"); + char* env_log_filename = getenv("DLT_LOG_FILENAME"); if (env_log_filename != NULL) dlt_log_set_filename(env_log_filename); - char *env_log_level_str = getenv("DLT_LOG_LEVEL"); + char* env_log_level_str = getenv("DLT_LOG_LEVEL"); if (env_log_level_str != NULL) { int level = 0; @@ -6140,7 +5800,7 @@ void dlt_check_envvar() dlt_log_set_level(level); } - char *env_log_mode = getenv("DLT_LOG_MODE"); + char* env_log_mode = getenv("DLT_LOG_MODE"); if (env_log_mode != NULL) { int mode = 0; @@ -6150,7 +5810,7 @@ void dlt_check_envvar() } #if defined DLT_DAEMON_USE_FIFO_IPC || defined DLT_LIB_USE_FIFO_IPC - char *env_pipe_dir = getenv("DLT_PIPE_DIR"); + char* env_pipe_dir = getenv("DLT_PIPE_DIR"); if (env_pipe_dir != NULL) dlt_log_set_fifo_basedir(env_pipe_dir); @@ -6160,7 +5820,7 @@ void dlt_check_envvar() #endif #ifdef DLT_SHM_ENABLE - char *env_shm_name = getenv("DLT_SHM_NAME"); + char* env_shm_name = getenv("DLT_SHM_NAME"); if (env_shm_name != NULL) dlt_log_set_shm_name(env_shm_name); @@ -6168,9 +5828,7 @@ void dlt_check_envvar() #endif } -int dlt_set_loginfo_parse_service_id(char *resp_text, - uint32_t *service_id, - uint8_t *service_opt) +int dlt_set_loginfo_parse_service_id(char* resp_text, uint32_t* service_id, uint8_t* service_opt) { int ret = -1; char get_log_info_tag[GET_LOG_INFO_LENGTH]; @@ -6182,7 +5840,7 @@ int dlt_set_loginfo_parse_service_id(char *resp_text, /* ascii type, syntax is 'get_log_info, ..' */ /* check target id */ strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info") + 1); - ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag) - 1); + ret = memcmp((void*)resp_text, (void*)get_log_info_tag, sizeof(get_log_info_tag) - 1); if (ret == 0) { *service_id = DLT_SERVICE_ID_GET_LOG_INFO; @@ -6190,16 +5848,16 @@ int dlt_set_loginfo_parse_service_id(char *resp_text, service_opt_str[0] = *(resp_text + GET_LOG_INFO_LENGTH + 1); service_opt_str[1] = *(resp_text + GET_LOG_INFO_LENGTH + 2); service_opt_str[2] = 0; - *service_opt = (uint8_t) atoi(service_opt_str); + *service_opt = (uint8_t)atoi(service_opt_str); } return ret; } -uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count) +uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char* rp, int* rp_count) { - char num_work[5] = { 0 }; - char *endptr; + char num_work[5] = {0}; + char* endptr; if ((rp == NULL) || (rp_count == NULL)) return (uint16_t)0xFFFF; @@ -6217,10 +5875,10 @@ uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count) return (uint16_t)strtol(num_work, &endptr, 16); } -int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count) +int16_t dlt_getloginfo_conv_ascii_to_int16_t(char* rp, int* rp_count) { - char num_work[3] = { 0 }; - char *endptr; + char num_work[3] = {0}; + char* endptr; if ((rp == NULL) || (rp_count == NULL)) return -1; @@ -6236,10 +5894,10 @@ int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count) return (signed char)strtol(num_work, &endptr, 16); } -uint8_t dlt_getloginfo_conv_ascii_to_uint8_t(char *rp, int *rp_count) +uint8_t dlt_getloginfo_conv_ascii_to_uint8_t(char* rp, int* rp_count) { - char num_work[3] = { 0 }; - char *endptr; + char num_work[3] = {0}; + char* endptr; if ((rp == NULL) || (rp_count == NULL)) return (uint8_t)-1; @@ -6255,9 +5913,9 @@ uint8_t dlt_getloginfo_conv_ascii_to_uint8_t(char *rp, int *rp_count) return (uint8_t)strtol(num_work, &endptr, 16); } -void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int len) +void dlt_getloginfo_conv_ascii_to_string(char* rp, int* rp_count, char* wp, int len) { - if ((rp == NULL ) || (rp_count == NULL ) || (wp == NULL )) + if ((rp == NULL) || (rp_count == NULL) || (wp == NULL)) return; /* ------------------------------------------------------ * from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00] @@ -6269,10 +5927,10 @@ void dlt_getloginfo_conv_ascii_to_string(char *rp, int *rp_count, char *wp, int return; } -int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len) +int dlt_getloginfo_conv_ascii_to_id(char* rp, int* rp_count, char* wp, int len) { - char number16[3] = { 0 }; - char *endptr; + char number16[3] = {0}; + char* endptr; int count; if ((rp == NULL) || (rp_count == NULL) || (wp == NULL)) @@ -6284,14 +5942,14 @@ int dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len) for (count = 0; count < len; count++) { number16[0] = *(rp + *rp_count + 0); number16[1] = *(rp + *rp_count + 1); - *(wp + count) = (char) strtol(number16, &endptr, 16); + *(wp + count) = (char)strtol(number16, &endptr, 16); *rp_count += 3; } return count; } -void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size) +void dlt_hex_ascii_to_binary(const char* ptr, uint8_t* binary, int* size) { char ch = *ptr; int pos = 0; @@ -6308,25 +5966,20 @@ void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size) found = 0; if ((ch >= '0') && (ch <= '9')) { - binary[pos] = (uint8_t) ((binary[pos] << 4) + (ch - '0')); + binary[pos] = (uint8_t)((binary[pos] << 4) + (ch - '0')); found = 1; - } - else if ((ch >= 'A') && (ch <= 'F')) - { - binary[pos] = (uint8_t) ((binary[pos] << 4) + (ch - 'A' + 10)); + } else if ((ch >= 'A') && (ch <= 'F')) { + binary[pos] = (uint8_t)((binary[pos] << 4) + (ch - 'A' + 10)); found = 1; - } - else if ((ch >= 'a') && (ch <= 'f')) - { - binary[pos] = (uint8_t) ((binary[pos] << 4) + (ch - 'a' + 10)); + } else if ((ch >= 'a') && (ch <= 'f')) { + binary[pos] = (uint8_t)((binary[pos] << 4) + (ch - 'a' + 10)); found = 1; } if (found) { if (first) { first = 0; - } - else { + } else { first = 1; pos++; @@ -6341,17 +5994,16 @@ void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size) } } -DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, - int type, int verbose) +DltReturnValue dlt_file_quick_parsing(DltFile* file, const char* filename, int type, int verbose) { PRINT_FUNCTION_VERBOSE(verbose); int ret = DLT_RETURN_OK; - char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 }; + char text[DLT_CONVERT_TEXTBUFSIZE] = {0}; if ((file == NULL) || (filename == NULL)) return DLT_RETURN_WRONG_PARAMETER; - FILE *output = fopen(filename, "w+"); + FILE* output = fopen(filename, "w+"); if (output == NULL) { dlt_vlog(LOG_ERR, "Cannot open output file %s for parsing\n", filename); @@ -6387,16 +6039,14 @@ DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, continue; } - ret = dlt_message_header(&(file->msg), text, - DLT_CONVERT_TEXTBUFSIZE, verbose); + ret = dlt_message_header(&(file->msg), text, DLT_CONVERT_TEXTBUFSIZE, verbose); if (ret < DLT_RETURN_OK) break; fprintf(output, "%s", text); - ret = dlt_message_payload(&(file->msg), text, - DLT_CONVERT_TEXTBUFSIZE, type, verbose); + ret = dlt_message_payload(&(file->msg), text, DLT_CONVERT_TEXTBUFSIZE, type, verbose); if (ret < DLT_RETURN_OK) break; @@ -6417,11 +6067,11 @@ DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, } -int dlt_execute_command(char *filename, char *command, ...) +int dlt_execute_command(char* filename, char* command, ...) { va_list val; int argc; - char **args = NULL; + char** args = NULL; int ret = 0; if (command == NULL) @@ -6430,18 +6080,19 @@ int dlt_execute_command(char *filename, char *command, ...) /* Determine number of variadic arguments */ va_start(val, command); - for (argc = 2; va_arg(val, char *) != NULL; argc++); + for (argc = 2; va_arg(val, char*) != NULL; argc++) + ; va_end(val); /* Allocate args, put references to command */ - args = (char **) malloc( (uint32_t) argc * sizeof(char*)); + args = (char**)malloc((uint32_t)argc * sizeof(char*)); args[0] = command; va_start(val, command); for (int i = 0; args[i] != NULL; i++) - args[i + 1] = va_arg(val, char *); + args[i + 1] = va_arg(val, char*); va_end(val); @@ -6466,13 +6117,11 @@ int dlt_execute_command(char *filename, char *command, ...) } /* Run command */ - execvp(command, (char **)args); - } - else if (pid == -1) /* error in fork */ + execvp(command, (char**)args); + } else if (pid == -1) /* error in fork */ { ret = -1; - } - else /* parent */ + } else /* parent */ { if (wait(&ret) == -1) { err(-1, "%s failed on wait()", __func__); @@ -6483,22 +6132,25 @@ int dlt_execute_command(char *filename, char *command, ...) return ret; } -const char *get_filename_ext(const char *filename) +const char* get_filename_ext(const char* filename) { if (filename == NULL) { fprintf(stderr, "ERROR: %s: invalid arguments\n", __func__); return ""; } - const char *dot = strrchr(filename, '.'); + const char* dot = strrchr(filename, '.'); return (!dot || dot == filename) ? NULL : dot; } -bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len) { - if (abs_file_name == NULL || base_name == NULL) return false; +bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* base_name, long base_name_len) +{ + if (abs_file_name == NULL || base_name == NULL) + return false; const char* last_separator = strrchr(abs_file_name, '.'); - if (!last_separator) return false; + if (!last_separator) + return false; long length = last_separator - abs_file_name; /* Ensure length fits within buffer, leaving room for null terminator */ if (length >= base_name_len) @@ -6511,22 +6163,18 @@ bool dlt_extract_base_name_without_ext(const char* const abs_file_name, char* ba #ifdef DLT_TRACE_LOAD_CTRL_ENABLE static int32_t dlt_output_soft_limit_over_warning( - DltTraceLoadSettings* const tl_settings, - DltLogInternal log_internal, - void *const log_params) + DltTraceLoadSettings* const tl_settings, DltLogInternal log_internal, void* const log_params) { char local_str[255]; - if (!tl_settings || !tl_settings->tl_stat.is_over_soft_limit || tl_settings->tl_stat.slot_left_soft_limit_warn) - { + if (!tl_settings || !tl_settings->tl_stat.is_over_soft_limit || tl_settings->tl_stat.slot_left_soft_limit_warn) { /* No need to output warning message */ return 0; } /* Calculate extra trace load which was over limit */ - const uint64_t dropped_message_load - = (tl_settings->tl_stat.hard_limit_over_bytes * DLT_TIMESTAMP_RESOLUTION) - / TIMESTAMP_BASED_WINDOW_SIZE; + const uint64_t dropped_message_load = + (tl_settings->tl_stat.hard_limit_over_bytes * DLT_TIMESTAMP_RESOLUTION) / TIMESTAMP_BASED_WINDOW_SIZE; const uint64_t curr_trace_load = tl_settings->tl_stat.avg_trace_load + dropped_message_load; if (curr_trace_load <= tl_settings->soft_limit) { /* No need to output warning message */ @@ -6535,26 +6183,22 @@ static int32_t dlt_output_soft_limit_over_warning( /* Warning for exceeded soft limit */ if (tl_settings->ctid[0] == 0) { - snprintf(local_str, sizeof(local_str), - "Trace load exceeded trace soft limit on apid %.4s " - "(soft limit: %u bytes/sec, current: %lu bytes/sec)", - tl_settings->apid, - tl_settings->soft_limit, - curr_trace_load); + snprintf( + local_str, sizeof(local_str), + "Trace load exceeded trace soft limit on apid %.4s " + "(soft limit: %u bytes/sec, current: %lu bytes/sec)", + tl_settings->apid, tl_settings->soft_limit, curr_trace_load); } else { - snprintf(local_str, sizeof(local_str), - "Trace load exceeded trace soft limit on apid %.4s, ctid %.4s " - "(soft limit: %u bytes/sec, current: %lu bytes/sec)", - tl_settings->apid, - tl_settings->ctid, - tl_settings->soft_limit, - curr_trace_load); + snprintf( + local_str, sizeof(local_str), + "Trace load exceeded trace soft limit on apid %.4s, ctid %.4s " + "(soft limit: %u bytes/sec, current: %lu bytes/sec)", + tl_settings->apid, tl_settings->ctid, tl_settings->soft_limit, curr_trace_load); } // must be signed int for error return value int32_t sent_size = log_internal(DLT_LOG_WARN, local_str, log_params); - if (sent_size < DLT_RETURN_OK) - { + if (sent_size < DLT_RETURN_OK) { /* Output warning message via other route for safety */ dlt_log(DLT_LOG_WARN, local_str); sent_size = 0; @@ -6568,21 +6212,17 @@ static int32_t dlt_output_soft_limit_over_warning( } static int32_t dlt_output_hard_limit_warning( - DltTraceLoadSettings* const tl_settings, - DltLogInternal log_internal, - void *const log_params) + DltTraceLoadSettings* const tl_settings, DltLogInternal log_internal, void* const log_params) { char local_str[255]; - if (!tl_settings || !tl_settings->tl_stat.is_over_hard_limit || tl_settings->tl_stat.slot_left_hard_limit_warn) - { + if (!tl_settings || !tl_settings->tl_stat.is_over_hard_limit || tl_settings->tl_stat.slot_left_hard_limit_warn) { /* No need to output warning message */ return 0; } /* Calculate extra trace load which was over limit */ - const uint64_t dropped_message_load - = (tl_settings->tl_stat.hard_limit_over_bytes * DLT_TIMESTAMP_RESOLUTION) - / TIMESTAMP_BASED_WINDOW_SIZE; + const uint64_t dropped_message_load = + (tl_settings->tl_stat.hard_limit_over_bytes * DLT_TIMESTAMP_RESOLUTION) / TIMESTAMP_BASED_WINDOW_SIZE; const uint64_t curr_trace_load = tl_settings->tl_stat.avg_trace_load + dropped_message_load; if (curr_trace_load <= tl_settings->hard_limit) { /* No need to output warning message */ @@ -6590,28 +6230,23 @@ static int32_t dlt_output_hard_limit_warning( } if (tl_settings->ctid[0] == 0) { - snprintf(local_str, sizeof(local_str), - "Trace load exceeded trace hard limit on apid %.4s " - "(hard limit: %u bytes/sec, current: %lu bytes/sec) %u messages discarded. ", - tl_settings->apid, - tl_settings->hard_limit, - curr_trace_load, - tl_settings->tl_stat.hard_limit_over_counter); + snprintf( + local_str, sizeof(local_str), + "Trace load exceeded trace hard limit on apid %.4s " + "(hard limit: %u bytes/sec, current: %lu bytes/sec) %u messages discarded. ", + tl_settings->apid, tl_settings->hard_limit, curr_trace_load, tl_settings->tl_stat.hard_limit_over_counter); } else { - snprintf(local_str, sizeof(local_str), - "Trace load exceeded trace hard limit on apid %.4s, ctid %.4s." - "(hard limit: %u bytes/sec, current: %lu bytes/sec) %u messages discarded.", - tl_settings->apid, - tl_settings->ctid, - tl_settings->hard_limit, - curr_trace_load, - tl_settings->tl_stat.hard_limit_over_counter); + snprintf( + local_str, sizeof(local_str), + "Trace load exceeded trace hard limit on apid %.4s, ctid %.4s." + "(hard limit: %u bytes/sec, current: %lu bytes/sec) %u messages discarded.", + tl_settings->apid, tl_settings->ctid, tl_settings->hard_limit, curr_trace_load, + tl_settings->tl_stat.hard_limit_over_counter); } // must be signed int for error return int32_t sent_size = log_internal(DLT_LOG_WARN, local_str, log_params); - if (sent_size < DLT_RETURN_OK) - { + if (sent_size < DLT_RETURN_OK) { /* Output warning message via other route for safety */ dlt_log(DLT_LOG_WARN, local_str); sent_size = 0; @@ -6626,22 +6261,20 @@ static int32_t dlt_output_hard_limit_warning( return sent_size; } -static bool dlt_user_cleanup_window(DltTraceLoadStat *const tl_stat) +static bool dlt_user_cleanup_window(DltTraceLoadStat* const tl_stat) { - if (!tl_stat) - { + if (!tl_stat) { return false; } - uint32_t elapsed_slots = 0; + uint32_t elapsed_slots = 0; /* check if overflow of timestamp happened, after ~119 hours */ if (tl_stat->curr_abs_slot < tl_stat->last_abs_slot) { /* calculate where the next slot starts according to the last slot * This works because the value after the uint32 rollover equals is equal to the remainder that did not fit * into uint32 before. Therefore, we always have slots that are DLT_TIMESTAMP_RESOLUTION long * */ - const uint32_t next_slot_start = - DLT_TIMESTAMP_RESOLUTION + tl_stat->last_abs_slot; + const uint32_t next_slot_start = DLT_TIMESTAMP_RESOLUTION + tl_stat->last_abs_slot; /* Check if we are already in the next slot */ if (next_slot_start <= tl_stat->curr_abs_slot) { @@ -6654,22 +6287,20 @@ static bool dlt_user_cleanup_window(DltTraceLoadStat *const tl_stat) elapsed_slots = (tl_stat->curr_abs_slot - tl_stat->last_abs_slot); } - if (!elapsed_slots) - { + if (!elapsed_slots) { /* Same slot can be still used. No need to cleanup slot */ return false; } /* Slot-Based Count down for next warning messages */ - tl_stat->slot_left_soft_limit_warn = (tl_stat->slot_left_soft_limit_warn > elapsed_slots) ? - (tl_stat->slot_left_soft_limit_warn - elapsed_slots) : 0; + tl_stat->slot_left_soft_limit_warn = + (tl_stat->slot_left_soft_limit_warn > elapsed_slots) ? (tl_stat->slot_left_soft_limit_warn - elapsed_slots) : 0; - tl_stat->slot_left_hard_limit_warn = (tl_stat->slot_left_hard_limit_warn > elapsed_slots) ? - (tl_stat->slot_left_hard_limit_warn - elapsed_slots) : 0; + tl_stat->slot_left_hard_limit_warn = + (tl_stat->slot_left_hard_limit_warn > elapsed_slots) ? (tl_stat->slot_left_hard_limit_warn - elapsed_slots) : 0; /* Clear whole window when time elapsed longer than window size from last message */ - if (elapsed_slots >= DLT_TRACE_LOAD_WINDOW_SIZE) - { + if (elapsed_slots >= DLT_TRACE_LOAD_WINDOW_SIZE) { tl_stat->total_bytes_of_window = 0; memset(tl_stat->window, 0, sizeof(tl_stat->window)); return true; @@ -6677,8 +6308,7 @@ static bool dlt_user_cleanup_window(DltTraceLoadStat *const tl_stat) /* Clear skipped no data slots */ uint32_t temp_slot = tl_stat->last_slot; - while (temp_slot != tl_stat->curr_slot) - { + while (temp_slot != tl_stat->curr_slot) { temp_slot++; temp_slot %= DLT_TRACE_LOAD_WINDOW_SIZE; tl_stat->total_bytes_of_window -= tl_stat->window[temp_slot]; @@ -6689,13 +6319,10 @@ static bool dlt_user_cleanup_window(DltTraceLoadStat *const tl_stat) } static int32_t dlt_switch_slot_if_needed( - DltTraceLoadSettings* const tl_settings, - DltLogInternal log_internal, - void* const log_internal_params, + DltTraceLoadSettings* const tl_settings, DltLogInternal log_internal, void* const log_internal_params, const uint32_t timestamp) { - if (!tl_settings) - { + if (!tl_settings) { return 0; } @@ -6704,8 +6331,7 @@ static int32_t dlt_switch_slot_if_needed( tl_settings->tl_stat.curr_slot = tl_settings->tl_stat.curr_abs_slot % DLT_TRACE_LOAD_WINDOW_SIZE; /* Cleanup window */ - if (!dlt_user_cleanup_window(&tl_settings->tl_stat)) - { + if (!dlt_user_cleanup_window(&tl_settings->tl_stat)) { /* No need to switch slot because same slot can be still used */ return 0; } @@ -6715,15 +6341,14 @@ static int32_t dlt_switch_slot_if_needed( * The warning messages will be also counted as trace load. */ const int32_t sent_warn_msg_bytes = - dlt_output_soft_limit_over_warning(tl_settings, log_internal, log_internal_params) + - dlt_output_hard_limit_warning(tl_settings, log_internal, log_internal_params); + dlt_output_soft_limit_over_warning(tl_settings, log_internal, log_internal_params) + + dlt_output_hard_limit_warning(tl_settings, log_internal, log_internal_params); return sent_warn_msg_bytes; } -static void dlt_record_trace_load(DltTraceLoadStat *const tl_stat, const int32_t size) +static void dlt_record_trace_load(DltTraceLoadStat* const tl_stat, const int32_t size) { - if (!tl_stat) - { + if (!tl_stat) { return; } @@ -6741,15 +6366,13 @@ static void dlt_record_trace_load(DltTraceLoadStat *const tl_stat, const int32_t * The division is necessary to normalize the average to bytes per second even if * the slot size is not equal to 1s * */ - tl_stat->avg_trace_load - = (tl_stat->total_bytes_of_window * DLT_TIMESTAMP_RESOLUTION) / TIMESTAMP_BASED_WINDOW_SIZE; + tl_stat->avg_trace_load = (tl_stat->total_bytes_of_window * DLT_TIMESTAMP_RESOLUTION) / TIMESTAMP_BASED_WINDOW_SIZE; } static inline bool dlt_is_over_trace_load_soft_limit(DltTraceLoadSettings* const tl_settings) { if (tl_settings - && (tl_settings->tl_stat.avg_trace_load > tl_settings->soft_limit || tl_settings->soft_limit == 0)) - { + && (tl_settings->tl_stat.avg_trace_load > tl_settings->soft_limit || tl_settings->soft_limit == 0)) { /* Mark as soft limit over */ tl_settings->tl_stat.is_over_soft_limit = true; return true; @@ -6758,13 +6381,10 @@ static inline bool dlt_is_over_trace_load_soft_limit(DltTraceLoadSettings* const return false; } -static inline bool dlt_is_over_trace_load_hard_limit( - DltTraceLoadSettings* const tl_settings, const int size) +static inline bool dlt_is_over_trace_load_hard_limit(DltTraceLoadSettings* const tl_settings, const int size) { if (tl_settings - && (tl_settings->tl_stat.avg_trace_load > tl_settings->hard_limit - || tl_settings->hard_limit == 0)) - { + && (tl_settings->tl_stat.avg_trace_load > tl_settings->hard_limit || tl_settings->hard_limit == 0)) { /* Mark as limit over */ tl_settings->tl_stat.is_over_hard_limit = true; tl_settings->tl_stat.hard_limit_over_counter++; @@ -6780,27 +6400,20 @@ static inline bool dlt_is_over_trace_load_hard_limit( } bool dlt_check_trace_load( - DltTraceLoadSettings * const tl_settings, - const int32_t log_level, - const uint32_t timestamp, - const int32_t size, - DltLogInternal internal_dlt_log, - void* const internal_dlt_log_params) + DltTraceLoadSettings* const tl_settings, const int32_t log_level, const uint32_t timestamp, const int32_t size, + DltLogInternal internal_dlt_log, void* const internal_dlt_log_params) { /* Unconditionally allow message which has log level: Debug/Verbose to be output */ - if (log_level == DLT_LOG_DEBUG || log_level == DLT_LOG_VERBOSE) - { + if (log_level == DLT_LOG_DEBUG || log_level == DLT_LOG_VERBOSE) { return true; } - if (tl_settings == NULL) - { + if (tl_settings == NULL) { internal_dlt_log(DLT_LOG_ERROR, "tl_settings is NULL", internal_dlt_log_params); return false; } - if (size < 0) - { + if (size < 0) { dlt_vlog(LOG_ERR, "Invalid size: %d", size); return false; } @@ -6809,8 +6422,8 @@ bool dlt_check_trace_load( * If warning messages for hard/soft limit over are sent, * the message size will be returned. */ - const int32_t sent_warn_msg_bytes = dlt_switch_slot_if_needed( - tl_settings, internal_dlt_log, internal_dlt_log_params, timestamp); + const int32_t sent_warn_msg_bytes = + dlt_switch_slot_if_needed(tl_settings, internal_dlt_log, internal_dlt_log_params, timestamp); /* Record trace load */ dlt_record_trace_load(&tl_settings->tl_stat, size + sent_warn_msg_bytes); @@ -6829,8 +6442,9 @@ bool dlt_check_trace_load( return allow_output; } -DltTraceLoadSettings* -dlt_find_runtime_trace_load_settings(DltTraceLoadSettings *settings, uint32_t settings_count, const char* apid, const char* ctid) { +DltTraceLoadSettings* dlt_find_runtime_trace_load_settings( + DltTraceLoadSettings* settings, uint32_t settings_count, const char* apid, const char* ctid) +{ if ((apid == NULL) || (strnlen(apid, DLT_ID_SIZE) == 0)) return NULL; diff --git a/src/shared/dlt_common_cfg.h b/src/shared/dlt_common_cfg.h index 97621df63..b935d2f8c 100644 --- a/src/shared/dlt_common_cfg.h +++ b/src/shared/dlt_common_cfg.h @@ -75,16 +75,16 @@ /* Number of ASCII chars to be printed in one line as HEX and as ASCII */ /* e.g. XX XX XX XX ABCD is DLT_COMMON_HEX_CHARS = 4 */ -#define DLT_COMMON_HEX_CHARS 16 +#define DLT_COMMON_HEX_CHARS 16 /* Length of line number */ #define DLT_COMMON_HEX_LINELEN 8 /* Length of one char */ -#define DLT_COMMON_CHARLEN 1 +#define DLT_COMMON_CHARLEN 1 /* Number of indices to be allocated at one, if no more indeces are left */ -#define DLT_COMMON_INDEX_ALLOC 1000 +#define DLT_COMMON_INDEX_ALLOC 1000 /* If limited output is called, * this is the maximum number of characters to be printed out */ @@ -100,13 +100,12 @@ /************************/ /* ASCII value for space */ -#define DLT_COMMON_ASCII_CHAR_SPACE 32 +#define DLT_COMMON_ASCII_CHAR_SPACE 32 /* ASCII value for tilde */ #define DLT_COMMON_ASCII_CHAR_TILDE 126 /* ASCII value for lesser than */ -#define DLT_COMMON_ASCII_CHAR_LT 60 +#define DLT_COMMON_ASCII_CHAR_LT 60 #endif /* DLT_COMMON_CFG_H */ - diff --git a/src/shared/dlt_config_file_parser.c b/src/shared/dlt_config_file_parser.c index ee3f7bd82..c946d2a0c 100644 --- a/src/shared/dlt_config_file_parser.c +++ b/src/shared/dlt_config_file_parser.c @@ -37,7 +37,7 @@ /* internal defines */ #define DLT_CONFIG_FILE_NEW_SECTION 0x0a -#define DLT_CONFIG_FILE_NEW_DATA 0x0b +#define DLT_CONFIG_FILE_NEW_DATA 0x0b /* internal helper functions */ @@ -49,13 +49,13 @@ * * @param line String to remove whitespace from */ -static void dlt_config_file_trim_line(char *line) +static void dlt_config_file_trim_line(char* line) { if (line == NULL) return; - char *i = line; - char *j = line; + char* i = line; + char* j = line; while (*j != '\0') { *i = *j++; @@ -75,10 +75,9 @@ static void dlt_config_file_trim_line(char *line) * @param line Line of configuration file * @return 0 if ignore, -1 do not ignore */ -static int dlt_config_file_ignore_line(char *line) +static int dlt_config_file_ignore_line(char* line) { - if ((line[0] == '#') || (line[0] == ';') || (line[0] == '\n') || - (line[0] == '\0')) + if ((line[0] == '#') || (line[0] == ';') || (line[0] == '\n') || (line[0] == '\0')) return 0; /* ignore */ else return -1; /* do not ignore */ @@ -93,7 +92,7 @@ static int dlt_config_file_ignore_line(char *line) * @param name Name of section * @return 0, section name not used, -1 section name already used */ -static int dlt_config_file_is_section_name(DltConfigFile *file, char *name) +static int dlt_config_file_is_section_name(DltConfigFile* file, char* name) { int i = 0; @@ -101,7 +100,7 @@ static int dlt_config_file_is_section_name(DltConfigFile *file, char *name) return -1; for (i = 0; i < file->num_sections; i++) { - DltConfigFileSection *s = &file->sections[i]; + DltConfigFileSection* s = &file->sections[i]; if (strncmp(s->name, name, DLT_CONFIG_FILE_ENTRY_MAX_LEN) == 0) return -1; @@ -119,7 +118,7 @@ static int dlt_config_file_is_section_name(DltConfigFile *file, char *name) * @param name Name of section * @return 0 on success, else -1 */ -static int dlt_config_file_set_section(DltConfigFile *file, char *name) +static int dlt_config_file_set_section(DltConfigFile* file, char* name) { int section = file->num_sections; @@ -135,7 +134,7 @@ static int dlt_config_file_set_section(DltConfigFile *file, char *name) return -1; } - DltConfigFileSection *s = &file->sections[section]; + DltConfigFileSection* s = &file->sections[section]; /* alloc data for entries */ s->name = calloc(DLT_CONFIG_FILE_ENTRY_MAX_LEN + 1, sizeof(char)); @@ -169,14 +168,14 @@ static int dlt_config_file_set_section(DltConfigFile *file, char *name) * @param str2 string used for value * @return 0 on success, else -1 */ -static int dlt_config_file_set_section_data(DltConfigFile *file, char *str1, char *str2) +static int dlt_config_file_set_section_data(DltConfigFile* file, char* str1, char* str2) { - DltConfigKeyData **tmp = NULL; + DltConfigKeyData** tmp = NULL; if ((file == NULL) || (str1 == NULL) || (str2 == NULL)) return -1; - DltConfigFileSection *s = &file->sections[file->num_sections - 1]; + DltConfigFileSection* s = &file->sections[file->num_sections - 1]; int key_number = s->num_entries; if (key_number + 1 >= DLT_CONFIG_FILE_KEYS_MAX) { @@ -197,8 +196,7 @@ static int dlt_config_file_set_section_data(DltConfigFile *file, char *str1, cha } tmp = &s->list; - } - else { + } else { tmp = &s->list; while (*(tmp) != NULL) @@ -230,7 +228,7 @@ static int dlt_config_file_set_section_data(DltConfigFile *file, char *str1, cha * @param line Line in configuration file * @return 0 if section header, else -1 */ -static int dlt_config_file_line_has_section(char *line) +static int dlt_config_file_line_has_section(char* line) { (void)line; /* avoid compiler warnings */ @@ -249,7 +247,7 @@ static int dlt_config_file_line_has_section(char *line) * @param name Section name * @return 0 on success, else -1 */ -static int dlt_config_file_get_section_name_from_string(char *line, char *name) +static int dlt_config_file_get_section_name_from_string(char* line, char* name) { int i = 0; int j = 0; @@ -279,11 +277,11 @@ static int dlt_config_file_get_section_name_from_string(char *line, char *name) * @param[out] str2 String to be used as value * @return 0 on success, else -1 */ -static int dlt_config_file_get_key_value(char *line, char *str1, char *str2) +static int dlt_config_file_get_key_value(char* line, char* str1, char* str2) { - char *delimiter = "="; - char *ptr; - char *save_ptr; + char* delimiter = "="; + char* ptr; + char* save_ptr; if ((line == NULL) || (str1 == NULL) || (str2 == NULL)) return -1; @@ -319,7 +317,7 @@ static int dlt_config_file_get_key_value(char *line, char *str1, char *str2) * @param[out] str2 String contains value or is empty * @return 0 on success, else -1 */ -static int dlt_config_file_read_line(char *line, char *str1, char *str2) +static int dlt_config_file_read_line(char* line, char* str1, char* str2) { if ((line == NULL) || (str1 == NULL) || (str2 == NULL)) return -1; @@ -352,12 +350,12 @@ static int dlt_config_file_read_line(char *line, char *str1, char *str2) * @param file DltConfigFile * @param hdl FILE handle of opened configuration file */ -static void dlt_config_file_read_file(DltConfigFile *file, FILE *hdl) +static void dlt_config_file_read_file(DltConfigFile* file, FILE* hdl) { int ret = 0; - char line[DLT_CONFIG_FILE_LINE_MAX_LEN] = { '\0' }; - char str1[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; - char str2[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = { '\0' }; + char line[DLT_CONFIG_FILE_LINE_MAX_LEN] = {'\0'}; + char str1[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {'\0'}; + char str2[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {'\0'}; int line_number = 0; int is_section_valid = -1; /* to check if section name is given twice or invalid */ @@ -376,22 +374,21 @@ static void dlt_config_file_read_file(DltConfigFile *file, FILE *hdl) ret = dlt_config_file_read_line(line, str1, str2); switch (ret) { - case DLT_CONFIG_FILE_NEW_SECTION: /* store str1 as new section */ + case DLT_CONFIG_FILE_NEW_SECTION: /* store str1 as new section */ is_section_valid = -1; if ((ret = dlt_config_file_set_section(file, str1)) == 0) is_section_valid = 0; break; - case DLT_CONFIG_FILE_NEW_DATA: /* store str1 and str2 as new data for section */ + case DLT_CONFIG_FILE_NEW_DATA: /* store str1 and str2 as new data for section */ if (is_section_valid == 0) dlt_config_file_set_section_data(file, str1, str2); break; - default: /* something is wrong with the line */ - dlt_vlog(LOG_WARNING, "Line (%d) \"%s\" is invalid\n", line_number, - line); + default: /* something is wrong with the line */ + dlt_vlog(LOG_WARNING, "Line (%d) \"%s\" is invalid\n", line_number, line); } } } @@ -405,8 +402,7 @@ static void dlt_config_file_read_file(DltConfigFile *file, FILE *hdl) * @param section Name of section * @return number of section on success, else -1 */ -static int dlt_config_file_find_section(const DltConfigFile *file, - const char *section) +static int dlt_config_file_find_section(const DltConfigFile* file, const char* section) { int i = 0; @@ -416,7 +412,7 @@ static int dlt_config_file_find_section(const DltConfigFile *file, } for (i = 0; i < file->num_sections; i++) { - DltConfigFileSection *s = &file->sections[i]; + DltConfigFileSection* s = &file->sections[i]; if (strncmp(s->name, section, DLT_CONFIG_FILE_ENTRY_MAX_LEN) == 0) return i; @@ -426,10 +422,10 @@ static int dlt_config_file_find_section(const DltConfigFile *file, } /************************** interface implementation ***************************/ -DltConfigFile *dlt_config_file_init(char *file_name) +DltConfigFile* dlt_config_file_init(char* file_name) { - DltConfigFile *file; - FILE *hdl = NULL; + DltConfigFile* file; + FILE* hdl = NULL; if ((file_name == NULL) || (strlen(file_name) >= DLT_PATH_MAX)) { dlt_log(LOG_ERR, "Given configuration file invalid\n"); @@ -460,7 +456,7 @@ DltConfigFile *dlt_config_file_init(char *file_name) return file; } -void dlt_config_file_release(DltConfigFile *file) +void dlt_config_file_release(DltConfigFile* file) { int i = 0; @@ -468,15 +464,15 @@ void dlt_config_file_release(DltConfigFile *file) int max = file->num_sections; for (i = 0; i < max; i++) { - DltConfigFileSection *s = &file->sections[i]; - DltConfigKeyData *node = file->sections[i].list; + DltConfigFileSection* s = &file->sections[i]; + DltConfigKeyData* node = file->sections[i].list; free(s->name); if (s->keys != NULL) free(s->keys); while (node) { - DltConfigKeyData *tmp = node; + DltConfigKeyData* tmp = node; node = node->next; free(tmp->key); free(tmp->data); @@ -489,9 +485,7 @@ void dlt_config_file_release(DltConfigFile *file) } } -int dlt_config_file_get_section_name(const DltConfigFile *file, - int num, - char *name) +int dlt_config_file_get_section_name(const DltConfigFile* file, int num, char* name) { if ((file == NULL) || (name == NULL) || (num < 0) || (num >= file->num_sections)) return -1; @@ -502,7 +496,7 @@ int dlt_config_file_get_section_name(const DltConfigFile *file, return 0; } -int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num) +int dlt_config_file_get_num_sections(const DltConfigFile* file, int* num) { if ((file == NULL) || (file->num_sections < 0)) return -1; @@ -516,12 +510,10 @@ int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num) return 0; } -int dlt_config_file_get_value(const DltConfigFile *file, - const char *section, - const char *key, char *value) +int dlt_config_file_get_value(const DltConfigFile* file, const char* section, const char* key, char* value) { - DltConfigFileSection *s = NULL; - DltConfigKeyData **tmp = NULL; + DltConfigFileSection* s = NULL; + DltConfigKeyData** tmp = NULL; int num_section = 0; if ((file == NULL) || (section == NULL) || (key == NULL) || (value == NULL)) @@ -543,8 +535,7 @@ int dlt_config_file_get_value(const DltConfigFile *file, if (strncmp((*tmp)->key, key, DLT_CONFIG_FILE_ENTRY_MAX_LEN) == 0) { strncpy(value, (*tmp)->data, DLT_CONFIG_FILE_ENTRY_MAX_LEN); return 0; - } - else { /* not found yet see list for more */ + } else { /* not found yet see list for more */ tmp = &(*tmp)->next; } } @@ -553,8 +544,7 @@ int dlt_config_file_get_value(const DltConfigFile *file, return -1; } -int dlt_config_file_check_section_name_exists(const DltConfigFile *file, - const char *name) +int dlt_config_file_check_section_name_exists(const DltConfigFile* file, const char* name) { int ret = 0; diff --git a/src/shared/dlt_config_file_parser.h b/src/shared/dlt_config_file_parser.h index 1de8b009f..2a1d4f790 100644 --- a/src/shared/dlt_config_file_parser.h +++ b/src/shared/dlt_config_file_parser.h @@ -59,32 +59,29 @@ /* definitions */ -#define DLT_CONFIG_FILE_PATH_MAX_LEN 100 /* absolute path including filename */ -#define DLT_CONFIG_FILE_ENTRY_MAX_LEN 100 /* Entry for section, key and value */ -#define DLT_CONFIG_FILE_LINE_MAX_LEN 210 -#define DLT_CONFIG_FILE_SECTIONS_MAX 125 -#define DLT_CONFIG_FILE_KEYS_MAX 25 /* Maximal keys per section */ - -typedef struct DltConfigKeyData -{ - char *key; - char *data; - struct DltConfigKeyData *next; +#define DLT_CONFIG_FILE_PATH_MAX_LEN 100 /* absolute path including filename */ +#define DLT_CONFIG_FILE_ENTRY_MAX_LEN 100 /* Entry for section, key and value */ +#define DLT_CONFIG_FILE_LINE_MAX_LEN 210 +#define DLT_CONFIG_FILE_SECTIONS_MAX 125 +#define DLT_CONFIG_FILE_KEYS_MAX 25 /* Maximal keys per section */ + +typedef struct DltConfigKeyData { + char* key; + char* data; + struct DltConfigKeyData* next; } DltConfigKeyData; /* Config file section structure */ -typedef struct -{ - int num_entries; /* number of entries */ - char *name; /* name of section */ - char *keys; /* keys */ - DltConfigKeyData *list; +typedef struct { + int num_entries; /* number of entries */ + char* name; /* name of section */ + char* keys; /* keys */ + DltConfigKeyData* list; } DltConfigFileSection; -typedef struct -{ +typedef struct { int num_sections; /* number of sections */ - DltConfigFileSection *sections; /* sections */ + DltConfigFileSection* sections; /* sections */ } DltConfigFile; /** @@ -96,7 +93,7 @@ typedef struct * @param file_name File to be opened * @return Pointer to DltConfigFile object or NULL on error */ -DltConfigFile *dlt_config_file_init(char *file_name); +DltConfigFile* dlt_config_file_init(char* file_name); /** * dlt_config_file_release @@ -106,7 +103,7 @@ DltConfigFile *dlt_config_file_init(char *file_name); * * @param file DltConfigFile */ -void dlt_config_file_release(DltConfigFile *file); +void dlt_config_file_release(DltConfigFile* file); /** * dlt_config_file_get_section_name @@ -118,9 +115,7 @@ void dlt_config_file_release(DltConfigFile *file); * @param[out] name Section name * @return 0 on success, else -1 */ -int dlt_config_file_get_section_name(const DltConfigFile *file, - int num, - char *name); +int dlt_config_file_get_section_name(const DltConfigFile* file, int num, char* name); /** * dlt_config_file_get_num_sections @@ -131,7 +126,7 @@ int dlt_config_file_get_section_name(const DltConfigFile *file, * @param[out] num Number of sections inside configuration file * @return 0 on success, else -1 */ -int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num); +int dlt_config_file_get_num_sections(const DltConfigFile* file, int* num); /** * dlt_config_file_get_value @@ -144,10 +139,7 @@ int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num); * @param[out] value Value * @return 0 on success, else -1 */ -int dlt_config_file_get_value(const DltConfigFile *file, - const char *section, - const char *key, - char *value); +int dlt_config_file_get_value(const DltConfigFile* file, const char* section, const char* key, char* value); /** * dlt_config_file_check_section_name_exists @@ -158,6 +150,5 @@ int dlt_config_file_get_value(const DltConfigFile *file, * @param[in] name Section name * @return 0 on success/exist, else -1 */ -int dlt_config_file_check_section_name_exists(const DltConfigFile *file, - const char *name); +int dlt_config_file_check_section_name_exists(const DltConfigFile* file, const char* name); #endif diff --git a/src/shared/dlt_log.c b/src/shared/dlt_log.c index 1ade3f6e3..4126f6900 100644 --- a/src/shared/dlt_log.c +++ b/src/shared/dlt_log.c @@ -28,31 +28,31 @@ #include "dlt_multiple_files.h" #include #include -#include /* dirname */ -#include /* for NAME_MAX */ -#include /* for strlen() */ -#include /* for calloc(), free() */ -#include /* va_list, va_start */ +#include /* dirname */ +#include /* for NAME_MAX */ +#include /* for strlen() */ +#include /* for calloc(), free() */ +#include /* va_list, va_start */ /* internal logging parameters */ static int logging_level = LOG_INFO; static char logging_filename[NAME_MAX + 1] = ""; DltLoggingMode logging_mode = DLT_LOG_TO_STDERR; -FILE *logging_handle = NULL; +FILE* logging_handle = NULL; -//use ohandle as an indicator that multiple files logging is active +// use ohandle as an indicator that multiple files logging is active MultipleFilesRingBuffer multiple_files_ring_buffer = { - .directory={0}, - .filename={0}, - .fileSize=0, - .maxSize=0, - .filenameTimestampBased=false, - .filenameBase={0}, - .filenameExt={0}, - .ohandle=-1}; + .directory = {0}, + .filename = {0}, + .fileSize = 0, + .maxSize = 0, + .filenameTimestampBased = false, + .filenameBase = {0}, + .filenameExt = {0}, + .ohandle = -1}; -void dlt_log_set_filename(const char *filename) +void dlt_log_set_filename(const char* filename) { /* check nullpointer */ if (filename == NULL) { @@ -71,8 +71,7 @@ void dlt_log_set_level(int level) logging_level = LOG_WARNING; dlt_vlog(LOG_WARNING, "Wrong parameter for level: %d\n", level); - } - else { + } else { logging_level = level; } } @@ -83,8 +82,9 @@ DltReturnValue dlt_log_init(int mode) } -DltReturnValue dlt_log_init_multiple_logfiles_support(const DltLoggingMode mode, const bool enable_multiple_logfiles, - const int logging_file_size, const int logging_files_max_size) +DltReturnValue dlt_log_init_multiple_logfiles_support( + const DltLoggingMode mode, const bool enable_multiple_logfiles, const int logging_file_size, + const int logging_files_max_size) { if ((mode < DLT_LOG_TO_CONSOLE) || (mode > DLT_LOG_DROPPED)) { dlt_vlog(LOG_WARNING, "Wrong parameter for mode: %d\n", mode); @@ -102,7 +102,8 @@ DltReturnValue dlt_log_init_multiple_logfiles_support(const DltLoggingMode mode, dlt_user_printf("configure dlt logging using file limits\n"); result = dlt_log_init_multiple_logfiles(logging_file_size, logging_files_max_size); if (result != DLT_RETURN_OK) { - dlt_user_printf("dlt logging for limits fails with error code=%d, use logging without limits as fallback\n", result); + dlt_user_printf( + "dlt logging for limits fails with error code=%d, use logging without limits as fallback\n", result); result = dlt_log_init_single_logfile(); } } else { @@ -132,28 +133,24 @@ DltReturnValue dlt_log_init_multiple_logfiles(const int logging_file_size, const strncpy(path_logging_filename, logging_filename, PATH_MAX); path_logging_filename[PATH_MAX] = 0; - const char *directory = dirname(path_logging_filename); + const char* directory = dirname(path_logging_filename); if (directory[0]) { char basename_logging_filename[NAME_MAX + 1]; strncpy(basename_logging_filename, logging_filename, NAME_MAX); basename_logging_filename[NAME_MAX] = 0; - const char *file_name = basename(basename_logging_filename); + const char* file_name = basename(basename_logging_filename); char filename_base[NAME_MAX]; - if (!dlt_extract_base_name_without_ext(file_name, filename_base, sizeof(filename_base))) return DLT_RETURN_ERROR; + if (!dlt_extract_base_name_without_ext(file_name, filename_base, sizeof(filename_base))) + return DLT_RETURN_ERROR; - const char *filename_ext = get_filename_ext(file_name); - if (!filename_ext) return DLT_RETURN_ERROR; + const char* filename_ext = get_filename_ext(file_name); + if (!filename_ext) + return DLT_RETURN_ERROR; DltReturnValue result = multiple_files_buffer_init( - &multiple_files_ring_buffer, - directory, - logging_file_size, - logging_files_max_size, - false, - true, - filename_base, - filename_ext); + &multiple_files_ring_buffer, directory, logging_file_size, logging_files_max_size, false, true, + filename_base, filename_ext); return result; } @@ -161,9 +158,10 @@ DltReturnValue dlt_log_init_multiple_logfiles(const int logging_file_size, const return DLT_RETURN_ERROR; } -int dlt_user_printf(const char *format, ...) +int dlt_user_printf(const char* format, ...) { - if (format == NULL) return -1; + if (format == NULL) + return -1; va_list args; va_start(args, format); @@ -171,16 +169,16 @@ int dlt_user_printf(const char *format, ...) int ret = 0; switch (logging_mode) { - case DLT_LOG_TO_CONSOLE: - case DLT_LOG_TO_SYSLOG: - case DLT_LOG_TO_FILE: - case DLT_LOG_DROPPED: - default: - ret = vfprintf(stdout, format, args); - break; - case DLT_LOG_TO_STDERR: - ret = vfprintf(stderr, format, args); - break; + case DLT_LOG_TO_CONSOLE: + case DLT_LOG_TO_SYSLOG: + case DLT_LOG_TO_FILE: + case DLT_LOG_DROPPED: + default: + ret = vfprintf(stdout, format, args); + break; + case DLT_LOG_TO_STDERR: + ret = vfprintf(stderr, format, args); + break; } va_end(args); @@ -188,12 +186,10 @@ int dlt_user_printf(const char *format, ...) return ret; } -DltReturnValue dlt_log(int prio, const char *s) +DltReturnValue dlt_log(int prio, const char* s) { - static const char asSeverity[LOG_DEBUG + - 2][11] = - { "EMERGENCY", "ALERT ", "CRITICAL ", "ERROR ", "WARNING ", "NOTICE ", "INFO ", "DEBUG ", - " " }; + static const char asSeverity[LOG_DEBUG + 2][11] = {"EMERGENCY", "ALERT ", "CRITICAL ", "ERROR ", "WARNING ", + "NOTICE ", "INFO ", "DEBUG ", " "}; static const char sFormatString[] = "[%5u.%06u]~DLT~%5d~%s~%s"; struct timespec sTimeSpec; @@ -209,64 +205,55 @@ DltReturnValue dlt_log(int prio, const char *s) clock_gettime(CLOCK_MONOTONIC, &sTimeSpec); switch (logging_mode) { - case DLT_LOG_TO_CONSOLE: - /* log to stdout */ - fprintf(stdout, sFormatString, - (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), - getpid(), - asSeverity[prio], - s); - fflush(stdout); - break; - case DLT_LOG_TO_STDERR: - /* log to stderr */ - fprintf(stderr, sFormatString, - (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), - getpid(), - asSeverity[prio], - s); - break; - case DLT_LOG_TO_SYSLOG: - /* log to syslog */ -#if !defined (__WIN32__) && !defined(_MSC_VER) - openlog("DLT", LOG_PID, LOG_DAEMON); - syslog(prio, - sFormatString, - (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), - getpid(), - asSeverity[prio], - s); - closelog(); + case DLT_LOG_TO_CONSOLE: + /* log to stdout */ + fprintf( + stdout, sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), + asSeverity[prio], s); + fflush(stdout); + break; + case DLT_LOG_TO_STDERR: + /* log to stderr */ + fprintf( + stderr, sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), + asSeverity[prio], s); + break; + case DLT_LOG_TO_SYSLOG: + /* log to syslog */ +#if !defined(__WIN32__) && !defined(_MSC_VER) + openlog("DLT", LOG_PID, LOG_DAEMON); + syslog( + prio, sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), + asSeverity[prio], s); + closelog(); #endif - break; - case DLT_LOG_TO_FILE: - /* log to file */ - - if (dlt_is_log_in_multiple_files_active()) { - dlt_log_multiple_files_write(sFormatString, (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), asSeverity[prio], s); - } - else if (logging_handle) { - fprintf(logging_handle, sFormatString, (unsigned int)sTimeSpec.tv_sec, - (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), asSeverity[prio], s); - fflush(logging_handle); - } - - break; - case DLT_LOG_DROPPED: - default: - break; + break; + case DLT_LOG_TO_FILE: + /* log to file */ + + if (dlt_is_log_in_multiple_files_active()) { + dlt_log_multiple_files_write( + sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec / 1000), getpid(), + asSeverity[prio], s); + } else if (logging_handle) { + fprintf( + logging_handle, sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec / 1000), + getpid(), asSeverity[prio], s); + fflush(logging_handle); + } + + break; + case DLT_LOG_DROPPED: + default: + break; } return DLT_RETURN_OK; } -DltReturnValue dlt_vlog(int prio, const char *format, ...) +DltReturnValue dlt_vlog(int prio, const char* format, ...) { - char outputString[2048] = { 0 }; /* TODO: what is a reasonable string length here? */ + char outputString[2048] = {0}; /* TODO: what is a reasonable string length here? */ va_list args; @@ -285,9 +272,9 @@ DltReturnValue dlt_vlog(int prio, const char *format, ...) return DLT_RETURN_OK; } -DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) +DltReturnValue dlt_vnlog(int prio, size_t size, const char* format, ...) { - char *outputString = NULL; + char* outputString = NULL; va_list args; @@ -297,7 +284,7 @@ DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) if ((logging_level < prio) || (size == 0)) return DLT_RETURN_OK; - if ((outputString = (char *)calloc(size + 1, sizeof(char))) == NULL) + if ((outputString = (char*)calloc(size + 1, sizeof(char))) == NULL) return DLT_RETURN_ERROR; va_start(args, format); @@ -314,11 +301,11 @@ DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) void dlt_log_multiple_files_write(const char* format, ...) { - char output_string[2048] = { 0 }; + char output_string[2048] = {0}; va_list args; - va_start (args, format); + va_start(args, format); vsnprintf(output_string, 2047, format, args); - va_end (args); + va_end(args); multiple_files_buffer_write(&multiple_files_ring_buffer, (unsigned char*)output_string, (int)strlen(output_string)); } @@ -342,7 +329,8 @@ void dlt_log_free_single_logfile() void dlt_log_free_multiple_logfiles() { - if (DLT_RETURN_ERROR == multiple_files_buffer_free(&multiple_files_ring_buffer)) return; + if (DLT_RETURN_ERROR == multiple_files_buffer_free(&multiple_files_ring_buffer)) + return; // reset indicator of multiple files usage multiple_files_ring_buffer.ohandle = -1; diff --git a/src/shared/dlt_multiple_files.c b/src/shared/dlt_multiple_files.c index f71b422f1..885abb593 100644 --- a/src/shared/dlt_multiple_files.c +++ b/src/shared/dlt_multiple_files.c @@ -41,14 +41,13 @@ #include "dlt_common.h" #include "dlt_log.h" -unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char *file_name, - char *newest, char *oldest) +unsigned int multiple_files_buffer_storage_dir_info(const char* path, const char* file_name, char* newest, char* oldest) { int i = 0; unsigned int num_log_files = 0; - struct dirent **files = { 0 }; - char *tmp_old = NULL; - char *tmp_new = NULL; + struct dirent** files = {0}; + char* tmp_old = NULL; + char* tmp_new = NULL; if ((path == NULL) || (file_name == NULL) || (newest == NULL) || (oldest == NULL)) { fprintf(stderr, "multiple_files_buffer_storage_dir_info: Invalid parameter(s)"); @@ -56,14 +55,15 @@ unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char } const int file_cnt = scandir(path, &files, NULL, alphasort); - if (file_cnt <= 0) return 0; + if (file_cnt <= 0) + return 0; for (i = 0; i < file_cnt; i++) { int len = 0; len = (int)strlen(file_name); - if ((strncmp(files[i]->d_name, file_name, (size_t)len) == 0) && - (files[i]->d_name[len] == MULTIPLE_FILES_FILENAME_INDEX_DELIM[0])) { + if ((strncmp(files[i]->d_name, file_name, (size_t)len) == 0) + && (files[i]->d_name[len] == MULTIPLE_FILES_FILENAME_INDEX_DELIM[0])) { num_log_files++; if ((tmp_old == NULL) || (strlen(tmp_old) >= strlen(files[i]->d_name))) { @@ -95,27 +95,28 @@ unsigned int multiple_files_buffer_storage_dir_info(const char *path, const char if ((tmp_old != NULL) && (strlen(tmp_old) < NAME_MAX)) { strncpy(oldest, tmp_old, NAME_MAX); oldest[NAME_MAX] = '\0'; - } else if ((tmp_old != NULL) && (strlen(tmp_old) >= NAME_MAX)) { + } else if ((tmp_old != NULL) && (strlen(tmp_old) >= NAME_MAX)) { printf("length mismatch of file %s\n", tmp_old); } if ((tmp_new != NULL) && (strlen(tmp_new) < NAME_MAX)) { strncpy(newest, tmp_new, NAME_MAX); newest[NAME_MAX] = '\0'; - } else if ((tmp_new != NULL) && (strlen(tmp_new) >= NAME_MAX)) { + } else if ((tmp_new != NULL) && (strlen(tmp_new) >= NAME_MAX)) { printf("length mismatch of file %s\n", tmp_new); } } /* free scandir result */ - for (i = 0; i < file_cnt; i++) free(files[i]); + for (i = 0; i < file_cnt; i++) + free(files[i]); free(files); return num_log_files; } -void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, const unsigned int idx) +void multiple_files_buffer_file_name(MultipleFilesRingBuffer* files_buffer, const unsigned int idx) { char file_index[11]; /* UINT_MAX = 4294967295 -> 10 digits */ snprintf(file_index, sizeof(file_index), "%010u", idx); @@ -125,22 +126,21 @@ void multiple_files_buffer_file_name(MultipleFilesRingBuffer *files_buffer, cons size_t bufsize = sizeof(files_buffer->filename); memset(file_name, 0, bufsize); - int written = snprintf(file_name, bufsize, "%s%s%s%s", - files_buffer->filenameBase, - MULTIPLE_FILES_FILENAME_INDEX_DELIM, - file_index, - files_buffer->filenameExt); + int written = snprintf( + file_name, bufsize, "%s%s%s%s", files_buffer->filenameBase, MULTIPLE_FILES_FILENAME_INDEX_DELIM, file_index, + files_buffer->filenameExt); if (written < 0 || (size_t)written >= bufsize) { file_name[bufsize - 1] = '\0'; } } -unsigned int multiple_files_buffer_get_idx_of_log_file(char *file) +unsigned int multiple_files_buffer_get_idx_of_log_file(char* file) { - if ((file == NULL) || (file[0] == '\0')) return 0; + if ((file == NULL) || (file[0] == '\0')) + return 0; const char d[2] = MULTIPLE_FILES_FILENAME_INDEX_DELIM; - char *token; + char* token; token = strtok(file, d); /* we are interested in 2. token because of log file name */ @@ -149,7 +149,7 @@ unsigned int multiple_files_buffer_get_idx_of_log_file(char *file) return token != NULL ? (unsigned int)strtol(token, NULL, 10) : 0; } -DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer *files_buffer) +DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer* files_buffer) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); @@ -172,40 +172,35 @@ DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer *fi strftime(timestamp, sizeof(timestamp), "%Y%m%d_%H%M%S", &tmp); - ret = snprintf(files_buffer->filename, sizeof(files_buffer->filename), "%s%s%s%s", - files_buffer->filenameBase, - MULTIPLE_FILES_FILENAME_TIMESTAMP_DELIM, timestamp, - files_buffer->filenameExt); + ret = snprintf( + files_buffer->filename, sizeof(files_buffer->filename), "%s%s%s%s", files_buffer->filenameBase, + MULTIPLE_FILES_FILENAME_TIMESTAMP_DELIM, timestamp, files_buffer->filenameExt); if ((ret < 0) || ((size_t)ret >= (int)sizeof(files_buffer->filename))) { fprintf(stderr, "filename cannot be concatenated\n"); return DLT_RETURN_ERROR; } - ret = snprintf(file_path, sizeof(file_path), "%s/%s", - files_buffer->directory, files_buffer->filename); + ret = snprintf(file_path, sizeof(file_path), "%s/%s", files_buffer->directory, files_buffer->filename); if ((ret < 0) || ((size_t)ret >= (int)sizeof(file_path))) { fprintf(stderr, "file path cannot be concatenated\n"); return DLT_RETURN_ERROR; } - } - else { - char newest[NAME_MAX + 1] = { 0 }; - char oldest[NAME_MAX + 1] = { 0 }; + } else { + char newest[NAME_MAX + 1] = {0}; + char oldest[NAME_MAX + 1] = {0}; /* targeting newest file, ignoring number of files in dir returned */ - if (0 == multiple_files_buffer_storage_dir_info(files_buffer->directory, - files_buffer->filenameBase, - newest, - oldest)) { + if (0 + == multiple_files_buffer_storage_dir_info( + files_buffer->directory, files_buffer->filenameBase, newest, oldest)) { printf("No multiple files found\n"); } idx = multiple_files_buffer_get_idx_of_log_file(newest) + 1; multiple_files_buffer_file_name(files_buffer, idx); - ret = snprintf(file_path, sizeof(file_path), "%s/%s", - files_buffer->directory, files_buffer->filename); + ret = snprintf(file_path, sizeof(file_path), "%s/%s", files_buffer->directory, files_buffer->filename); if ((ret < 0) || (ret >= NAME_MAX)) { fprintf(stderr, "filename cannot be concatenated\n"); @@ -215,8 +210,7 @@ DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer *fi /* open DLT output file */ errno = 0; - files_buffer->ohandle = open(file_path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | - S_IRGRP | S_IROTH); /* mode: wb */ + files_buffer->ohandle = open(file_path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ if (files_buffer->ohandle == -1) { /* file cannot be opened */ @@ -227,20 +221,20 @@ DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer *fi return DLT_RETURN_OK; } -ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer *files_buffer) +ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer* files_buffer) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); return -1; } - struct dirent *dp; + struct dirent* dp; char filename[PATH_MAX + 1]; ssize_t size = 0; struct stat status; /* go through all dlt files in directory */ - DIR *dir = opendir(files_buffer->directory); + DIR* dir = opendir(files_buffer->directory); if (!dir) { fprintf(stderr, "directory %s cannot be opened, error=%s\n", files_buffer->directory, strerror(errno)); return -1; @@ -248,7 +242,7 @@ ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer *file while ((dp = readdir(dir)) != NULL) { // consider files matching with a specific base name and a particular extension - if (strstr(dp->d_name, files_buffer->filenameBase) && strstr(dp->d_name, files_buffer->filenameExt)) { + if (strstr(dp->d_name, files_buffer->filenameBase) && strstr(dp->d_name, files_buffer->filenameExt)) { int res = snprintf(filename, sizeof(filename), "%s/%s", files_buffer->directory, dp->d_name); /* if the total length of the string is greater than the buffer, silently forget it. */ @@ -270,14 +264,14 @@ ssize_t multiple_files_buffer_get_total_size(const MultipleFilesRingBuffer *file return size; } -int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer *files_buffer) +int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer* files_buffer) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); - return -1; /* ERROR */ + return -1; /* ERROR */ } - struct dirent *dp; + struct dirent* dp; char filename[PATH_MAX + 1]; char filename_oldest[PATH_MAX + 1]; unsigned long size_oldest = 0; @@ -289,9 +283,9 @@ int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer *files_buff filename_oldest[0] = 0; /* go through all dlt files in directory */ - DIR *dir = opendir(files_buffer->directory); + DIR* dir = opendir(files_buffer->directory); - if(!dir) + if (!dir) return -1; while ((dp = readdir(dir)) != NULL) { @@ -301,7 +295,7 @@ int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer *files_buff /* if the total length of the string is greater than the buffer, silently forget it. */ /* snprintf: a return value of size or more means that the output was truncated */ /* if an output error is encountered, a negative value is returned. */ - if (((unsigned int) res >= sizeof(filename)) || (res <= 0)) { + if (((unsigned int)res >= sizeof(filename)) || (res <= 0)) { printf("Filename for delete oldest too long. Skip file.\n"); continue; } @@ -319,17 +313,17 @@ int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer *files_buff printf("Old file %s cannot be stat-ed, error=%s\n", filename, strerror(errno)); } } else { - //index based + // index based const unsigned int index = multiple_files_buffer_get_idx_of_log_file(filename); if (index < (unsigned int)index_oldest) { index_oldest = (int)index; #if defined(__GNUC__) && __GNUC__ >= 7 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wformat-truncation" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation" #endif snprintf(filename, sizeof(filename), "%s/%s", files_buffer->directory, dp->d_name); #if defined(__GNUC__) && __GNUC__ >= 7 -# pragma GCC diagnostic pop +#pragma GCC diagnostic pop #endif strncpy(filename_oldest, filename, PATH_MAX); filename_oldest[PATH_MAX] = 0; @@ -355,7 +349,7 @@ int multiple_files_buffer_delete_oldest_file(MultipleFilesRingBuffer *files_buff return (int)size_oldest; } -DltReturnValue multiple_files_buffer_check_size(MultipleFilesRingBuffer *files_buffer) +DltReturnValue multiple_files_buffer_check_size(MultipleFilesRingBuffer* files_buffer) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); @@ -367,7 +361,8 @@ DltReturnValue multiple_files_buffer_check_size(MultipleFilesRingBuffer *files_b /* check for existence of buffer files directory */ errno = 0; if (stat(files_buffer->directory, &status) == -1) { - fprintf(stderr, "Buffer files directory: %s doesn't exist, error=%s\n", files_buffer->directory, strerror(errno)); + fprintf( + stderr, "Buffer files directory: %s doesn't exist, error=%s\n", files_buffer->directory, strerror(errno)); return DLT_RETURN_ERROR; } /* check for accessibility of buffer files directory */ @@ -378,31 +373,35 @@ DltReturnValue multiple_files_buffer_check_size(MultipleFilesRingBuffer *files_b ssize_t total_size = 0; /* check size of complete buffer file */ - while ((total_size = multiple_files_buffer_get_total_size(files_buffer)) > (files_buffer->maxSize - files_buffer->fileSize)) { + while ((total_size = multiple_files_buffer_get_total_size(files_buffer)) + > (files_buffer->maxSize - files_buffer->fileSize)) { /* remove the oldest files as long as new file will not fit in completely into complete multiple files buffer */ - if (multiple_files_buffer_delete_oldest_file(files_buffer) < 0) return DLT_RETURN_ERROR; + if (multiple_files_buffer_delete_oldest_file(files_buffer) < 0) + return DLT_RETURN_ERROR; } return total_size == -1 ? DLT_RETURN_ERROR : DLT_RETURN_OK; } -DltReturnValue multiple_files_buffer_open_file_for_append(MultipleFilesRingBuffer *files_buffer) { - if (files_buffer == NULL || files_buffer->filenameTimestampBased) return DLT_RETURN_ERROR; +DltReturnValue multiple_files_buffer_open_file_for_append(MultipleFilesRingBuffer* files_buffer) +{ + if (files_buffer == NULL || files_buffer->filenameTimestampBased) + return DLT_RETURN_ERROR; char newest[NAME_MAX + 1] = {0}; char oldest[NAME_MAX + 1] = {0}; /* targeting the newest file, ignoring number of files in dir returned */ - if (0 == multiple_files_buffer_storage_dir_info(files_buffer->directory, - files_buffer->filenameBase, newest, oldest) ) { + if (0 + == multiple_files_buffer_storage_dir_info( + files_buffer->directory, files_buffer->filenameBase, newest, oldest)) { // no file for appending found. Create a new one printf("No multiple files for appending found. Create a new one\n"); return multiple_files_buffer_create_new_file(files_buffer); } char file_path[PATH_MAX + 1]; - int ret = snprintf(file_path, sizeof(file_path), "%s/%s", - files_buffer->directory, newest); + int ret = snprintf(file_path, sizeof(file_path), "%s/%s", files_buffer->directory, newest); if ((ret < 0) || (ret >= NAME_MAX)) { fprintf(stderr, "filename cannot be concatenated\n"); @@ -416,14 +415,9 @@ DltReturnValue multiple_files_buffer_open_file_for_append(MultipleFilesRingBuffe return files_buffer->ohandle == -1 ? DLT_RETURN_ERROR : DLT_RETURN_OK; } -DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer, - const char *directory, - const int file_size, - const int max_size, - const bool filename_timestamp_based, - const bool append, - const char *filename_base, - const char *filename_ext) +DltReturnValue multiple_files_buffer_init( + MultipleFilesRingBuffer* files_buffer, const char* directory, const int file_size, const int max_size, + const bool filename_timestamp_based, const bool append, const char* filename_base, const char* filename_ext) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); @@ -441,32 +435,34 @@ DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer, strncpy(files_buffer->filenameExt, filename_ext, NAME_MAX); files_buffer->filenameExt[NAME_MAX] = 0; - if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) return DLT_RETURN_ERROR; + if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) + return DLT_RETURN_ERROR; - return (!files_buffer->filenameTimestampBased && append) - ? multiple_files_buffer_open_file_for_append(files_buffer) - : multiple_files_buffer_create_new_file(files_buffer); + return (!files_buffer->filenameTimestampBased && append) ? + multiple_files_buffer_open_file_for_append(files_buffer) : + multiple_files_buffer_create_new_file(files_buffer); } -void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer *files_buffer, const int size) +void multiple_files_buffer_rotate_file(MultipleFilesRingBuffer* files_buffer, const int size) { /* check file size here */ - if ((lseek(files_buffer->ohandle, 0, SEEK_CUR) + size) < files_buffer->fileSize) return; + if ((lseek(files_buffer->ohandle, 0, SEEK_CUR) + size) < files_buffer->fileSize) + return; /* close old file */ close(files_buffer->ohandle); files_buffer->ohandle = -1; /* check complete files size, remove old logs if needed */ - if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) return; + if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) + return; /* create new file */ multiple_files_buffer_create_new_file(files_buffer); } -DltReturnValue multiple_files_buffer_write_chunk(const MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - const int size) +DltReturnValue multiple_files_buffer_write_chunk( + const MultipleFilesRingBuffer* files_buffer, const unsigned char* data, const int size) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); @@ -482,11 +478,11 @@ DltReturnValue multiple_files_buffer_write_chunk(const MultipleFilesRingBuffer * return DLT_RETURN_OK; } -DltReturnValue multiple_files_buffer_write(MultipleFilesRingBuffer *files_buffer, - const unsigned char *data, - const int size) +DltReturnValue multiple_files_buffer_write( + MultipleFilesRingBuffer* files_buffer, const unsigned char* data, const int size) { - if (files_buffer->ohandle < 0) return DLT_RETURN_ERROR; + if (files_buffer->ohandle < 0) + return DLT_RETURN_ERROR; multiple_files_buffer_rotate_file(files_buffer, size); @@ -494,14 +490,15 @@ DltReturnValue multiple_files_buffer_write(MultipleFilesRingBuffer *files_buffer return multiple_files_buffer_write_chunk(files_buffer, data, size); } -DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer *files_buffer) +DltReturnValue multiple_files_buffer_free(const MultipleFilesRingBuffer* files_buffer) { if (files_buffer == NULL) { fprintf(stderr, "multiple files buffer not set\n"); return DLT_RETURN_ERROR; } - if (files_buffer->ohandle < 0) return DLT_RETURN_ERROR; + if (files_buffer->ohandle < 0) + return DLT_RETURN_ERROR; /* close last used log file */ close(files_buffer->ohandle); diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c index 988ed7e9f..d6523a01b 100644 --- a/src/shared/dlt_offline_trace.c +++ b/src/shared/dlt_offline_trace.c @@ -66,23 +66,22 @@ #include #include -DltReturnValue dlt_offline_trace_write(MultipleFilesRingBuffer *trace, - const unsigned char *data1, - const int size1, - const unsigned char *data2, - const int size2, - const unsigned char *data3, - const int size3) +DltReturnValue dlt_offline_trace_write( + MultipleFilesRingBuffer* trace, const unsigned char* data1, const int size1, const unsigned char* data2, + const int size2, const unsigned char* data3, const int size3) { - - if (trace->ohandle < 0) return DLT_RETURN_ERROR; + if (trace->ohandle < 0) + return DLT_RETURN_ERROR; multiple_files_buffer_rotate_file(trace, size1 + size2 + size3); /* write data into log file */ - if (multiple_files_buffer_write_chunk(trace, data1, size1) != DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (multiple_files_buffer_write_chunk(trace, data2, size2) != DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (multiple_files_buffer_write_chunk(trace, data3, size3) != DLT_RETURN_OK) return DLT_RETURN_ERROR; + if (multiple_files_buffer_write_chunk(trace, data1, size1) != DLT_RETURN_OK) + return DLT_RETURN_ERROR; + if (multiple_files_buffer_write_chunk(trace, data2, size2) != DLT_RETURN_OK) + return DLT_RETURN_ERROR; + if (multiple_files_buffer_write_chunk(trace, data3, size3) != DLT_RETURN_OK) + return DLT_RETURN_ERROR; return DLT_RETURN_OK; } diff --git a/src/shared/dlt_protocol.c b/src/shared/dlt_protocol.c index e2a34f1de..2f52d9e2c 100644 --- a/src/shared/dlt_protocol.c +++ b/src/shared/dlt_protocol.c @@ -27,7 +27,7 @@ #include "dlt_protocol.h" -const char *const dlt_service_names[] = { +const char* const dlt_service_names[] = { "DLT_SERVICE_ID", "DLT_SERVICE_ID_SET_LOG_LEVEL", "DLT_SERVICE_ID_SET_TRACE_STATUS", @@ -48,9 +48,8 @@ const char *const dlt_service_names[] = { "DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL", "DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS", "DLT_SERVICE_ID_GET_SOFTWARE_VERSION", - "DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW" -}; -const char *const dlt_user_service_names[] = { + "DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW"}; +const char* const dlt_user_service_names[] = { "DLT_USER_SERVICE_ID", "DLT_SERVICE_ID_UNREGISTER_CONTEXT", "DLT_SERVICE_ID_CONNECTION_INFO", @@ -65,15 +64,15 @@ const char *const dlt_user_service_names[] = { "DLT_SERVICE_ID_RESERVED", "DLT_SERVICE_ID_RESERVED", "DLT_SERVICE_ID_RESERVED", - "DLT_SERVICE_ID_RESERVED" -}; + "DLT_SERVICE_ID_RESERVED"}; -const char *dlt_get_service_name(unsigned int id) +const char* dlt_get_service_name(unsigned int id) { if (id == DLT_SERVICE_ID_CALLSW_CINJECTION) return "DLT_SERVICE_ID_CALLSW_CINJECTION"; - else if ((id == DLT_SERVICE_ID) || (id >= DLT_USER_SERVICE_ID_LAST_ENTRY) || - ((id >= DLT_SERVICE_ID_LAST_ENTRY) && (id <= DLT_USER_SERVICE_ID))) + else if ( + (id == DLT_SERVICE_ID) || (id >= DLT_USER_SERVICE_ID_LAST_ENTRY) + || ((id >= DLT_SERVICE_ID_LAST_ENTRY) && (id <= DLT_USER_SERVICE_ID))) return "UNDEFINED"; else if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_LAST_ENTRY)) return dlt_service_names[id]; diff --git a/src/shared/dlt_shm.c b/src/shared/dlt_shm.c index 5702f9f19..6a11dc00c 100644 --- a/src/shared/dlt_shm.c +++ b/src/shared/dlt_shm.c @@ -69,27 +69,26 @@ #include #include -void dlt_shm_print_hex(char *ptr, int size) +void dlt_shm_print_hex(char* ptr, int size) { int num; for (num = 0; num < size; num++) { if ((num % 16) == 15) - printf("%.2x\n", ((unsigned char *)ptr)[num]); + printf("%.2x\n", ((unsigned char*)ptr)[num]); else - printf("%.2x ", ((unsigned char *)ptr)[num]); + printf("%.2x ", ((unsigned char*)ptr)[num]); } printf("\n"); } -DltReturnValue dlt_shm_init_server(DltShm *buf, const char *name, int size) +DltReturnValue dlt_shm_init_server(DltShm* buf, const char* name, int size) { - unsigned char *ptr; + unsigned char* ptr; /* Check if buffer and name available */ - if (buf == NULL || name == NULL) - { + if (buf == NULL || name == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -109,28 +108,21 @@ DltReturnValue dlt_shm_init_server(DltShm *buf, const char *name, int size) * The shared memory object's permission. */ buf->shmfd = shm_open(name, O_CREAT | O_EXCL | O_RDWR, 0666); - if (buf->shmfd == -1) - { - dlt_vlog(LOG_ERR, "%s: shm_open() failed: %s\n", - __func__, strerror(errno)); + if (buf->shmfd == -1) { + dlt_vlog(LOG_ERR, "%s: shm_open() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } /* Set the size of shm */ - if (ftruncate(buf->shmfd, size) == -1) - { - dlt_vlog(LOG_ERR, "%s: ftruncate() failed: %s\n", - __func__, strerror(errno)); + if (ftruncate(buf->shmfd, size) == -1) { + dlt_vlog(LOG_ERR, "%s: ftruncate() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } /* Now we attach the segment to our data space. */ - ptr = (unsigned char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, - buf->shmfd, 0); - if (ptr == MAP_FAILED) - { - dlt_vlog(LOG_ERR, "%s: mmap() failed: %s\n", - __func__, strerror(errno)); + ptr = (unsigned char*)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, buf->shmfd, 0); + if (ptr == MAP_FAILED) { + dlt_vlog(LOG_ERR, "%s: mmap() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } @@ -147,10 +139,8 @@ DltReturnValue dlt_shm_init_server(DltShm *buf, const char *name, int size) * Initial value for the new semaphore. */ buf->sem = sem_open(name, O_CREAT | O_EXCL, 0666, 1); - if (buf->sem == SEM_FAILED) - { - dlt_vlog(LOG_ERR, "%s: sem_open() failed: %s\n", - __func__, strerror(errno)); + if (buf->sem == SEM_FAILED) { + dlt_vlog(LOG_ERR, "%s: sem_open() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } @@ -158,24 +148,25 @@ DltReturnValue dlt_shm_init_server(DltShm *buf, const char *name, int size) dlt_buffer_init_static_server(&(buf->buffer), ptr, size); /* The 'buf->shmfd' is no longer needed */ - if (close(buf->shmfd) == -1) - { - dlt_vlog(LOG_ERR, "%s: Failed to close shared memory" - " file descriptor: %s\n", __func__, strerror(errno)); + if (close(buf->shmfd) == -1) { + dlt_vlog( + LOG_ERR, + "%s: Failed to close shared memory" + " file descriptor: %s\n", + __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } return DLT_RETURN_OK; /* OK */ } -DltReturnValue dlt_shm_init_client(DltShm *buf, const char *name) +DltReturnValue dlt_shm_init_client(DltShm* buf, const char* name) { struct stat shm_buf; - unsigned char *ptr; + unsigned char* ptr; /* Check if buffer and name available */ - if (buf == NULL || name == NULL) - { + if (buf == NULL || name == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -194,28 +185,21 @@ DltReturnValue dlt_shm_init_client(DltShm *buf, const char *name) * We are not creating a new object, this argument should be specified as 0. */ buf->shmfd = shm_open(name, O_RDWR, 0); - if (buf->shmfd == -1) - { - dlt_vlog(LOG_ERR, "%s: shm_open() failed: %s\n", - __func__, strerror(errno)); + if (buf->shmfd == -1) { + dlt_vlog(LOG_ERR, "%s: shm_open() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } /* Get the size of shm */ - if (fstat(buf->shmfd, &shm_buf) == -1) - { - dlt_vlog(LOG_ERR, "%s: fstat() failed: %s\n", - __func__, strerror(errno)); + if (fstat(buf->shmfd, &shm_buf) == -1) { + dlt_vlog(LOG_ERR, "%s: fstat() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } /* Now we attach the segment to our data space. */ - ptr = (unsigned char *)mmap(NULL, shm_buf.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, buf->shmfd, 0); - if (ptr == MAP_FAILED) - { - dlt_vlog(LOG_ERR, "%s: mmap() failed: %s\n", - __func__, strerror(errno)); + ptr = (unsigned char*)mmap(NULL, shm_buf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, buf->shmfd, 0); + if (ptr == MAP_FAILED) { + dlt_vlog(LOG_ERR, "%s: mmap() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } @@ -229,10 +213,8 @@ DltReturnValue dlt_shm_init_client(DltShm *buf, const char *name) * We are accessing an existing semaphore, oflag should be specified as 0. */ buf->sem = sem_open(name, 0); - if (buf->sem == SEM_FAILED) - { - dlt_vlog(LOG_ERR, "%s: sem_open() failed: %s\n", - __func__, strerror(errno)); + if (buf->sem == SEM_FAILED) { + dlt_vlog(LOG_ERR, "%s: sem_open() failed: %s\n", __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } @@ -240,21 +222,22 @@ DltReturnValue dlt_shm_init_client(DltShm *buf, const char *name) dlt_buffer_init_static_client(&(buf->buffer), ptr, shm_buf.st_size); /* The 'buf->shmfd' is no longer needed */ - if (close(buf->shmfd) == -1) - { - dlt_vlog(LOG_ERR, "%s: Failed to close shared memory" - " file descriptor: %s\n", __func__, strerror(errno)); + if (close(buf->shmfd) == -1) { + dlt_vlog( + LOG_ERR, + "%s: Failed to close shared memory" + " file descriptor: %s\n", + __func__, strerror(errno)); return DLT_RETURN_ERROR; /* ERROR */ } return DLT_RETURN_OK; /* OK */ } -void dlt_shm_info(DltShm *buf) +void dlt_shm_info(DltShm* buf) { /* Check if buffer available */ - if (buf == NULL) - { + if (buf == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return; } @@ -262,11 +245,10 @@ void dlt_shm_info(DltShm *buf) dlt_buffer_info(&(buf->buffer)); } -void dlt_shm_status(DltShm *buf) +void dlt_shm_status(DltShm* buf) { /* Check if buffer available */ - if (buf == NULL) - { + if (buf == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return; } @@ -274,11 +256,10 @@ void dlt_shm_status(DltShm *buf) dlt_buffer_status(&(buf->buffer)); } -int dlt_shm_get_total_size(DltShm *buf) +int dlt_shm_get_total_size(DltShm* buf) { /* Check if buffer available */ - if (buf == NULL) - { + if (buf == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } @@ -286,67 +267,58 @@ int dlt_shm_get_total_size(DltShm *buf) return dlt_buffer_get_total_size(&(buf->buffer)); } -int dlt_shm_get_used_size(DltShm *buf) +int dlt_shm_get_used_size(DltShm* buf) { int ret; /* Check if buffer available */ - if ((buf == NULL) || (buf->buffer.mem == NULL)) - { + if ((buf == NULL) || (buf->buffer.mem == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } DLT_SHM_SEM_GET(buf->sem); - ret = dlt_buffer_get_used_size(&(buf->buffer)); + ret = dlt_buffer_get_used_size(&(buf->buffer)); DLT_SHM_SEM_FREE(buf->sem); return ret; } -int dlt_shm_get_message_count(DltShm *buf) +int dlt_shm_get_message_count(DltShm* buf) { /* Check if buffer available */ - if (buf == NULL) - { + if (buf == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } return dlt_buffer_get_message_count(&(buf->buffer)); } -int dlt_shm_push(DltShm *buf, - const unsigned char *data1, - unsigned int size1, - const unsigned char *data2, - unsigned int size2, - const unsigned char *data3, - unsigned int size3) +int dlt_shm_push( + DltShm* buf, const unsigned char* data1, unsigned int size1, const unsigned char* data2, unsigned int size2, + const unsigned char* data3, unsigned int size3) { int ret; /* Check if buffer available */ - if ((buf == NULL) || (buf->buffer.mem == NULL)) - { + if ((buf == NULL) || (buf->buffer.mem == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } DLT_SHM_SEM_GET(buf->sem); - ret = dlt_buffer_push3(&(buf->buffer), - data1, size1, data2, size2, data3, size3); + ret = dlt_buffer_push3(&(buf->buffer), data1, size1, data2, size2, data3, size3); DLT_SHM_SEM_FREE(buf->sem); return ret; } -int dlt_shm_pull(DltShm *buf, unsigned char *data, int max_size) +int dlt_shm_pull(DltShm* buf, unsigned char* data, int max_size) { int ret; /* Check if buffer available */ - if ((buf == NULL) || (buf->buffer.mem == NULL)) - { + if ((buf == NULL) || (buf->buffer.mem == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } @@ -358,13 +330,12 @@ int dlt_shm_pull(DltShm *buf, unsigned char *data, int max_size) return ret; } -int dlt_shm_copy(DltShm *buf, unsigned char *data, int max_size) +int dlt_shm_copy(DltShm* buf, unsigned char* data, int max_size) { int ret; /* Check if buffer available */ - if ((buf == NULL) || (buf->buffer.mem == NULL)) - { + if ((buf == NULL) || (buf->buffer.mem == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } @@ -376,13 +347,12 @@ int dlt_shm_copy(DltShm *buf, unsigned char *data, int max_size) return ret; } -int dlt_shm_remove(DltShm *buf) +int dlt_shm_remove(DltShm* buf) { int ret; /* Check if buffer available */ - if ((buf == NULL) || (buf->buffer.mem == NULL)) - { + if ((buf == NULL) || (buf->buffer.mem == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return -1; } @@ -394,36 +364,27 @@ int dlt_shm_remove(DltShm *buf) return ret; } -DltReturnValue dlt_shm_free_server(DltShm *buf, const char *name) +DltReturnValue dlt_shm_free_server(DltShm* buf, const char* name) { - if ((buf == NULL) || (buf->buffer.shm == NULL) || name == NULL) - { + if ((buf == NULL) || (buf->buffer.shm == NULL) || name == NULL) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if (munmap(buf->buffer.shm, buf->buffer.min_size) == -1) - { - dlt_vlog(LOG_ERR, "%s: munmap() failed: %s\n", - __func__, strerror(errno)); + if (munmap(buf->buffer.shm, buf->buffer.min_size) == -1) { + dlt_vlog(LOG_ERR, "%s: munmap() failed: %s\n", __func__, strerror(errno)); } - if (shm_unlink(name) == -1) - { - dlt_vlog(LOG_ERR, "%s: shm_unlink() failed: %s\n", - __func__, strerror(errno)); + if (shm_unlink(name) == -1) { + dlt_vlog(LOG_ERR, "%s: shm_unlink() failed: %s\n", __func__, strerror(errno)); } - if (sem_close(buf->sem) == -1) - { - dlt_vlog(LOG_ERR, "%s: sem_close() failed: %s\n", - __func__, strerror(errno)); + if (sem_close(buf->sem) == -1) { + dlt_vlog(LOG_ERR, "%s: sem_close() failed: %s\n", __func__, strerror(errno)); } - if (sem_unlink(name) == -1) - { - dlt_vlog(LOG_ERR, "%s: sem_unlink() failed: %s\n", - __func__, strerror(errno)); + if (sem_unlink(name) == -1) { + dlt_vlog(LOG_ERR, "%s: sem_unlink() failed: %s\n", __func__, strerror(errno)); } /* Reset parameters */ @@ -433,24 +394,19 @@ DltReturnValue dlt_shm_free_server(DltShm *buf, const char *name) return dlt_buffer_free_static(&(buf->buffer)); } -DltReturnValue dlt_shm_free_client(DltShm *buf) +DltReturnValue dlt_shm_free_client(DltShm* buf) { - if ((buf == NULL) || (buf->buffer.shm == NULL)) - { + if ((buf == NULL) || (buf->buffer.shm == NULL)) { dlt_vlog(LOG_ERR, "%s: Wrong parameter: Null pointer\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if (munmap(buf->buffer.shm, buf->buffer.min_size) == -1) - { - dlt_vlog(LOG_ERR, "%s: munmap() failed: %s\n", - __func__, strerror(errno)); + if (munmap(buf->buffer.shm, buf->buffer.min_size) == -1) { + dlt_vlog(LOG_ERR, "%s: munmap() failed: %s\n", __func__, strerror(errno)); } - if (sem_close(buf->sem) == -1) - { - dlt_vlog(LOG_ERR, "%s: sem_close() failed: %s\n", - __func__, strerror(errno)); + if (sem_close(buf->sem) == -1) { + dlt_vlog(LOG_ERR, "%s: sem_close() failed: %s\n", __func__, strerror(errno)); } /* Reset parameters */ diff --git a/src/shared/dlt_user_shared.c b/src/shared/dlt_user_shared.c index 127e30426..0c2f65159 100644 --- a/src/shared/dlt_user_shared.c +++ b/src/shared/dlt_user_shared.c @@ -76,7 +76,7 @@ #include "dlt_user_shared.h" #include "dlt_user_shared_cfg.h" -DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype) +DltReturnValue dlt_user_set_userheader(DltUserHeader* userheader, uint32_t mtype) { if (userheader == 0) return DLT_RETURN_ERROR; @@ -93,7 +93,7 @@ DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype return DLT_RETURN_OK; } -DltReturnValue dlt_user_set_userheader_v2(DltUserHeader *userheader, uint32_t mtype) +DltReturnValue dlt_user_set_userheader_v2(DltUserHeader* userheader, uint32_t mtype) { if (userheader == 0) return DLT_RETURN_ERROR; @@ -110,27 +110,26 @@ DltReturnValue dlt_user_set_userheader_v2(DltUserHeader *userheader, uint32_t mt return DLT_RETURN_OK; } -int dlt_user_check_userheader(DltUserHeader *userheader) +int dlt_user_check_userheader(DltUserHeader* userheader) { if (userheader == 0) return -1; - return (userheader->pattern[0] == 'D') && - (userheader->pattern[1] == 'U') && - (userheader->pattern[2] == 'H') && - ((userheader->pattern[3] == 1) || (userheader->pattern[3] == 2)); + return (userheader->pattern[0] == 'D') && (userheader->pattern[1] == 'U') && (userheader->pattern[2] == 'H') + && ((userheader->pattern[3] == 1) || (userheader->pattern[3] == 2)); } -int dlt_get_version_from_userheader(DltUserHeader *userheader){ +int dlt_get_version_from_userheader(DltUserHeader* userheader) +{ if (userheader == 0) return -1; - + int version = userheader->pattern[3]; - + return version; } -DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2) +DltReturnValue dlt_user_log_out2(int handle, void* ptr1, size_t len1, void* ptr2, size_t len2) { struct iovec iov[2]; uint32_t bytes_written; @@ -144,7 +143,7 @@ DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2 iov[1].iov_base = ptr2; iov[1].iov_len = len2; - bytes_written = (uint32_t) writev(handle, iov, 2); + bytes_written = (uint32_t)writev(handle, iov, 2); if (bytes_written != (len1 + len2)) return DLT_RETURN_ERROR; @@ -152,7 +151,7 @@ DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2 return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2) +DltReturnValue dlt_user_log_out2_with_timeout(int handle, void* ptr1, size_t len1, void* ptr2, size_t len2) { if (handle < 0) /* Invalid handle */ @@ -173,7 +172,7 @@ DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len } } -DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3) +DltReturnValue dlt_user_log_out3(int handle, void* ptr1, size_t len1, void* ptr2, size_t len2, void* ptr3, size_t len3) { struct iovec iov[3]; uint32_t bytes_written; @@ -189,32 +188,27 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2 iov[2].iov_base = ptr3; iov[2].iov_len = len3; - bytes_written = (uint32_t) writev(handle, iov, 3); + bytes_written = (uint32_t)writev(handle, iov, 3); if (bytes_written != (len1 + len2 + len3)) { switch (errno) { - case ETIMEDOUT: - { - return DLT_RETURN_PIPE_ERROR; /* ETIMEDOUT - connect timeout */ + case ETIMEDOUT: { + return DLT_RETURN_PIPE_ERROR; /* ETIMEDOUT - connect timeout */ break; } - case EBADF: - { - return DLT_RETURN_PIPE_ERROR; /* EBADF - handle not open */ + case EBADF: { + return DLT_RETURN_PIPE_ERROR; /* EBADF - handle not open */ break; } - case EPIPE: - { - return DLT_RETURN_PIPE_ERROR; /* EPIPE - pipe error */ + case EPIPE: { + return DLT_RETURN_PIPE_ERROR; /* EPIPE - pipe error */ break; } - case EAGAIN: - { - return DLT_RETURN_PIPE_FULL; /* EAGAIN - data could not be written */ + case EAGAIN: { + return DLT_RETURN_PIPE_FULL; /* EAGAIN - data could not be written */ break; } - default: - { + default: { break; } } @@ -225,7 +219,8 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2 return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_out3_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3) +DltReturnValue dlt_user_log_out3_with_timeout( + int handle, void* ptr1, size_t len1, void* ptr2, size_t len2, void* ptr3, size_t len3) { if (handle < 0) /* Invalid handle */ diff --git a/src/shared/dlt_user_shared.h b/src/shared/dlt_user_shared.h index 6be13bb7b..f43eb6eef 100644 --- a/src/shared/dlt_user_shared.h +++ b/src/shared/dlt_user_shared.h @@ -76,181 +76,165 @@ /** * This is the header of each message to be exchanged between application and daemon. */ -typedef struct -{ - char pattern[DLT_ID_SIZE]; /**< This pattern should be DUH0x01 */ - uint32_t message; /**< messsage info */ +typedef struct { + char pattern[DLT_ID_SIZE]; /**< This pattern should be DUH0x01 */ + uint32_t message; /**< messsage info */ } DLT_PACKED DltUserHeader; /** * This is the internal message content to exchange control msg register app information between application and daemon. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - pid_t pid; /**< process id of user application */ - uint32_t description_length; /**< length of description */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + pid_t pid; /**< process id of user application */ + uint32_t description_length; /**< length of description */ } DLT_PACKED DltUserControlMsgRegisterApplication; /** * This is the internal message content to exchange control msg register app information between application and daemon. */ -typedef struct -{ - uint8_t apidlen; /**< length of apllication id */ - char *apid; /**< application id */ - pid_t pid; /**< process id of user application */ - uint32_t description_length; /**< length of description */ +typedef struct { + uint8_t apidlen; /**< length of apllication id */ + char* apid; /**< application id */ + pid_t pid; /**< process id of user application */ + uint32_t description_length; /**< length of description */ } DLT_PACKED DltUserControlMsgRegisterApplicationV2; /** - * This is the internal message content to exchange control msg unregister app information between application and daemon. + * This is the internal message content to exchange control msg unregister app information between application and + * daemon. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - pid_t pid; /**< process id of user application */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + pid_t pid; /**< process id of user application */ } DLT_PACKED DltUserControlMsgUnregisterApplication; /** - * This is the internal message content to exchange control msg unregister app information between application and daemon. + * This is the internal message content to exchange control msg unregister app information between application and + * daemon. */ -typedef struct -{ - uint8_t apidlen; /**< length of apllication id */ - char *apid; /**< application id */ - pid_t pid; /**< process id of user application */ +typedef struct { + uint8_t apidlen; /**< length of apllication id */ + char* apid; /**< application id */ + pid_t pid; /**< process id of user application */ } DLT_PACKED DltUserControlMsgUnregisterApplicationV2; /** * This is the internal message content to exchange control msg register information between application and daemon. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ - int32_t log_level_pos; /**< offset in management structure on user-application side */ - int8_t log_level; /**< log level */ - int8_t trace_status; /**< trace status */ - pid_t pid; /**< process id of user application */ - uint32_t description_length; /**< length of description */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + int32_t log_level_pos; /**< offset in management structure on user-application side */ + int8_t log_level; /**< log level */ + int8_t trace_status; /**< trace status */ + pid_t pid; /**< process id of user application */ + uint32_t description_length; /**< length of description */ } DLT_PACKED DltUserControlMsgRegisterContext; /** * This is the internal message content to exchange control msg register information between application and daemon. */ -typedef struct -{ - uint8_t apidlen; /**< length of apllication id */ - char *apid; /**< application id */ - uint8_t ctidlen; /**< length of context id */ - char *ctid; /**< context id */ - int32_t log_level_pos; /**< offset in management structure on user-application side */ - int8_t log_level; /**< log level */ - int8_t trace_status; /**< trace status */ - pid_t pid; /**< process id of user application */ - uint32_t description_length; /**< length of description */ +typedef struct { + uint8_t apidlen; /**< length of apllication id */ + char* apid; /**< application id */ + uint8_t ctidlen; /**< length of context id */ + char* ctid; /**< context id */ + int32_t log_level_pos; /**< offset in management structure on user-application side */ + int8_t log_level; /**< log level */ + int8_t trace_status; /**< trace status */ + pid_t pid; /**< process id of user application */ + uint32_t description_length; /**< length of description */ } DLT_PACKED DltUserControlMsgRegisterContextV2; /** * This is the internal message content to exchange control msg unregister information between application and daemon. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - char ctid[DLT_ID_SIZE]; /**< context id */ - pid_t pid; /**< process id of user application */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + pid_t pid; /**< process id of user application */ } DLT_PACKED DltUserControlMsgUnregisterContext; /** * This is the internal message content to exchange control msg unregister information between application and daemon. */ -typedef struct -{ - uint8_t apidlen; /**< length of apllication id */ - char *apid; /**< application id */ - uint8_t ctidlen; /**< length of context id */ - char *ctid; /**< context id */ - pid_t pid; /**< process id of user application */ +typedef struct { + uint8_t apidlen; /**< length of apllication id */ + char* apid; /**< application id */ + uint8_t ctidlen; /**< length of context id */ + char* ctid; /**< context id */ + pid_t pid; /**< process id of user application */ } DLT_PACKED DltUserControlMsgUnregisterContextV2; /** * This is the internal message content to exchange control msg log level information between application and daemon. */ -typedef struct -{ - uint8_t log_level; /**< log level */ - uint8_t trace_status; /**< trace status */ - int32_t log_level_pos; /**< offset in management structure on user-application side */ +typedef struct { + uint8_t log_level; /**< log level */ + uint8_t trace_status; /**< trace status */ + int32_t log_level_pos; /**< offset in management structure on user-application side */ } DLT_PACKED DltUserControlMsgLogLevel; /** * This is the internal message content to exchange control msg injection information between application and daemon. */ -typedef struct -{ - int32_t log_level_pos; /**< offset in management structure on user-application side */ - uint32_t service_id; /**< service id of injection */ - uint32_t data_length_inject; /**< length of injection message data field */ +typedef struct { + int32_t log_level_pos; /**< offset in management structure on user-application side */ + uint32_t service_id; /**< service id of injection */ + uint32_t data_length_inject; /**< length of injection message data field */ } DLT_PACKED DltUserControlMsgInjection; /** * This is the internal message content to exchange information about application log level and trace stats between * application and daemon. */ -typedef struct -{ - char apid[DLT_ID_SIZE]; /**< application id */ - uint8_t log_level; /**< log level */ - uint8_t trace_status; /**< trace status */ +typedef struct { + char apid[DLT_ID_SIZE]; /**< application id */ + uint8_t log_level; /**< log level */ + uint8_t trace_status; /**< trace status */ } DLT_PACKED DltUserControlMsgAppLogLevelTraceStatus; /** * This is the internal message content to exchange information about application log level and trace stats between * application and daemon. */ -typedef struct -{ - uint8_t apidlen; /**< length of apllication id */ - char *apid; /**< application id */ - uint8_t log_level; /**< log level */ - uint8_t trace_status; /**< trace status */ +typedef struct { + uint8_t apidlen; /**< length of apllication id */ + char* apid; /**< application id */ + uint8_t log_level; /**< log level */ + uint8_t trace_status; /**< trace status */ } DLT_PACKED DltUserControlMsgAppLogLevelTraceStatusV2; /** * This is the internal message content to set the logging mode: off, external, internal, both. */ -typedef struct -{ - int8_t log_mode; /**< the mode to be used for logging: off, external, internal, both */ +typedef struct { + int8_t log_mode; /**< the mode to be used for logging: off, external, internal, both */ } DLT_PACKED DltUserControlMsgLogMode; /** * This is the internal message content to get the logging state: 0 = off, 1 = external client connected. */ -typedef struct -{ - int8_t log_state; /**< the state to be used for logging state: 0 = off, 1 = external client connected */ +typedef struct { + int8_t log_state; /**< the state to be used for logging state: 0 = off, 1 = external client connected */ } DLT_PACKED DltUserControlMsgLogState; /** * This is the internal message content to get the number of lost messages reported to the daemon. */ -typedef struct -{ - uint32_t overflow_counter; /**< counts the number of lost messages */ - char apid[4]; /**< application which lost messages */ +typedef struct { + uint32_t overflow_counter; /**< counts the number of lost messages */ + char apid[4]; /**< application which lost messages */ } DLT_PACKED DltUserControlMsgBufferOverflow; -typedef struct -{ - uint32_t overflow_counter; /**< counts the number of lost messages */ - uint8_t apidlen; /**< length of apllication id */ - char *apid; /**< application which lost messages */ +typedef struct { + uint32_t overflow_counter; /**< counts the number of lost messages */ + uint8_t apidlen; /**< length of apllication id */ + char* apid; /**< application which lost messages */ } DLT_PACKED DltUserControlMsgBufferOverflowV2; #ifdef DLT_TRACE_LOAD_CTRL_ENABLE -typedef struct -{ +typedef struct { char ctid[DLT_ID_SIZE]; uint32_t soft_limit; uint32_t hard_limit; @@ -259,8 +243,8 @@ typedef struct #endif /************************************************************************************************** -* The folowing functions are used shared between the user lib and the daemon implementation -**************************************************************************************************/ + * The folowing functions are used shared between the user lib and the daemon implementation + **************************************************************************************************/ /** * Set user header marker and store message type in user header @@ -268,7 +252,7 @@ typedef struct * @param mtype user message type of internal message * @return Value from DltReturnValue enum */ -DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype); +DltReturnValue dlt_user_set_userheader(DltUserHeader* userheader, uint32_t mtype); /** * DLTv2 Set user header marker and store message type in user header @@ -276,21 +260,21 @@ DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype * @param mtype user message type of internal message * @return Value from DltReturnValue enum */ -DltReturnValue dlt_user_set_userheader_v2(DltUserHeader *userheader, uint32_t mtype); +DltReturnValue dlt_user_set_userheader_v2(DltUserHeader* userheader, uint32_t mtype); /** * Check if user header contains its marker * @param userheader pointer to the userheader * @return 0 no, 1 yes, negative value if there was an error */ -int dlt_user_check_userheader(DltUserHeader *userheader); +int dlt_user_check_userheader(DltUserHeader* userheader); /** * Get version from user header * @param userheader pointer to the userheader * @return DLT Version */ -int dlt_get_version_from_userheader(DltUserHeader *userheader); +int dlt_get_version_from_userheader(DltUserHeader* userheader); /** * Atomic write to file descriptor, using vector of 2 elements @@ -301,7 +285,7 @@ int dlt_get_version_from_userheader(DltUserHeader *userheader); * @param len2 length of second segment of data to be written * @return Value from DltReturnValue enum */ -DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2); +DltReturnValue dlt_user_log_out2(int handle, void* ptr1, size_t len1, void* ptr2, size_t len2); /** * Atomic write to file descriptor, using vector of 2 elements with a timeout of 1s @@ -312,7 +296,7 @@ DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2 * @param len2 length of second segment of data to be written * @return Value from DltReturnValue enum */ -DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2); +DltReturnValue dlt_user_log_out2_with_timeout(int handle, void* ptr1, size_t len1, void* ptr2, size_t len2); /** * Atomic write to file descriptor, using vector of 3 elements @@ -325,7 +309,7 @@ DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len * @param len3 length of third segment of data to be written * @return Value from DltReturnValue enum */ -DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3); +DltReturnValue dlt_user_log_out3(int handle, void* ptr1, size_t len1, void* ptr2, size_t len2, void* ptr3, size_t len3); /** * Atomic write to file descriptor, using vector of 3 elements with a timeout of 1s @@ -338,7 +322,8 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2 * @param len3 length of third segment of data to be written * @return Value from DltReturnValue enum */ -DltReturnValue dlt_user_log_out3_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3); +DltReturnValue dlt_user_log_out3_with_timeout( + int handle, void* ptr1, size_t len1, void* ptr2, size_t len2, void* ptr3, size_t len3); #endif /* DLT_USER_SHARED_H */ diff --git a/src/shared/dlt_user_shared_cfg.h b/src/shared/dlt_user_shared_cfg.h index 773bb316e..b35b2232d 100644 --- a/src/shared/dlt_user_shared_cfg.h +++ b/src/shared/dlt_user_shared_cfg.h @@ -96,9 +96,8 @@ /* Internal defined values */ /* must be different from DltLogLevelType */ -#define DLT_USER_LOG_LEVEL_NOT_SET -2 +#define DLT_USER_LOG_LEVEL_NOT_SET -2 /* must be different from DltTraceStatusType */ #define DLT_USER_TRACE_STATUS_NOT_SET -2 #endif /* DLT_USER_SHARED_CFG_H */ - diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c index e7d1beb0d..bef45ed90 100644 --- a/src/system/dlt-system-filetransfer.c +++ b/src/system/dlt-system-filetransfer.c @@ -51,7 +51,7 @@ #include #ifdef linux -# include +#include #endif #include #include @@ -67,8 +67,8 @@ #include "dlt_filetransfer.h" #ifdef linux -# define INOTIFY_SZ (sizeof(struct inotify_event)) -# define INOTIFY_LEN (INOTIFY_SZ + NAME_MAX + 1) +#define INOTIFY_SZ (sizeof(struct inotify_event)) +#define INOTIFY_LEN (INOTIFY_SZ + NAME_MAX + 1) #endif #define Z_CHUNK_SZ 1024 * 128 #define COMPRESS_EXTENSION ".gz" @@ -77,7 +77,7 @@ /* From dlt_filetransfer */ -extern uint32_t getFileSerialNumber(const char *file, int *ok); +extern uint32_t getFileSerialNumber(const char* file, int* ok); DLT_IMPORT_CONTEXT(dltsystem) DLT_DECLARE_CONTEXT(filetransferContext) @@ -87,41 +87,39 @@ s_ft_inotify ino; #endif -char *origin_name(char *src) +char* origin_name(char* src) { - if (strlen((char *)basename(src)) > 10) { - return (char *)(basename(src) + 10); - } - else { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-filetransfer, error in recreating origin name!")); + if (strlen((char*)basename(src)) > 10) { + return (char*)(basename(src) + 10); + } else { + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-filetransfer, error in recreating origin name!")); return NULL; } } -char *unique_name(char *src) +char* unique_name(char* src) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, creating unique temporary file name.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, creating unique temporary file name.")); time_t t = time(NULL); int ok; uint32_t l = getFileSerialNumber(src, &ok) ^ (uint32_t)t; if (!ok) - return (char *)NULL; + return (char*)NULL; - char *basename_f = basename(src); + char* basename_f = basename(src); /* Length of ULONG_MAX + 1 */ size_t len = 11 + strlen(basename_f); if (len > NAME_MAX) { - DLT_LOG(dltsystem, DLT_LOG_WARN, - DLT_STRING("dlt-system-filetransfer, unique name creation needs to shorten the filename:"), - DLT_STRING(basename_f)); + DLT_LOG( + dltsystem, DLT_LOG_WARN, + DLT_STRING("dlt-system-filetransfer, unique name creation needs to shorten the filename:"), + DLT_STRING(basename_f)); len = NAME_MAX; } - char *ret = malloc(len); + char* ret = malloc(len); MALLOC_ASSERT(ret); snprintf(ret, len, "%010" PRIu32 "%s", l, basename_f); @@ -132,15 +130,14 @@ char *unique_name(char *src) * Function which only calls the relevant part to transfer the payload */ -void send_dumped_file(FiletransferOptions const *opts, char *dst_tosend) +void send_dumped_file(FiletransferOptions const* opts, char* dst_tosend) { /* check if a client is connected to the deamon. If not, try again in a second */ while (dlt_get_log_state() != 1) sleep(1); - char *fn = origin_name(dst_tosend); - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, sending dumped file:"), DLT_STRING(fn)); + char* fn = origin_name(dst_tosend); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sending dumped file:"), DLT_STRING(fn)); if (dlt_user_log_file_header_alias(&filetransferContext, dst_tosend, fn) == 0) { int pkgcount = dlt_user_log_file_packagesCount(&filetransferContext, dst_tosend); @@ -173,8 +170,7 @@ void send_dumped_file(FiletransferOptions const *opts, char *dst_tosend) dlt_user_log_file_end(&filetransferContext, dst_tosend, 1); } - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, sent dumped file")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sent dumped file")); } /** @@ -185,22 +181,19 @@ void send_dumped_file(FiletransferOptions const *opts, char *dst_tosend) * @param dst destination where to compress the file * @param level of compression **/ -int compress_file_to(char *src, char *dst, int level) +int compress_file_to(char* src, char* dst, int level) { - DLT_LOG(dltsystem, - DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, compressing file from:"), - DLT_STRING(src), - DLT_STRING("to:"), - DLT_STRING(dst)); - char *buf; + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, compressing file from:"), DLT_STRING(src), + DLT_STRING("to:"), DLT_STRING(dst)); + char* buf; char dst_mode[8]; snprintf(dst_mode, 8, "wb%d", level); gzFile dst_file; - FILE *src_file; + FILE* src_file; dst_file = gzopen(dst, dst_mode); @@ -249,48 +242,45 @@ int compress_file_to(char *src, char *dst, int level) * uses subdirecties for compressing and before sending, to avoid that those files get changed in the meanwhile * */ -int send_one(char *src, FiletransferOptions const *opts, int which) +int send_one(char* src, FiletransferOptions const* opts, int which) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, sending a file.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sending a file.")); /* Prepare all needed file names */ - char *fn = basename(src); + char* fn = basename(src); if (fn == NULL) { - DLT_LOG(dltsystem, - DLT_LOG_ERROR, - DLT_STRING("basename not valid")); + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("basename not valid")); return -1; } - char *src_copy = strndup(src, PATH_MAX); + char* src_copy = strndup(src, PATH_MAX); MALLOC_ASSERT(src_copy); /*dirname overwrites its argument anyway, */ /*but depending on argument returned address might change */ - char *fdir = dirname(src_copy); + char* fdir = dirname(src_copy); - char *dst_tosend;/*file which is going to be sent */ + char* dst_tosend; /*file which is going to be sent */ - char *rn = unique_name(src);/*new unique filename based on inode */ + char* rn = unique_name(src); /*new unique filename based on inode */ if (rn == NULL) { - DLT_LOG(dltsystem, - DLT_LOG_ERROR, - DLT_STRING("file information not available, may be file got overwritten")); + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("file information not available, may be file got overwritten")); return -1; } /* Compress if needed */ if (opts->Compression[which] > 0) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory for compressing it.")); + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory for compressing it.")); - char *dst_tocompress;/*file which is going to be compressed, the compressed one is named dst_tosend */ + char* dst_tocompress; /*file which is going to be compressed, the compressed one is named dst_tosend */ - size_t len = strlen(fdir) + strlen(SUBDIR_COMPRESS) + strlen(rn) + 3;/*the filename in .tocompress +2 for 2*"/", +1 for \0 */ + size_t len = strlen(fdir) + strlen(SUBDIR_COMPRESS) + strlen(rn) + + 3; /*the filename in .tocompress +2 for 2*"/", +1 for \0 */ dst_tocompress = malloc(len); MALLOC_ASSERT(dst_tocompress); @@ -298,17 +288,17 @@ int send_one(char *src, FiletransferOptions const *opts, int which) /*moving in subdir, from where it can be compressed */ if (rename(src, dst_tocompress) < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("Could not move file"), - DLT_STRING(src), - DLT_STRING(dst_tocompress)); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not move file"), DLT_STRING(src), + DLT_STRING(dst_tocompress)); free(rn); free(dst_tocompress); free(src_copy); return -1; } - len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + strlen(COMPRESS_EXTENSION) + 3;/*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */ + len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + strlen(COMPRESS_EXTENSION) + + 3; /*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */ dst_tosend = malloc(len); MALLOC_ASSERT(dst_tosend); snprintf(dst_tosend, len, "%s/%s/%s%s", fdir, SUBDIR_TOSEND, rn, COMPRESS_EXTENSION); @@ -323,26 +313,22 @@ int send_one(char *src, FiletransferOptions const *opts, int which) free(dst_tocompress); - } - else { + } else { /*move it directly into "tosend" */ - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory.")); size_t len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + 3; - dst_tosend = malloc(len);/*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */ + dst_tosend = malloc(len); /*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */ snprintf(dst_tosend, len, "%s/%s/%s", fdir, SUBDIR_TOSEND, rn); - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, Rename:"), DLT_STRING(src), DLT_STRING("to: "), - DLT_STRING(dst_tosend)); + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, Rename:"), DLT_STRING(src), + DLT_STRING("to: "), DLT_STRING(dst_tosend)); /*moving in subdir, from where it can be compressed */ if (rename(src, dst_tosend) < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("Could not move file"), - DLT_STRING(src), - DLT_STRING(dst_tosend)); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not move file"), DLT_STRING(src), DLT_STRING(dst_tosend)); free(rn); free(dst_tosend); free(src_copy); @@ -350,8 +336,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which) } } - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, File ready to send")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, File ready to send")); send_dumped_file(opts, dst_tosend); @@ -364,10 +349,10 @@ int send_one(char *src, FiletransferOptions const *opts, int which) } -int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, const char *send_dir) +int flush_dir_send(FiletransferOptions const* opts, const char* compress_dir, const char* send_dir) { - struct dirent *dp; - DIR *dir; + struct dirent* dp; + DIR* dir; dir = opendir(send_dir); if (dir != NULL) { @@ -375,27 +360,29 @@ int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, co if (dp->d_type != DT_REG) continue; - char *fn; - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, old compressed file found in send directory:"), - DLT_STRING(dp->d_name)); + char* fn; + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-filetransfer, old compressed file found in send directory:"), + DLT_STRING(dp->d_name)); size_t len = strlen(send_dir) + strlen(dp->d_name) + 2; fn = malloc(len); MALLOC_ASSERT(fn); snprintf(fn, len, "%s/%s", send_dir, dp->d_name); - /*if we have a file here and in the to_compress dir, we delete the to_send file: we can not be sure, that it has been properly compressed! */ - if (!strncmp(dp->d_name + strlen(dp->d_name) - strlen(COMPRESS_EXTENSION), COMPRESS_EXTENSION, - strlen(COMPRESS_EXTENSION))) { - + /*if we have a file here and in the to_compress dir, we delete the to_send file: we can not be sure, that it + * has been properly compressed! */ + if (!strncmp( + dp->d_name + strlen(dp->d_name) - strlen(COMPRESS_EXTENSION), COMPRESS_EXTENSION, + strlen(COMPRESS_EXTENSION))) { /*ends with ".gz" */ /*old file name (not: path) would have been: */ char tmp[strlen(dp->d_name) - strlen(COMPRESS_EXTENSION) + 1]; strncpy(tmp, dp->d_name, strlen(dp->d_name) - strlen(COMPRESS_EXTENSION)); tmp[strlen(dp->d_name) - strlen(COMPRESS_EXTENSION)] = '\0'; - len = strlen(tmp) + strlen(compress_dir) + 1 + 1;/*2 sizes + 1*"/" + \0 */ - char *path_uncompressed = malloc(len); + len = strlen(tmp) + strlen(compress_dir) + 1 + 1; /*2 sizes + 1*"/" + \0 */ + char* path_uncompressed = malloc(len); MALLOC_ASSERT(path_uncompressed); snprintf(path_uncompressed, len, "%s/%s", compress_dir, tmp); @@ -403,66 +390,61 @@ int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, co if (stat(path_uncompressed, &sb) == -1) { /*uncompressed equivalent does not exist. We can send it out. */ - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, sending file.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, sending file.")); send_dumped_file(opts, fn); - } - else { - /*There is an uncompressed file. Compression seems to have been interrupted -> delete the compressed file instead of sending it! */ - DLT_LOG(dltsystem, - DLT_LOG_DEBUG, - DLT_STRING( - "dlt-system-filetransfer, uncompressed version exists. Deleting partially compressed version.")); + } else { + /*There is an uncompressed file. Compression seems to have been interrupted -> delete the compressed + * file instead of sending it! */ + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-filetransfer, uncompressed version exists. Deleting partially " + "compressed version.")); if (sb.st_mode & S_IFREG) { - if (remove(fn) != 0) - /*"Error deleting file". Continue? If we would cancel, maybe the dump is never sent! Deletion would again be tried in next LC. */ - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("Error deleting file:"), DLT_STRING(fn)); - } - else { - /*"Oldfile is a not reg file. Is this possible? Can we compress a directory?: %s\n",path_uncompressed); */ - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING( - "dlt-system-filetransfer, Oldfile is a not regular file! Do we have a problem?"), - DLT_STRING(fn)); + /*"Error deleting file". Continue? If we would cancel, maybe the dump is never sent! + * Deletion would again be tried in next LC. */ + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error deleting file:"), DLT_STRING(fn)); + } else { + /*"Oldfile is a not reg file. Is this possible? Can we compress a directory?: + * %s\n",path_uncompressed); */ + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-filetransfer, Oldfile is a not regular file! Do we have a problem?"), + DLT_STRING(fn)); } } - free(path_uncompressed);/*it is no more used. It would be transferred in next step. */ - }/*it is a .gz file */ + free(path_uncompressed); /*it is no more used. It would be transferred in next step. */ + } /*it is a .gz file */ else { /*uncompressed file. We can just resend it, the action to put it here was a move action. */ - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, Sending uncompressed file from previous LC."), - DLT_STRING(fn)); + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, + DLT_STRING("dlt-system-filetransfer, Sending uncompressed file from previous LC."), DLT_STRING(fn)); send_dumped_file(opts, fn); } free(fn); } - } - else { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("Could not open directory"), - DLT_STRING(send_dir)); + } else { + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not open directory"), DLT_STRING(send_dir)); return -1; } - closedir(dir);/*end: send_dir */ + closedir(dir); /*end: send_dir */ return 0; } -int flush_dir_compress(FiletransferOptions const *opts, int which, const char *compress_dir, const char *send_dir) +int flush_dir_compress(FiletransferOptions const* opts, int which, const char* compress_dir, const char* send_dir) { - - /*check for files in compress_dir. Assumption: a file which lies here, should have been compressed, but that action was interrupted. */ + /*check for files in compress_dir. Assumption: a file which lies here, should have been compressed, but that action + * was interrupted. */ /*As it can arrive here only by a rename, it is most likely to be a complete file */ - struct dirent *dp; - DIR *dir; + struct dirent* dp; + DIR* dir; dir = opendir(compress_dir); if (dir != NULL) { @@ -470,19 +452,19 @@ int flush_dir_compress(FiletransferOptions const *opts, int which, const char *c if (dp->d_type != DT_REG) continue; - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, old file found in compress-directory.")); + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, old file found in compress-directory.")); /*compress file into to_send dir */ size_t len = strlen(compress_dir) + strlen(dp->d_name) + 2; - char *cd_filename = malloc(len); + char* cd_filename = malloc(len); MALLOC_ASSERT(cd_filename); snprintf(cd_filename, len, "%s/%s", compress_dir, dp->d_name); len = strlen(send_dir) + strlen(dp->d_name) + strlen(COMPRESS_EXTENSION) + 2; - char *dst_tosend = malloc(len);/*the resulting filename in .tosend +2 for 1*"/", +1 for \0 + .gz */ + char* dst_tosend = malloc(len); /*the resulting filename in .tosend +2 for 1*"/", +1 for \0 + .gz */ MALLOC_ASSERT(dst_tosend); snprintf(dst_tosend, len, "%s/%s%s", send_dir, dp->d_name, COMPRESS_EXTENSION); @@ -498,24 +480,21 @@ int flush_dir_compress(FiletransferOptions const *opts, int which, const char *c free(dst_tosend); free(cd_filename); } - } - else { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("Could not open directory"), - DLT_STRING(compress_dir)); + } else { + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not open directory"), DLT_STRING(compress_dir)); return -1; } - closedir(dir);/*end: compress_dir */ + closedir(dir); /*end: compress_dir */ return 0; } -int flush_dir_original(FiletransferOptions const *opts, int which) +int flush_dir_original(FiletransferOptions const* opts, int which) { - struct dirent *dp; - DIR *dir; - const char *sdir = opts->Directory[which]; + struct dirent* dp; + DIR* dir; + const char* sdir = opts->Directory[which]; dir = opendir(sdir); if (dir != NULL) { @@ -524,10 +503,9 @@ int flush_dir_original(FiletransferOptions const *opts, int which) /*we don't send directories */ continue; - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, old file found in directory.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, old file found in directory.")); size_t len = strlen(sdir) + strlen(dp->d_name) + 2; - char *fn = malloc(len); + char* fn = malloc(len); MALLOC_ASSERT(fn); snprintf(fn, len, "%s/%s", sdir, dp->d_name); @@ -539,11 +517,8 @@ int flush_dir_original(FiletransferOptions const *opts, int which) free(fn); } - } - else { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("Could not open directory"), - DLT_STRING(sdir)); + } else { + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not open directory"), DLT_STRING(sdir)); return -1; } @@ -557,20 +532,19 @@ int flush_dir_original(FiletransferOptions const *opts, int which) * @param which which directory is affected -> position in list of opts->Directory * @return Returns 0 if everything was okay. If there was a failure a value < 0 will be returned. */ -int flush_dir(FiletransferOptions const *opts, int which) +int flush_dir(FiletransferOptions const* opts, int which) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, flush directory of old files.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, flush directory of old files.")); - char *compress_dir; - char *send_dir; + char* compress_dir; + char* send_dir; size_t len = strlen(opts->Directory[which]) + strlen(SUBDIR_COMPRESS) + 2; - compress_dir = malloc (len); + compress_dir = malloc(len); MALLOC_ASSERT(compress_dir); snprintf(compress_dir, len, "%s/%s", opts->Directory[which], SUBDIR_COMPRESS); len = strlen(opts->Directory[which]) + strlen(SUBDIR_TOSEND) + 2; - send_dir = malloc (len); + send_dir = malloc(len); MALLOC_ASSERT(send_dir); snprintf(send_dir, len, "%s/%s", opts->Directory[which], SUBDIR_TOSEND); @@ -588,7 +562,7 @@ int flush_dir(FiletransferOptions const *opts, int which) return -1; } - free(send_dir);/*no more used */ + free(send_dir); /*no more used */ free(compress_dir); /*last step: scan the original directory - we can reuse the send_one function */ @@ -603,19 +577,19 @@ int flush_dir(FiletransferOptions const *opts, int which) * @param config DltSystemConfiguration * @return Returns 0 if everything was okay. If there was a failure a value < 0 will be returned. */ -int init_filetransfer_dirs(DltSystemConfiguration *config) +int init_filetransfer_dirs(DltSystemConfiguration* config) { - FiletransferOptions const *opts = &(config->Filetransfer); + FiletransferOptions const* opts = &(config->Filetransfer); DLT_REGISTER_CONTEXT(filetransferContext, config->Filetransfer.ContextId, "Filetransfer Adapter"); - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, initializing inotify on directories.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, initializing inotify on directories.")); int i; #ifdef linux ino.handle = inotify_init(); if (ino.handle < 0) { - DLT_LOG(filetransferContext, DLT_LOG_FATAL, - DLT_STRING("Failed to initialize inotify in dlt-system file transfer.")); + DLT_LOG( + filetransferContext, DLT_LOG_FATAL, + DLT_STRING("Failed to initialize inotify in dlt-system file transfer.")); return -1; } @@ -624,67 +598,59 @@ int init_filetransfer_dirs(DltSystemConfiguration *config) for (i = 0; i < opts->Count; i++) { /*create subdirectories for processing the files */ - char *subdirpath; + char* subdirpath; size_t len = strlen(opts->Directory[i]) + strlen(SUBDIR_COMPRESS) + 2; - subdirpath = malloc (len); + subdirpath = malloc(len); MALLOC_ASSERT(subdirpath); snprintf(subdirpath, len, "%s/%s", opts->Directory[i], SUBDIR_COMPRESS); int ret = mkdir(subdirpath, 0777); if ((0 != ret) && (EEXIST != errno)) { - DLT_LOG(dltsystem, - DLT_LOG_ERROR, - DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "), - DLT_STRING(subdirpath), - DLT_STRING(" Errorcode: "), - DLT_INT(errno)); - free (subdirpath); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "), + DLT_STRING(subdirpath), DLT_STRING(" Errorcode: "), DLT_INT(errno)); + free(subdirpath); return -1; } free(subdirpath); len = strlen(opts->Directory[i]) + strlen(SUBDIR_TOSEND) + 2; - subdirpath = malloc (len); + subdirpath = malloc(len); MALLOC_ASSERT(subdirpath); snprintf(subdirpath, len, "%s/%s", opts->Directory[i], SUBDIR_TOSEND); ret = mkdir(subdirpath, 0777); if ((0 != ret) && (EEXIST != errno)) { - DLT_LOG(dltsystem, - DLT_LOG_ERROR, - DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "), - DLT_STRING(subdirpath), - DLT_STRING(" Errorcode: "), - DLT_INT(errno)); - free (subdirpath); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-filetransfer, error creating subdirectory: "), + DLT_STRING(subdirpath), DLT_STRING(" Errorcode: "), DLT_INT(errno)); + free(subdirpath); return -1; } free(subdirpath); #ifdef linux - ino.fd[i] = inotify_add_watch(ino.handle, opts->Directory[i], - IN_CLOSE_WRITE | IN_MOVED_TO); + ino.fd[i] = inotify_add_watch(ino.handle, opts->Directory[i], IN_CLOSE_WRITE | IN_MOVED_TO); if (ino.fd[i] < 0) { char buf[1024]; - snprintf(buf, 1024, "Failed to add inotify watch to directory %s in dlt-system file transfer.", - opts->Directory[i]); - DLT_LOG(filetransferContext, DLT_LOG_FATAL, - DLT_STRING(buf)); + snprintf( + buf, 1024, "Failed to add inotify watch to directory %s in dlt-system file transfer.", + opts->Directory[i]); + DLT_LOG(filetransferContext, DLT_LOG_FATAL, DLT_STRING(buf)); return -1; } #endif flush_dir(opts, i); - } return 0; } -int process_files(FiletransferOptions const *opts) +int process_files(FiletransferOptions const* opts) { #ifdef linux DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, processing files.")); @@ -692,15 +658,16 @@ int process_files(FiletransferOptions const *opts) ssize_t len = read(ino.handle, buf, INOTIFY_LEN); if (len < 0) { - DLT_LOG(filetransferContext, DLT_LOG_ERROR, - DLT_STRING("Error while reading events for files in dlt-system file transfer.")); + DLT_LOG( + filetransferContext, DLT_LOG_ERROR, + DLT_STRING("Error while reading events for files in dlt-system file transfer.")); return -1; } ssize_t i = 0; while (i < (len - (ssize_t)INOTIFY_SZ)) { - struct inotify_event *ie = (struct inotify_event *)&buf[i]; + struct inotify_event* ie = (struct inotify_event*)&buf[i]; if (ie->len > 0) { if ((ie->mask & IN_CLOSE_WRITE) || (ie->mask & IN_MOVED_TO)) { @@ -708,22 +675,21 @@ int process_files(FiletransferOptions const *opts) for (j = 0; j < opts->Count; j++) if (ie->wd == ino.fd[j]) { - DLT_LOG(dltsystem, - DLT_LOG_DEBUG, - DLT_STRING("dlt-system-filetransfer, found new file."), - DLT_STRING(ie->name)); + DLT_LOG( + dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, found new file."), + DLT_STRING(ie->name)); size_t length = strlen(opts->Directory[j]) + ie->len + 1 + 1; if (length > PATH_MAX) { - DLT_LOG(filetransferContext, - DLT_LOG_ERROR, - DLT_STRING( - "dlt-system-filetransfer: Very long path for file transfer. Cancelling transfer! Length is: "), - DLT_INT((int)length)); + DLT_LOG( + filetransferContext, DLT_LOG_ERROR, + DLT_STRING("dlt-system-filetransfer: Very long path for file transfer. Cancelling " + "transfer! Length is: "), + DLT_INT((int)length)); return -1; } - char *tosend = malloc(length); + char* tosend = malloc(length); snprintf(tosend, length, "%s/%s", opts->Directory[j], ie->name); send_one(tosend, opts, j); free(tosend); @@ -738,7 +704,7 @@ int process_files(FiletransferOptions const *opts) return 0; } -void filetransfer_fd_handler(DltSystemConfiguration *config) +void filetransfer_fd_handler(DltSystemConfiguration* config) { process_files(&(config->Filetransfer)); } diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c index d9dfbc4ba..b22b6536e 100644 --- a/src/system/dlt-system-journal.c +++ b/src/system/dlt-system-journal.c @@ -64,8 +64,7 @@ #define DLT_SYSTEM_JOURNAL_ASCII_FIRST_VISIBLE_CHARACTER 31 #define DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH 9 + 32 + 1 -typedef struct -{ +typedef struct { char real[DLT_SYSTEM_JOURNAL_BUFFER_SIZE]; char monotonic[DLT_SYSTEM_JOURNAL_BUFFER_SIZE]; } MessageTimestamp; @@ -85,9 +84,9 @@ int journal_checkUserBufferForFreeSpace() return 1; } -int dlt_system_journal_get(sd_journal *j, char *target, const char *field, size_t max_size) +int dlt_system_journal_get(sd_journal* j, char* target, const char* field, size_t max_size) { - char *data; + char* data; size_t length; int error_code; size_t field_size; @@ -100,7 +99,7 @@ int dlt_system_journal_get(sd_journal *j, char *target, const char *field, size_ target[0] = 0; /* get data from journal */ - error_code = sd_journal_get_data(j, field, (const void **)&data, &length); + error_code = sd_journal_get_data(j, field, (const void**)&data, &length); /* check if an error */ if (error_code) @@ -118,12 +117,10 @@ int dlt_system_journal_get(sd_journal *j, char *target, const char *field, size_ /* truncate */ strncpy(target, data + field_size, max_size - 1); target[max_size - 1] = 0; - } - else { + } else { /* full copy */ strncpy(target, data + field_size, length - field_size); target[length - field_size] = 0; - } /* debug messages */ @@ -133,16 +130,16 @@ int dlt_system_journal_get(sd_journal *j, char *target, const char *field, size_ return 0; } -void dlt_system_journal_get_timestamp(sd_journal *journal, MessageTimestamp *timestamp) +void dlt_system_journal_get_timestamp(sd_journal* journal, MessageTimestamp* timestamp) { int ret = 0; time_t time_secs = 0; uint64_t time_usecs = 0; struct tm timeinfo; - char buffer_realtime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }; - char buffer_realtime_formatted[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }; - char buffer_monotime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }; + char buffer_realtime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}; + char buffer_realtime_formatted[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}; + char buffer_monotime[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}; /* Try to get realtime from message source and if not successful try to get realtime from journal entry */ ret = dlt_system_journal_get(journal, buffer_realtime, "_SOURCE_REALTIME_TIMESTAMP", sizeof(buffer_realtime)); @@ -153,12 +150,10 @@ void dlt_system_journal_get_timestamp(sd_journal *journal, MessageTimestamp *tim if (errno != 0) time_usecs = 0; - } - else if ((ret = sd_journal_get_realtime_usec(journal, &time_usecs)) < 0) - { - DLT_LOG(dltsystem, DLT_LOG_WARN, - DLT_STRING("dlt-system-journal failed to get realtime: "), - DLT_STRING(strerror(-ret))); + } else if ((ret = sd_journal_get_realtime_usec(journal, &time_usecs)) < 0) { + DLT_LOG( + dltsystem, DLT_LOG_WARN, DLT_STRING("dlt-system-journal failed to get realtime: "), + DLT_STRING(strerror(-ret))); /* just to be sure to have a defined value */ time_usecs = 0; @@ -169,10 +164,11 @@ void dlt_system_journal_get_timestamp(sd_journal *journal, MessageTimestamp *tim localtime_r(&time_secs, &timeinfo); strftime(buffer_realtime_formatted, sizeof(buffer_realtime_formatted), "%Y/%m/%d %H:%M:%S", &timeinfo); - snprintf(timestamp->real, sizeof(timestamp->real), "%s.%06" PRIu64, buffer_realtime_formatted, - time_usecs % 1000000); + snprintf( + timestamp->real, sizeof(timestamp->real), "%s.%06" PRIu64, buffer_realtime_formatted, time_usecs % 1000000); - /* Try to get monotonic time from message source and if not successful try to get monotonic time from journal entry */ + /* Try to get monotonic time from message source and if not successful try to get monotonic time from journal entry + */ ret = dlt_system_journal_get(journal, buffer_monotime, "_SOURCE_MONOTONIC_TIMESTAMP", sizeof(buffer_monotime)); if ((ret == 0) && (strlen(buffer_monotime) > 0)) { @@ -181,58 +177,51 @@ void dlt_system_journal_get_timestamp(sd_journal *journal, MessageTimestamp *tim if (errno != 0) time_usecs = 0; - } - else if ((ret = sd_journal_get_monotonic_usec(journal, &time_usecs, NULL)) < 0) - { - DLT_LOG(dltsystem, DLT_LOG_WARN, - DLT_STRING("dlt-system-journal failed to get monotonic time: "), - DLT_STRING(strerror(-ret))); + } else if ((ret = sd_journal_get_monotonic_usec(journal, &time_usecs, NULL)) < 0) { + DLT_LOG( + dltsystem, DLT_LOG_WARN, DLT_STRING("dlt-system-journal failed to get monotonic time: "), + DLT_STRING(strerror(-ret))); /* just to be sure to have a defined value */ time_usecs = 0; } - snprintf(timestamp->monotonic, - sizeof(timestamp->monotonic), - "%" PRId64 ".%06" PRIu64, - time_usecs / 1000000, - time_usecs % 1000000); + snprintf( + timestamp->monotonic, sizeof(timestamp->monotonic), "%" PRId64 ".%06" PRIu64, time_usecs / 1000000, + time_usecs % 1000000); } -void get_journal_msg(sd_journal *j, DltSystemConfiguration *config) -{ +void get_journal_msg(sd_journal* j, DltSystemConfiguration* config) +{ uint32_t ts; int r; - char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, - buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, - buffer_pid[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, - buffer_comm[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, - buffer_message[DLT_SYSTEM_JOURNAL_BUFFER_SIZE_BIG] = { 0 }, - buffer_transport[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }; + char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}, buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}, + buffer_pid[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}, buffer_comm[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}, + buffer_message[DLT_SYSTEM_JOURNAL_BUFFER_SIZE_BIG] = {0}, + buffer_transport[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = {0}; MessageTimestamp timestamp; int loglevel, systemd_loglevel; - char *systemd_log_levels[] = - { "Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug" }; + char* systemd_log_levels[] = { + "Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug"}; - for(;;) - { + for (;;) { r = sd_journal_next(j); if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal failed to get next entry:"), DLT_STRING(strerror(-r))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to get next entry:"), + DLT_STRING(strerror(-r))); sd_journal_close(j); return; - } - else if (r == 0) { + } else if (r == 0) { return; } - #if defined(DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM) && defined(DLT_SYSTEMD_JOURNAL_ENABLE) +#if defined(DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM) && defined(DLT_SYSTEMD_JOURNAL_ENABLE) config->Journal.MessageReceived = 1; - #endif +#endif /* get all data from current journal entry */ dlt_system_journal_get_timestamp(j, ×tamp); @@ -257,22 +246,22 @@ void get_journal_msg(sd_journal *j, DltSystemConfiguration *config) if (config->Journal.MapLogLevels) { /* Map log levels from journal to DLT */ switch (systemd_loglevel) { - case 0: /* Emergency */ - case 1: /* Alert */ - case 2: /* Critical */ + case 0: /* Emergency */ + case 1: /* Alert */ + case 2: /* Critical */ loglevel = DLT_LOG_FATAL; break; - case 3: /* Error */ + case 3: /* Error */ loglevel = DLT_LOG_ERROR; break; - case 4: /* Warning */ + case 4: /* Warning */ loglevel = DLT_LOG_WARN; break; - case 5: /* Notice */ - case 6: /* Informational */ + case 5: /* Notice */ + case 6: /* Informational */ loglevel = DLT_LOG_INFO; break; - case 7: /* Debug */ + case 7: /* Debug */ loglevel = DLT_LOG_DEBUG; break; default: @@ -288,34 +277,22 @@ void get_journal_msg(sd_journal *j, DltSystemConfiguration *config) if (config->Journal.UseUptimeOnly == 1) { /* write log entry (uptime only, no timestamp) */ - DLT_LOG(journalContext, loglevel, - DLT_STRING(timestamp.monotonic), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); - } - else { + DLT_LOG( + journalContext, loglevel, DLT_STRING(timestamp.monotonic), DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), DLT_STRING(buffer_message)); + } else { /* write log entry (including timestamp) */ if (config->Journal.UseOriginalTimestamp == 0) { - DLT_LOG(journalContext, loglevel, - DLT_STRING(timestamp.real), - DLT_STRING(timestamp.monotonic), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); + DLT_LOG( + journalContext, loglevel, DLT_STRING(timestamp.real), DLT_STRING(timestamp.monotonic), + DLT_STRING(buffer_process), DLT_STRING(buffer_priority), DLT_STRING(buffer_message)); - } - else { + } else { /* since we are talking about points in time, I'd prefer truncating over arithmetic rounding */ ts = (uint32_t)(atof(timestamp.monotonic) * 10000); - DLT_LOG_TS(journalContext, loglevel, ts, - DLT_STRING(timestamp.real), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); + DLT_LOG_TS( + journalContext, loglevel, ts, DLT_STRING(timestamp.real), DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), DLT_STRING(buffer_message)); } } @@ -331,10 +308,10 @@ void get_journal_msg(sd_journal *j, DltSystemConfiguration *config) } } -void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSystemConfiguration *config) +void register_journal_fd(sd_journal** j, struct pollfd* pollfd, int i, DltSystemConfiguration* config) { DLT_REGISTER_CONTEXT(journalContext, config->Journal.ContextId, "Journal Adapter"); - sd_journal *j_tmp; + sd_journal* j_tmp; char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID="; sd_id128_t boot_id; int r; @@ -342,8 +319,8 @@ void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSyste r = sd_journal_open(&j_tmp, SD_JOURNAL_LOCAL_ONLY /*SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_RUNTIME_ONLY*/); printf("journal open return %d\n", r); if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal, cannot open journal:"), DLT_STRING(strerror(-r))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal, cannot open journal:"), DLT_STRING(strerror(-r))); printf("journal open failed: %s\n", strerror(-r)); j_tmp = NULL; } @@ -352,8 +329,9 @@ void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSyste /* show only current boot entries */ r = sd_id128_get_boot(&boot_id); if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal failed to get boot id:"), DLT_STRING(strerror(-r))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to get boot id:"), + DLT_STRING(strerror(-r))); sd_journal_close(j_tmp); j_tmp = NULL; } @@ -361,8 +339,9 @@ void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSyste sd_id128_to_string(boot_id, match + 9); r = sd_journal_add_match(j_tmp, match, strlen(match)); if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal failed to get match:"), DLT_STRING(strerror(-r))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to get match:"), + DLT_STRING(strerror(-r))); sd_journal_close(j_tmp); j_tmp = NULL; } @@ -372,30 +351,34 @@ void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSyste /* show only last 10 entries and follow */ r = sd_journal_seek_tail(j_tmp); if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal failed to seek to tail:"), DLT_STRING(strerror(-r))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to seek to tail:"), + DLT_STRING(strerror(-r))); sd_journal_close(j_tmp); j_tmp = NULL; } r = sd_journal_previous_skip(j_tmp, 10); if (r < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-journal failed to seek back 10 entries:"), DLT_STRING(strerror(-r))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-journal failed to seek back 10 entries:"), + DLT_STRING(strerror(-r))); sd_journal_close(j_tmp); j_tmp = NULL; } } pollfd[i].fd = sd_journal_get_fd(j_tmp); - if(pollfd[i].fd < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal fd: "), + if (pollfd[i].fd < 0) { + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal fd: "), DLT_STRING(strerror(pollfd[i].fd))); j_tmp = NULL; } pollfd[i].events = (short int)sd_journal_get_events(j_tmp); - if(pollfd[i].events < 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal events: "), + if (pollfd[i].events < 0) { + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal events: "), DLT_STRING(strerror(pollfd[i].events))); j_tmp = NULL; } @@ -410,12 +393,11 @@ void* journal_thread(void* journalParams) while (*params->quit == 0) { ready = poll(params->journalPollFd, 1, -1); if (ready == -1) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while poll. Exit with: "), - DLT_STRING(strerror(ready))); + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while poll. Exit with: "), DLT_STRING(strerror(ready))); continue; } - if(params->journalPollFd->revents & POLLIN) { + if (params->journalPollFd->revents & POLLIN) { if (sd_journal_process(params->j) == SD_JOURNAL_APPEND) { get_journal_msg(params->j, params->config); } diff --git a/src/system/dlt-system-logfile.c b/src/system/dlt-system-logfile.c index 6a488e41c..f7b274bc2 100644 --- a/src/system/dlt-system-logfile.c +++ b/src/system/dlt-system-logfile.c @@ -48,20 +48,19 @@ #include "dlt-system.h" /* Modes of sending */ -#define SEND_MODE_OFF 0 +#define SEND_MODE_OFF 0 #define SEND_MODE_ONCE 1 -#define SEND_MODE_ON 2 +#define SEND_MODE_ON 2 DLT_IMPORT_CONTEXT(dltsystem) DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX]; int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX]; -void send_file(LogFileOptions const *fileopt, int n) +void send_file(LogFileOptions const* fileopt, int n) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-logfile, sending file.")); - FILE *pFile; + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, sending file.")); + FILE* pFile; DltContext context = logfileContext[n]; char buffer[1024]; size_t bytes; @@ -77,37 +76,32 @@ void send_file(LogFileOptions const *fileopt, int n) if (feof(pFile)) { DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq * -1), DLT_STRING(buffer)); break; - } - else { + } else { DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer)); } } fclose(pFile); - } - else { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-logfile, failed to open file."), - DLT_STRING((*fileopt).Filename[n])); + } else { + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-logfile, failed to open file."), + DLT_STRING((*fileopt).Filename[n])); } } -void register_contexts(LogFileOptions const *fileopts) +void register_contexts(LogFileOptions const* fileopts) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-logfile, registering file contexts.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, registering file contexts.")); int i; for (i = 0; i < (*fileopts).Count; i++) - DLT_REGISTER_CONTEXT(logfileContext[i], (*fileopts).ContextId[i], - (*fileopts).Filename[i]); + DLT_REGISTER_CONTEXT(logfileContext[i], (*fileopts).ContextId[i], (*fileopts).Filename[i]); } -void logfile_init(void *v_conf) +void logfile_init(void* v_conf) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-logfile, in thread.")); - DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-logfile, in thread.")); + DltSystemConfiguration* conf = (DltSystemConfiguration*)v_conf; register_contexts(&(conf->LogFile)); @@ -115,9 +109,9 @@ void logfile_init(void *v_conf) logfile_delays[i] = conf->LogFile.TimeDelay[i]; } -void logfile_fd_handler(void *v_conf) +void logfile_fd_handler(void* v_conf) { - DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DltSystemConfiguration* conf = (DltSystemConfiguration*)v_conf; for (int i = 0; i < conf->LogFile.Count; i++) { if (conf->LogFile.Mode[i] == SEND_MODE_OFF) continue; @@ -128,10 +122,8 @@ void logfile_fd_handler(void *v_conf) if (conf->LogFile.Mode[i] == SEND_MODE_ONCE) conf->LogFile.Mode[i] = SEND_MODE_OFF; - } - else { + } else { logfile_delays[i]--; } } } - diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c index c02b3d341..e67dcaaf5 100644 --- a/src/system/dlt-system-options.c +++ b/src/system/dlt-system-options.c @@ -61,7 +61,7 @@ /** * Print information how to use this program. */ -void usage(char *prog_name) +void usage(char* prog_name) { char version[255]; dlt_get_version(version, 255); @@ -79,7 +79,7 @@ void usage(char *prog_name) /** * Initialize command line options with default values. */ -void init_cli_options(DltSystemCliOptions *options) +void init_cli_options(DltSystemCliOptions* options) { options->ConfigurationFileName = strdup(DEFAULT_CONF_FILE); options->freeConfigFileName = 0; @@ -89,34 +89,32 @@ void init_cli_options(DltSystemCliOptions *options) /** * Read command line options and set the values in provided structure */ -int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]) +int read_command_line(DltSystemCliOptions* options, int argc, char* argv[]) { init_cli_options(options); int opt; while ((opt = getopt(argc, argv, "c:hd")) != -1) switch (opt) { - case 'd': - { + case 'd': { options->Daemonize = 1; break; } - case 'c': - { + case 'c': { options->ConfigurationFileName = malloc(strlen(optarg) + 1); options->freeConfigFileName = 1; MALLOC_ASSERT(options->ConfigurationFileName); - strcpy(options->ConfigurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */ + strcpy( + options->ConfigurationFileName, + optarg); /* strcpy unritical here, because size matches exactly the size to be copied */ break; } - case 'h': - { + case 'h': { usage(argv[0]); exit(0); - return -1; /*for parasoft */ + return -1; /*for parasoft */ } - default: - { + default: { fprintf(stderr, "Unknown option '%c'\n", optopt); usage(argv[0]); return -1; @@ -129,7 +127,7 @@ int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]) /** * Initialize configuration to default values. */ -void init_configuration(DltSystemConfiguration *config) +void init_configuration(DltSystemConfiguration* config) { int i = 0; @@ -192,9 +190,9 @@ void init_configuration(DltSystemConfiguration *config) /** * Read options from the configuration file */ -int read_configuration_file(DltSystemConfiguration *config, char *file_name) +int read_configuration_file(DltSystemConfiguration* config, char* file_name) { - FILE *file; + FILE* file; char *line, *token, *value, *pch; int ret = 0; @@ -219,7 +217,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) token[0] = 0; value[0] = 0; - pch = strtok (line, " =\r\n"); + pch = strtok(line, " =\r\n"); while (pch != NULL) { if (pch[0] == '#') @@ -228,14 +226,13 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) if (token[0] == 0) { strncpy(token, pch, MAX_LINE - 1); token[MAX_LINE - 1] = 0; - } - else { + } else { strncpy(value, pch, MAX_LINE); value[MAX_LINE - 1] = 0; break; } - pch = strtok (NULL, " =\r\n"); + pch = strtok(NULL, " =\r\n"); } if (token[0] && value[0]) { @@ -245,169 +242,119 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) } /* Shell */ - else if (strcmp(token, "ShellEnable") == 0) - { + else if (strcmp(token, "ShellEnable") == 0) { config->Shell.Enable = (uint16_t)atoi(value); } /* Syslog */ - else if (strcmp(token, "SyslogEnable") == 0) - { + else if (strcmp(token, "SyslogEnable") == 0) { config->Syslog.Enable = atoi(value); - } - else if (strcmp(token, "SyslogContextId") == 0) - { + } else if (strcmp(token, "SyslogContextId") == 0) { strncpy(config->Syslog.ContextId, value, DLT_ID_SIZE); - } - else if (strcmp(token, "SyslogPort") == 0) - { + } else if (strcmp(token, "SyslogPort") == 0) { config->Syslog.Port = (uint16_t)atoi(value); } /* Journal */ - else if (strcmp(token, "JournalEnable") == 0) - { + else if (strcmp(token, "JournalEnable") == 0) { config->Journal.Enable = atoi(value); - } - else if (strcmp(token, "JournalContextId") == 0) - { + } else if (strcmp(token, "JournalContextId") == 0) { strncpy(config->Journal.ContextId, value, DLT_ID_SIZE); - } - else if (strcmp(token, "JournalCurrentBoot") == 0) - { + } else if (strcmp(token, "JournalCurrentBoot") == 0) { config->Journal.CurrentBoot = atoi(value); - } - else if (strcmp(token, "JournalFollow") == 0) - { + } else if (strcmp(token, "JournalFollow") == 0) { config->Journal.Follow = atoi(value); - } - else if (strcmp(token, "JournalMapLogLevels") == 0) - { + } else if (strcmp(token, "JournalMapLogLevels") == 0) { config->Journal.MapLogLevels = atoi(value); - } - else if (strcmp(token, "JournalUseOriginalTimestamp") == 0) - { + } else if (strcmp(token, "JournalUseOriginalTimestamp") == 0) { config->Journal.UseOriginalTimestamp = atoi(value); - } - else if (strcmp(token, "JournalUseUptimeOnly") == 0) - { + } else if (strcmp(token, "JournalUseUptimeOnly") == 0) { config->Journal.UseUptimeOnly = atoi(value); } /* File transfer */ - else if (strcmp(token, "FiletransferEnable") == 0) - { + else if (strcmp(token, "FiletransferEnable") == 0) { config->Filetransfer.Enable = atoi(value); - } - else if (strcmp(token, "FiletransferContextId") == 0) - { + } else if (strcmp(token, "FiletransferContextId") == 0) { strncpy(config->Filetransfer.ContextId, value, DLT_ID_SIZE); - } - else if (strcmp(token, "FiletransferTimeStartup") == 0) - { + } else if (strcmp(token, "FiletransferTimeStartup") == 0) { config->Filetransfer.TimeStartup = atoi(value); - } - else if (strcmp(token, "FiletransferTimeoutBetweenLogs") == 0) - { + } else if (strcmp(token, "FiletransferTimeoutBetweenLogs") == 0) { config->Filetransfer.TimeoutBetweenLogs = (unsigned int)atoi(value); - } - else if (strcmp(token, "FiletransferDirectory") == 0) - { + } else if (strcmp(token, "FiletransferDirectory") == 0) { config->Filetransfer.Directory[config->Filetransfer.Count] = malloc(strlen(value) + 1); MALLOC_ASSERT(config->Filetransfer.Directory[config->Filetransfer.Count]); - strcpy(config->Filetransfer.Directory[config->Filetransfer.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */ - } - else if (strcmp(token, "FiletransferCompression") == 0) - { + strcpy( + config->Filetransfer.Directory[config->Filetransfer.Count], + value); /* strcpy unritical here, because size matches exactly the size to be copied */ + } else if (strcmp(token, "FiletransferCompression") == 0) { config->Filetransfer.Compression[config->Filetransfer.Count] = atoi(value); - } - else if (strcmp(token, "FiletransferCompressionLevel") == 0) - { + } else if (strcmp(token, "FiletransferCompressionLevel") == 0) { config->Filetransfer.CompressionLevel[config->Filetransfer.Count] = atoi(value); if (config->Filetransfer.Count < (DLT_SYSTEM_LOG_DIRS_MAX - 1)) { config->Filetransfer.Count++; - } - else { - fprintf(stderr, - "Too many file transfer directories configured. Maximum: %d\n", - DLT_SYSTEM_LOG_DIRS_MAX); + } else { + fprintf( + stderr, "Too many file transfer directories configured. Maximum: %d\n", + DLT_SYSTEM_LOG_DIRS_MAX); ret = -1; break; } } /* Log files */ - else if (strcmp(token, "LogFileEnable") == 0) - { + else if (strcmp(token, "LogFileEnable") == 0) { config->LogFile.Enable = atoi(value); - } - else if (strcmp(token, "LogFileFilename") == 0) - { + } else if (strcmp(token, "LogFileFilename") == 0) { config->LogFile.Filename[config->LogFile.Count] = malloc(strlen(value) + 1); MALLOC_ASSERT(config->LogFile.Filename[config->LogFile.Count]); - strcpy(config->LogFile.Filename[config->LogFile.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */ - } - else if (strcmp(token, "LogFileMode") == 0) - { + strcpy( + config->LogFile.Filename[config->LogFile.Count], + value); /* strcpy unritical here, because size matches exactly the size to be copied */ + } else if (strcmp(token, "LogFileMode") == 0) { config->LogFile.Mode[config->LogFile.Count] = atoi(value); - } - else if (strcmp(token, "LogFileTimeDelay") == 0) - { + } else if (strcmp(token, "LogFileTimeDelay") == 0) { config->LogFile.TimeDelay[config->LogFile.Count] = atoi(value); - } - else if (strcmp(token, "LogFileContextId") == 0) - { + } else if (strcmp(token, "LogFileContextId") == 0) { strncpy(config->LogFile.ContextId[config->LogFile.Count], value, DLT_ID_SIZE); if (config->LogFile.Count < (DLT_SYSTEM_LOG_FILE_MAX - 1)) { config->LogFile.Count++; - } - else { - fprintf(stderr, - "Too many log files configured. Maximum: %d\n", - DLT_SYSTEM_LOG_FILE_MAX); + } else { + fprintf(stderr, "Too many log files configured. Maximum: %d\n", DLT_SYSTEM_LOG_FILE_MAX); ret = -1; break; } } /* Log Processes */ - else if (strcmp(token, "LogProcessesEnable") == 0) - { + else if (strcmp(token, "LogProcessesEnable") == 0) { config->LogProcesses.Enable = atoi(value); - } - else if (strcmp(token, "LogProcessesContextId") == 0) - { + } else if (strcmp(token, "LogProcessesContextId") == 0) { strncpy(config->LogProcesses.ContextId, value, DLT_ID_SIZE); - } - else if (strcmp(token, "LogProcessName") == 0) - { + } else if (strcmp(token, "LogProcessName") == 0) { config->LogProcesses.Name[config->LogProcesses.Count] = malloc(strlen(value) + 1); MALLOC_ASSERT(config->LogProcesses.Name[config->LogProcesses.Count]); - strcpy(config->LogProcesses.Name[config->LogProcesses.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */ - } - else if (strcmp(token, "LogProcessFilename") == 0) - { + strcpy( + config->LogProcesses.Name[config->LogProcesses.Count], + value); /* strcpy unritical here, because size matches exactly the size to be copied */ + } else if (strcmp(token, "LogProcessFilename") == 0) { config->LogProcesses.Filename[config->LogProcesses.Count] = malloc(strlen(value) + 1); MALLOC_ASSERT(config->LogProcesses.Filename[config->LogProcesses.Count]); - strcpy(config->LogProcesses.Filename[config->LogProcesses.Count], value); /* strcpy unritical here, because size matches exactly the size to be copied */ - } - else if (strcmp(token, "LogProcessMode") == 0) - { + strcpy( + config->LogProcesses.Filename[config->LogProcesses.Count], + value); /* strcpy unritical here, because size matches exactly the size to be copied */ + } else if (strcmp(token, "LogProcessMode") == 0) { config->LogProcesses.Mode[config->LogProcesses.Count] = atoi(value); - } - else if (strcmp(token, "LogProcessTimeDelay") == 0) - { + } else if (strcmp(token, "LogProcessTimeDelay") == 0) { config->LogProcesses.TimeDelay[config->LogProcesses.Count] = atoi(value); if (config->LogProcesses.Count < (DLT_SYSTEM_LOG_PROCESSES_MAX - 1)) { config->LogProcesses.Count++; - } - else { - fprintf(stderr, - "Too many processes to log configured. Maximum: %d\n", - DLT_SYSTEM_LOG_PROCESSES_MAX); + } else { + fprintf( + stderr, "Too many processes to log configured. Maximum: %d\n", DLT_SYSTEM_LOG_PROCESSES_MAX); ret = -1; break; } @@ -422,45 +369,37 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) return ret; } -void cleanup_config(DltSystemConfiguration *config, DltSystemCliOptions *options) +void cleanup_config(DltSystemConfiguration* config, DltSystemCliOptions* options) { /* command line options */ - if ((options->ConfigurationFileName) != NULL && options->freeConfigFileName) - { + if ((options->ConfigurationFileName) != NULL && options->freeConfigFileName) { free(options->ConfigurationFileName); options->ConfigurationFileName = NULL; } /* File transfer */ - for(int i = 0 ; i < DLT_SYSTEM_LOG_DIRS_MAX ; i++) - { - if ((config->Filetransfer.Directory[i]) != NULL) - { + for (int i = 0; i < DLT_SYSTEM_LOG_DIRS_MAX; i++) { + if ((config->Filetransfer.Directory[i]) != NULL) { free(config->Filetransfer.Directory[i]); config->Filetransfer.Directory[i] = NULL; } } /* Log files */ - for(int i = 0 ; i < DLT_SYSTEM_LOG_FILE_MAX ; i++) - { - if ((config->LogFile.Filename[i]) != NULL) - { + for (int i = 0; i < DLT_SYSTEM_LOG_FILE_MAX; i++) { + if ((config->LogFile.Filename[i]) != NULL) { free(config->LogFile.Filename[i]); config->LogFile.Filename[i] = NULL; } } /* Log Processes */ - for(int i = 0 ; i < DLT_SYSTEM_LOG_PROCESSES_MAX ; i++) - { - if ((config->LogProcesses.Filename[i]) != NULL) - { + for (int i = 0; i < DLT_SYSTEM_LOG_PROCESSES_MAX; i++) { + if ((config->LogProcesses.Filename[i]) != NULL) { free(config->LogProcesses.Filename[i]); config->LogProcesses.Filename[i] = NULL; } - if ((config->LogProcesses.Name[i]) != NULL) - { + if ((config->LogProcesses.Name[i]) != NULL) { free(config->LogProcesses.Name[i]); config->LogProcesses.Name[i] = NULL; } diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c index 2122433e7..d277302c6 100644 --- a/src/system/dlt-system-process-handling.c +++ b/src/system/dlt-system-process-handling.c @@ -74,8 +74,7 @@ extern s_ft_inotify ino; int daemonize() { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-process-handling, daemonize")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-process-handling, daemonize")); /* Fork new process */ int f = fork(); @@ -122,20 +121,21 @@ int daemonize() } /* Unregisters all DLT Contexts and closes all file descriptors */ -void cleanup_processes(struct pollfd *pollfd, struct pollfd *journalPollFd, sd_journal *j, DltSystemConfiguration *config) +void cleanup_processes( + struct pollfd* pollfd, struct pollfd* journalPollFd, sd_journal* j, DltSystemConfiguration* config) { - //Syslog cleanup + // Syslog cleanup if (config->Syslog.Enable) DLT_UNREGISTER_CONTEXT(syslogContext); - //Journal cleanup + // Journal cleanup #if defined(DLT_SYSTEMD_JOURNAL_ENABLE) if (config->Journal.Enable) DLT_UNREGISTER_CONTEXT(journalContext); - if(j != NULL) + if (j != NULL) sd_journal_close(j); - if(journalPollFd->fd > 0) + if (journalPollFd->fd > 0) close(journalPollFd->fd); #else // silence warnings @@ -143,23 +143,23 @@ void cleanup_processes(struct pollfd *pollfd, struct pollfd *journalPollFd, sd_j (void)journalPollFd->fd; #endif - //Logfile cleanup + // Logfile cleanup if (config->LogFile.Enable) { for (int i = 0; i < config->LogFile.Count; i++) DLT_UNREGISTER_CONTEXT(logfileContext[i]); } - //LogProcess cleanup + // LogProcess cleanup if (config->LogProcesses.Enable) { DLT_UNREGISTER_CONTEXT(procContext); } - //Watchdog cleanup + // Watchdog cleanup #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) DLT_UNREGISTER_CONTEXT(watchdogContext); #endif - //FileTransfer cleanup + // FileTransfer cleanup #if defined(DLT_FILETRANSFER_ENABLE) if (config->Filetransfer.Enable) { DLT_UNREGISTER_CONTEXT(filetransferContext); @@ -167,13 +167,13 @@ void cleanup_processes(struct pollfd *pollfd, struct pollfd *journalPollFd, sd_j #endif for (int i = 0; i < MAX_FD_NUMBER; i++) { - if(pollfd[i].fd > 0) + if (pollfd[i].fd > 0) close(pollfd[i].fd); } } /* Creates timer for LogFile and LogProcess, that need to be called every second. */ -int register_timer_fd(struct pollfd *pollfd, int fdcnt) +int register_timer_fd(struct pollfd* pollfd, int fdcnt) { struct itimerspec timerValue; memset(&timerValue, '\0', sizeof(timerValue)); @@ -190,7 +190,7 @@ int register_timer_fd(struct pollfd *pollfd, int fdcnt) pollfd[fdcnt].fd = timerfd; pollfd[fdcnt].events = POLLIN; - if (timerfd_settime(timerfd, 0, &timerValue, NULL) < 0) { // init timer with 1 second + if (timerfd_settime(timerfd, 0, &timerValue, NULL) < 0) { // init timer with 1 second DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Could not start timer")); return -1; } @@ -198,24 +198,22 @@ int register_timer_fd(struct pollfd *pollfd, int fdcnt) } /* Routine for executing LogProcess and LogFile, when timer expires */ -void timer_fd_handler(int fd, DltSystemConfiguration *config) +void timer_fd_handler(int fd, DltSystemConfiguration* config) { uint64_t timersElapsed = 0ULL; - ssize_t r = read(fd, &timersElapsed, 8U); // only needed to reset fd event - if (r < 0) - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while reading timer fd: "), - DLT_STRING(strerror((int)r))); + ssize_t r = read(fd, &timersElapsed, 8U); // only needed to reset fd event + if (r < 0) + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while reading timer fd: "), DLT_STRING(strerror((int)r))); - if(config->LogProcesses.Enable) + if (config->LogProcesses.Enable) logprocess_fd_handler(config); - if(config->LogFile.Enable) + if (config->LogFile.Enable) logfile_fd_handler(config); } -void start_dlt_system_processes(DltSystemConfiguration *config) +void start_dlt_system_processes(DltSystemConfiguration* config) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-process-handling, start threads")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-process-handling, start threads")); if (config->Shell.Enable) init_shell(); @@ -223,27 +221,27 @@ void start_dlt_system_processes(DltSystemConfiguration *config) int fdcnt = 0; /* Init FDs for all activated processes*/ - struct pollfd pollfd[MAX_FD_NUMBER]; // Holds all FDs and events - uint8_t fdType[MAX_FD_NUMBER]; // Holds corresponding enum for process identification + struct pollfd pollfd[MAX_FD_NUMBER]; // Holds all FDs and events + uint8_t fdType[MAX_FD_NUMBER]; // Holds corresponding enum for process identification - for(int cnt = 0 ; cnt < MAX_FD_NUMBER ; cnt++) { + for (int cnt = 0; cnt < MAX_FD_NUMBER; cnt++) { pollfd[cnt].fd = 0; pollfd[cnt].events = 0; } - //init FD for LogFile and LogProcesses + // init FD for LogFile and LogProcesses if (config->LogProcesses.Enable || config->LogFile.Enable) { fdType[fdcnt] = fdType_timer; if (register_timer_fd(pollfd, fdcnt) == 0) { - if(config->LogProcesses.Enable) + if (config->LogProcesses.Enable) logprocess_init(config); - if(config->LogFile.Enable) + if (config->LogFile.Enable) logfile_init(config); fdcnt++; } } - //init FD for Syslog + // init FD for Syslog int syslogSock = 0; if (config->Syslog.Enable) { fdType[fdcnt] = fdType_syslog; @@ -251,27 +249,23 @@ void start_dlt_system_processes(DltSystemConfiguration *config) fdcnt++; } - //init FD for Journal - sd_journal *j = NULL; + // init FD for Journal + sd_journal* j = NULL; struct pollfd journalPollFd; #if defined(DLT_SYSTEMD_JOURNAL_ENABLE) pthread_t journalThreadHandle; if (config->Journal.Enable) { register_journal_fd(&j, &journalPollFd, 0, config); - struct journal_fd_params params = { - &quit, - &journalPollFd, - j, - config - }; + struct journal_fd_params params = {&quit, &journalPollFd, j, config}; if (pthread_create(&journalThreadHandle, NULL, &journal_thread, (void*)¶ms) != 0) { - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Failed to create journal_thread thread "), - DLT_STRING(strerror(errno))); + DLT_LOG( + dltsystem, DLT_LOG_ERROR, DLT_STRING("Failed to create journal_thread thread "), + DLT_STRING(strerror(errno))); } } #endif - //init FD for FileTransfer + // init FD for FileTransfer #if defined(DLT_FILETRANSFER_ENABLE) if (config->Filetransfer.Enable) { init_filetransfer_dirs(config); @@ -282,42 +276,39 @@ void start_dlt_system_processes(DltSystemConfiguration *config) } #endif - //init FD for Watchdog + // init FD for Watchdog #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) fdType[fdcnt] = fdType_watchdog; register_watchdog_fd(pollfd, fdcnt); #endif - while (quit == 0) - { + while (quit == 0) { int ready; ready = poll(pollfd, MAX_FD_NUMBER, -1); if (ready == -1 && quit == 0) - DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while poll. Exit with: "), - DLT_STRING(strerror(ready))); + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while poll. Exit with: "), DLT_STRING(strerror(ready))); for (int i = 0; i < MAX_FD_NUMBER; i++) { - if(pollfd[i].revents & POLLIN){ + if (pollfd[i].revents & POLLIN) { if (fdType[i] == fdType_syslog && syslogSock > 0) { syslog_fd_handler(syslogSock); - } - else if (fdType[i] == fdType_timer) { + } else if (fdType[i] == fdType_timer) { timer_fd_handler(pollfd[i].fd, config); } - #if defined(DLT_FILETRANSFER_ENABLE) +#if defined(DLT_FILETRANSFER_ENABLE) else if (fdType[i] == fdType_filetransfer) { filetransfer_fd_handler(config); } - #endif - #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) +#endif +#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) else if (fdType[i] == fdType_watchdog) { - #if defined(DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM) && defined(DLT_SYSTEMD_JOURNAL_ENABLE) +#if defined(DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM) && defined(DLT_SYSTEMD_JOURNAL_ENABLE) watchdog_fd_handler(pollfd[i].fd, &config->Journal.MessageReceived); - #else +#else watchdog_fd_handler(pollfd[i].fd); - #endif +#endif } - #endif +#endif } } } diff --git a/src/system/dlt-system-processes.c b/src/system/dlt-system-processes.c index b17b8ee46..0ed407fe1 100644 --- a/src/system/dlt-system-processes.c +++ b/src/system/dlt-system-processes.c @@ -55,28 +55,27 @@ #include "dlt-system.h" /* Modes of sending */ -#define SEND_MODE_OFF 0 +#define SEND_MODE_OFF 0 #define SEND_MODE_ONCE 1 -#define SEND_MODE_ON 2 +#define SEND_MODE_ON 2 int process_delays[DLT_SYSTEM_LOG_PROCESSES_MAX]; DLT_IMPORT_CONTEXT(dltsystem) DLT_DECLARE_CONTEXT(procContext) -void send_process(LogProcessOptions const *popts, int n) +void send_process(LogProcessOptions const* popts, int n) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-processes, send process info.")); - FILE *pFile; - struct dirent *dp; + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-processes, send process info.")); + FILE* pFile; + struct dirent* dp; char filename[PATH_MAX]; char buffer[1024]; size_t bytes; int found = 0; /* go through all process files in directory */ - DIR *dir = opendir("/proc"); + DIR* dir = opendir("/proc"); if (dir != NULL) { while ((dp = readdir(dir)) != NULL) @@ -90,8 +89,7 @@ void send_process(LogProcessOptions const *popts, int n) fclose(pFile); } - if ((strcmp((*popts).Name[n], "*") == 0) || - (strcmp(buffer, (*popts).Name[n]) == 0)) { + if ((strcmp((*popts).Name[n], "*") == 0) || (strcmp(buffer, (*popts).Name[n]) == 0)) { found = 1; snprintf(filename, PATH_MAX, "/proc/%s/%s", dp->d_name, (*popts).Filename[n]); pFile = fopen(filename, "r"); @@ -102,8 +100,9 @@ void send_process(LogProcessOptions const *popts, int n) if (bytes > 0) { buffer[bytes] = 0; - DLT_LOG(procContext, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), - DLT_STRING((*popts).Filename[n]), DLT_STRING(buffer)); + DLT_LOG( + procContext, DLT_LOG_INFO, DLT_INT(atoi(dp->d_name)), DLT_STRING((*popts).Filename[n]), + DLT_STRING(buffer)); } } @@ -113,32 +112,29 @@ void send_process(LogProcessOptions const *popts, int n) } closedir(dir); - } - else { - DLT_LOG(dltsystem, DLT_LOG_ERROR, - DLT_STRING("dlt-system-processes, failed to open /proc.")); + } else { + DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("dlt-system-processes, failed to open /proc.")); } if (!found) - DLT_LOG(procContext, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING((*popts).Name[n]), - DLT_STRING("not running!")); + DLT_LOG( + procContext, DLT_LOG_INFO, DLT_STRING("Process"), DLT_STRING((*popts).Name[n]), DLT_STRING("not running!")); } -void logprocess_init(void *v_conf) +void logprocess_init(void* v_conf) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-processes, in thread.")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-processes, in thread.")); - DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DltSystemConfiguration* conf = (DltSystemConfiguration*)v_conf; DLT_REGISTER_CONTEXT(procContext, conf->LogProcesses.ContextId, "Log Processes"); for (int i = 0; i < conf->LogProcesses.Count; i++) process_delays[i] = conf->LogProcesses.TimeDelay[i]; } -void logprocess_fd_handler(void *v_conf) +void logprocess_fd_handler(void* v_conf) { - DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf; + DltSystemConfiguration* conf = (DltSystemConfiguration*)v_conf; for (int i = 0; i < conf->LogProcesses.Count; i++) { if (conf->LogProcesses.Mode[i] == SEND_MODE_OFF) continue; @@ -149,8 +145,7 @@ void logprocess_fd_handler(void *v_conf) if (conf->LogProcesses.Mode[i] == SEND_MODE_ONCE) conf->LogProcesses.Mode[i] = SEND_MODE_OFF; - } - else { + } else { process_delays[i]--; } } diff --git a/src/system/dlt-system-shell.c b/src/system/dlt-system-shell.c index f48945bcd..c3fd01cda 100644 --- a/src/system/dlt-system-shell.c +++ b/src/system/dlt-system-shell.c @@ -62,50 +62,41 @@ DLT_IMPORT_CONTEXT(dltsystem) DLT_DECLARE_CONTEXT(shellContext) -int dlt_shell_injection_callback(uint32_t service_id, void *data, uint32_t length) +int dlt_shell_injection_callback(uint32_t service_id, void* data, uint32_t length) { (void)length; - DLT_LOG(shellContext, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-shell, injection callback")); + DLT_LOG(shellContext, DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, injection callback")); char text[DLT_SHELL_COMMAND_MAX_LENGTH]; int syserr = 0; if (length <= DLT_SHELL_COMMAND_MAX_LENGTH - 1) { strncpy(text, data, length); text[length] = 0; - } - else { + } else { strncpy(text, data, DLT_SHELL_COMMAND_MAX_LENGTH - 1); text[DLT_SHELL_COMMAND_MAX_LENGTH - 1] = 0; } - DLT_LOG(shellContext, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-shell, injection injection id:"), - DLT_UINT32(service_id)); - DLT_LOG(shellContext, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-shell, injection data:"), - DLT_STRING(text)); + DLT_LOG( + shellContext, DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, injection injection id:"), DLT_UINT32(service_id)); + DLT_LOG(shellContext, DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, injection data:"), DLT_STRING(text)); switch (service_id) { case 0x1001: if ((syserr = system(text)) != 0) - DLT_LOG(shellContext, DLT_LOG_ERROR, - DLT_STRING("dlt-system-shell, abnormal exit status."), - DLT_STRING(text), - DLT_INT(syserr)); + DLT_LOG( + shellContext, DLT_LOG_ERROR, DLT_STRING("dlt-system-shell, abnormal exit status."), DLT_STRING(text), + DLT_INT(syserr)); else - DLT_LOG(shellContext, DLT_LOG_INFO, - DLT_STRING("Shell command executed:"), - DLT_STRING(text)); + DLT_LOG(shellContext, DLT_LOG_INFO, DLT_STRING("Shell command executed:"), DLT_STRING(text)); break; default: - DLT_LOG(shellContext, DLT_LOG_ERROR, - DLT_STRING("dlt-system-shell, unknown command received."), - DLT_UINT32(service_id), - DLT_STRING(text)); + DLT_LOG( + shellContext, DLT_LOG_ERROR, DLT_STRING("dlt-system-shell, unknown command received."), + DLT_UINT32(service_id), DLT_STRING(text)); break; } @@ -114,8 +105,7 @@ int dlt_shell_injection_callback(uint32_t service_id, void *data, uint32_t lengt void init_shell() { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-shell, register callback")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-shell, register callback")); DLT_REGISTER_CONTEXT(shellContext, "CMD", "Execute Shell commands"); DLT_REGISTER_INJECTION_CALLBACK(shellContext, 0x1001, dlt_shell_injection_callback); } diff --git a/src/system/dlt-system-syslog.c b/src/system/dlt-system-syslog.c index 37ab696cd..dba641d99 100644 --- a/src/system/dlt-system-syslog.c +++ b/src/system/dlt-system-syslog.c @@ -61,9 +61,7 @@ DLT_DECLARE_CONTEXT(syslogContext) int init_socket(SyslogOptions opts) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-syslog, init socket, port: "), - DLT_INT(opts.Port)); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-syslog, init socket, port: "), DLT_INT(opts.Port)); int sock = -1; @@ -78,8 +76,7 @@ int init_socket(SyslogOptions opts) #endif if (sock < 0) { - DLT_LOG(syslogContext, DLT_LOG_FATAL, - DLT_STRING("Unable to create socket for SYSLOG.")); + DLT_LOG(syslogContext, DLT_LOG_FATAL, DLT_STRING("Unable to create socket for SYSLOG.")); return -1; } @@ -97,11 +94,10 @@ int init_socket(SyslogOptions opts) #endif /* bind the socket address to local interface */ - if (bind(sock, (struct sockaddr *)&syslog_addr, - sizeof(syslog_addr)) == -1) { - DLT_LOG(syslogContext, DLT_LOG_FATAL, - DLT_STRING("Unable to bind socket for SYSLOG, error description: "), - DLT_STRING(strerror(errno))); + if (bind(sock, (struct sockaddr*)&syslog_addr, sizeof(syslog_addr)) == -1) { + DLT_LOG( + syslogContext, DLT_LOG_FATAL, DLT_STRING("Unable to bind socket for SYSLOG, error description: "), + DLT_STRING(strerror(errno))); close(sock); return -1; } @@ -111,37 +107,32 @@ int init_socket(SyslogOptions opts) ssize_t read_socket(int sock) { - DLT_LOG(dltsystem, DLT_LOG_DEBUG, - DLT_STRING("dlt-system-syslog, read socket")); + DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-syslog, read socket")); char recv_data[RECV_BUF_SZ]; struct sockaddr_in client_addr; socklen_t addr_len = sizeof(struct sockaddr_in); - ssize_t bytes_read = recvfrom(sock, recv_data, RECV_BUF_SZ, 0, - (struct sockaddr *)&client_addr, &addr_len); + ssize_t bytes_read = recvfrom(sock, recv_data, RECV_BUF_SZ, 0, (struct sockaddr*)&client_addr, &addr_len); if (bytes_read == -1) { if (errno == EINTR) { return 0; - } - else { - DLT_LOG(syslogContext, DLT_LOG_FATAL, - DLT_STRING("Read from socket failed in SYSLOG.")); + } else { + DLT_LOG(syslogContext, DLT_LOG_FATAL, DLT_STRING("Read from socket failed in SYSLOG.")); return -1; } } recv_data[bytes_read] = '\0'; - if (bytes_read != 0) - { + if (bytes_read != 0) { DLT_LOG(syslogContext, DLT_LOG_INFO, DLT_STRING(recv_data)); } return bytes_read; } -int register_syslog_fd(struct pollfd *pollfd, int i, DltSystemConfiguration *config) +int register_syslog_fd(struct pollfd* pollfd, int i, DltSystemConfiguration* config) { DLT_REGISTER_CONTEXT(syslogContext, config->Syslog.ContextId, "SYSLOG Adapter"); int syslogSock = init_socket(config->Syslog); diff --git a/src/system/dlt-system-watchdog.c b/src/system/dlt-system-watchdog.c index 2761baba8..ebb640944 100644 --- a/src/system/dlt-system-watchdog.c +++ b/src/system/dlt-system-watchdog.c @@ -39,12 +39,12 @@ DLT_DECLARE_CONTEXT(watchdogContext) DLT_IMPORT_CONTEXT(dltsystem) -int calculate_period(struct itimerspec *itval) +int calculate_period(struct itimerspec* itval) { unsigned int ns; unsigned int sec; char str[512]; - char *watchdogUSec; + char* watchdogUSec; unsigned int watchdogTimeoutSeconds; unsigned int notifiyPeriodNSec; @@ -54,7 +54,7 @@ int calculate_period(struct itimerspec *itval) DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("systemd watchdog timeout (WATCHDOG_USEC) is null\n")); return -1; } - + DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("watchdogusec: "), DLT_STRING(watchdogUSec)); watchdogTimeoutSeconds = (unsigned int)atoi(watchdogUSec); @@ -67,11 +67,9 @@ int calculate_period(struct itimerspec *itval) /* Calculate half of WATCHDOG_USEC in ns for timer tick */ notifiyPeriodNSec = watchdogTimeoutSeconds / 2; - snprintf(str, - 512, - "systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", - watchdogTimeoutSeconds, - notifiyPeriodNSec); + snprintf( + str, 512, "systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", watchdogTimeoutSeconds, + notifiyPeriodNSec); DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING(str)); /* Make the timer periodic */ @@ -85,7 +83,7 @@ int calculate_period(struct itimerspec *itval) return 0; } -int register_watchdog_fd(struct pollfd *pollfd, int fdcnt) +int register_watchdog_fd(struct pollfd* pollfd, int fdcnt) { DLT_REGISTER_CONTEXT(watchdogContext, "DOG", "dlt system watchdog context."); struct itimerspec timerValue; @@ -114,18 +112,19 @@ void watchdog_fd_handler(int fd) #endif { uint64_t timersElapsed = 0ULL; - ssize_t r = read(fd, &timersElapsed, 8U); // only needed to reset fd event - if(r < 0) - DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog. Exit with: "), + ssize_t r = read(fd, &timersElapsed, 8U); // only needed to reset fd event + if (r < 0) + DLT_LOG( + watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog. Exit with: "), DLT_STRING(strerror((int)r))); - #ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM +#ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM if (!*received_message_since_last_watchdog_interval) { - dlt_log(LOG_WARNING, "No new messages received since last watchdog timer run\n"); - return; + dlt_log(LOG_WARNING, "No new messages received since last watchdog timer run\n"); + return; } *received_message_since_last_watchdog_interval = 0; - #endif +#endif if (sd_notify(0, "WATCHDOG=1") < 0) DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog\n")); diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c index 7c64eab4f..80633e874 100644 --- a/src/system/dlt-system.c +++ b/src/system/dlt-system.c @@ -52,12 +52,12 @@ #include #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE) -# include "sd-daemon.h" +#include "sd-daemon.h" #endif DLT_DECLARE_CONTEXT(dltsystem) -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { DltSystemCliOptions options = {0}; DltSystemConfiguration config = {0}; @@ -84,13 +84,10 @@ int main(int argc, char *argv[]) if (ret == 0) { DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system not booted with systemd!\n")); - } - else if (ret < 0) - { + } else if (ret < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("sd_booted failed!\n")); return -1; - } - else { + } else { DLT_LOG(dltsystem, DLT_LOG_INFO, DLT_STRING("system booted with systemd\n")); } @@ -120,5 +117,3 @@ int main(int argc, char *argv[]) cleanup_config(&config, &options); exit(0); } - - diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h index c1d45e52d..a11b58524 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -74,17 +74,19 @@ #define MAX_LINE 1024 /** Total number of file descriptors needed for processing all features: -* - Syslog file descriptor -* - Timer file descriptor for processing LogFile and LogProcesses every second -* - Inotify file descriptor for FileTransfer -* - Timer file descriptor for Watchdog -*/ -#define MAX_FD_NUMBER 4 + * - Syslog file descriptor + * - Timer file descriptor for processing LogFile and LogProcesses every second + * - Inotify file descriptor for FileTransfer + * - Timer file descriptor for Watchdog + */ +#define MAX_FD_NUMBER 4 /* Macros */ -#define MALLOC_ASSERT(x) if (x == NULL) { \ - fprintf(stderr, "Out of memory\n"); \ - abort(); } +#define MALLOC_ASSERT(x) \ + if (x == NULL) { \ + fprintf(stderr, "Out of memory\n"); \ + abort(); \ + } /* enum for classification of FD */ enum fdType { @@ -101,7 +103,7 @@ enum fdType { /* Command line options */ typedef struct { - char *ConfigurationFileName; + char* ConfigurationFileName; int freeConfigFileName; int Daemonize; } DltSystemCliOptions; @@ -142,7 +144,7 @@ typedef struct { int Count; int Compression[DLT_SYSTEM_LOG_DIRS_MAX]; int CompressionLevel[DLT_SYSTEM_LOG_DIRS_MAX]; - char *Directory[DLT_SYSTEM_LOG_DIRS_MAX]; + char* Directory[DLT_SYSTEM_LOG_DIRS_MAX]; } FiletransferOptions; typedef struct { @@ -156,7 +158,7 @@ typedef struct { /* Variable number of files to transfer */ int Count; char ContextId[DLT_SYSTEM_LOG_FILE_MAX][DLT_ID_SIZE]; - char *Filename[DLT_SYSTEM_LOG_FILE_MAX]; + char* Filename[DLT_SYSTEM_LOG_FILE_MAX]; int Mode[DLT_SYSTEM_LOG_FILE_MAX]; int TimeDelay[DLT_SYSTEM_LOG_FILE_MAX]; } LogFileOptions; @@ -167,8 +169,8 @@ typedef struct { /* Variable number of processes */ int Count; - char *Name[DLT_SYSTEM_LOG_PROCESSES_MAX]; - char *Filename[DLT_SYSTEM_LOG_PROCESSES_MAX]; + char* Name[DLT_SYSTEM_LOG_PROCESSES_MAX]; + char* Filename[DLT_SYSTEM_LOG_PROCESSES_MAX]; int Mode[DLT_SYSTEM_LOG_PROCESSES_MAX]; int TimeDelay[DLT_SYSTEM_LOG_PROCESSES_MAX]; } LogProcessOptions; @@ -188,9 +190,9 @@ typedef struct { */ /* In dlt-system-options.c */ -int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]); -int read_configuration_file(DltSystemConfiguration *config, char *file_name); -void cleanup_config(DltSystemConfiguration *config, DltSystemCliOptions *options); +int read_command_line(DltSystemCliOptions* options, int argc, char* argv[]); +int read_configuration_file(DltSystemConfiguration* config, char* file_name); +void cleanup_config(DltSystemConfiguration* config, DltSystemCliOptions* options); /* For dlt-process-handling.c */ int daemonize(); @@ -198,33 +200,33 @@ void init_shell(); void dlt_system_signal_handler(int sig); /* Main function for creating/registering all needed file descriptors and starting the poll for all of them. */ -void start_dlt_system_processes(DltSystemConfiguration *config); +void start_dlt_system_processes(DltSystemConfiguration* config); /* Init process, create file descriptors and register them into main pollfd. */ -int register_watchdog_fd(struct pollfd *pollfd, int fdcnt); -int init_filetransfer_dirs(DltSystemConfiguration *config); -void logfile_init(void *v_conf); -void logprocess_init(void *v_conf); -void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSystemConfiguration *config); -int register_syslog_fd(struct pollfd *pollfd, int i, DltSystemConfiguration *config); +int register_watchdog_fd(struct pollfd* pollfd, int fdcnt); +int init_filetransfer_dirs(DltSystemConfiguration* config); +void logfile_init(void* v_conf); +void logprocess_init(void* v_conf); +void register_journal_fd(sd_journal** j, struct pollfd* pollfd, int i, DltSystemConfiguration* config); +int register_syslog_fd(struct pollfd* pollfd, int i, DltSystemConfiguration* config); /* Routines that are called, when a fd event was raised. */ -void logfile_fd_handler(void *v_conf); -void logprocess_fd_handler(void *v_conf); -void filetransfer_fd_handler(DltSystemConfiguration *config); +void logfile_fd_handler(void* v_conf); +void logprocess_fd_handler(void* v_conf); +void filetransfer_fd_handler(DltSystemConfiguration* config); #if defined(DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM) && defined(DLT_SYSTEMD_JOURNAL_ENABLE) void watchdog_fd_handler(int fd, int* received_message_since_last_watchdog_interval); #else void watchdog_fd_handler(int fd); #endif -void journal_fd_handler(sd_journal *j, DltSystemConfiguration *config); +void journal_fd_handler(sd_journal* j, DltSystemConfiguration* config); struct journal_fd_params { volatile uint8_t* quit; struct pollfd* journalPollFd; - sd_journal *j; - DltSystemConfiguration *config; + sd_journal* j; + DltSystemConfiguration* config; }; -void *journal_thread(void* journalParams); +void* journal_thread(void* journalParams); void syslog_fd_handler(int syslogSock); #endif /* DLT_SYSTEM_H_ */ diff --git a/tests/components/dlt-logd-converter/gtest_dlt_logd_converter.cpp b/tests/components/dlt-logd-converter/gtest_dlt_logd_converter.cpp index ec2851003..ab1292e17 100644 --- a/tests/components/dlt-logd-converter/gtest_dlt_logd_converter.cpp +++ b/tests/components/dlt-logd-converter/gtest_dlt_logd_converter.cpp @@ -43,7 +43,7 @@ #define CONFIGURATION_FILE_DIR "dlt-logd-converter.conf" #define JSON_FILE_DIR "dlt-logdctxt.json" #define ABNORMAL_CONFIGURATION_FILE_DIR "abnormal-dlt-logd-converter.conf" -extern dlt_logd_configuration *logd_conf; +extern dlt_logd_configuration* logd_conf; extern unordered_map map_ctx_json; extern bool json_is_available; extern volatile sig_atomic_t exit_parser_loop; @@ -57,16 +57,16 @@ DLT_IMPORT_CONTEXT(dlt_ctx_stat) DLT_IMPORT_CONTEXT(dlt_ctx_secu) DLT_IMPORT_CONTEXT(dlt_ctx_krnl) DLT_IMPORT_CONTEXT(dlt_ctx_othe) -struct logger_list *t_logger_list = nullptr; -struct dlt_log_container *dlt_log_data = nullptr; +struct logger_list* t_logger_list = nullptr; +struct dlt_log_container* dlt_log_data = nullptr; struct log_msg t_log_msg; string t_load_json_file() { ifstream file(JSON_FILE_DIR); - char *token; + char* token; string pattern; string json_sequence; - if(!file.is_open()) + if (!file.is_open()) return ""; while (!file.eof()) { getline(file, pattern); @@ -75,32 +75,31 @@ string t_load_json_file() } if (pattern[0] != '#') { token = strtok(&pattern[0], " {\":,}"); - while( token != NULL ) { - if(strcmp(token, "tag") != 0 && strcmp(token, "description") != 0) { + while (token != NULL) { + if (strcmp(token, "tag") != 0 && strcmp(token, "description") != 0) { json_sequence = json_sequence + strdup(token) + " "; - } - else { - if(pattern.find("\"\"") != string::npos) { + } else { + if (pattern.find("\"\"") != string::npos) { json_sequence = json_sequence + strdup("null") + " "; } } - token = strtok(NULL, " {\":,}"); + token = strtok(NULL, " {\":,}"); } } } file.close(); return json_sequence; } -struct logger *t_android_logger_open(struct logger_list *logger_list, log_id_t log_id) +struct logger* t_android_logger_open(struct logger_list* logger_list, log_id_t log_id) { - if (logger_list ==nullptr || (log_id >= LOG_ID_MAX)) { + if (logger_list == nullptr || (log_id >= LOG_ID_MAX)) { return nullptr; } logger_list->log_mask |= 1 << log_id; uintptr_t t_logger = log_id | LOGGER_LOGD; return reinterpret_cast(t_logger); } -struct logger_list *t_android_logger_list_alloc(int mode, unsigned int tail, pid_t pid) +struct logger_list* t_android_logger_list_alloc(int mode, unsigned int tail, pid_t pid) { t_logger_list = new logger_list; t_logger_list->mode = mode; @@ -109,7 +108,7 @@ struct logger_list *t_android_logger_list_alloc(int mode, unsigned int tail, pid t_logger_list->log_mask = 0; return t_logger_list; } -int t_android_logger_list_read(logger_list *logger_list, struct log_msg *_t_log_msg) +int t_android_logger_list_read(logger_list* logger_list, struct log_msg* _t_log_msg) { if (!_t_log_msg->entry.len) { _t_log_msg->entry.len = LOGGER_ENTRY_MAX_LEN; @@ -118,7 +117,7 @@ int t_android_logger_list_read(logger_list *logger_list, struct log_msg *_t_log_ _t_log_msg->entry.hdr_size = 100; } if (!_t_log_msg->entry.sec) { - _t_log_msg->entry.sec = 1/10000; + _t_log_msg->entry.sec = 1 / 10000; } if (!_t_log_msg->entry.nsec) { _t_log_msg->entry.nsec = 100000; @@ -154,26 +153,17 @@ TEST(t_usage, normal) char version[255]; dlt_get_version(version, 255); stringstream buffer; - streambuf *prev_cout_buf = cout.rdbuf(buffer.rdbuf()); + streambuf* prev_cout_buf = cout.rdbuf(buffer.rdbuf()); usage(strdup("dlt-logd-converter")); - EXPECT_NE(buffer.str().find("Usage: dlt-logd-converter [-h] [-c FILENAME]"), - string::npos); - EXPECT_NE(buffer.str().find("Application to manage Android logs."), - string::npos); - EXPECT_NE(buffer.str().find("Format and forward Android messages from ANDROID to DLT."), - string::npos); - EXPECT_NE(buffer.str().find(string(version)), - string::npos); - EXPECT_NE(buffer.str().find("Options:"), - string::npos); - EXPECT_NE(buffer.str().find(" -h Display a short help text."), - string::npos); - EXPECT_NE(buffer.str().find(" -c filename Use an alternative configuration file."), - string::npos); - EXPECT_NE(buffer.str().find(" Default: "), - string::npos); - EXPECT_NE(buffer.str().find("/vendor/etc/dlt-logd-converter.conf"), - string::npos); + EXPECT_NE(buffer.str().find("Usage: dlt-logd-converter [-h] [-c FILENAME]"), string::npos); + EXPECT_NE(buffer.str().find("Application to manage Android logs."), string::npos); + EXPECT_NE(buffer.str().find("Format and forward Android messages from ANDROID to DLT."), string::npos); + EXPECT_NE(buffer.str().find(string(version)), string::npos); + EXPECT_NE(buffer.str().find("Options:"), string::npos); + EXPECT_NE(buffer.str().find(" -h Display a short help text."), string::npos); + EXPECT_NE(buffer.str().find(" -c filename Use an alternative configuration file."), string::npos); + EXPECT_NE(buffer.str().find(" Default: "), string::npos); + EXPECT_NE(buffer.str().find("/vendor/etc/dlt-logd-converter.conf"), string::npos); cout.rdbuf(prev_cout_buf); } TEST(t_init_configuration, normal) @@ -188,11 +178,11 @@ TEST(t_init_configuration, normal) } TEST(t_read_command_line, normal) { - char *arg[2]; + char* arg[2]; arg[0] = strdup("dlt-logd-converter"); arg[1] = strdup("h"); EXPECT_EQ(DLT_RETURN_OK, read_command_line(2, arg)); - char *t_arg[3]; + char* t_arg[3]; t_arg[0] = strdup("dlt-logd-converter"); t_arg[1] = strdup("c"); t_arg[2] = strdup("custom.conf"); @@ -242,8 +232,8 @@ TEST(t_clean_mem, normal) string json_tag; string json_description; string str = t_load_json_file(); - char *token = strtok(&str[0], " "); - while(token != nullptr) { + char* token = strtok(&str[0], " "); + while (token != nullptr) { json_ctxID = string(token); token = strtok(nullptr, " "); json_tag = string(token); @@ -253,7 +243,7 @@ TEST(t_clean_mem, normal) json_description = ""; } token = strtok(nullptr, " "); - DltContext *ctx = new DltContext(); + DltContext* ctx = new DltContext(); auto ret = map_ctx_json.emplace(json_tag, ctx); if (!ret.second) { delete ctx; @@ -278,10 +268,10 @@ TEST(t_json_parser, normal) EXPECT_TRUE(map_ctx_json.find("ProcessState") != map_ctx_json.end()); EXPECT_TRUE(map_ctx_json.find("Zygote") != map_ctx_json.end()); DLT_UNREGISTER_CONTEXT(dlt_ctx_self); - for (auto &map_malloc: map_ctx_json) { - DLT_UNREGISTER_CONTEXT(*(map_malloc.second)); - delete map_malloc.second; - map_malloc.second = nullptr; + for (auto& map_malloc : map_ctx_json) { + DLT_UNREGISTER_CONTEXT(*(map_malloc.second)); + delete map_malloc.second; + map_malloc.second = nullptr; } map_ctx_json.clear(); DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS(); @@ -292,8 +282,8 @@ TEST(t_find_tag_in_json, normal) string json_tag; string json_description; string str = t_load_json_file(); - char *token = strtok(&str[0], " "); - while(token != nullptr) { + char* token = strtok(&str[0], " "); + while (token != nullptr) { json_ctxID = string(token); token = strtok(nullptr, " "); json_tag = string(token); @@ -303,25 +293,21 @@ TEST(t_find_tag_in_json, normal) json_description = ""; } token = strtok(nullptr, " "); - DltContext *ctx = new DltContext(); + DltContext* ctx = new DltContext(); auto ret = map_ctx_json.emplace(json_tag, ctx); if (!ret.second) { delete ctx; ctx = nullptr; } } - EXPECT_EQ(find_tag_in_json("QtiVehicleHal"), - (map_ctx_json.find("QtiVehicleHal")->second)); - EXPECT_EQ(find_tag_in_json("NetworkSecurityConfig"), - (map_ctx_json.find("NetworkSecurityConfig")->second)); - EXPECT_EQ(find_tag_in_json("ProcessState"), - (map_ctx_json.find("ProcessState")->second)); - EXPECT_EQ(find_tag_in_json("Zygote"), - (map_ctx_json.find("Zygote")->second)); + EXPECT_EQ(find_tag_in_json("QtiVehicleHal"), (map_ctx_json.find("QtiVehicleHal")->second)); + EXPECT_EQ(find_tag_in_json("NetworkSecurityConfig"), (map_ctx_json.find("NetworkSecurityConfig")->second)); + EXPECT_EQ(find_tag_in_json("ProcessState"), (map_ctx_json.find("ProcessState")->second)); + EXPECT_EQ(find_tag_in_json("Zygote"), (map_ctx_json.find("Zygote")->second)); EXPECT_EQ(find_tag_in_json("Other tags"), &(dlt_ctx_othe)); - for (auto &map_malloc: map_ctx_json) { - delete map_malloc.second; - map_malloc.second = nullptr; + for (auto& map_malloc : map_ctx_json) { + delete map_malloc.second; + map_malloc.second = nullptr; } map_ctx_json.clear(); } @@ -336,7 +322,7 @@ TEST(t_init_logger, normal) t_logger_list->mode = READ_ONLY; t_logger_list->tail = 0; t_logger_list->pid = 0; - struct logger *logger_ptr = reinterpret_cast(LOG_ID_MAIN | LOGGER_LOGD); + struct logger* logger_ptr = reinterpret_cast(LOG_ID_MAIN | LOGGER_LOGD); EXPECT_EQ(logger_ptr, init_logger(t_logger_list, LOG_ID_MAIN)); logger_ptr = reinterpret_cast(LOG_ID_RADIO | LOGGER_LOGD); EXPECT_EQ(logger_ptr, init_logger(t_logger_list, LOG_ID_RADIO)); @@ -376,7 +362,7 @@ TEST(t_init_logger_list, normal) } TEST(t_get_log_context_from_log_msg, normal) { - struct log_msg *_t_log_msg = nullptr; + struct log_msg* _t_log_msg = nullptr; _t_log_msg = new log_msg; _t_log_msg->entry.lid = LOG_ID_MAIN; EXPECT_EQ(&dlt_ctx_main, get_log_context_from_log_msg(_t_log_msg)); @@ -401,17 +387,17 @@ TEST(t_get_log_context_from_log_msg, normal) } TEST(t_get_log_context_from_log_msg, nullpointer) { - struct log_msg *_t_log_msg = nullptr; + struct log_msg* _t_log_msg = nullptr; EXPECT_EQ(&dlt_ctx_self, get_log_context_from_log_msg(_t_log_msg)); } TEST(t_get_timestamp_from_log_msg, normal) { - struct log_msg *_t_log_msg = nullptr; + struct log_msg* _t_log_msg = nullptr; _t_log_msg = new log_msg; _t_log_msg->entry.sec = 0; _t_log_msg->entry.nsec = 0; EXPECT_EQ(0, get_timestamp_from_log_msg(_t_log_msg)); - _t_log_msg->entry.sec = 1/10000; + _t_log_msg->entry.sec = 1 / 10000; _t_log_msg->entry.nsec = 100000; EXPECT_EQ(1, get_timestamp_from_log_msg(_t_log_msg)); _t_log_msg->entry.sec = 100; @@ -420,12 +406,12 @@ TEST(t_get_timestamp_from_log_msg, normal) } TEST(t_get_timestamp_from_log_msg, nullpointer) { - struct log_msg *_t_log_msg = nullptr; + struct log_msg* _t_log_msg = nullptr; EXPECT_EQ(DLT_FAIL_TO_GET_LOG_MSG, get_timestamp_from_log_msg(_t_log_msg)); } TEST(t_get_log_level_from_log_msg, normal) { - struct log_msg *_t_log_msg = nullptr; + struct log_msg* _t_log_msg = nullptr; _t_log_msg = new log_msg; _t_log_msg->entry.hdr_size = 0; _t_log_msg->buf[0] = (unsigned char)ANDROID_LOG_VERBOSE; @@ -451,7 +437,7 @@ TEST(t_get_log_level_from_log_msg, normal) } TEST(t_get_log_level_from_log_msg, nullpointer) { - struct log_msg *_t_log_msg = nullptr; + struct log_msg* _t_log_msg = nullptr; EXPECT_EQ(DLT_LOG_DEFAULT, get_log_level_from_log_msg(_t_log_msg)); } TEST(t_signal_handler, normal) @@ -465,7 +451,7 @@ TEST(t_signal_handler, normal) } TEST(t_logd_parser_loop, normal) { - struct logger_list *t_list = nullptr; + struct logger_list* t_list = nullptr; t_list = new logger_list; t_list->mode = READ_ONLY; t_list->tail = 0; @@ -494,8 +480,8 @@ TEST(t_logd_parser_loop, normal) string json_tag; string json_description; string str = t_load_json_file(); - char *token = strtok(&str[0], " "); - while(token != nullptr) { + char* token = strtok(&str[0], " "); + while (token != nullptr) { json_ctxID = string(token); token = strtok(nullptr, " "); json_tag = string(token); @@ -505,7 +491,7 @@ TEST(t_logd_parser_loop, normal) json_description = ""; } token = strtok(nullptr, " "); - DltContext *ctx = new DltContext(); + DltContext* ctx = new DltContext(); auto ret = map_ctx_json.emplace(json_tag, ctx); if (!ret.second) { delete ctx; @@ -588,7 +574,8 @@ TEST(t_logd_parser_loop, normal) delete t_logger_list; t_logger_list = nullptr; } -int main(int argc, char** argv) { +int main(int argc, char** argv) +{ ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/tests/components/logstorage/disable_network/disable_network.cpp b/tests/components/logstorage/disable_network/disable_network.cpp index f3664156a..733e4a290 100644 --- a/tests/components/logstorage/disable_network/disable_network.cpp +++ b/tests/components/logstorage/disable_network/disable_network.cpp @@ -4,7 +4,7 @@ #include "dlt/dlt.h" #include "dlt/dlt_user_macros.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int i = 0; int c = 0; @@ -13,31 +13,28 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "c:n:")) != -1) { switch (c) { - case 'c': - { - num_context = atoi(optarg); - break; - } - case 'n': - { - max_msg = atoi(optarg); - break; - } - default: - { - break; - } + case 'c': { + num_context = atoi(optarg); + break; + } + case 'n': { + max_msg = atoi(optarg); + break; + } + default: { + break; + } } } - DltContext *ctx = (DltContext *)malloc(sizeof(DltContext) * num_context); + DltContext* ctx = (DltContext*)malloc(sizeof(DltContext) * num_context); if (!ctx) { fprintf(stderr, "Failed to allocate memory for contexts\n"); return 1; } DLT_REGISTER_APP("DSNW", "APP: Disable network routing"); - for(i = 0; i < num_context; i++) { + for (i = 0; i < num_context; i++) { char ctid[16], ctdesc[255]; snprintf(ctid, sizeof(ctid), "CT%02d", i + 1); snprintf(ctdesc, sizeof(ctdesc), "Test Context %02d", i + 1); diff --git a/tests/components/logstorage/logstorage_filepath/logstorage_filepath.cpp b/tests/components/logstorage/logstorage_filepath/logstorage_filepath.cpp index 2d460f549..148500632 100644 --- a/tests/components/logstorage/logstorage_filepath/logstorage_filepath.cpp +++ b/tests/components/logstorage/logstorage_filepath/logstorage_filepath.cpp @@ -4,7 +4,7 @@ #include "dlt/dlt.h" #include "dlt/dlt_user_macros.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int i = 0; int c = 0; @@ -13,31 +13,28 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "c:n:")) != -1) { switch (c) { - case 'c': - { - num_context = atoi(optarg); - break; - } - case 'n': - { - max_msg = atoi(optarg); - break; - } - default: - { - break; - } + case 'c': { + num_context = atoi(optarg); + break; + } + case 'n': { + max_msg = atoi(optarg); + break; + } + default: { + break; + } } } - DltContext *ctx = (DltContext *)malloc(sizeof(DltContext) * num_context); + DltContext* ctx = (DltContext*)malloc(sizeof(DltContext) * num_context); if (!ctx) { fprintf(stderr, "Failed to allocate memory for contexts\n"); return 1; } DLT_REGISTER_APP("FPTH", "Logstorage filepath"); - for(i = 0; i < num_context; i++) { + for (i = 0; i < num_context; i++) { char ctid[16], ctdesc[255]; snprintf(ctid, sizeof(ctid), "CT%02d", i + 1); snprintf(ctdesc, sizeof(ctdesc), "Test Context %02d", i + 1); diff --git a/tests/components/logstorage/logstorage_fsync/logstorage_fsync.cpp b/tests/components/logstorage/logstorage_fsync/logstorage_fsync.cpp index 4ef74d886..5c2fd0d76 100644 --- a/tests/components/logstorage/logstorage_fsync/logstorage_fsync.cpp +++ b/tests/components/logstorage/logstorage_fsync/logstorage_fsync.cpp @@ -4,7 +4,7 @@ #include "dlt/dlt.h" #include "dlt/dlt_user_macros.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int i = 0; int c = 0; @@ -13,31 +13,28 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "c:n:")) != -1) { switch (c) { - case 'c': - { - num_context = atoi(optarg); - break; - } - case 'n': - { - max_msg = atoi(optarg); - break; - } - default: - { - break; - } + case 'c': { + num_context = atoi(optarg); + break; + } + case 'n': { + max_msg = atoi(optarg); + break; + } + default: { + break; + } } } - DltContext *ctx = (DltContext *)malloc(sizeof(DltContext) * num_context); + DltContext* ctx = (DltContext*)malloc(sizeof(DltContext) * num_context); if (!ctx) { fprintf(stderr, "Failed to allocate memory for contexts\n"); return 1; } DLT_REGISTER_APP("FSNC", "CT: Logstorage fsync"); - for(i = 0; i < num_context; i++) { + for (i = 0; i < num_context; i++) { char ctid[16], ctdesc[255]; snprintf(ctid, sizeof(ctid), "CT%02d", i + 1); snprintf(ctdesc, sizeof(ctdesc), "Test Context %02d", i + 1); diff --git a/tests/components/logstorage/logstorage_max_cache_size/logstorage_max_cache_size.cpp b/tests/components/logstorage/logstorage_max_cache_size/logstorage_max_cache_size.cpp index dc80ed3bc..ec83b64f7 100644 --- a/tests/components/logstorage/logstorage_max_cache_size/logstorage_max_cache_size.cpp +++ b/tests/components/logstorage/logstorage_max_cache_size/logstorage_max_cache_size.cpp @@ -10,14 +10,14 @@ int main() int num_context = 4; int max_msg = 20; - DltContext *ctx = (DltContext *)malloc(sizeof(DltContext) * num_context); + DltContext* ctx = (DltContext*)malloc(sizeof(DltContext) * num_context); if (!ctx) { fprintf(stderr, "Failed to allocate memory for contexts\n"); return 1; } DLT_REGISTER_APP("LMAX", "CT: Logstorage max cache size"); - for(i = 0; i < num_context; i++) { + for (i = 0; i < num_context; i++) { char ctid[DLT_ID_SIZE + 1], ctdesc[255]; snprintf(ctid, DLT_ID_SIZE + 1, "CT%02d", i + 1); snprintf(ctdesc, 255, "Test Context %02d", i + 1); @@ -26,7 +26,8 @@ int main() for (i = 0; i <= max_msg; i++) { for (int j = 0; j < num_context; j++) { - DLT_LOG(ctx[j], DLT_LOG_INFO, DLT_STRING("Max Cache Size: Log message"), DLT_UINT32(j + 1), DLT_STRING("#")); + DLT_LOG( + ctx[j], DLT_LOG_INFO, DLT_STRING("Max Cache Size: Log message"), DLT_UINT32(j + 1), DLT_STRING("#")); } struct timespec tv = {0, 1000000}; nanosleep(&tv, NULL); diff --git a/tests/components/logstorage/logstorage_multi_file/logstorage_multi_file.cpp b/tests/components/logstorage/logstorage_multi_file/logstorage_multi_file.cpp index d90b3cf39..f56934092 100644 --- a/tests/components/logstorage/logstorage_multi_file/logstorage_multi_file.cpp +++ b/tests/components/logstorage/logstorage_multi_file/logstorage_multi_file.cpp @@ -4,7 +4,7 @@ #include "dlt/dlt.h" #include "dlt/dlt_user_macros.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int i = 0; int c = 0; @@ -13,31 +13,28 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "c:n:")) != -1) { switch (c) { - case 'c': - { - num_context = atoi(optarg); - break; - } - case 'n': - { - max_msg = atoi(optarg); - break; - } - default: - { - break; - } + case 'c': { + num_context = atoi(optarg); + break; + } + case 'n': { + max_msg = atoi(optarg); + break; + } + default: { + break; + } } } - DltContext *ctx = (DltContext *)malloc(sizeof(DltContext) * num_context); + DltContext* ctx = (DltContext*)malloc(sizeof(DltContext) * num_context); if (!ctx) { fprintf(stderr, "Failed to allocate memory for contexts\n"); return 1; } DLT_REGISTER_APP("MLTI", "CT: Logstorage multi file"); - for(i = 0; i < num_context; i++) { + for (i = 0; i < num_context; i++) { char ctid[16], ctdesc[255]; snprintf(ctid, sizeof(ctid), "CT%02d", i + 1); snprintf(ctdesc, sizeof(ctdesc), "Test Context %02d", i + 1); diff --git a/tests/components/logstorage/logstorage_one_file/logstorage_one_file.cpp b/tests/components/logstorage/logstorage_one_file/logstorage_one_file.cpp index eadea4f48..03b848ca2 100644 --- a/tests/components/logstorage/logstorage_one_file/logstorage_one_file.cpp +++ b/tests/components/logstorage/logstorage_one_file/logstorage_one_file.cpp @@ -4,7 +4,7 @@ #include "dlt/dlt.h" #include "dlt/dlt_user_macros.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int i = 0; int c = 0; @@ -13,31 +13,28 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "c:n:")) != -1) { switch (c) { - case 'c': - { - num_context = atoi(optarg); - break; - } - case 'n': - { - max_msg = atoi(optarg); - break; - } - default: - { - break; - } + case 'c': { + num_context = atoi(optarg); + break; + } + case 'n': { + max_msg = atoi(optarg); + break; + } + default: { + break; + } } } - DltContext *ctx = (DltContext *)malloc(sizeof(DltContext) * num_context); + DltContext* ctx = (DltContext*)malloc(sizeof(DltContext) * num_context); if (!ctx) { fprintf(stderr, "Failed to allocate memory for contexts\n"); return 1; } DLT_REGISTER_APP("LONE", "CT: Logstorage one file"); - for(i = 0; i < num_context; i++) { + for (i = 0; i < num_context; i++) { char ctid[16], ctdesc[255]; snprintf(ctid, sizeof(ctid), "CT%02d", i + 1); snprintf(ctdesc, sizeof(ctdesc), "Test Context %02d", i + 1); diff --git a/tests/dlt_env_ll_unit_test.cpp b/tests/dlt_env_ll_unit_test.cpp index 1e9a88eda..7f463b0a8 100644 --- a/tests/dlt_env_ll_unit_test.cpp +++ b/tests/dlt_env_ll_unit_test.cpp @@ -29,7 +29,7 @@ /* simply include the whole file to allow testing it */ #include "src/lib/dlt_env_ll.c" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); @@ -41,7 +41,7 @@ TEST(DltExtensionTests, extract_id) char id[4u]; char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; + char* tmp = &env0[0]; ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); ASSERT_EQ(tmp - &env0[0], 4); /* moved 4 bytes */ ASSERT_EQ(id[0], 'a'); @@ -125,7 +125,7 @@ TEST(DltExtensionTests, extract_ll) int8_t ll; char env_1[] = "-1"; - char *tmp = &env_1[0]; + char* tmp = &env_1[0]; ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); ASSERT_EQ(tmp - &env_1[0], 2); /* moved 2 bytes */ ASSERT_EQ(ll, -1); @@ -207,7 +207,7 @@ TEST(DltExtensionTests, extract_ll_item) dlt_env_ll_item item; char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; + char* tmp = &env0[0]; ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); ASSERT_EQ(tmp - &env0[0], 11); /* moved 11 bytes */ ASSERT_EQ(item.appId[0], 'a'); @@ -269,8 +269,8 @@ TEST(DltExtensionTests, extract_ll_item) TEST(DltExtensionTests, basic_ll_set_handling) { - dlt_env_init_ll_set(NULL); /* must not crash */ - dlt_env_free_ll_set(NULL); /* must not crash */ + dlt_env_init_ll_set(NULL); /* must not crash */ + dlt_env_free_ll_set(NULL); /* must not crash */ dlt_env_increase_ll_set(NULL); /* must not crash */ dlt_env_ll_set ll_set; @@ -287,7 +287,7 @@ TEST(DltExtensionTests, basic_ll_set_handling) dlt_env_init_ll_set(&ll_set); for (int i = 0; i < DLT_ENV_LL_SET_INCREASE; ++i) - ll_set.item[i].ll = (uint8_t)i; + ll_set.item[i].ll = (uint8_t)i; dlt_env_increase_ll_set(&ll_set); EXPECT_EQ(2 * DLT_ENV_LL_SET_INCREASE, ll_set.array_size); @@ -307,7 +307,7 @@ TEST(DltExtensionTests, extract_ll_set) dlt_env_ll_set ll_set; char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; + char* tmp = &env0[0]; ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); EXPECT_EQ(ll_set.array_size, DLT_ENV_LL_SET_INCREASE); @@ -318,7 +318,8 @@ TEST(DltExtensionTests, extract_ll_set) /* force increasing the list */ char env1[] = - "abcd:0000:3;abcd:0001:3;abcd:0002:3;abcd:0003:3;abcd:0004:3;abcd:0005:3;abcd:0006:3;abcd:0007:3;abcd:0008:3;abcd:0009:3;abcd:0010:3"; + "abcd:0000:3;abcd:0001:3;abcd:0002:3;abcd:0003:3;abcd:0004:3;abcd:0005:3;abcd:0006:3;abcd:0007:3;abcd:0008:3;" + "abcd:0009:3;abcd:0010:3"; tmp = &env1[0]; ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); EXPECT_EQ(ll_set.array_size, 2 * DLT_ENV_LL_SET_INCREASE); @@ -391,7 +392,7 @@ TEST(DltExtensionTests, adjust_ll_from_env) dlt_env_ll_set ll_set; dlt_env_init_ll_set(&ll_set); - EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(NULL, apid, ctid, ll)); /* orig value in case of error */ + EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(NULL, apid, ctid, ll)); /* orig value in case of error */ EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, NULL, ctid, ll)); /* orig value in case of error */ EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, NULL, ll)); /* orig value in case of error */ @@ -442,41 +443,41 @@ TEST(DltExtensionTests, dlt_env_helper_to_lower) /* default behavior */ char env0[] = "1238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo;ABcd"; char res0[] = "1238<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; - char *tmp0 = &env0[0]; + char* tmp0 = &env0[0]; char result0[sizeof(res0)]; ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp0, result0, sizeof(result0))); - ASSERT_EQ(';', *tmp0); /* next char is ';' */ + ASSERT_EQ(';', *tmp0); /* next char is ';' */ ASSERT_STREQ(res0, result0); /* stops at ';' and is correctly converted */ /* default behavior with end of string */ char env1[] = "1238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; char res1[] = "1238<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; - char *tmp1 = &env1[0]; + char* tmp1 = &env1[0]; char result1[sizeof(res1)]; ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp1, result1, sizeof(result1))); - ASSERT_EQ(0, *tmp1); /* next char is void */ + ASSERT_EQ(0, *tmp1); /* next char is void */ ASSERT_STREQ(res1, result1); /* stops at end-of-string and is correctly converted */ /* result string too short */ char env2[] = "2238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; char res2[] = "2238<><<>>>>#$//abcdabcdedfg"; - char *tmp2 = &env2[0]; + char* tmp2 = &env2[0]; char result2[sizeof(res2)]; ASSERT_EQ(-1, dlt_env_helper_to_lower(&tmp2, result2, sizeof(result2))); - ASSERT_EQ('H', *tmp2); /* next char is void */ + ASSERT_EQ('H', *tmp2); /* next char is void */ ASSERT_STREQ(res2, result2); /* stops at end-of-string and is partially converted */ /* input string shorter than result */ char env3[] = "3338<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; char res3[] = "3338<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; - char *tmp3 = &env3[0]; + char* tmp3 = &env3[0]; char result3[sizeof(res3) + 5]; ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp3, result3, sizeof(result3))); - ASSERT_EQ(0, *tmp3); /* next char is void */ + ASSERT_EQ(0, *tmp3); /* next char is void */ ASSERT_STREQ(res3, result3); /* stops at end-of-string and is correctly converted */ } @@ -487,7 +488,7 @@ TEST(DltExtensionTests, dlt_env_extract_symbolic_ll) /* correct behavior */ char env0[] = "DEFAULT;off;fatal;error;warning;info;DeBuG;verbose"; - char *tmp0 = &env0[0]; + char* tmp0 = &env0[0]; ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); ASSERT_EQ('o', *tmp0); @@ -523,7 +524,7 @@ TEST(DltExtensionTests, dlt_env_extract_symbolic_ll) /* incorrect behavior */ char env1[] = "DEF"; - char *tmp1 = &env1[0]; + char* tmp1 = &env1[0]; result = 18; ASSERT_EQ(-1, dlt_env_extract_symbolic_ll(&tmp1, &result)); @@ -532,7 +533,7 @@ TEST(DltExtensionTests, dlt_env_extract_symbolic_ll) /* incorrect behavior */ char env2[] = "DEFaultingfBa"; - char *tmp2 = &env2[0]; + char* tmp2 = &env2[0]; result = 28; ASSERT_EQ(-1, dlt_env_extract_symbolic_ll(&tmp2, &result)); diff --git a/tests/dlt_test_receiver.c b/tests/dlt_test_receiver.c index 9e86d25d0..cd1e8f99a 100644 --- a/tests/dlt_test_receiver.c +++ b/tests/dlt_test_receiver.c @@ -69,11 +69,11 @@ * aw 13.01.2010 initial */ -#include /* for isprint() */ -#include /* for atoi() */ -#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ -#include /* for open() */ -#include /* for writev() */ +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ +#include /* for writev() */ #include #include @@ -82,13 +82,13 @@ #define DLT_RECEIVE_ECU_ID "RECV" /* Function prototypes */ -int dlt_receive_filetransfer_callback(DltMessage *message, void *data); +int dlt_receive_filetransfer_callback(DltMessage* message, void* data); typedef struct { int vflag; int yflag; - char *ovalue; - char *evalue; + char* ovalue; + char* evalue; int bvalue; int filetransfervalue; int systemjournalvalue; @@ -101,7 +101,7 @@ typedef struct { DltFilter filter; } DltReceiveData; -FILE *fp; +FILE* fp; int result = 0; /** @@ -134,7 +134,7 @@ void usage() /** * Main function of tool. */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { DltClient dltclient; DltReceiveData dltdata; @@ -157,78 +157,65 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "vshSRyfla:o:e:b:")) != -1) switch (c) { - case 'v': - { + case 'v': { dltdata.vflag = 1; break; } - case 'h': - { + case 'h': { usage(); return -1; } - case 'S': - { + case 'S': { dltdata.sendSerialHeaderFlag = 1; break; } - case 'R': - { + case 'R': { dltdata.resyncSerialHeaderFlag = 1; break; } - case 'y': - { + case 'y': { dltdata.yflag = 1; break; } - case 'f': - { + case 'f': { dltdata.filetransfervalue = 1; break; } - case 's': - { + case 's': { dltdata.systemjournalvalue = 1; break; } - case 'l': - { + case 'l': { dltdata.systemloggervalue = 1; break; } - case 'o': - { + case 'o': { dltdata.ovalue = optarg; break; } - case 'e': - { + case 'e': { dltdata.evalue = optarg; break; } - case 'b': - { + case 'b': { dltdata.bvalue = atoi(optarg); break; } - case '?': - { + case '?': { if (optopt == 'o') - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); /* unknown or wrong option used, show usage information and terminate */ usage(); return -1; } - default: - { - abort (); - return -1; /*for parasoft */ + default: { + abort(); + return -1; /*for parasoft */ } } @@ -257,8 +244,7 @@ int main(int argc, char *argv[]) dlt_client_cleanup(&dltclient, dltdata.vflag); return -1; } - } - else { + } else { for (int index = optind; index < argc; index++) if (dlt_client_set_serial_device(&dltclient, argv[index]) == -1) { fprintf(stderr, "set serial device didn't succeed\n"); @@ -289,7 +275,8 @@ int main(int argc, char *argv[]) /* open DLT output file */ if (dltdata.ovalue) { - dltdata.ohandle = open(dltdata.ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + dltdata.ohandle = + open(dltdata.ovalue, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ if (dltdata.ohandle == -1) { dlt_file_free(&(dltdata.file), dltdata.vflag); @@ -305,7 +292,6 @@ int main(int argc, char *argv[]) /* Connect to TCP socket or open serial device */ if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) { - /* Dlt Client Main Loop */ dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); @@ -324,9 +310,9 @@ int main(int argc, char *argv[]) return 0; } -int dlt_receive_filetransfer_callback(DltMessage *message, void *data) +int dlt_receive_filetransfer_callback(DltMessage* message, void* data) { - DltReceiveData *dltdata; + DltReceiveData* dltdata; static char text[DLT_RECEIVE_BUFSIZE]; char filename[255]; struct iovec iov[2]; @@ -335,14 +321,14 @@ int dlt_receive_filetransfer_callback(DltMessage *message, void *data) if ((message == 0) || (data == 0)) return -1; - dltdata = (DltReceiveData *)data; + dltdata = (DltReceiveData*)data; if (dltdata->filetransfervalue) { dlt_message_print_ascii(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); /* 1st find starting point of tranfering data packages */ if (strncmp(text, "FLST", 4) == 0) { - char *tmpFilename; + char* tmpFilename; tmpFilename = strrchr(text, '/') + 1; unsigned int i; @@ -367,7 +353,7 @@ int dlt_receive_filetransfer_callback(DltMessage *message, void *data) if (strncmp(text, "FLDA", 4) == 0) { /* truncate beginning of data stream ( FLDA, File identifier and package number) */ int space_char = 32; - char *position = strchr(text, space_char); /* search for space */ + char* position = strchr(text, space_char); /* search for space */ if (position == NULL) { printf("Filetransfer FLDA: No space found in text: '%s'\n", text); return -1; @@ -398,10 +384,10 @@ int dlt_receive_filetransfer_callback(DltMessage *message, void *data) if (dltdata->systemjournalvalue) { dlt_message_print_ascii(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); /* 1st find the relevant packages */ - char *tmp = message->extendedheader->ctid; + char* tmp = message->extendedheader->ctid; tmp[4] = '\0'; - if (strcmp(tmp, (const char *)"JOUR") == 0) { + if (strcmp(tmp, (const char*)"JOUR") == 0) { if (strstr(text, "DLT SYSTEM JOURNAL TEST")) { result++; @@ -414,13 +400,13 @@ int dlt_receive_filetransfer_callback(DltMessage *message, void *data) if (dltdata->systemloggervalue) { dlt_message_print_ascii(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); /* 1st find the relevant packages */ - char *tmp = message->extendedheader->ctid; + char* tmp = message->extendedheader->ctid; tmp[4] = '\0'; - const char *substring = text; - const char *founding = "Test Systemlogger"; + const char* substring = text; + const char* founding = "Test Systemlogger"; int length = (int)strlen(founding); - if (strcmp(tmp, (const char *)"PROC") == 0) { + if (strcmp(tmp, (const char*)"PROC") == 0) { substring = strstr(text, founding); while (substring != NULL) { @@ -451,9 +437,9 @@ int dlt_receive_filetransfer_callback(DltMessage *message, void *data) return 0; } -int dlt_receive_filetransfer_callback_v2(DltMessageV2 *message, void *data) +int dlt_receive_filetransfer_callback_v2(DltMessageV2* message, void* data) { - DltReceiveData *dltdata; + DltReceiveData* dltdata; static char text[DLT_RECEIVE_BUFSIZE]; char filename[255]; struct iovec iov[2]; @@ -462,14 +448,14 @@ int dlt_receive_filetransfer_callback_v2(DltMessageV2 *message, void *data) if ((message == 0) || (data == 0)) return -1; - dltdata = (DltReceiveData *)data; + dltdata = (DltReceiveData*)data; if (dltdata->filetransfervalue) { dlt_message_print_ascii_v2(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag); /* 1st find starting point of tranfering data packages */ if (strncmp(text, "FLST", 4) == 0) { - char *tmpFilename; + char* tmpFilename; tmpFilename = strrchr(text, '/') + 1; unsigned int i; @@ -493,7 +479,7 @@ int dlt_receive_filetransfer_callback_v2(DltMessageV2 *message, void *data) /* 2nd check if incomming data are filetransfer data */ if (strncmp(text, "FLDA", 4) == 0) { /* truncate beginning of data stream ( FLDA, File identifier and package number) */ - char *position = strchr(text, 32); /* search for space */ + char* position = strchr(text, 32); /* search for space */ strncpy(text, position + 1, DLT_RECEIVE_BUFSIZE); position = strchr(text, 32); strncpy(text, position + 1, DLT_RECEIVE_BUFSIZE); @@ -523,7 +509,8 @@ int dlt_receive_filetransfer_callback_v2(DltMessageV2 *message, void *data) char tmp_ctid[DLT_V2_ID_SIZE]; memset(tmp_ctid, 0, DLT_V2_ID_SIZE); int ctidlen = (int)message->extendedheaderv2.ctidlen; - if (ctidlen > DLT_V2_ID_SIZE - 1) ctidlen = DLT_V2_ID_SIZE - 1; + if (ctidlen > DLT_V2_ID_SIZE - 1) + ctidlen = DLT_V2_ID_SIZE - 1; if (message->extendedheaderv2.ctid && ctidlen > 0) memcpy(tmp_ctid, message->extendedheaderv2.ctid, (size_t)ctidlen); @@ -543,11 +530,12 @@ int dlt_receive_filetransfer_callback_v2(DltMessageV2 *message, void *data) char tmp_ctid[DLT_V2_ID_SIZE]; memset(tmp_ctid, 0, DLT_V2_ID_SIZE); int ctidlen = (int)message->extendedheaderv2.ctidlen; - if (ctidlen > DLT_V2_ID_SIZE - 1) ctidlen = DLT_V2_ID_SIZE - 1; + if (ctidlen > DLT_V2_ID_SIZE - 1) + ctidlen = DLT_V2_ID_SIZE - 1; if (message->extendedheaderv2.ctid && ctidlen > 0) memcpy(tmp_ctid, message->extendedheaderv2.ctid, (size_t)ctidlen); - const char *substring = text; - const char *founding = "Test Systemlogger"; + const char* substring = text; + const char* founding = "Test Systemlogger"; int length = (int)strlen(founding); if (strcmp(tmp_ctid, "PROC") == 0) { diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp index 3d9c6744b..9bd3dfebc 100644 --- a/tests/gtest_dlt_common.cpp +++ b/tests/gtest_dlt_common.cpp @@ -32,8 +32,7 @@ #define BINARY_FILE_NAME "/testfile.dlt" #define FILTER_FILE_NAME "/testfilter.txt" -extern "C" -{ +extern "C" { #include "dlt-daemon.h" #include "dlt-daemon_cfg.h" #include "dlt_user_cfg.h" @@ -41,24 +40,20 @@ extern "C" #include "dlt_client.h" #include "dlt_protocol.h" -int dlt_buffer_increase_size(DltBuffer *); -int dlt_buffer_minimize_size(DltBuffer *); -int dlt_buffer_reset(DltBuffer *); -DltReturnValue dlt_buffer_push(DltBuffer *, const unsigned char *, unsigned int); -DltReturnValue dlt_buffer_push3(DltBuffer *, - const unsigned char *, - unsigned int, - const unsigned char *, - unsigned int, - const unsigned char *, - unsigned int); -int dlt_buffer_get(DltBuffer *, unsigned char *, int, int); -int dlt_buffer_pull(DltBuffer *, unsigned char *, int); -int dlt_buffer_remove(DltBuffer *); -void dlt_buffer_status(DltBuffer *); -void dlt_buffer_write_block(DltBuffer *, int *, const unsigned char *, unsigned int); -void dlt_buffer_read_block(DltBuffer *, int *, unsigned char *, unsigned int); -void dlt_buffer_info(DltBuffer *); +int dlt_buffer_increase_size(DltBuffer*); +int dlt_buffer_minimize_size(DltBuffer*); +int dlt_buffer_reset(DltBuffer*); +DltReturnValue dlt_buffer_push(DltBuffer*, const unsigned char*, unsigned int); +DltReturnValue dlt_buffer_push3( + DltBuffer*, const unsigned char*, unsigned int, const unsigned char*, unsigned int, const unsigned char*, + unsigned int); +int dlt_buffer_get(DltBuffer*, unsigned char*, int, int); +int dlt_buffer_pull(DltBuffer*, unsigned char*, int); +int dlt_buffer_remove(DltBuffer*); +void dlt_buffer_status(DltBuffer*); +void dlt_buffer_write_block(DltBuffer*, int*, const unsigned char*, unsigned int); +void dlt_buffer_read_block(DltBuffer*, int*, unsigned char*, unsigned int); +void dlt_buffer_info(DltBuffer*); } @@ -68,9 +63,10 @@ TEST(t_dlt_buffer_init_dynamic, normal) DltBuffer init_dynamic; /* Normal Use-Case for initializing a buffer */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&init_dynamic, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &init_dynamic, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&init_dynamic)); /* Min Values for a success init */ @@ -79,29 +75,33 @@ TEST(t_dlt_buffer_init_dynamic, normal) } TEST(t_dlt_buffer_init_dynamic, abnormal) { -/* DltBuffer buf; */ + /* DltBuffer buf; */ /* Initialze buffer twice, expected -1 for second init */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, + * DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ /* Initialize buffer with max-value of uint32, expected 0 */ /* TODO: what should the maximum parameter values be? UINT_MAX is too large and leads to segfault */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, UINT_MAX,UINT_MAX,UINT_MAX)); */ -/* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, UINT_MAX,UINT_MAX,UINT_MAX)); */ + /* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ /* Initialize buffer with min-value of uint32, expected 0 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, 0,0,0)); */ -/* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, 0,0,0)); */ + /* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ /* Initialize buffer min-value > max-value, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ /* Initialsize buffer step-value > max-value, expected -1 */ -/* EXPECT_GE(-1,dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE * 2)); */ -/* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_GE(-1,dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE * 2)); */ + /* EXPECT_LE(DLT_RETURN_OK,dlt_buffer_free_dynamic(&buf)); */ } TEST(t_dlt_buffer_init_dynamic, nullpointer) { @@ -111,41 +111,46 @@ TEST(t_dlt_buffer_init_dynamic, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(NULL, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(NULL, 0, 0, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(NULL, 0, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(NULL, 0, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_init_dynamic(NULL, 0, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(NULL, DLT_USER_RINGBUFFER_MIN_SIZE, 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(NULL, DLT_USER_RINGBUFFER_MIN_SIZE, 0, DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(NULL, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(NULL, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_init_dynamic(NULL, DLT_USER_RINGBUFFER_MIN_SIZE, 0, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_init_dynamic(NULL, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_init_dynamic( + NULL, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(&buf, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(&buf, 0, 0, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(&buf, 0, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(&buf, 0, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_init_dynamic(&buf, 0, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, 0, DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, 0, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); } /* End Method: dlt_common::dlt_buffer_init_dynamic */ - /* Begin Method: dlt_common::dlt_buffer_free_dynamic */ TEST(t_dlt_buffer_free_dynamic, normal) { DltBuffer buf; /* Normal Use-Case szenario */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case szenario */ @@ -154,16 +159,16 @@ TEST(t_dlt_buffer_free_dynamic, normal) } TEST(t_dlt_buffer_free_dynamic, abnormal) { -/* DltBuffer buf; */ + /* DltBuffer buf; */ /* Free uninizialised buffer, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_free_dynamic(&buf)); */ /* Free buffer twice, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ -/* EXPECT_GE(-1, dlt_buffer_free_dynamic(&buf)); */ - + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_free_dynamic(&buf)); */ } TEST(t_dlt_buffer_free_dynamic, nullpointer) { @@ -174,26 +179,26 @@ TEST(t_dlt_buffer_free_dynamic, nullpointer) - /* Begin Method: dlt_common::dlt_buffer_increase_size */ TEST(t_dlt_buffer_increase_size, normal) { DltBuffer buf; /* Normal Use-Case, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(0, dlt_buffer_increase_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Fill buffer to max-value, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (int i = 0; - i <= (DLT_USER_RINGBUFFER_MAX_SIZE / DLT_USER_RINGBUFFER_MIN_SIZE); + for (int i = 0; i <= (DLT_USER_RINGBUFFER_MAX_SIZE / DLT_USER_RINGBUFFER_MIN_SIZE); i += DLT_USER_RINGBUFFER_STEP_SIZE) EXPECT_LE(0, dlt_buffer_increase_size(&buf)); @@ -207,12 +212,17 @@ TEST(t_dlt_buffer_increase_size, abnormal) EXPECT_GE(-1, dlt_buffer_increase_size(&buf)); /* Fill buffer over max-value, expected -1 */ - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_increase_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* min-value > max-value, init should fail, expected -1 */ - EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + -1, dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /* init with 0 step size should fail, expected -1 */ EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); @@ -230,19 +240,20 @@ TEST(t_dlt_buffer_minimize_size, normal) DltBuffer buf; /* Normal Use-Case, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(0, dlt_buffer_minimize_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* minimize buffer to min-value, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (int i = (DLT_USER_RINGBUFFER_MAX_SIZE / DLT_USER_RINGBUFFER_MIN_SIZE); - i >= 0; + for (int i = (DLT_USER_RINGBUFFER_MAX_SIZE / DLT_USER_RINGBUFFER_MIN_SIZE); i >= 0; i -= DLT_USER_RINGBUFFER_STEP_SIZE) EXPECT_LE(0, dlt_buffer_minimize_size(&buf)); @@ -253,12 +264,17 @@ TEST(t_dlt_buffer_minimize_size, abnormal) DltBuffer buf; /* minimize buffer already at min-value, expected 0 (no-op) */ - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_EQ(DLT_RETURN_OK, dlt_buffer_minimize_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* min-value > max-value, init should fail, expected -1 */ - EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE( + -1, dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /* init with 0 step size should fail, expected -1 */ EXPECT_GE(-1, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, 0)); @@ -277,11 +293,11 @@ TEST(t_dlt_buffer_reset, normal) DltBuffer buf; /* Normal Use-Case. expect 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(0, dlt_buffer_reset(&buf)); - } TEST(t_dlt_buffer_reset, nullpointer) { @@ -294,24 +310,25 @@ TEST(t_dlt_buffer_reset, nullpointer) TEST(t_dlt_buffer_push, normal) { DltBuffer buf; - char *test; + char* test; unsigned int size = sizeof(test); /* Normal Use-Case, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&test, size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&test, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Push till buffer is full, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (unsigned int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / (size + sizeof(DltBufferBlockHead))); i++) - { - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&test, size)); + for (unsigned int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / (size + sizeof(DltBufferBlockHead))); i++) { + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&test, size)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); @@ -319,185 +336,179 @@ TEST(t_dlt_buffer_push, normal) TEST(t_dlt_buffer_push, abnormal) { DltBuffer buf; - char * test = nullptr; + char* test = nullptr; int size = sizeof(test); /* Push till buffer is overfilled , expected -1 */ - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for(int i=0; i<= (DLT_USER_RINGBUFFER_MIN_SIZE/size) + size; i++) - { - if(i <= DLT_USER_RINGBUFFER_MIN_SIZE) - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&test,size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + for (int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / size) + size; i++) { + if (i <= DLT_USER_RINGBUFFER_MIN_SIZE) + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&test, size)); else - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(&buf,(unsigned char *)&test,size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(&buf, (unsigned char*)&test, size)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - } TEST(t_dlt_buffer_push, nullpointer) { - char *test; + char* test; int size = sizeof(test); /* NULL-Pointer, expected -1 */ EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(NULL, NULL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(NULL, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(NULL, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(NULL, (unsigned char *)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(NULL, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push(NULL, (unsigned char*)&test, size)); } /* End Method: dlt_common::dlt_buffer_push*/ - /* Begin Method: dlt_common::dlt_buffer_push3 */ TEST(t_dlt_buffer_push3, normal) { DltBuffer buf; - char *test; + char* test; int size = sizeof(test); /* Normal Use-Case, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push3(&buf, (unsigned char *)&test, size, 0, 0, 0, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push3(&buf, (unsigned char*)&test, size, 0, 0, 0, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_push3(&buf, (unsigned char *)&test, size, (unsigned char *)&test, size, (unsigned char *)&test, - size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_push3(&buf, (unsigned char*)&test, size, (unsigned char*)&test, size, (unsigned char*)&test, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Push till buffer is full, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); for (unsigned int i = 0; i <= (DLT_USER_RINGBUFFER_MIN_SIZE / (size * 3 + sizeof(DltBufferBlockHead))); i++) - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_push3(&buf, (unsigned char *)&test, size, (unsigned char *)&test, size, - (unsigned char *)&test, - size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_push3( + &buf, (unsigned char*)&test, size, (unsigned char*)&test, size, (unsigned char*)&test, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_push3, nullpointer) { - char *test; + char* test; int size = sizeof(test); /*Null Pointer, expected -1 */ EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, 0, NULL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, 0, (unsigned char *)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, 0, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, 0, (unsigned char*)&test, size)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, size, NULL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, size, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, size, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, 0, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, size, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, size, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, 0, (unsigned char *)&test, size, (unsigned char *)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, size, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, NULL, size, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, 0, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, 0, NULL, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, 0, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, 0, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, size, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, size, NULL, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, size, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, 0, (unsigned char*)&test, size, (unsigned char*)&test, size)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, 0, NULL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, 0, (unsigned char *)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, 0, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, 0, (unsigned char*)&test, size)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, size, NULL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, size, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, size, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, 0, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, size, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, size, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, NULL, size, (unsigned char *)&test, size, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, 0, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, size, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, size, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, NULL, size, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, 0, (unsigned char *)&test, - size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, size, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, size, (unsigned char *)&test, - 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, 0, (unsigned char *)&test, size, (unsigned char *)&test, - size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, 0, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, 0, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, size, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, size, (unsigned char *)&test, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, NULL, size, (unsigned char *)&test, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, 0, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, 0, (unsigned char *)&test, - 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, 0, (unsigned char *)&test, - size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, size, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, size, NULL, size)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, size, (unsigned char *)&test, - 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_buffer_push3(NULL, (unsigned char *)&test, size, (unsigned char *)&test, size, (unsigned char *)&test, - size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, size, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, NULL, size, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, 0, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, 0, NULL, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, 0, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, 0, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, size, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, size, NULL, size)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, size, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, NULL, size, (unsigned char*)&test, size, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, 0, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, 0, NULL, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, 0, (unsigned char*)&test, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, 0, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, size, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, size, NULL, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, size, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, NULL, size, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, 0, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, 0, NULL, size)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, 0, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, 0, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, size, NULL, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, size, NULL, size)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, size, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, 0, (unsigned char*)&test, size, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, 0, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, 0, NULL, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, 0, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, 0, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, size, NULL, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, size, NULL, size)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, size, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, NULL, size, (unsigned char*)&test, size)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, 0, NULL, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, 0, NULL, size)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, 0, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, 0, (unsigned char*)&test, size)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, size, NULL, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, size, NULL, size)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, size, (unsigned char*)&test, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_buffer_push3(NULL, (unsigned char*)&test, size, (unsigned char*)&test, size, (unsigned char*)&test, size)); } /* End Method: dlt_common::dlt_buffer_push3 */ - /* Begin Method: dlt_common::dlt_buffer_pull */ TEST(t_dlt_buffer_pull, normal) { @@ -507,38 +518,42 @@ TEST(t_dlt_buffer_pull, normal) int size = sizeof(DltUserHeader); /* Normal Use-Case, empty pull, expected -1 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_GE(-1, dlt_buffer_pull(&buf, (unsigned char *)&header, size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE(-1, dlt_buffer_pull(&buf, (unsigned char*)&header, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case, expected > 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); - EXPECT_LE(1, dlt_buffer_pull(&buf, (unsigned char *)&header, size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); + EXPECT_LE(1, dlt_buffer_pull(&buf, (unsigned char*)&header, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_pull, abnormal) { -/* DltBuffer buf; */ -/* DltUserHeader header; */ + /* DltBuffer buf; */ + /* DltUserHeader header; */ /* Uninizialised, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_pull(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); */ + /* EXPECT_GE(-1, dlt_buffer_pull(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); */ /* data == 0 and max_size == 0, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&header,sizeof(DltUserHeader))); */ -/* EXPECT_GE(-1, dlt_buffer_pull(&buf, 0, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&header,sizeof(DltUserHeader))); */ + /* EXPECT_GE(-1, dlt_buffer_pull(&buf, 0, 0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ /* no push before pull, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_GE(-1, dlt_buffer_pull(&buf, 0, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_GE(-1, dlt_buffer_pull(&buf, 0, 0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ } TEST(t_dlt_buffer_pull, nullpointer) { @@ -548,16 +563,18 @@ TEST(t_dlt_buffer_pull, nullpointer) /* NULL-Point, expected -1 */ EXPECT_GE(-1, dlt_buffer_pull(NULL, NULL, 0)); EXPECT_GE(-1, dlt_buffer_pull(NULL, NULL, sizeof(DltUserHeader))); - EXPECT_GE(-1, dlt_buffer_pull(NULL, (unsigned char *)&header, 0)); - EXPECT_GE(-1, dlt_buffer_pull(NULL, (unsigned char *)&header, sizeof(DltUserHeader))); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE(-1, dlt_buffer_pull(NULL, (unsigned char*)&header, 0)); + EXPECT_GE(-1, dlt_buffer_pull(NULL, (unsigned char*)&header, sizeof(DltUserHeader))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_pull(&buf, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_pull(&buf, NULL, sizeof(DltUserHeader))); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } @@ -573,46 +590,50 @@ TEST(t_dlt_buffer_remove, normal) int size = sizeof(DltUserHeader); /* Normal Use-Case, empty pull, expected -1 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_remove(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case, expected > 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, size)); EXPECT_LE(0, dlt_buffer_remove(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_remove, abnormal) { -/* DltBuffer buf; */ -/* DltUserHeader header; */ -/* int size = sizeof(DltUserHeader); */ + /* DltBuffer buf; */ + /* DltUserHeader header; */ + /* int size = sizeof(DltUserHeader); */ /* Uninizialised, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_remove(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_remove(&buf)); */ /* no push before remove, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_GE(-1, dlt_buffer_remove(&buf)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_GE(-1, dlt_buffer_remove(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ /* Call remove 10 time, expected > 1 till buffer is empty */ /* pushed one time so expect one > 1 and 9 times < 0 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&header,size)); */ -/* for(int i=0; i<10;i++) */ -/* { */ -/* if(i == 0) */ -/* EXPECT_LE(1, dlt_buffer_remove(&buf)); */ -/* else */ -/* EXPECT_GE(-1, dlt_buffer_remove(&buf)); */ -/* } */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&header,size)); */ + /* for(int i=0; i<10;i++) */ + /* { */ + /* if(i == 0) */ + /* EXPECT_LE(1, dlt_buffer_remove(&buf)); */ + /* else */ + /* EXPECT_GE(-1, dlt_buffer_remove(&buf)); */ + /* } */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ } TEST(t_dlt_buffer_remove, nullpointer) { @@ -623,7 +644,6 @@ TEST(t_dlt_buffer_remove, nullpointer) - /* Begin Method: dlt_common::dlt_buffer_copy */ TEST(t_dlt_buffer_copy, normal) { @@ -632,33 +652,36 @@ TEST(t_dlt_buffer_copy, normal) int size = sizeof(DltUserHeader); /* Normal Use-Case, empty pull, expected -1 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_GE(-1, dlt_buffer_copy(&buf, (unsigned char *)&header, size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE(-1, dlt_buffer_copy(&buf, (unsigned char*)&header, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case, expected > 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); - EXPECT_LE(1, dlt_buffer_copy(&buf, (unsigned char *)&header, size)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); + EXPECT_LE(1, dlt_buffer_copy(&buf, (unsigned char*)&header, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_copy, abnormal) { -/* DltBuffer buf; */ -/* DltUserHeader header; */ -/* int size = sizeof(DltUserHeader); */ + /* DltBuffer buf; */ + /* DltUserHeader header; */ + /* int size = sizeof(DltUserHeader); */ /* Uninizialised buffer , expected -1 */ -/* EXPECT_LE(-1, dlt_buffer_copy(&buf, (unsigned char *)&header, size)); */ + /* EXPECT_LE(-1, dlt_buffer_copy(&buf, (unsigned char *)&header, size)); */ /* no push before copy, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(-1, dlt_buffer_copy(&buf, (unsigned char *)&header, size)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(-1, dlt_buffer_copy(&buf, (unsigned char *)&header, size)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ } TEST(t_dlt_buffer_copy, nullpointer) { @@ -669,16 +692,18 @@ TEST(t_dlt_buffer_copy, nullpointer) /* NULL-Pointer, expected -1 */ EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL, NULL, size)); EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL, NULL, 0)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL, (unsigned char *)&header, size)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL, (unsigned char *)&header, 0)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL, (unsigned char*)&header, size)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL, (unsigned char*)&header, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(&buf, NULL, size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(&buf, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } @@ -695,122 +720,135 @@ TEST(t_dlt_buffer_get, normal) int size = sizeof(DltUserHeader); /* Normal Use-Case */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, size)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - EXPECT_LE(0, dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, size)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + EXPECT_LE(0, dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, size)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - EXPECT_LE(0, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, size)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + EXPECT_LE(0, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[0] = 50000; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[0] = 50000; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[1] = 50000; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[1] = 50000; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[2] = -50000; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[2] = -50000; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[2] = 0; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[2] = 0; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[0] = 4000; - ((int *)(buf.shm))[1] = 5000; - ((int *)(buf.shm))[2] = 0; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[0] = 4000; + ((int*)(buf.shm))[1] = 5000; + ((int*)(buf.shm))[2] = 0; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[0] = 10; - ((int *)(buf.shm))[1] = 5; - ((int *)(buf.shm))[2] = 5; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[0] = 10; + ((int*)(buf.shm))[1] = 5; + ((int*)(buf.shm))[2] = 5; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[2] = 50000; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[2] = 50000; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, size)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[0] = 19; - EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char *)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, size)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[0] = 19; + EXPECT_GE(-1, dlt_buffer_get(&buf, (unsigned char*)&header, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, size)); - printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char *)&header, size, 0)); - ((int *)(buf.shm))[2] = 19; - EXPECT_LE(0, dlt_buffer_get(&buf, (unsigned char *)&header, 5, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, size)); + printf("#### %i\n", dlt_buffer_get(&buf, (unsigned char*)&header, size, 0)); + ((int*)(buf.shm))[2] = 19; + EXPECT_LE(0, dlt_buffer_get(&buf, (unsigned char*)&header, 5, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_get, abnormal) { -/* DltBuffer buf; */ -/* DltUserHeader header; */ -/* int size = sizeof(DltUserHeader); */ + /* DltBuffer buf; */ + /* DltUserHeader header; */ + /* int size = sizeof(DltUserHeader); */ /* Uninizialsied, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_get(&buf,(unsigned char *)&header,size, 0)); */ + /* EXPECT_GE(-1, dlt_buffer_get(&buf,(unsigned char *)&header,size, 0)); */ /* Integer with 12345678 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&header,size)); */ -/* printf("#### %i\n", dlt_buffer_get(&buf,(unsigned char*)&header,size,0)); */ -/* EXPECT_LE(0, dlt_buffer_get(&buf,(unsigned char*)&header,size,12345678)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, + * DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf,(unsigned char *)&header,size)); */ + /* printf("#### %i\n", dlt_buffer_get(&buf,(unsigned char*)&header,size,0)); */ + /* EXPECT_LE(0, dlt_buffer_get(&buf,(unsigned char*)&header,size,12345678)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); */ } TEST(t_dlt_buffer_get, nullpointer) { @@ -823,28 +861,32 @@ TEST(t_dlt_buffer_get, nullpointer) EXPECT_GE(-1, dlt_buffer_get(NULL, NULL, 0, 1)); EXPECT_GE(-1, dlt_buffer_get(NULL, NULL, size, 0)); EXPECT_GE(-1, dlt_buffer_get(NULL, NULL, size, 1)); - EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char *)&header, 0, 0)); - EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char *)&header, 0, 1)); - EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char *)&header, size, 0)); - EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char *)&header, size, 1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char*)&header, 0, 0)); + EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char*)&header, 0, 1)); + EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char*)&header, size, 0)); + EXPECT_GE(-1, dlt_buffer_get(NULL, (unsigned char*)&header, size, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_get(&buf, NULL, 0, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_get(&buf, NULL, 0, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_get(&buf, NULL, size, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_GE(-1, dlt_buffer_get(&buf, NULL, size, 1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } @@ -852,7 +894,6 @@ TEST(t_dlt_buffer_get, nullpointer) - /* Begin MEthod: dlt_common::dlt_buffer_get_message_count */ TEST(t_dlt_buffer_get_message_count, normal) { @@ -860,53 +901,55 @@ TEST(t_dlt_buffer_get_message_count, normal) DltUserHeader header; /* Normal Usce-Case without pushing data, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /*printf("##### %i\n", dlt_buffer_get_message_count(&buf)); */ EXPECT_EQ(0, dlt_buffer_get_message_count(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case, with pushing data, expected 1 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); /*printf("#### %i\n", dlt_buffer_get_message_count(&buf)); */ EXPECT_EQ(1, dlt_buffer_get_message_count(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Pushing DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)) mesages */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - - for (unsigned int i = 1; i <= DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); i++) { - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + + for (unsigned int i = 1; i <= DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); + i++) { + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); /*printf("#### %i\n", dlt_buffer_get_message_count(&buf)); */ EXPECT_EQ(i, dlt_buffer_get_message_count(&buf)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - } TEST(t_dlt_buffer_get_message_count, abnormal) { -/* DltBuffer buf; */ + /* DltBuffer buf; */ /* Uninizialised, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_get_message_count(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_get_message_count(&buf)); */ } TEST(t_dlt_buffer_get_message_count, nullpointer) { /*NULL-Pointer, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_get_message_count(NULL)); */ + /* EXPECT_GE(-1, dlt_buffer_get_message_count(NULL)); */ } /* Begin MEthod: dlt_common::dlt_buffer_get_message_count */ - /* Begin Method: dlt_common::dlt_buffer_get_total_size*/ TEST(t_dlt_buffer_get_total_size, normal) { @@ -914,28 +957,30 @@ TEST(t_dlt_buffer_get_total_size, normal) DltUserHeader header; /* Normal Use-Case, expected max buffer size (DLT_USER_RINGBUFFER_MAX_SIZE) */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /*printf("##### %i\n", dlt_buffer_get_total_size(&buf)); */ EXPECT_LE(DLT_USER_RINGBUFFER_MAX_SIZE, dlt_buffer_get_total_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case, 1st pushing data, expected max buffer size (DLT_USER_RINGBUFFER_MAX_SIZE) */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); /*printf("##### %i\n", dlt_buffer_get_total_size(&buf)); */ EXPECT_LE(DLT_USER_RINGBUFFER_MAX_SIZE, dlt_buffer_get_total_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_get_total_size, abnormal) { -/* DltBuffer buf; */ + /* DltBuffer buf; */ /* Uninizialised, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_get_total_size(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_get_total_size(&buf)); */ } TEST(t_dlt_buffer_get_total_size, nullpointer) { @@ -954,29 +999,34 @@ TEST(t_dlt_buffer_get_used_size, normal) int sum = 0; /* Normal Use Cas buffer empty, expected 0 */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); /*printf("##### %i\n", dlt_buffer_get_used_size(&buf)); */ EXPECT_EQ(0, dlt_buffer_get_used_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); /* Normal Use-Case with pushing data, expected sum of DltUserHeader and DltBufferBlockHead */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); /*printf("##### %i\n", dlt_buffer_get_used_size(&buf)); */ EXPECT_EQ(sizeof(DltUserHeader) + sizeof(DltBufferBlockHead), dlt_buffer_get_used_size(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - /* Normal Use-Case with pushing DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)) data */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + /* Normal Use-Case with pushing DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)) + * data */ + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - for (unsigned int i = 1; i <= DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); i++) { - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char *)&header, sizeof(DltUserHeader))); + for (unsigned int i = 1; i <= DLT_USER_RINGBUFFER_MIN_SIZE / (sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); + i++) { + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_push(&buf, (unsigned char*)&header, sizeof(DltUserHeader))); /*printf("#### %i\n", dlt_buffer_get_used_size(&buf)); */ sum += (int)(sizeof(DltUserHeader) + sizeof(DltBufferBlockHead)); EXPECT_EQ(sum, dlt_buffer_get_used_size(&buf)); @@ -986,10 +1036,10 @@ TEST(t_dlt_buffer_get_used_size, normal) } TEST(t_dlt_buffer_get_used_size, abnormal) { -/* DltBuffer buf; */ + /* DltBuffer buf; */ /* Uninizialised, expected -1 */ -/* EXPECT_GE(-1, dlt_buffer_get_used_size(&buf)); */ + /* EXPECT_GE(-1, dlt_buffer_get_used_size(&buf)); */ } TEST(t_dlt_buffer_get_used_size, nullpointer) { @@ -1000,32 +1050,34 @@ TEST(t_dlt_buffer_get_used_size, nullpointer) - /* Begin Method: dlt_common::dlt_buffer_write_block */ TEST(t_dlt_buffer_write_block, normal) { DltBuffer buf; - unsigned char *data = NULL; + unsigned char* data = NULL; int write; int size1 = 516; int size2 = 1024; /* Normal Use-Case, void method, expected no error */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, data, size1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, data, size2)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); for (int i = 0; i <= 10000; i += 10) { EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, data, i)); } @@ -1036,63 +1088,70 @@ TEST(t_dlt_buffer_write_block, abnormal) { /* Boundary check of write position */ DltBuffer buf; - const char *data = "data"; + const char* data = "data"; int write = DLT_USER_RINGBUFFER_MIN_SIZE; write -= (int)sizeof(DltBufferHead); int size = sizeof(data); // when write = buf->size, it should not throw any warning // and write should equal to size. - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf,DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, (unsigned char *)&data, size)); - EXPECT_EQ(size , write); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, (unsigned char*)&data, size)); + EXPECT_EQ(size, write); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_write_block, nullpointer) { DltBuffer buf; - char *data; + char* data; int write; int test1 = 1000; /* NULL-Pointer, expected < 0 */ EXPECT_NO_THROW(dlt_buffer_write_block(NULL, NULL, NULL, 0)); EXPECT_NO_THROW(dlt_buffer_write_block(NULL, NULL, NULL, test1)); - EXPECT_NO_THROW(dlt_buffer_write_block(NULL, NULL, (unsigned char *)&data, 0)); - EXPECT_NO_THROW(dlt_buffer_write_block(NULL, NULL, (unsigned char *)&data, test1)); + EXPECT_NO_THROW(dlt_buffer_write_block(NULL, NULL, (unsigned char*)&data, 0)); + EXPECT_NO_THROW(dlt_buffer_write_block(NULL, NULL, (unsigned char*)&data, test1)); EXPECT_NO_THROW(dlt_buffer_write_block(NULL, &write, NULL, 0)); EXPECT_NO_THROW(dlt_buffer_write_block(NULL, &write, NULL, test1)); - EXPECT_NO_THROW(dlt_buffer_write_block(NULL, &write, (unsigned char *)&data, 0)); - EXPECT_NO_THROW(dlt_buffer_write_block(NULL, &write, (unsigned char *)&data, test1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_write_block(NULL, &write, (unsigned char*)&data, 0)); + EXPECT_NO_THROW(dlt_buffer_write_block(NULL, &write, (unsigned char*)&data, test1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, NULL, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, NULL, NULL, test1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_write_block(&buf, NULL, (unsigned char *)&data, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_write_block(&buf, NULL, (unsigned char*)&data, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_write_block(&buf, NULL, (unsigned char *)&data, test1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_write_block(&buf, NULL, (unsigned char*)&data, test1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, NULL, test1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } @@ -1100,27 +1159,28 @@ TEST(t_dlt_buffer_write_block, nullpointer) - /* Begin Method: dlt_common::dlt_buffer_read_block */ TEST(t_dlt_buffer_read_block, normal) { DltBuffer buf; - unsigned char *data = NULL; + unsigned char* data = NULL; int write, read; int size1 = 516; int size2 = 1024; /* Normal Use-Case, void method, expected no error */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, data, size1)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &write, data, size1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &read, data, size2)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &write, data, size2)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); @@ -1130,87 +1190,95 @@ TEST(t_dlt_buffer_read_block, abnormal) /* Boundary check of read position */ DltBuffer buf; /* Buffer to read data from DltBuffer */ - unsigned char *data_read; - data_read = (unsigned char *) calloc(1000, sizeof(char)); + unsigned char* data_read; + data_read = (unsigned char*)calloc(1000, sizeof(char)); int read = DLT_USER_RINGBUFFER_MIN_SIZE; read -= (int)sizeof(DltBufferHead); int size = 1000; // when read = buf->size, it should not throw any warning // and read position should equal to size. - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, data_read, size)); - EXPECT_EQ(size,read); + EXPECT_EQ(size, read); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); free(data_read); } TEST(t_dlt_buffer_read_block, nullpointer) { DltBuffer buf; - char *data; + char* data; int read = -1; int test1 = 1000; /* NULL-Pointer, expected < 0 */ EXPECT_NO_THROW(dlt_buffer_read_block(NULL, NULL, NULL, 0)); EXPECT_NO_THROW(dlt_buffer_read_block(NULL, NULL, NULL, test1)); - EXPECT_NO_THROW(dlt_buffer_read_block(NULL, NULL, (unsigned char *)&data, 0)); - EXPECT_NO_THROW(dlt_buffer_read_block(NULL, NULL, (unsigned char *)&data, test1)); + EXPECT_NO_THROW(dlt_buffer_read_block(NULL, NULL, (unsigned char*)&data, 0)); + EXPECT_NO_THROW(dlt_buffer_read_block(NULL, NULL, (unsigned char*)&data, test1)); EXPECT_NO_THROW(dlt_buffer_read_block(NULL, &read, NULL, 0)); EXPECT_NO_THROW(dlt_buffer_read_block(NULL, &read, NULL, test1)); - EXPECT_NO_THROW(dlt_buffer_read_block(NULL, &read, (unsigned char *)&data, 0)); - EXPECT_NO_THROW(dlt_buffer_read_block(NULL, &read, (unsigned char *)&data, test1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_read_block(NULL, &read, (unsigned char*)&data, 0)); + EXPECT_NO_THROW(dlt_buffer_read_block(NULL, &read, (unsigned char*)&data, test1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, NULL, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, NULL, NULL, test1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_read_block(&buf, NULL, (unsigned char *)&data, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_read_block(&buf, NULL, (unsigned char*)&data, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_read_block(&buf, NULL, (unsigned char *)&data, test1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_read_block(&buf, NULL, (unsigned char*)&data, test1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, NULL, test1)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, (unsigned char *)&data, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, (unsigned char*)&data, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } /* End Method: dlt_common::dlt_buffer_read_block */ - /* Begin Method: dlt_common::dlt_buffer_info */ TEST(t_dlt_buffer_info, normal) { DltBuffer buf; /* Normal Use-Case */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_info(&buf)); } TEST(t_dlt_buffer_info, abnormal) @@ -1227,16 +1295,16 @@ TEST(t_dlt_buffer_info, nullpointer) - /* Begin Method: dlt_common::dlt_buffer_status */ TEST(t_dlt_buffer_status, normal) { DltBuffer buf; /* Normal Use-Case */ - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_status(&buf)); } TEST(t_dlt_buffer_status, abnormal) @@ -1253,14 +1321,12 @@ TEST(t_dlt_buffer_status, nullpointer) - /*##############################################################################################################################*/ /*##############################################################################################################################*/ /*##############################################################################################################################*/ - /* Begin Method: dlt_common::dlt_message_init*/ TEST(t_dlt_message_init, normal) { @@ -1275,18 +1341,18 @@ TEST(t_dlt_message_init, normal) } TEST(t_dlt_message_init, abnormal) { -/* DltMessage msg; */ + /* DltMessage msg; */ /* Double use init, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,1)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,1)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,1)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,1)); */ /* set Verbose to 12345678, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,12345678)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,12345678)); */ } TEST(t_dlt_message_init, nullpointer) { @@ -1298,7 +1364,6 @@ TEST(t_dlt_message_init, nullpointer) - /* Begin Method: dlt_common::dlt_message_free */ TEST(t_dlt_message_free, normal) { @@ -1313,19 +1378,19 @@ TEST(t_dlt_message_free, normal) } TEST(t_dlt_message_free, abnormal) { -/* DltMessage msg; */ + /* DltMessage msg; */ /* Double use free, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_free(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_free(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_free(&msg,1)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_free(&msg,1)); */ /* set Verbose to 12345678, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_free(&msg,12345678)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_free(&msg,12345678)); */ } TEST(t_dlt_message_free, nullpointer) { @@ -1337,17 +1402,16 @@ TEST(t_dlt_message_free, nullpointer) - /* Begin Method: dlt_common::dlt_file_open */ TEST(t_dlt_file_open, normal) { DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1363,33 +1427,33 @@ TEST(t_dlt_file_open, normal) } TEST(t_dlt_file_open, abnormal) { -/* DltFile file; */ -/* / * Get PWD so file can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* DltFile file; */ + /* / * Get PWD so file can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* Uninizialsied, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, openfile, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, openfile, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, openfile, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, openfile, 1)); */ /* Verbose set to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, openfile, 12345678)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, openfile, 12345678)); */ /* Path doesn't exist, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, "This Path doesn't exist!!", 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_file_open(&file, "This Path doesn't exist!!", 0)); */ } TEST(t_dlt_file_open, nullpointer) { DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1406,18 +1470,17 @@ TEST(t_dlt_file_open, nullpointer) - /* Begin Method: dlt_common::dlt_file_quick_parsing */ TEST(t_dlt_file_quick_parsing, normal) { DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; char output[128] = "/tmp/output_testfile.txt"; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1435,11 +1498,11 @@ TEST(t_dlt_file_quick_parsing, abnormal) DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; char output[128] = "/tmp/output_testfile.txt"; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1459,20 +1522,18 @@ TEST(t_dlt_file_quick_parsing, abnormal) - /* Begin Method: dlt_common::dlt_message_print_ascii*/ TEST(t_dlt_message_print_ascii, normal) { - DltFile file; static char text[DLT_DAEMON_TEXTSIZE]; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1481,7 +1542,7 @@ TEST(t_dlt_message_print_ascii, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1497,32 +1558,32 @@ TEST(t_dlt_message_print_ascii, normal) } TEST(t_dlt_message_print_ascii, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ -/* / * Get PWD so file and filter can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* / * Get PWD so file and filter can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* No messages read, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ /* Set verbose to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1610,7 +1670,6 @@ TEST(t_dlt_message_print_ascii_with_filter, nullpointer) - /* Begin Method: dlt_common::dlt_message_print_header */ TEST(t_dlt_message_print_header, normal) { @@ -1619,10 +1678,10 @@ TEST(t_dlt_message_print_header, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1631,7 +1690,7 @@ TEST(t_dlt_message_print_header, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1647,32 +1706,32 @@ TEST(t_dlt_message_print_header, normal) } TEST(t_dlt_message_print_header, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ -/* / * Get PWD so file and filter can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* / * Get PWD so file and filter can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* No messages read, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ /* Set verbose to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1761,7 +1818,6 @@ TEST(t_dlt_message_print_header_with_filter, nullpointer) - /* Begin Method: dlt_common::dlt_message_print_hex */ TEST(t_dlt_message_print_hex, normal) { @@ -1770,10 +1826,10 @@ TEST(t_dlt_message_print_hex, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1782,7 +1838,7 @@ TEST(t_dlt_message_print_hex, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1798,32 +1854,32 @@ TEST(t_dlt_message_print_hex, normal) } TEST(t_dlt_message_print_hex, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ -/* / * Get PWD so file and filter can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* / * Get PWD so file and filter can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* No messages read, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_hex(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_hex(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_hex(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_hex(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ /* Set verbose to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_hex(&file.msg, text, DLT_DAEMON_TEXTSIZE, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1912,7 +1966,6 @@ TEST(t_dlt_message_print_hex_with_filter, nullpointer) - /* Begin Method: dlt_common::dlt_message_print_mixed_plain */ TEST(t_dlt_message_print_mixed_plain, normal) { @@ -1921,10 +1974,10 @@ TEST(t_dlt_message_print_mixed_plain, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -1933,7 +1986,7 @@ TEST(t_dlt_message_print_mixed_plain, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1949,32 +2002,33 @@ TEST(t_dlt_message_print_mixed_plain, normal) } TEST(t_dlt_message_print_mixed_plain, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ -/* / * Get PWD so file and filter can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* / * Get PWD so file and filter can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* No messages read, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_plain(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_plain(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_plain(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_plain(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ /* Set verbose to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_plain(&file.msg, text, DLT_DAEMON_TEXTSIZE, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2071,10 +2123,10 @@ TEST(t_dlt_message_print_mixed_html, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -2083,7 +2135,7 @@ TEST(t_dlt_message_print_mixed_html, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2099,32 +2151,33 @@ TEST(t_dlt_message_print_mixed_html, normal) } TEST(t_dlt_message_print_mixed_html, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ -/* / * Get PWD so file and filter can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* / * Get PWD so file and filter can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* No messages read, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_html(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_html(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_html(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_html(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ /* Set verbose to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_mixed_html(&file.msg, text, DLT_DAEMON_TEXTSIZE, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2212,7 +2264,6 @@ TEST(t_dlt_message_print_mixed_html_with_filter, nullpointer) - /* Begin Method:dlt_common::dlt_message_filter_check */ TEST(t_dlt_message_filter_check, normal) { @@ -2221,12 +2272,12 @@ TEST(t_dlt_message_filter_check, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -2238,7 +2289,7 @@ TEST(t_dlt_message_filter_check, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2254,34 +2305,34 @@ TEST(t_dlt_message_filter_check, normal) } TEST(t_dlt_message_filter_check, abnormal) { -/* DltFile file; */ -/* DltFilter filter; */ + /* DltFile file; */ + /* DltFilter filter; */ /* Get PWD so file and filter can be used*/ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; */ -/* char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ -/* sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; */ + /* char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); */ /*---------------------------------------*/ /* No messages read, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_filter_check(&file.msg, &filter, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_filter_check(&file.msg, &filter, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_filter_check(&file.msg, &filter, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_filter_check(&file.msg, &filter, 1)); */ /* Set verbose to 12345678 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_filter_check(&file.msg, &filter, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2348,31 +2398,31 @@ TEST(t_dlt_message_get_extraparamters, normal) } TEST(t_dlt_message_get_extraparamters, abnormal) { -/* DltFile file; */ + /* DltFile file; */ /* Get PWD so file and filter can be used*/ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* Uninizialised, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_get_extraparameters(&file.msg, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_get_extraparameters(&file.msg, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_get_extraparameters(&file.msg, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_get_extraparameters(&file.msg, 1)); */ /* set verbose to 12345678, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_get_extraparameters(&file.msg, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2423,33 +2472,33 @@ TEST(t_dlt_message_header, normal) } TEST(t_dlt_message_header, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ /* Get PWD so file and filter can be used*/ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* Uninizialised, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1)); */ /* set verbose to 12345678, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header(&file.msg, text, DLT_DAEMON_TEXTSIZE, 12345678)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); printf("%s \n", text); } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); printf("%s \n", text); } @@ -2609,55 +2661,79 @@ TEST(t_dlt_message_header_flags, normal) } TEST(t_dlt_message_header_flags, abnormal) { -/* DltFile file; */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* DltFile file; */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ -/* / * Get PWD so file and filter can be used* / */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];;; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* / * Get PWD so file and filter can be used* / */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];;; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* Uninizialised, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_NONE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_TIME, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_TMSTP, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_MSGCNT, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_ECUID, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_APID, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_CTID, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_MSGTYPE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_MSGSUBTYPE, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_VNVSTATUS, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_NOARG, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_ALL, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_NONE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_TIME, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_TMSTP, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_MSGCNT, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_ECUID, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_APID, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_CTID, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_MSGTYPE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_MSGSUBTYPE, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_VNVSTATUS, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_NOARG, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, + * DLT_HEADER_SHOW_ALL, 1)); */ /* USE own DLT_HEADER_SHOW , expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0x1234, 0)); */ - -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -2929,14 +3006,14 @@ TEST(t_dlt_message_payload, normal) printf("%s \n", text); EXPECT_LE(DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); printf("%s \n", text); } @@ -2946,14 +3023,14 @@ TEST(t_dlt_message_payload, normal) printf("%s \n", text); EXPECT_LE(DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); printf("%s \n", text); } @@ -2966,9 +3043,10 @@ TEST(t_dlt_message_payload, abnormal) /* Get PWD so file and filter can be used*/ char pwd[MAX_LINE]; - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; + ; sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -2977,13 +3055,17 @@ TEST(t_dlt_message_payload, abnormal) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); /* USE own DLT_HEADER_SHOW , expected -1 */ @@ -2991,12 +3073,11 @@ TEST(t_dlt_message_payload, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file,0)>=0){} - for(int i=0;i= 0) { } + for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 99, 0)); - printf("%s \n",text); + printf("%s \n", text); } EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); } @@ -3070,17 +3151,17 @@ TEST(t_dlt_message_payload, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, 0, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, 0, 0, 1)); @@ -3101,24 +3182,23 @@ TEST(t_dlt_message_payload, nullpointer) /* (gdb) p ptr */ /* $28 = (uint8_t *) 0x5124010337d46c00 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 1)); */ } /* End Method:dlt_common::dlt_message_payload */ - /* Begin Method:dlt_common::dlt_message_set_extraparameters */ TEST(t_dlt_message_set_extraparamters, normal) { DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -3127,7 +3207,7 @@ TEST(t_dlt_message_set_extraparamters, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -3143,28 +3223,28 @@ TEST(t_dlt_message_set_extraparamters, normal) } TEST(t_dlt_message_set_extraparamters, abnormal) { -/* DltFile file; */ -/* // Get PWD so file and filter can be used */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* DltFile file; */ + /* // Get PWD so file and filter can be used */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ /*---------------------------------------*/ /* Uninizialised, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_set_extraparameters(&file.msg, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_set_extraparameters(&file.msg, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_set_extraparameters(&file.msg, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_set_extraparameters(&file.msg, 1)); */ /* set verbos to 12345678 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (unsigned char *)buffer, 255, 0, 1)); + EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (unsigned char*)buffer, 255, 0, 1)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (unsigned char *)buffer, 255, 1, 1)); + EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (unsigned char*)buffer, 255, 1, 1)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_message_read, abnormal) -{} +{ +} TEST(t_dlt_message_read, nullpointer) { DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); /*---------------------------------------*/ @@ -3244,40 +3325,38 @@ TEST(t_dlt_message_read, nullpointer) /* NULL_Pointer, expected -1 */ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(NULL, NULL, 0, 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(NULL, (uint8_t *)&buf, 0, 0, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(NULL, (uint8_t*)&buf, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, NULL, 0, 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (uint8_t *)&buf, 0, 0, 0)); - + EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (uint8_t*)&buf, 0, 0, 0)); } /* End Method:dlt_common::dlt_message_read */ - /* Begin Method:dlt_common::dlt_message_argument_print */ TEST(t_dlt_message_argument_print, normal) { DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); static char text[DLT_DAEMON_TEXTSIZE]; /*---------------------------------------*/ - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; - uint8_t **pptr; - int32_t *pdatalength; + uint8_t** pptr; + int32_t* pdatalength; /* Normal Use-Case, expect 0 */ EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -3285,9 +3364,9 @@ TEST(t_dlt_message_argument_print, normal) datalength = file.msg.datasize; pptr = &ptr; pdatalength = &datalength; - EXPECT_GE(DLT_RETURN_OK, - dlt_message_argument_print(&file.msg, DLT_TYPE_INFO_BOOL, pptr, pdatalength, text, - DLT_DAEMON_TEXTSIZE, 0, 1)); + EXPECT_GE( + DLT_RETURN_OK, dlt_message_argument_print( + &file.msg, DLT_TYPE_INFO_BOOL, pptr, pdatalength, text, DLT_DAEMON_TEXTSIZE, 0, 1)); /*printf("### ARGUMENT:%s\n", text); */ } @@ -3296,7 +3375,7 @@ TEST(t_dlt_message_argument_print, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -3304,66 +3383,67 @@ TEST(t_dlt_message_argument_print, normal) datalength = file.msg.datasize; pptr = &ptr; pdatalength = &datalength; - EXPECT_GE(DLT_RETURN_OK, - dlt_message_argument_print(&file.msg, DLT_TYPE_INFO_RAWD, pptr, pdatalength, text, - DLT_DAEMON_TEXTSIZE, 0, 1)); + EXPECT_GE( + DLT_RETURN_OK, dlt_message_argument_print( + &file.msg, DLT_TYPE_INFO_RAWD, pptr, pdatalength, text, DLT_DAEMON_TEXTSIZE, 0, 1)); /*printf("### ARGUMENT:%s\n", text); */ } EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); - } TEST(t_dlt_message_argument_print, abnormal) { -/* DltFile file; */ + /* DltFile file; */ /* Get PWD so file and filter can be used */ -/* char pwd[MAX_LINE]; */ -/* getcwd(pwd, MAX_LINE); */ -/* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ -/* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ -/* static char text[DLT_DAEMON_TEXTSIZE]; */ + /* char pwd[MAX_LINE]; */ + /* getcwd(pwd, MAX_LINE); */ + /* char openfile[MAX_LINE+sizeof(BINARY_FILE_NAME)];; */ + /* sprintf(openfile, "%s" BINARY_FILE_NAME, pwd); */ + /* static char text[DLT_DAEMON_TEXTSIZE]; */ /*---------------------------------------*/ -/* uint8_t *ptr; */ -/* int32_t datalength; */ -/* uint8_t **pptr; */ -/* int32_t *pdatalength; */ + /* uint8_t *ptr; */ + /* int32_t datalength; */ + /* uint8_t **pptr; */ + /* int32_t *pdatalength; */ /* Uninizialised, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_argument_print(&file.msg,12345678,pptr,pdatalength,text,DLT_DAEMON_TEXTSIZE,0,1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, + * dlt_message_argument_print(&file.msg,12345678,pptr,pdatalength,text,DLT_DAEMON_TEXTSIZE,0,1)); */ /* Use a non defined type_info, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); */ -/* while (dlt_file_read(&file,0)>=0){} */ -/* for(int i=0;i=0){} */ + /* for(int i=0;i(EMERG))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ALERT, const_cast(ALERT))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_CRIT, const_cast(CRIT))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ERR, const_cast(ERR))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_WARNING, const_cast(WARNING))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_NOTICE, const_cast(NOTICE))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_INFO, const_cast(INFO))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_DEBUG, const_cast(DEBUG))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_EMERG, const_cast(EMERG))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ALERT, const_cast(ALERT))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_CRIT, const_cast(CRIT))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ERR, const_cast(ERR))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_WARNING, const_cast(WARNING))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_NOTICE, const_cast(NOTICE))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_INFO, const_cast(INFO))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_DEBUG, const_cast(DEBUG))); dlt_log_init(DLT_LOG_DROPPED); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_EMERG, const_cast(EMERG))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ALERT, const_cast(ALERT))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_CRIT, const_cast(CRIT))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ERR, const_cast(ERR))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_WARNING, const_cast(WARNING))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_NOTICE, const_cast(NOTICE))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_INFO, const_cast(INFO))); - EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_DEBUG, const_cast(DEBUG))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_EMERG, const_cast(EMERG))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ALERT, const_cast(ALERT))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_CRIT, const_cast(CRIT))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_ERR, const_cast(ERR))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_WARNING, const_cast(WARNING))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_NOTICE, const_cast(NOTICE))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_INFO, const_cast(INFO))); + EXPECT_LE(DLT_RETURN_OK, dlt_log(LOG_DEBUG, const_cast(DEBUG))); } TEST(t_dlt_log, abnormal) { /* LOG MODE don't exists, expected -1 */ -/* int DLT_LOG_DONT_EXISTS = 123456789; */ -/* const char * EXIST = "SYSLOG DONT EXISTS\n"; */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_log(DLT_LOG_DONT_EXISTS, (char *) EXIST)); */ + /* int DLT_LOG_DONT_EXISTS = 123456789; */ + /* const char * EXIST = "SYSLOG DONT EXISTS\n"; */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_log(DLT_LOG_DONT_EXISTS, (char *) EXIST)); */ } TEST(t_dlt_log, nullpointer) { @@ -3576,7 +3649,6 @@ TEST(t_dlt_log, nullpointer) - /*##############################################################################################################################*/ /*##############################################################################################################################*/ /*##############################################################################################################################*/ @@ -3589,33 +3661,34 @@ TEST(t_dlt_uptime, normal) EXPECT_LE(1, dlt_uptime()); } TEST(t_dlt_uptime, abnormal) -{} +{ +} TEST(t_dlt_uptime, nullpointer) -{} +{ +} /* End Method:dlt_common::dlt_uptime */ - /* Begin Method:dlt_common::dlt_set_id */ TEST(t_dlt_set_id, normal) { -/* char id[4]; */ -/* const char * text = "DLTD"; */ -/* dlt_set_id(id, text); */ -/* EXPECT_STREQ(text, id); */ + /* char id[4]; */ + /* const char * text = "DLTD"; */ + /* dlt_set_id(id, text); */ + /* EXPECT_STREQ(text, id); */ } TEST(t_dlt_set_id, abnormal) { -/* char id[10]; */ -/* const char * text = "1234567890"; */ -/* dlt_set_id(id, text); */ -/* EXPECT_STRNE(text, id); */ + /* char id[10]; */ + /* const char * text = "1234567890"; */ + /* dlt_set_id(id, text); */ + /* EXPECT_STRNE(text, id); */ } TEST(t_dlt_set_id, nullpointer) { char id[4]; - const char *text = "TEST"; + const char* text = "TEST"; EXPECT_NO_THROW(dlt_set_id(NULL, NULL)); EXPECT_NO_THROW(dlt_set_id(NULL, text)); @@ -3625,21 +3698,24 @@ TEST(t_dlt_set_id, nullpointer) - /* Begin Method:dlt_common::dlt_print_hex_string */ TEST(t_dlt_print_hex_string, normal) { /* Normal Use-Case, exptect 0 */ - const char *test1 = "HELLO_HEX"; + const char* test1 = "HELLO_HEX"; char text1[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, dlt_print_hex_string(text1, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test1)), (int)strlen(test1))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_hex_string( + text1, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test1)), + (int)strlen(test1))); /*printf("text:%s\n", text1); */ /* convert text1 to an ascii string to compare with the original */ - char *converted = (char *)malloc(strlen(test1) + 1); + char* converted = (char*)malloc(strlen(test1) + 1); int t = 0; for (unsigned int i = 0; i < strlen(text1); i += 3) { - char tmp[3] = { '\0' }; + char tmp[3] = {'\0'}; tmp[0] = text1[i]; tmp[1] = text1[i + 1]; char k = (char)strtol(tmp, NULL, 16); @@ -3652,16 +3728,20 @@ TEST(t_dlt_print_hex_string, normal) EXPECT_STREQ(test1, converted); free(converted); - const char *test2 = "qwertzuiopasdfghjklyxcvbnm1234567890"; + const char* test2 = "qwertzuiopasdfghjklyxcvbnm1234567890"; char text2[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, dlt_print_hex_string(text2, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test2)), (int)strlen(test2))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_hex_string( + text2, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test2)), + (int)strlen(test2))); /*printf("text:%s\n", text2); */ /* convert text2 to an ascii string to compare with the original */ - converted = (char *)malloc(strlen(test2) + 1); + converted = (char*)malloc(strlen(test2) + 1); t = 0; for (unsigned int i = 0; i < strlen(text2); i += 3) { - char tmp[3] = { '\0' }; + char tmp[3] = {'\0'}; tmp[0] = text2[i]; tmp[1] = text2[i + 1]; char k = (char)strtol(tmp, NULL, 16); @@ -3677,121 +3757,158 @@ TEST(t_dlt_print_hex_string, normal) TEST(t_dlt_print_hex_string, abnormal) { /* print special characters, expected 0 */ -/* const char * test3 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; */ -/* char text3[DLT_DAEMON_TEXTSIZE]; */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_print_hex_string(text3,DLT_DAEMON_TEXTSIZE,(unsigned char *)test3, strlen(test3))); */ + /* const char * test3 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; */ + /* char text3[DLT_DAEMON_TEXTSIZE]; */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_print_hex_string(text3,DLT_DAEMON_TEXTSIZE,(unsigned char *)test3, + * strlen(test3))); */ /*printf("text:%s\n", text3); */ /* convert text3 to an ascii string to compare with the original */ -/* char * converted = (char*) malloc(strlen(test3) +1); */ -/* int t = 0; */ -/* for(unsigned int i=0;i(reinterpret_cast(test5)), 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_print_hex_string(NULL, 0, const_cast(reinterpret_cast(test5)), 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_print_hex_string(text5, 0, NULL, 0)); } /* End Method:dlt_common::dlt_print_hex_string */ - /* Begin Method:dlt_common::dlt_print_mixed_string */ TEST(t_dlt_print_mixed_string, normal) { - const char *test1 = "HELLO_MIXED"; + const char* test1 = "HELLO_MIXED"; char text1[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, - dlt_print_mixed_string(text1, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test1)), (int)strlen(test1), 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text1, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test1)), + (int)strlen(test1), 0)); printf("%s\n", text1); - const char *test2 = "HELLO_MIXED"; + const char* test2 = "HELLO_MIXED"; char text2[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, - dlt_print_mixed_string(text2, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test2)), (int)strlen(test2), 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text2, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test2)), + (int)strlen(test2), 1)); printf("%s\n", text2); - const char *test3 = "qwertzuiopasdfghjklyxcvbnm1234567890"; + const char* test3 = "qwertzuiopasdfghjklyxcvbnm1234567890"; char text3[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, - dlt_print_mixed_string(text3, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test3)), (int)strlen(test3), 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text3, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test3)), + (int)strlen(test3), 0)); printf("%s\n", text3); - const char *test4 = "qwertzuiopasdfghjklyxcvbnm1234567890"; + const char* test4 = "qwertzuiopasdfghjklyxcvbnm1234567890"; char text4[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, - dlt_print_mixed_string(text4, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test4)), (int)strlen(test4), 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text4, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test4)), + (int)strlen(test4), 1)); printf("%s\n", text4); } TEST(t_dlt_print_mixed_string, abnormal) { - const char * test5 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; + const char* test5 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; char text5[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, dlt_print_mixed_string(text5, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test5)), (int)strlen(test5), 0)); -/* printf("%s\n", text5); */ - - const char * test6 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text5, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test5)), + (int)strlen(test5), 0)); + /* printf("%s\n", text5); */ + + const char* test6 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; char text6[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, dlt_print_mixed_string(text6, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test6)), (int)strlen(test6), 1)); -/* printf("%s\n", text6); */ - - const char * test7 = ""; + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text6, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test6)), + (int)strlen(test6), 1)); + /* printf("%s\n", text6); */ + + const char* test7 = ""; char text7[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, dlt_print_mixed_string(text7, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test7)), (int)strlen(test7), 0)); -/* printf("%s\n", text7); */ - - const char * test8 = ""; + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text7, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test7)), + (int)strlen(test7), 0)); + /* printf("%s\n", text7); */ + + const char* test8 = ""; char text8[DLT_DAEMON_TEXTSIZE]; - EXPECT_LE(DLT_RETURN_OK, dlt_print_mixed_string(text8, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test8)), (int)strlen(test8), 1)); -/* printf("%s\n", text8); */ + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_mixed_string( + text8, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test8)), + (int)strlen(test8), 1)); + /* printf("%s\n", text8); */ } TEST(t_dlt_print_mixed_string, nullpointer) { - const char *test9 = ""; + const char* test9 = ""; char text9[DLT_DAEMON_TEXTSIZE]; EXPECT_GE(DLT_RETURN_ERROR, dlt_print_mixed_string(NULL, 0, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_print_mixed_string(NULL, 0, 0, 0, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_print_mixed_string(NULL, 0, const_cast(reinterpret_cast(test9)), 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_print_mixed_string(NULL, 0, const_cast(reinterpret_cast(test9)), 0, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_print_mixed_string( + NULL, 0, const_cast(reinterpret_cast(test9)), 0, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_print_mixed_string( + NULL, 0, const_cast(reinterpret_cast(test9)), 0, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_print_mixed_string(text9, 0, NULL, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_print_mixed_string(text9, 0, NULL, 0, 1)); } @@ -3799,58 +3916,68 @@ TEST(t_dlt_print_mixed_string, nullpointer) - /* Begin Method:dlt_common::dlt_print_char_string */ TEST(t_dlt_print_char_string, normal) { /* Normal Use-Case, expect 0 */ - const char *test1 = "HELLO"; + const char* test1 = "HELLO"; char text1[DLT_DAEMON_TEXTSIZE]; - char *ptr1 = text1; - EXPECT_LE(DLT_RETURN_OK, dlt_print_char_string(&ptr1, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test1)), (int)strlen(test1))); + char* ptr1 = text1; + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_char_string( + &ptr1, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test1)), + (int)strlen(test1))); printf("text:%s\n", text1); EXPECT_STREQ(text1, test1); - const char *test2 = "qwertzuiopasdfghjklyxcvbnm1234567890"; + const char* test2 = "qwertzuiopasdfghjklyxcvbnm1234567890"; char text2[DLT_DAEMON_TEXTSIZE]; - char *ptr2 = text2; - EXPECT_LE(DLT_RETURN_OK, dlt_print_char_string(&ptr2, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test2)), (int)strlen(test2))); + char* ptr2 = text2; + EXPECT_LE( + DLT_RETURN_OK, + dlt_print_char_string( + &ptr2, DLT_DAEMON_TEXTSIZE, const_cast(reinterpret_cast(test2)), + (int)strlen(test2))); printf("text:%s\n", text2); EXPECT_STREQ(text2, test2); } TEST(t_dlt_print_char_string, abnormal) { /* print special characters, expected 0 */ -/* const char * test3 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; */ -/* char text3[DLT_DAEMON_TEXTSIZE]; */ -/* char * ptr3 = text3; */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_print_char_string(&ptr3,DLT_DAEMON_TEXTSIZE,(unsigned char *)test3, strlen(test3))); */ -/* printf("text:%s\n", text3); */ -/* EXPECT_STREQ(text3, test3); */ + /* const char * test3 = "^°!\"§$%&/()=?`´¹²³¼½¬{[]}\\¸@€üöä+#*'~`,.-;:_·…–<>|"; */ + /* char text3[DLT_DAEMON_TEXTSIZE]; */ + /* char * ptr3 = text3; */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_print_char_string(&ptr3,DLT_DAEMON_TEXTSIZE,(unsigned char *)test3, + * strlen(test3))); */ + /* printf("text:%s\n", text3); */ + /* EXPECT_STREQ(text3, test3); */ /* Empty char *, expect 0 */ -/* const char * test4 = ""; */ -/* char text4[DLT_DAEMON_TEXTSIZE]; */ -/* char * ptr4 = text4; */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_print_char_string(&ptr4,DLT_DAEMON_TEXTSIZE,(unsigned char *)test4, strlen(test4))); */ -/* printf("text:%s\n", text4); */ -/* EXPECT_STREQ(text4, test4); */ + /* const char * test4 = ""; */ + /* char text4[DLT_DAEMON_TEXTSIZE]; */ + /* char * ptr4 = text4; */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_print_char_string(&ptr4,DLT_DAEMON_TEXTSIZE,(unsigned char *)test4, + * strlen(test4))); */ + /* printf("text:%s\n", text4); */ + /* EXPECT_STREQ(text4, test4); */ } TEST(t_dlt_print_char_string, nullpointer) { - const char *test5 = "HELLO"; + const char* test5 = "HELLO"; char text5[DLT_DAEMON_TEXTSIZE]; - char *ptr5 = text5; + char* ptr5 = text5; EXPECT_GE(DLT_RETURN_ERROR, dlt_print_char_string(NULL, 0, NULL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_print_char_string(NULL, 0, const_cast(reinterpret_cast(test5)), 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_print_char_string(NULL, 0, const_cast(reinterpret_cast(test5)), 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_print_char_string(&ptr5, 0, NULL, 0)); } /* End Method:dlt_common::dlt_print_char_string */ - /* Begin Method:dlt_common::dlt_strnlen_s*/ TEST(t_dlt_strnlen_s, nullpointer) { @@ -3893,12 +4020,11 @@ TEST(t_dlt_strnlen_s, len_larger) - /* Begin Method:dlt_common::dlt_print_id */ TEST(t_dlt_print_id, normal) { /* Normal Use-Case, expect text==id */ - const char *id = "DLTD"; + const char* id = "DLTD"; char text[DLT_DAEMON_TEXTSIZE]; dlt_print_id(text, id); EXPECT_STREQ(text, id); @@ -3906,19 +4032,19 @@ TEST(t_dlt_print_id, normal) TEST(t_dlt_print_id, abnormal) { /* id to long, expect only first 4 chars */ -/* const char* id = "DLTD123456789"; */ -/* char text[DLT_DAEMON_TEXTSIZE]; */ -/* dlt_print_id(text,id); */ -/* EXPECT_STREQ(text,"DLTD"); */ + /* const char* id = "DLTD123456789"; */ + /* char text[DLT_DAEMON_TEXTSIZE]; */ + /* dlt_print_id(text,id); */ + /* EXPECT_STREQ(text,"DLTD"); */ /* id to short, expect expend with "-" to 4 chars */ -/* id = "DL"; */ -/* dlt_print_id(text,id); */ -/* EXPECT_STREQ(text,"DL--"); */ + /* id = "DL"; */ + /* dlt_print_id(text,id); */ + /* EXPECT_STREQ(text,"DL--"); */ } TEST(t_dlt_print_id, nullpointer) { - const char *id = "DLTD"; + const char* id = "DLTD"; char text[DLT_DAEMON_TEXTSIZE]; /* NULL-Pointer, expected nothing in return */ @@ -3930,7 +4056,6 @@ TEST(t_dlt_print_id, nullpointer) - /* Begin Method:dlt_common::dlt_get_version */ TEST(t_dlt_get_version, normal) { @@ -3942,13 +4067,13 @@ TEST(t_dlt_get_version, normal) TEST(t_dlt_get_version, abnormal) { /* Change default length of ver to 1 */ -/* char ver[1]; */ -/* dlt_get_version(ver, DLT_USER_MAX_LIB_VERSION_LENGTH); */ -/* printf("%s\n", ver); */ + /* char ver[1]; */ + /* dlt_get_version(ver, DLT_USER_MAX_LIB_VERSION_LENGTH); */ + /* printf("%s\n", ver); */ /* Change default length of ver to 1 and reduce second para to 1, too */ -/* dlt_get_version(ver, 1); */ -/* printf("%s\n", ver); */ + /* dlt_get_version(ver, 1); */ + /* printf("%s\n", ver); */ } TEST(t_dlt_get_version, nullpointer) { @@ -3958,7 +4083,6 @@ TEST(t_dlt_get_version, nullpointer) - /* Begin Method:dlt_common::dlt_get_major_version */ TEST(dlt_get_major_version, normal) { @@ -3969,13 +4093,13 @@ TEST(dlt_get_major_version, normal) TEST(dlt_get_major_version, abnormal) { /* Change default length of ver to 1 */ -/* char ver[1]; */ -/* dlt_get_major_version(ver, DLT_USER_MAX_LIB_VERSION_LENGTH); */ -/* EXPECT_STREQ(ver, _DLT_PACKAGE_MAJOR_VERSION); */ + /* char ver[1]; */ + /* dlt_get_major_version(ver, DLT_USER_MAX_LIB_VERSION_LENGTH); */ + /* EXPECT_STREQ(ver, _DLT_PACKAGE_MAJOR_VERSION); */ /* Change default length of ver to 1 and reduce second para to 1, too */ -/* dlt_get_major_version(ver, 1); */ -/* EXPECT_STREQ(ver, _DLT_PACKAGE_MAJOR_VERSION); */ + /* dlt_get_major_version(ver, 1); */ + /* EXPECT_STREQ(ver, _DLT_PACKAGE_MAJOR_VERSION); */ } TEST(dlt_get_major_version, nullpointer) { @@ -3986,7 +4110,6 @@ TEST(dlt_get_major_version, nullpointer) - /* Begin Method:dlt_common::dlt_get_minor_version */ TEST(dlt_get_minor_version, normal) { @@ -3997,13 +4120,13 @@ TEST(dlt_get_minor_version, normal) TEST(dlt_get_minor_version, abnormal) { /* Change default length of ver to 1 */ -/* char ver[1]; */ -/* dlt_get_minor_version(ver, DLT_USER_MAX_LIB_VERSION_LENGTH); */ -/* EXPECT_STREQ(ver, _DLT_PACKAGE_MINOR_VERSION); */ + /* char ver[1]; */ + /* dlt_get_minor_version(ver, DLT_USER_MAX_LIB_VERSION_LENGTH); */ + /* EXPECT_STREQ(ver, _DLT_PACKAGE_MINOR_VERSION); */ /* Change default length of ver to 1 and reduce second para to 1, too */ -/* dlt_get_minor_version(ver, 1); */ -/* EXPECT_STREQ(ver, _DLT_PACKAGE_MINOR_VERSION); */ + /* dlt_get_minor_version(ver, 1); */ + /* EXPECT_STREQ(ver, _DLT_PACKAGE_MINOR_VERSION); */ } TEST(dlt_get_minor_version, nullpointer) { @@ -4015,7 +4138,14 @@ TEST(dlt_get_minor_version, nullpointer) TEST(dlt_client_parse_get_log_info_resp_text, normal) { - char input[] = "get_log_info, 07, 02 00 4c 4f 47 00 03 00 54 45 53 54 ff ff 18 00 54 65 73 74 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 4c 6f 67 67 69 6e 67 54 53 31 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 31 20 66 6f 72 20 69 6e 6a 65 63 74 69 6f 6e 54 53 32 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 32 20 66 6f 72 20 69 6e 6a 65 63 74 69 6f 6e 1c 00 54 65 73 74 20 41 70 70 6c 69 63 61 74 69 6f 6e 20 66 6f 72 20 4c 6f 67 67 69 6e 67 53 59 53 00 02 00 4a 4f 55 52 ff ff 0f 00 4a 6f 75 72 6e 61 6c 20 41 64 61 70 74 65 72 4d 47 52 00 ff ff 22 00 43 6f 6e 74 65 78 74 20 6f 66 20 6d 61 69 6e 20 64 6c 74 20 73 79 73 74 65 6d 20 6d 61 6e 61 67 65 72 12 00 44 4c 54 20 53 79 73 74 65 6d 20 4d 61 6e 61 67 65 72 72 65 6d 6f"; + char input[] = + "get_log_info, 07, 02 00 4c 4f 47 00 03 00 54 45 53 54 ff ff 18 00 54 65 73 74 20 43 6f 6e 74 65 78 74 20 66 " + "6f 72 20 4c 6f 67 67 69 6e 67 54 53 31 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 31 20 66 6f 72 20 " + "69 6e 6a 65 63 74 69 6f 6e 54 53 32 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 32 20 66 6f 72 20 69 " + "6e 6a 65 63 74 69 6f 6e 1c 00 54 65 73 74 20 41 70 70 6c 69 63 61 74 69 6f 6e 20 66 6f 72 20 4c 6f 67 67 69 " + "6e 67 53 59 53 00 02 00 4a 4f 55 52 ff ff 0f 00 4a 6f 75 72 6e 61 6c 20 41 64 61 70 74 65 72 4d 47 52 00 ff " + "ff 22 00 43 6f 6e 74 65 78 74 20 6f 66 20 6d 61 69 6e 20 64 6c 74 20 73 79 73 74 65 6d 20 6d 61 6e 61 67 65 " + "72 12 00 44 4c 54 20 53 79 73 74 65 6d 20 4d 61 6e 61 67 65 72 72 65 6d 6f"; /* expected output: * APID:LOG- Test Application for Logging * CTID:TEST -1 -1 Test Context for Logging @@ -4026,9 +4156,8 @@ TEST(dlt_client_parse_get_log_info_resp_text, normal) * CTID:MGR- -1 -1 Context of main dlt system manager */ - DltServiceGetLogInfoResponse * resp = (DltServiceGetLogInfoResponse *)malloc(sizeof(DltServiceGetLogInfoResponse )); - DltReturnValue ret = (DltReturnValue) dlt_set_loginfo_parse_service_id( - input, &resp->service_id, &resp->status); + DltServiceGetLogInfoResponse* resp = (DltServiceGetLogInfoResponse*)malloc(sizeof(DltServiceGetLogInfoResponse)); + DltReturnValue ret = (DltReturnValue)dlt_set_loginfo_parse_service_id(input, &resp->service_id, &resp->status); EXPECT_EQ(DLT_RETURN_OK, ret); EXPECT_EQ(DLT_SERVICE_ID_GET_LOG_INFO, resp->service_id); EXPECT_EQ(GET_LOG_INFO_STATUS_MAX, resp->status); @@ -4036,52 +4165,60 @@ TEST(dlt_client_parse_get_log_info_resp_text, normal) ret = dlt_client_parse_get_log_info_resp_text(resp, input); EXPECT_EQ(DLT_RETURN_OK, ret); - EXPECT_EQ(2,resp->log_info_type.count_app_ids); + EXPECT_EQ(2, resp->log_info_type.count_app_ids); - EXPECT_EQ(0, memcmp( "LOG", resp->log_info_type.app_ids[0].app_id,4)); + EXPECT_EQ(0, memcmp("LOG", resp->log_info_type.app_ids[0].app_id, 4)); EXPECT_EQ(0, strcmp("Test Application for Logging", resp->log_info_type.app_ids[0].app_description)); EXPECT_EQ(28, resp->log_info_type.app_ids[0].len_app_description); EXPECT_EQ(3, resp->log_info_type.app_ids[0].count_context_ids); - EXPECT_EQ(0, memcmp( "TEST", resp->log_info_type.app_ids[0].context_id_info[0].context_id,4)); - EXPECT_EQ(0, strcmp( "Test Context for Logging",resp->log_info_type.app_ids[0].context_id_info[0].context_description )); - EXPECT_EQ(24,resp->log_info_type.app_ids[0].context_id_info[0].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[0].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[0].trace_status); - - EXPECT_EQ(0, memcmp( "TS1", resp->log_info_type.app_ids[0].context_id_info[1].context_id,4)); - EXPECT_EQ(0, strcmp( "Test Context1 for injection",resp->log_info_type.app_ids[0].context_id_info[1].context_description )); - EXPECT_EQ(27,resp->log_info_type.app_ids[0].context_id_info[1].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[1].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[1].trace_status); - - EXPECT_EQ(0, memcmp( "TS2", resp->log_info_type.app_ids[0].context_id_info[2].context_id,4)); - EXPECT_EQ(0, strcmp( "Test Context2 for injection",resp->log_info_type.app_ids[0].context_id_info[2].context_description )); - EXPECT_EQ(27,resp->log_info_type.app_ids[0].context_id_info[2].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[2].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[2].trace_status); - - EXPECT_EQ(0, memcmp( "SYS", resp->log_info_type.app_ids[1].app_id,4)); + EXPECT_EQ(0, memcmp("TEST", resp->log_info_type.app_ids[0].context_id_info[0].context_id, 4)); + EXPECT_EQ( + 0, strcmp("Test Context for Logging", resp->log_info_type.app_ids[0].context_id_info[0].context_description)); + EXPECT_EQ(24, resp->log_info_type.app_ids[0].context_id_info[0].len_context_description); + EXPECT_EQ(-1, resp->log_info_type.app_ids[0].context_id_info[0].log_level); + EXPECT_EQ(-1, resp->log_info_type.app_ids[0].context_id_info[0].trace_status); + + EXPECT_EQ(0, memcmp("TS1", resp->log_info_type.app_ids[0].context_id_info[1].context_id, 4)); + EXPECT_EQ( + 0, + strcmp("Test Context1 for injection", resp->log_info_type.app_ids[0].context_id_info[1].context_description)); + EXPECT_EQ(27, resp->log_info_type.app_ids[0].context_id_info[1].len_context_description); + EXPECT_EQ(-1, resp->log_info_type.app_ids[0].context_id_info[1].log_level); + EXPECT_EQ(-1, resp->log_info_type.app_ids[0].context_id_info[1].trace_status); + + EXPECT_EQ(0, memcmp("TS2", resp->log_info_type.app_ids[0].context_id_info[2].context_id, 4)); + EXPECT_EQ( + 0, + strcmp("Test Context2 for injection", resp->log_info_type.app_ids[0].context_id_info[2].context_description)); + EXPECT_EQ(27, resp->log_info_type.app_ids[0].context_id_info[2].len_context_description); + EXPECT_EQ(-1, resp->log_info_type.app_ids[0].context_id_info[2].log_level); + EXPECT_EQ(-1, resp->log_info_type.app_ids[0].context_id_info[2].trace_status); + + EXPECT_EQ(0, memcmp("SYS", resp->log_info_type.app_ids[1].app_id, 4)); EXPECT_EQ(0, strcmp("DLT System Manager", resp->log_info_type.app_ids[1].app_description)); EXPECT_EQ(18, resp->log_info_type.app_ids[1].len_app_description); EXPECT_EQ(2, resp->log_info_type.app_ids[1].count_context_ids); - EXPECT_EQ(0, memcmp( "JOUR", resp->log_info_type.app_ids[1].context_id_info[0].context_id,4)); - EXPECT_EQ(0, strcmp( "Journal Adapter",resp->log_info_type.app_ids[1].context_id_info[0].context_description )); - EXPECT_EQ(15,resp->log_info_type.app_ids[1].context_id_info[0].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[0].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[0].trace_status); - - EXPECT_EQ(0, memcmp( "MGR", resp->log_info_type.app_ids[1].context_id_info[1].context_id,4)); - EXPECT_EQ(0, strcmp( "Context of main dlt system manager",resp->log_info_type.app_ids[1].context_id_info[1].context_description )); - EXPECT_EQ(34,resp->log_info_type.app_ids[1].context_id_info[1].len_context_description); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[1].log_level); - EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[1].trace_status); + EXPECT_EQ(0, memcmp("JOUR", resp->log_info_type.app_ids[1].context_id_info[0].context_id, 4)); + EXPECT_EQ(0, strcmp("Journal Adapter", resp->log_info_type.app_ids[1].context_id_info[0].context_description)); + EXPECT_EQ(15, resp->log_info_type.app_ids[1].context_id_info[0].len_context_description); + EXPECT_EQ(-1, resp->log_info_type.app_ids[1].context_id_info[0].log_level); + EXPECT_EQ(-1, resp->log_info_type.app_ids[1].context_id_info[0].trace_status); + + EXPECT_EQ(0, memcmp("MGR", resp->log_info_type.app_ids[1].context_id_info[1].context_id, 4)); + EXPECT_EQ( + 0, strcmp( + "Context of main dlt system manager", + resp->log_info_type.app_ids[1].context_id_info[1].context_description)); + EXPECT_EQ(34, resp->log_info_type.app_ids[1].context_id_info[1].len_context_description); + EXPECT_EQ(-1, resp->log_info_type.app_ids[1].context_id_info[1].log_level); + EXPECT_EQ(-1, resp->log_info_type.app_ids[1].context_id_info[1].trace_status); ret = (DltReturnValue)dlt_client_cleanup_get_log_info(resp); - EXPECT_EQ(DLT_RETURN_OK,ret); + EXPECT_EQ(DLT_RETURN_OK, ret); } TEST(dlt_getloginfo_conv_ascii_to_string, normal) @@ -4090,8 +4227,7 @@ TEST(dlt_getloginfo_conv_ascii_to_string, normal) char rp_1[] = "72 65 6d 6f"; char rp_2[] = "123456789 72 65 6d 6f"; int rp_count = 0; - char rp_str[] = - { 0x72, 0x65, 0x6d, 0x6f, 0x00 }; + char rp_str[] = {0x72, 0x65, 0x6d, 0x6f, 0x00}; char wp[5]; dlt_getloginfo_conv_ascii_to_string(rp_1, &rp_count, wp, 4); @@ -4102,7 +4238,6 @@ TEST(dlt_getloginfo_conv_ascii_to_string, normal) dlt_getloginfo_conv_ascii_to_string(rp_2, &rp_count, wp, 4); EXPECT_EQ(0, strcmp(rp_str, wp)); EXPECT_EQ(22, rp_count); - } /*##############################################################################################################################*/ @@ -4111,8 +4246,7 @@ TEST(dlt_getloginfo_conv_ascii_to_string, normal) - -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_common_v2.cpp b/tests/gtest_dlt_common_v2.cpp index 0f89dce1f..34683628a 100644 --- a/tests/gtest_dlt_common_v2.cpp +++ b/tests/gtest_dlt_common_v2.cpp @@ -61,8 +61,7 @@ #define BINARY_FILE_V2_NAME "/testfile-v2.dlt" #define FILTER_FILE_NAME "/testfilter.txt" -extern "C" -{ +extern "C" { #include "dlt-daemon.h" #include "dlt-daemon_cfg.h" #include "dlt_user_cfg.h" @@ -70,24 +69,20 @@ extern "C" #include "dlt_client.h" #include "dlt_protocol.h" -int dlt_buffer_increase_size(DltBuffer *); -int dlt_buffer_minimize_size(DltBuffer *); -int dlt_buffer_reset(DltBuffer *); -DltReturnValue dlt_buffer_push(DltBuffer *, const unsigned char *, unsigned int); -DltReturnValue dlt_buffer_push3(DltBuffer *, - const unsigned char *, - unsigned int, - const unsigned char *, - unsigned int, - const unsigned char *, - unsigned int); -int dlt_buffer_get(DltBuffer *, unsigned char *, int, int); -int dlt_buffer_pull(DltBuffer *, unsigned char *, int); -int dlt_buffer_remove(DltBuffer *); -void dlt_buffer_status(DltBuffer *); -void dlt_buffer_write_block(DltBuffer *, int *, const unsigned char *, unsigned int); -void dlt_buffer_read_block(DltBuffer *, int *, unsigned char *, unsigned int); -void dlt_buffer_info(DltBuffer *); +int dlt_buffer_increase_size(DltBuffer*); +int dlt_buffer_minimize_size(DltBuffer*); +int dlt_buffer_reset(DltBuffer*); +DltReturnValue dlt_buffer_push(DltBuffer*, const unsigned char*, unsigned int); +DltReturnValue dlt_buffer_push3( + DltBuffer*, const unsigned char*, unsigned int, const unsigned char*, unsigned int, const unsigned char*, + unsigned int); +int dlt_buffer_get(DltBuffer*, unsigned char*, int, int); +int dlt_buffer_pull(DltBuffer*, unsigned char*, int); +int dlt_buffer_remove(DltBuffer*); +void dlt_buffer_status(DltBuffer*); +void dlt_buffer_write_block(DltBuffer*, int*, const unsigned char*, unsigned int); +void dlt_buffer_read_block(DltBuffer*, int*, unsigned char*, unsigned int); +void dlt_buffer_info(DltBuffer*); } @@ -105,18 +100,18 @@ TEST(t_dlt_message_init_v2, normal) } TEST(t_dlt_message_init, abnormal) { -/* DltMessage msg; */ + /* DltMessage msg; */ /* Double use init, expected -1 */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,0)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,1)); */ -/* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,1)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,0)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_init(&msg,1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,1)); */ + /* EXPECT_LE(DLT_RETURN_OK, dlt_message_free(&msg,1)); */ /* set Verbose to 12345678, expected -1 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,12345678)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_init(&msg,12345678)); */ } TEST(t_dlt_message_init, nullpointer) { @@ -164,16 +159,15 @@ TEST(t_dlt_message_free_v2, nullpointer) /* Begin Method: dlt_common::dlt_message_print_ascii*/ TEST(t_dlt_message_print_ascii_v2, normal) { - DltFile file; static char text[DLT_DAEMON_TEXTSIZE]; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -182,7 +176,7 @@ TEST(t_dlt_message_print_ascii_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -205,10 +199,10 @@ TEST(t_dlt_message_print_ascii_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -239,12 +233,12 @@ TEST(t_dlt_message_print_ascii_with_filter_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -256,7 +250,7 @@ TEST(t_dlt_message_print_ascii_with_filter_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -280,10 +274,10 @@ TEST(t_dlt_message_print_header_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -292,7 +286,7 @@ TEST(t_dlt_message_print_header_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -315,10 +309,10 @@ TEST(t_dlt_message_print_header_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -336,7 +330,6 @@ TEST(t_dlt_message_print_header_v2, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header_v2(&file.msgv2, NULL, 0, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_print_header_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, 1)); - } /* End Method: dlt_common::dlt_message_print_header */ @@ -350,12 +343,12 @@ TEST(t_dlt_message_print_header_with_filter_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -367,7 +360,7 @@ TEST(t_dlt_message_print_header_with_filter_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -391,10 +384,10 @@ TEST(t_dlt_message_print_hex_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -403,7 +396,7 @@ TEST(t_dlt_message_print_hex_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -425,10 +418,10 @@ TEST(t_dlt_message_print_hex_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -459,12 +452,12 @@ TEST(t_dlt_message_print_hex_with_filter_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -476,7 +469,7 @@ TEST(t_dlt_message_print_hex_with_filter_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -499,10 +492,10 @@ TEST(t_dlt_message_print_mixed_plain_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -511,7 +504,7 @@ TEST(t_dlt_message_print_mixed_plain_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -534,10 +527,10 @@ TEST(t_dlt_message_print_mixed_plain_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -568,12 +561,12 @@ TEST(t_dlt_message_print_mixed_plain_with_filter_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -585,7 +578,7 @@ TEST(t_dlt_message_print_mixed_plain_with_filter_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -609,12 +602,12 @@ TEST(t_dlt_message_filter_check_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -626,7 +619,7 @@ TEST(t_dlt_message_filter_check_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -648,12 +641,12 @@ TEST(t_dlt_message_filter_check_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfilter[MAX_LINE+sizeof(FILTER_FILE_NAME)]; + char openfilter[MAX_LINE + sizeof(FILTER_FILE_NAME)]; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); sprintf(openfilter, "%s" FILTER_FILE_NAME, pwd); /*---------------------------------------*/ @@ -676,10 +669,10 @@ TEST(t_dlt_message_get_extraparamters_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -688,7 +681,7 @@ TEST(t_dlt_message_get_extraparamters_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -712,10 +705,10 @@ TEST(t_dlt_message_header_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -724,7 +717,7 @@ TEST(t_dlt_message_header_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -748,10 +741,10 @@ TEST(t_dlt_message_header_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -799,10 +792,10 @@ TEST(t_dlt_message_header_flags_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -811,85 +804,107 @@ TEST(t_dlt_message_header_flags_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); printf("%s \n", text); } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_header_flags_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); printf("%s \n", text); } @@ -904,10 +919,10 @@ TEST(t_dlt_message_header_flags_v2, nullpointer) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -944,29 +959,33 @@ TEST(t_dlt_message_header_flags_v2, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, 0, 0, 0)); @@ -1000,29 +1019,33 @@ TEST(t_dlt_message_header_flags_v2, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(NULL, text, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, 0, 0, 0)); @@ -1053,52 +1076,68 @@ TEST(t_dlt_message_header_flags_v2, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, 0, DLT_HEADER_SHOW_ALL, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, 0, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NONE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TIME, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_TMSTP, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGCNT, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ECUID, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_APID, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_CTID, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGTYPE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_MSGSUBTYPE, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_VNVSTATUS, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_NOARG, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_HEADER_SHOW_ALL, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, text, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, text, 0, 0, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_header_flags_v2(&file.msgv2, text, 0, DLT_HEADER_SHOW_NONE, 0)); @@ -1145,10 +1184,10 @@ TEST(t_dlt_message_payload_v2, normal) /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -1157,7 +1196,7 @@ TEST(t_dlt_message_payload_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1165,14 +1204,16 @@ TEST(t_dlt_message_payload_v2, normal) printf("%s \n", text); EXPECT_LE(DLT_RETURN_OK, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); printf("%s \n", text); } @@ -1182,14 +1223,16 @@ TEST(t_dlt_message_payload_v2, normal) printf("%s \n", text); EXPECT_LE(DLT_RETURN_OK, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); printf("%s \n", text); - EXPECT_LE(DLT_RETURN_OK, - dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); printf("%s \n", text); } @@ -1203,9 +1246,10 @@ TEST(t_dlt_message_payload_v2, abnormal) /* Get PWD so file and filter can be used*/ char pwd[MAX_LINE]; - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)];; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; + ; sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -1214,26 +1258,33 @@ TEST(t_dlt_message_payload_v2, abnormal) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); /* USE own DLT_HEADER_SHOW , expected -1 */ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, 99, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file,0)>=0){} - for(int i=0;i= 0) { } + for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, DLT_DAEMON_TEXTSIZE, 99, 0)); - printf("%s \n",text); + printf("%s \n", text); } EXPECT_LE(DLT_RETURN_OK, dlt_file_free_v2(&file, 0)); } @@ -1310,18 +1361,22 @@ TEST(t_dlt_message_payload_v2, nullpointer) EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, 0, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 0)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_HEX, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_PLAIN, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_MIXED_FOR_HTML, 1)); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, NULL, DLT_DAEMON_TEXTSIZE, DLT_OUTPUT_ASCII_LIMITED, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, 0, 0, 1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload_v2(&file.msgv2, text, 0, DLT_OUTPUT_HEX, 0)); @@ -1341,8 +1396,8 @@ TEST(t_dlt_message_payload_v2, nullpointer) /* (gdb) p ptr */ /* $28 = (uint8_t *) 0x5124010337d46c00 */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 0)); */ -/* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 0)); */ + /* EXPECT_GE(DLT_RETURN_ERROR, dlt_message_payload(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0, 1)); */ } /* End Method:dlt_common::dlt_message_payload */ @@ -1353,10 +1408,10 @@ TEST(t_dlt_message_set_extraparamters_v2, normal) DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -1365,7 +1420,7 @@ TEST(t_dlt_message_set_extraparamters_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1387,43 +1442,45 @@ TEST(t_dlt_message_read_v2, normal) DltFile file; /* Get PWD so file can be used */ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ DltBuffer buf; - char *buffer = NULL; + char* buffer = NULL; - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, (unsigned char *)buffer, 255, 0, 1)); + EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, (unsigned char*)buffer, 255, 0, 1)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, - dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, - DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_buffer_init_dynamic( + &buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); - EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, (unsigned char *)buffer, 255, 1, 1)); + EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, (unsigned char*)buffer, 255, 1, 1)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); @@ -1435,10 +1492,10 @@ TEST(t_dlt_message_read_v2, nullpointer) DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); /*---------------------------------------*/ @@ -1447,10 +1504,9 @@ TEST(t_dlt_message_read_v2, nullpointer) /* NULL_Pointer, expected -1 */ EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read_v2(NULL, NULL, 0, 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read_v2(NULL, (uint8_t *)&buf, 0, 0, 0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read_v2(NULL, (uint8_t*)&buf, 0, 0, 0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, NULL, 0, 0, 0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, (uint8_t *)&buf, 0, 0, 0)); - + EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read_v2(&file.msgv2, (uint8_t*)&buf, 0, 0, 0)); } /* End Method:dlt_common::dlt_message_read_v2 */ @@ -1461,24 +1517,24 @@ TEST(t_dlt_message_argument_print_v2, normal) DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); static char text[DLT_DAEMON_TEXTSIZE]; /*---------------------------------------*/ - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; - uint8_t **pptr; - int32_t *pdatalength; + uint8_t** pptr; + int32_t* pdatalength; /* Normal Use-Case, expect 0 */ EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1486,9 +1542,9 @@ TEST(t_dlt_message_argument_print_v2, normal) datalength = file.msg.datasize; pptr = &ptr; pdatalength = &datalength; - EXPECT_GE(DLT_RETURN_OK, - dlt_message_argument_print_v2(&file.msgv2, DLT_TYPE_INFO_BOOL, pptr, pdatalength, text, - DLT_DAEMON_TEXTSIZE, 0, 1)); + EXPECT_GE( + DLT_RETURN_OK, dlt_message_argument_print_v2( + &file.msgv2, DLT_TYPE_INFO_BOOL, pptr, pdatalength, text, DLT_DAEMON_TEXTSIZE, 0, 1)); /*printf("### ARGUMENT:%s\n", text); */ } @@ -1497,7 +1553,7 @@ TEST(t_dlt_message_argument_print_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_init_v2(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -1505,14 +1561,13 @@ TEST(t_dlt_message_argument_print_v2, normal) datalength = file.msg.datasize; pptr = &ptr; pdatalength = &datalength; - EXPECT_GE(DLT_RETURN_OK, - dlt_message_argument_print_v2(&file.msgv2, DLT_TYPE_INFO_RAWD, pptr, pdatalength, text, - DLT_DAEMON_TEXTSIZE, 0, 1)); + EXPECT_GE( + DLT_RETURN_OK, dlt_message_argument_print_v2( + &file.msgv2, DLT_TYPE_INFO_RAWD, pptr, pdatalength, text, DLT_DAEMON_TEXTSIZE, 0, 1)); /*printf("### ARGUMENT:%s\n", text); */ } EXPECT_LE(DLT_RETURN_OK, dlt_file_free_v2(&file, 0)); - } @@ -1521,18 +1576,18 @@ TEST(t_dlt_message_argument_print_v2, nullpointer) DltFile file; /* Get PWD so file can be used*/ char pwd[MAX_LINE]; - char openfile[MAX_LINE+sizeof(BINARY_FILE_V2_NAME)]; + char openfile[MAX_LINE + sizeof(BINARY_FILE_V2_NAME)]; /* ignore returned value from getcwd */ - if (getcwd(pwd, MAX_LINE) == NULL) {} + if (getcwd(pwd, MAX_LINE) == NULL) { } sprintf(openfile, "%s" BINARY_FILE_V2_NAME, pwd); static char text[DLT_DAEMON_TEXTSIZE]; /*---------------------------------------*/ - uint8_t *ptr; + uint8_t* ptr; int32_t datalength; - uint8_t **pptr; - int32_t *pdatalength; + uint8_t** pptr; + int32_t* pdatalength; pptr = &ptr; pdatalength = &datalength; @@ -1564,8 +1619,7 @@ TEST(t_dlt_message_argument_print_v2, nullpointer) - -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_daemon.cpp b/tests/gtest_dlt_daemon.cpp index ee2f1250b..3beca42eb 100644 --- a/tests/gtest_dlt_daemon.cpp +++ b/tests/gtest_dlt_daemon.cpp @@ -30,8 +30,7 @@ #include #include -extern "C" -{ +extern "C" { #include "dlt-daemon.h" #include "dlt-daemon_cfg.h" #include "dlt_user_cfg.h" @@ -43,14 +42,15 @@ extern "C" const int _trace_load_send_size = 100; -static void init_daemon(DltDaemon* daemon, char* ecu) { +static void init_daemon(DltDaemon* daemon, char* ecu) +{ DltGateway gateway; strncpy(ecu, "ECU1", DLT_ID_SIZE); - EXPECT_EQ(0, - dlt_daemon_init(daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon->ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(daemon, &gateway, 0, 0)); @@ -60,8 +60,10 @@ static void setup_trace_load_settings(DltDaemon& daemon) { daemon.preconfigured_trace_load_settings_count = 6; daemon.preconfigured_trace_load_settings = - (DltTraceLoadSettings *)malloc(daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); - memset(daemon.preconfigured_trace_load_settings, 0, daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); + (DltTraceLoadSettings*)malloc(daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); + memset( + daemon.preconfigured_trace_load_settings, 0, + daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); // APP0 only has app id strncpy(daemon.preconfigured_trace_load_settings[0].apid, "APP0", DLT_ID_SIZE); @@ -97,8 +99,9 @@ static void setup_trace_load_settings(DltDaemon& daemon) // APP3 is not configured at all, but will be added via application_add // to make sure we assign default value in that case - qsort(daemon.preconfigured_trace_load_settings, daemon.preconfigured_trace_load_settings_count, - sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); + qsort( + daemon.preconfigured_trace_load_settings, daemon.preconfigured_trace_load_settings_count, + sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); } TEST(t_trace_load_config_file_parser, normal) @@ -115,7 +118,7 @@ TEST(t_trace_load_config_file_parser, normal) ASSERT_NE(fd, -1) << "Unable to create temporary file: " << strerror(errno); // Convert file descriptor to FILE* with fdopen - FILE *temp = fdopen(fd, "w"); + FILE* temp = fdopen(fd, "w"); if (temp == NULL) { close(fd); @@ -185,7 +188,7 @@ TEST(t_trace_load_config_file_parser, errors) ASSERT_NE(fd, -1) << "Unable to create temporary file: " << strerror(errno); // Convert file descriptor to FILE* with fdopen - FILE *temp = fdopen(fd, "w"); + FILE* temp = fdopen(fd, "w"); if (temp == NULL) { close(fd); @@ -229,7 +232,7 @@ TEST(t_trace_load_config_file_parser, errors) // Test case 10: Comments Misplacement or Format fprintf(temp, "APP1 CTX1 100 # This is a comment 200\n"); fprintf(temp, "APP1 CTX1 100 200 // This is a comment\n"); - + // Test case 11: empty lines fprintf(temp, " \n"); fprintf(temp, "\n"); @@ -259,77 +262,71 @@ TEST(t_trace_load_config_file_parser, errors) unlink(filename_template); } -static void matches_default_element(DltDaemonApplication *app, DltTraceLoadSettings *settings) { +static void matches_default_element(DltDaemonApplication* app, DltTraceLoadSettings* settings) +{ EXPECT_STREQ(settings->apid, app->apid); EXPECT_STREQ(settings->ctid, ""); EXPECT_EQ(settings->soft_limit, DLT_TRACE_LOAD_DAEMON_SOFT_LIMIT_DEFAULT); EXPECT_EQ(settings->hard_limit, DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT); } -TEST(t_find_runtime_trace_load_settings, normal) { +TEST(t_find_runtime_trace_load_settings, normal) +{ DltDaemon daemon; const int num_apps = 4; const char* app_ids[num_apps] = {"APP0", "APP1", "APP2", "APP3"}; - DltDaemonApplication *apps[num_apps] = {}; + DltDaemonApplication* apps[num_apps] = {}; DltTraceLoadSettings* settings; char ecu[DLT_ID_SIZE] = {}; pid_t pid = 0; int fd = 15; - const char *desc = "HELLO_TEST"; + const char* desc = "HELLO_TEST"; init_daemon(&daemon, ecu); setup_trace_load_settings(daemon); for (int i = 0; i < num_apps; i++) { - apps[i] = dlt_daemon_application_add(&daemon, (char *)app_ids[i], pid, (char *)desc, fd, ecu, 0); + apps[i] = dlt_daemon_application_add(&daemon, (char*)app_ids[i], pid, (char*)desc, fd, ecu, 0); EXPECT_FALSE(apps[i]->trace_load_settings == NULL); } // Find settings for APP0 with context that has not been configured settings = dlt_find_runtime_trace_load_settings( - apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, - apps[0]->apid, "FOO"); + apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, apps[0]->apid, "FOO"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[0], sizeof(DltTraceLoadSettings)), 0); // Find settings for APP1 with context that has been configured settings = dlt_find_runtime_trace_load_settings( - apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, - apps[1]->apid, "CT01"); + apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, apps[1]->apid, "CT01"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[1], sizeof(DltTraceLoadSettings)), 0); settings = dlt_find_runtime_trace_load_settings( - apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, - apps[1]->apid, "CT02"); + apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, apps[1]->apid, "CT02"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[2], sizeof(DltTraceLoadSettings)), 0); settings = dlt_find_runtime_trace_load_settings( - apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, - apps[1]->apid, "CT03"); + apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, apps[1]->apid, "CT03"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[3], sizeof(DltTraceLoadSettings)), 0); // This context does not have a configuration, so the default element should be returned settings = dlt_find_runtime_trace_load_settings( - apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, - apps[1]->apid, "CTXX"); + apps[1]->trace_load_settings, apps[1]->trace_load_settings_count, apps[1]->apid, "CTXX"); matches_default_element(apps[1], settings); // APP2 has app id and context configured settings = dlt_find_runtime_trace_load_settings( - apps[2]->trace_load_settings, apps[2]->trace_load_settings_count, - apps[2]->apid, "CTXX"); + apps[2]->trace_load_settings, apps[2]->trace_load_settings_count, apps[2]->apid, "CTXX"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[4], sizeof(DltTraceLoadSettings)), 0); settings = dlt_find_runtime_trace_load_settings( - apps[2]->trace_load_settings, apps[2]->trace_load_settings_count, - apps[2]->apid, "CT01"); + apps[2]->trace_load_settings, apps[2]->trace_load_settings_count, apps[2]->apid, "CT01"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[5], sizeof(DltTraceLoadSettings)), 0); // Find settings for APP3 that has not been configured at all settings = dlt_find_runtime_trace_load_settings( - apps[3]->trace_load_settings, apps[3]->trace_load_settings_count, - apps[3]->apid, "TEST"); + apps[3]->trace_load_settings, apps[3]->trace_load_settings_count, apps[3]->apid, "TEST"); matches_default_element(apps[3], settings); // Nullptr for everything @@ -338,82 +335,76 @@ TEST(t_find_runtime_trace_load_settings, normal) { // Nullptr for app settings = dlt_find_runtime_trace_load_settings( - apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, NULL, - NULL); + apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, NULL, NULL); EXPECT_TRUE(settings == NULL); // Empty appid settings = dlt_find_runtime_trace_load_settings( - apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, "", - NULL); + apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, "", NULL); EXPECT_TRUE(settings == NULL); // Context id invalid settings = dlt_find_runtime_trace_load_settings( - apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, - apps[0]->apid, "FOOBAR"); + apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, apps[0]->apid, "FOOBAR"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[0], sizeof(DltTraceLoadSettings)), 0); // remove application, add it again and check if the settings are still there dlt_daemon_application_del(&daemon, apps[0], ecu, 0); - apps[0] = dlt_daemon_application_add(&daemon, (char *)app_ids[0], pid, (char *)desc, fd, ecu, 0); + apps[0] = dlt_daemon_application_add(&daemon, (char*)app_ids[0], pid, (char*)desc, fd, ecu, 0); settings = dlt_find_runtime_trace_load_settings( - apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, - apps[0]->apid, "FOO"); + apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, apps[0]->apid, "FOO"); EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[0], sizeof(DltTraceLoadSettings)), 0); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); // Test after freeing daemon settings = dlt_find_runtime_trace_load_settings( - apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, - apps[0]->apid, NULL); + apps[0]->trace_load_settings, apps[0]->trace_load_settings_count, apps[0]->apid, NULL); EXPECT_TRUE(settings == NULL); EXPECT_TRUE(apps[0]->trace_load_settings == NULL); } -TEST(t_trace_load_keep_message, normal) { +TEST(t_trace_load_keep_message, normal) +{ DltDaemon daemon; DltDaemonLocal daemon_local = {}; const int num_apps = 4; const char* app_ids[num_apps] = {"APP0", "APP1", "APP2", "APP3"}; - DltDaemonApplication *apps[num_apps] = {}; + DltDaemonApplication* apps[num_apps] = {}; char ecu[DLT_ID_SIZE] = {}; pid_t pid = 0; int fd = 15; - const char *desc = "HELLO_TEST"; + const char* desc = "HELLO_TEST"; for (auto& app_id : app_ids) { dlt_register_app(app_id, app_id); } const auto set_extended_header = [&daemon_local]() { - daemon_local.msg.extendedheader = (DltExtendedHeader *)(daemon_local.msg.headerbuffer + sizeof(DltStorageHeader) + - sizeof(DltStandardHeader)); + daemon_local.msg.extendedheader = + (DltExtendedHeader*)(daemon_local.msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)); memset(daemon_local.msg.extendedheader, 0, sizeof(DltExtendedHeader)); }; const auto set_extended_header_log_level = [&daemon_local](unsigned int log_level) { - daemon_local.msg.extendedheader->msin = ((daemon_local.msg.extendedheader->msin) & ~DLT_MSIN_MTIN) | ((log_level) << DLT_MSIN_MTIN_SHIFT); + daemon_local.msg.extendedheader->msin = + ((daemon_local.msg.extendedheader->msin) & ~DLT_MSIN_MTIN) | ((log_level) << DLT_MSIN_MTIN_SHIFT); }; - const auto log_until_hard_limit_reached = [&daemon, &daemon_local] (DltDaemonApplication *app) { - while (trace_load_keep_message(app, _trace_load_send_size, &daemon, &daemon_local, 0)); + const auto log_until_hard_limit_reached = [&daemon, &daemon_local](DltDaemonApplication* app) { + while (trace_load_keep_message(app, _trace_load_send_size, &daemon, &daemon_local, 0)) + ; }; const auto check_debug_and_trace_can_log = [&](DltDaemonApplication* app) { // messages for debug and verbose logs are never dropped set_extended_header_log_level(DLT_LOG_VERBOSE); - EXPECT_TRUE(trace_load_keep_message(app, - app->trace_load_settings->hard_limit * 10, - &daemon, &daemon_local, 0)); + EXPECT_TRUE(trace_load_keep_message(app, app->trace_load_settings->hard_limit * 10, &daemon, &daemon_local, 0)); set_extended_header_log_level(DLT_LOG_DEBUG); - EXPECT_TRUE(trace_load_keep_message(app, - app->trace_load_settings->hard_limit * 10, - &daemon, &daemon_local, 0)); + EXPECT_TRUE(trace_load_keep_message(app, app->trace_load_settings->hard_limit * 10, &daemon, &daemon_local, 0)); set_extended_header_log_level(DLT_LOG_INFO); }; @@ -422,14 +413,13 @@ TEST(t_trace_load_keep_message, normal) { setup_trace_load_settings(daemon); for (int i = 0; i < num_apps; i++) { - apps[i] = dlt_daemon_application_add(&daemon, (char *)app_ids[i], pid, (char *)desc, fd, ecu, 0); + apps[i] = dlt_daemon_application_add(&daemon, (char*)app_ids[i], pid, (char*)desc, fd, ecu, 0); EXPECT_FALSE(apps[i]->trace_load_settings == NULL); } // messages without extended header will be kept daemon_local.msg.extendedheader = NULL; - EXPECT_TRUE(trace_load_keep_message( - apps[0], apps[0]->trace_load_settings->soft_limit, &daemon, &daemon_local, 0)); + EXPECT_TRUE(trace_load_keep_message(apps[0], apps[0]->trace_load_settings->soft_limit, &daemon, &daemon_local, 0)); set_extended_header(); memcpy(daemon_local.msg.extendedheader->apid, apps[0], DLT_ID_SIZE); @@ -485,8 +475,8 @@ TEST(t_trace_load_keep_message, normal) { dlt_daemon_context_add(&daemon, apps[1]->apid, "CTXX", DLT_LOG_VERBOSE, 0, 0, 0, "", "ECU1", 0); EXPECT_EQ( - trace_load_keep_message(apps[1], _trace_load_send_size, &daemon, &daemon_local, 0), - DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT != 0); + trace_load_keep_message(apps[1], _trace_load_send_size, &daemon, &daemon_local, 0), + DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT != 0); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -499,8 +489,7 @@ TEST(t_trace_load_keep_message, normal) { - -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_daemon_common.cpp b/tests/gtest_dlt_daemon_common.cpp index 57b0ba679..9b22ad59d 100644 --- a/tests/gtest_dlt_daemon_common.cpp +++ b/tests/gtest_dlt_daemon_common.cpp @@ -44,12 +44,12 @@ extern "C" { } #ifndef DLT_USER_DIR -# define DLT_USER_DIR "/tmp/dltpipes" +#define DLT_USER_DIR "/tmp/dltpipes" #endif /* Name of named pipe to DLT daemon */ #ifndef DLT_USER_FIFO -# define DLT_USER_FIFO "/tmp/dlt" +#define DLT_USER_FIFO "/tmp/dlt" #endif /* Begin Method:dlt_daemon_common::dlt_daemon_init_user_information */ @@ -59,12 +59,10 @@ TEST(t_dlt_daemon_init_user_information, normal_one_list) DltGateway gateway; char ecu[] = "ECU1"; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); @@ -81,19 +79,16 @@ TEST(t_dlt_daemon_init_user_information, normal_multiple_lists) char ecu2[] = "ECU2"; char ecu3[] = "ECU3"; - gateway.connections = - (DltGatewayConnection *)calloc(2, sizeof(DltGatewayConnection)); + gateway.connections = (DltGatewayConnection*)calloc(2, sizeof(DltGatewayConnection)); gateway.connections[0].ecuid = &ecu2[0]; gateway.connections[1].ecuid = &ecu3[0]; gateway.num_connections = 2; /* Normal Use-Case */ - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 1, 0)); @@ -122,15 +117,13 @@ TEST(t_dlt_daemon_find_users_list, normal_one_list) { DltDaemon daemon; DltGateway gateway; - DltDaemonRegisteredUsers *user_list; + DltDaemonRegisteredUsers* user_list; char ecu[] = "ECU1"; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); @@ -146,16 +139,14 @@ TEST(t_dlt_daemon_find_users_list, abnormal) { DltDaemon daemon; DltGateway gateway; - DltDaemonRegisteredUsers *user_list; + DltDaemonRegisteredUsers* user_list; char ecu[] = "ECU1"; char bla[] = "BLAH"; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); @@ -173,21 +164,18 @@ TEST(t_dlt_daemon_find_users_list, normal_multiple_lists) char ecu[] = "ECU1"; char ecu2[] = "ECU2"; char ecu3[] = "ECU3"; - DltDaemonRegisteredUsers *user_list; + DltDaemonRegisteredUsers* user_list; - gateway.connections = - (DltGatewayConnection *)calloc(2, sizeof(DltGatewayConnection)); + gateway.connections = (DltGatewayConnection*)calloc(2, sizeof(DltGatewayConnection)); gateway.connections[0].ecuid = &ecu2[0]; gateway.connections[1].ecuid = &ecu3[0]; gateway.num_connections = 2; /* Normal Use-Case */ - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 1, 0)); @@ -227,30 +215,31 @@ TEST(t_dlt_daemon_application_add, normal) { DltDaemon daemon; DltGateway gateway; - const char *apid = "TEST"; + const char* apid = "TEST"; pid_t pid = 0; - const char *desc = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 15; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid_buf[DLT_ID_SIZE+1] = {0}; + char apid_buf[DLT_ID_SIZE + 1] = {0}; char desc_buf[32] = {0}; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); - /*printf("### APP: APID=%s DESCR=%s NUMCONTEXT=%i PID=%i USERHANDLE=%i\n", app->apid,app->application_description, app->num_contexts, app->pid, app->user_handle); */ + /*printf("### APP: APID=%s DESCR=%s NUMCONTEXT=%i PID=%i USERHANDLE=%i\n", app->apid,app->application_description, + * app->num_contexts, app->pid, app->user_handle); */ EXPECT_EQ(0, strncmp(apid, app->apid, DLT_ID_SIZE)); EXPECT_STREQ(desc, app->application_description); EXPECT_EQ(pid, app->pid); @@ -261,8 +250,8 @@ TEST(t_dlt_daemon_application_add, normal) apid = "TO_LONG"; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); char tmp[5]; memcpy(tmp, apid, 4); @@ -274,102 +263,102 @@ TEST(t_dlt_daemon_application_add, normal) } TEST(t_dlt_daemon_application_add, abnormal) { -/* DltDaemon daemon; */ -/* const char * apid = "TEST"; */ -/* pid_t pid = 0; */ -/* const char * desc = "HELLO_TEST"; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* const char * apid = "TEST"; */ + /* pid_t pid = 0; */ + /* const char * desc = "HELLO_TEST"; */ + /* DltDaemonApplication *app = NULL; */ /* Add the same application with same pid twice */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_LE((DltDaemonApplication *) 0, app); */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_EQ((DltDaemonApplication *) 0, app); */ -/* dlt_daemon_application_del(&daemon,app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_LE((DltDaemonApplication *) 0, app); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_EQ((DltDaemonApplication *) 0, app); */ + /* dlt_daemon_application_del(&daemon,app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Add the same applicaiotn with different pid */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, 0, (char *) desc, 0); */ -/* EXPECT_LE((DltDaemonApplication *) 0, app); */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, 123, (char *) desc, 0); */ -/* EXPECT_EQ((DltDaemonApplication *) 0, app); */ -/* dlt_daemon_application_del(&daemon,app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, 0, (char *) desc, 0); */ + /* EXPECT_LE((DltDaemonApplication *) 0, app); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, 123, (char *) desc, 0); */ + /* EXPECT_EQ((DltDaemonApplication *) 0, app); */ + /* dlt_daemon_application_del(&daemon,app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* verbose value != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 12345678)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, + * 12345678)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Apid < 4, expected fill to 4 chars or error */ -/* apid = "SH"; */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* char tmp[5]; */ -/* strncpy(tmp, apid, 4); */ -/* tmp[4] = '\0'; */ -/* EXPECT_STREQ(tmp, app->apid); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ - + /* apid = "SH"; */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* char tmp[5]; */ + /* strncpy(tmp, apid, 4); */ + /* tmp[4] = '\0'; */ + /* EXPECT_STREQ(tmp, app->apid); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_application_add, nullpointer) { DltDaemon daemon; - const char *apid = "TEST"; - const char *desc = "HELLO_TEST"; + const char* apid = "TEST"; + const char* desc = "HELLO_TEST"; int fd = 42; char ecu[] = "ECU1"; - char apid_buf[DLT_ID_SIZE+1] = {0}; + char apid_buf[DLT_ID_SIZE + 1] = {0}; char desc_buf[32] = {0}; /* NULL-Pointer test */ - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(NULL, NULL, 0, NULL, 0, NULL, 0)); - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(NULL, NULL, 0, desc_buf, 0, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(NULL, NULL, 0, NULL, 0, NULL, 0)); + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(NULL, NULL, 0, desc_buf, 0, NULL, 0)); memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(NULL, apid_buf, 0, NULL, 0, NULL, 0)); - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(NULL, apid_buf, 0, desc_buf, 0, NULL, 0)); - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(&daemon, NULL, 0, NULL, 0, NULL, 0)); - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(&daemon, NULL, 0, desc_buf, 0, NULL, 0)); - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(NULL, NULL, 0, NULL, fd, NULL, 0)); - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_add(NULL, NULL, 0, NULL, 0, ecu, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(NULL, apid_buf, 0, NULL, 0, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(NULL, apid_buf, 0, desc_buf, 0, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(&daemon, NULL, 0, NULL, 0, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(&daemon, NULL, 0, desc_buf, 0, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(NULL, NULL, 0, NULL, fd, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_add(NULL, NULL, 0, NULL, 0, ecu, 0)); } /* End Method:dlt_daemon_common::dlt_daemon_application_add */ - /* Begin Method: dlt_daemon_common::dlt_daemon_application_del */ TEST(t_dlt_daemon_application_del, normal) { DltDaemon daemon; DltGateway gateway; - const char *apid = "TEST"; + const char* apid = "TEST"; pid_t pid = 0; - const char *desc = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case, retrun type cannot be tested, only apid and desc */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid_buf[DLT_ID_SIZE+1] = {0}; + char apid_buf[DLT_ID_SIZE + 1] = {0}; char desc_buf[32] = {0}; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); @@ -378,29 +367,29 @@ TEST(t_dlt_daemon_application_del, normal) TEST(t_dlt_daemon_application_del, abnormal) { -/* DltDaemon daemon; */ -/* const char * apid = "TEST"; */ -/* pid_t pid = 0; */ -/* const char * desc = "HELLO_TEST"; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* const char * apid = "TEST"; */ + /* pid_t pid = 0; */ + /* const char * desc = "HELLO_TEST"; */ + /* DltDaemonApplication *app = NULL; */ /* no application exists, expect < 0 */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_application_del(&daemon, app, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_application_del(&daemon, app, 0)); */ /* Call delete two times */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_LE(0, dlt_daemon_application_del(&daemon,app, 0)); */ -/* EXPECT_GE(-1, dlt_daemon_application_del(&daemon,app, 0)); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_LE(0, dlt_daemon_application_del(&daemon,app, 0)); */ + /* EXPECT_GE(-1, dlt_daemon_application_del(&daemon,app, 0)); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Verbose parameter != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_application_del(&daemon,app, 123456789)); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ - + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_application_del(&daemon,app, 123456789)); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_application_del, nullpointer) { @@ -417,33 +406,32 @@ TEST(t_dlt_daemon_application_del, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_applikation_find */ TEST(t_dlt_daemon_application_find, normal) { DltDaemon daemon; DltGateway gateway; - const char *apid = "TEST"; + const char* apid = "TEST"; pid_t pid = 0; - const char *desc = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid_buf[DLT_ID_SIZE+1] = {0}; + char apid_buf[DLT_ID_SIZE + 1] = {0}; char desc_buf[32] = {0}; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); EXPECT_EQ(0, strncmp(apid, app->apid, DLT_ID_SIZE)); EXPECT_STREQ(desc, app->application_description); @@ -452,59 +440,58 @@ TEST(t_dlt_daemon_application_find, normal) EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); /* Application doesn't exist, expect NULL */ - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_find(&daemon, ecu, apid_buf, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_find(&daemon, ecu, apid_buf, 0)); /* Use a different apid, expect NULL */ memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); - EXPECT_LE((DltDaemonApplication *)0, dlt_daemon_application_find(&daemon, ecu, apid_buf, 0)); - char nexi[DLT_ID_SIZE+1] = {0}; + EXPECT_LE((DltDaemonApplication*)0, dlt_daemon_application_find(&daemon, ecu, apid_buf, 0)); + char nexi[DLT_ID_SIZE + 1] = {0}; memcpy(nexi, "NEXI", DLT_ID_SIZE); nexi[DLT_ID_SIZE] = '\0'; - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_find(&daemon, ecu, nexi, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_find(&daemon, ecu, nexi, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_application_find, abnormal) { -/* DltDaemon daemon; */ -/* const char * apid = "TEST"; */ -/* pid_t pid = 0; */ -/* const char * desc = "HELLO_TEST"; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* const char * apid = "TEST"; */ + /* pid_t pid = 0; */ + /* const char * desc = "HELLO_TEST"; */ + /* DltDaemonApplication *app = NULL; */ /* Verbose != 0 or 1, expect error */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* dlt_daemon_application_find(&daemon, (char *) apid, 0); */ -/* EXPECT_EQ((DltDaemonApplication *) 0, dlt_daemon_application_find(&daemon, (char *) apid, 123456789)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ - + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* dlt_daemon_application_find(&daemon, (char *) apid, 0); */ + /* EXPECT_EQ((DltDaemonApplication *) 0, dlt_daemon_application_find(&daemon, (char *) apid, 123456789)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_application_find, nullpointer) { DltDaemon daemon; - const char *apid = "TEST"; + const char* apid = "TEST"; /* NULL-Pointer, expected NULL */ - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_find(NULL, NULL, NULL, 0)); - char apid_buf[DLT_ID_SIZE+1] = {0}; + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_find(NULL, NULL, NULL, 0)); + char apid_buf[DLT_ID_SIZE + 1] = {0}; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_find(NULL, apid_buf, NULL, 0)); - EXPECT_EQ((DltDaemonApplication *)0, dlt_daemon_application_find(&daemon, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_find(NULL, apid_buf, NULL, 0)); + EXPECT_EQ((DltDaemonApplication*)0, dlt_daemon_application_find(&daemon, NULL, NULL, 0)); } /* End Method: dlt_daemon_common::dlt_daemon_applikation_find */ - /* Begin Method: dlt_daemon_common::dlt_daemon_applications_clear */ TEST(t_dlt_daemon_applications_clear, normal) { @@ -515,50 +502,50 @@ TEST(t_dlt_daemon_applications_clear, normal) int fd = 42; /* Normal Use Case, expect >= 0 */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid1_buf[DLT_ID_SIZE+1] = {0}; + char apid1_buf[DLT_ID_SIZE + 1] = {0}; char desc1_buf[32] = {0}; memcpy(apid1_buf, "TES1", DLT_ID_SIZE); apid1_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc1_buf, "Test clear 1", sizeof(desc1_buf)-1); - desc1_buf[sizeof(desc1_buf)-1] = '\0'; - EXPECT_LE((DltDaemonApplication *)0, - dlt_daemon_application_add(&daemon, apid1_buf, pid, desc1_buf, fd, ecu, 0)); + strncpy(desc1_buf, "Test clear 1", sizeof(desc1_buf) - 1); + desc1_buf[sizeof(desc1_buf) - 1] = '\0'; + EXPECT_LE((DltDaemonApplication*)0, dlt_daemon_application_add(&daemon, apid1_buf, pid, desc1_buf, fd, ecu, 0)); memcpy(apid1_buf, "TES1", DLT_ID_SIZE); apid1_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc1_buf, "Test clear 1", sizeof(desc1_buf)-1); - desc1_buf[sizeof(desc1_buf)-1] = '\0'; + strncpy(desc1_buf, "Test clear 1", sizeof(desc1_buf) - 1); + desc1_buf[sizeof(desc1_buf) - 1] = '\0'; dlt_daemon_application_add(&daemon, apid1_buf, pid, desc1_buf, fd, ecu, 0); - char apid2_buf[DLT_ID_SIZE+1] = {0}; + char apid2_buf[DLT_ID_SIZE + 1] = {0}; char desc2_buf[32] = {0}; memcpy(apid2_buf, "TES2", DLT_ID_SIZE); apid2_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc2_buf, "Test clear 2", sizeof(desc2_buf)-1); - desc2_buf[sizeof(desc2_buf)-1] = '\0'; + strncpy(desc2_buf, "Test clear 2", sizeof(desc2_buf) - 1); + desc2_buf[sizeof(desc2_buf) - 1] = '\0'; dlt_daemon_application_add(&daemon, apid2_buf, pid, desc2_buf, fd, ecu, 0); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_applications_clear, abnormal) { -/* DltDaemon daemon; */ -/* pid_t pid = 0; */ + /* DltDaemon daemon; */ + /* pid_t pid = 0; */ /* No applications added, expect < -1 */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_applications_clear(&daemon, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_applications_clear(&daemon, 0)); */ /* Verbose != 0 or 1, expect error */ -/* dlt_daemon_application_add(&daemon, (char *) "TEST", pid, (char *) "Test clear", 0); */ -/* EXPECT_GE(-1, dlt_daemon_applications_clear(&daemon, 123456789)); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* dlt_daemon_application_add(&daemon, (char *) "TEST", pid, (char *) "Test clear", 0); */ + /* EXPECT_GE(-1, dlt_daemon_applications_clear(&daemon, 123456789)); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_applications_clear, nullpointer) { @@ -574,27 +561,27 @@ TEST(t_dlt_daemon_applications_invalidate_fd, normal) { DltDaemon daemon; DltGateway gateway; - const char *apid = "TEST"; + const char* apid = "TEST"; pid_t pid = 0; - const char *desc = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid_buf[DLT_ID_SIZE+1] = {0}; + char apid_buf[DLT_ID_SIZE + 1] = {0}; char desc_buf[32] = {0}; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); EXPECT_LE(0, dlt_daemon_applications_invalidate_fd(&daemon, ecu, app->user_handle, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -603,22 +590,23 @@ TEST(t_dlt_daemon_applications_invalidate_fd, normal) } TEST(t_dlt_daemon_applications_invalidate_fd, abnormal) { -/* DltDaemon daemon; */ -/* const char * apid = "TEST"; */ -/* pid_t pid = 0; */ -/* const char * desc = "HELLO_TEST"; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* const char * apid = "TEST"; */ + /* pid_t pid = 0; */ + /* const char * desc = "HELLO_TEST"; */ + /* DltDaemonApplication *app = NULL; */ /* Daemon isn't initialized, expected error */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_applications_invalidate_fd(&daemon, 0, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_applications_invalidate_fd(&daemon, 0, 0)); */ /* Verbose != 0 or 1, expect error */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_applications_invalidate_fd(&daemon, app->user_handle, 123456789)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_applications_invalidate_fd(&daemon, app->user_handle, 123456789)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_applications_invalidate_fd, nullpointer) { @@ -629,38 +617,37 @@ TEST(t_dlt_daemon_applications_invalidate_fd, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_applications_save */ TEST(t_dlt_daemon_applications_save, normal) { DltDaemon daemon; DltGateway gateway; - const char *apid = "TEST"; + const char* apid = "TEST"; pid_t pid = 0; - const char *desc = "HELLO_TEST"; - DltDaemonApplication *app = NULL; - const char *filename = "/tmp/dlt-runtime.cfg"; + const char* desc = "HELLO_TEST"; + DltDaemonApplication* app = NULL; + const char* filename = "/tmp/dlt-runtime.cfg"; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid_buf[DLT_ID_SIZE+1] = {0}; + char apid_buf[DLT_ID_SIZE + 1] = {0}; char desc_buf[32] = {0}; memcpy(apid_buf, apid, DLT_ID_SIZE); apid_buf[DLT_ID_SIZE] = '\0'; - strncpy(desc_buf, desc, sizeof(desc_buf)-1); - desc_buf[sizeof(desc_buf)-1] = '\0'; + strncpy(desc_buf, desc, sizeof(desc_buf) - 1); + desc_buf[sizeof(desc_buf) - 1] = '\0'; app = dlt_daemon_application_add(&daemon, apid_buf, pid, desc_buf, fd, ecu, 0); char filename_buf[256] = {0}; - strncpy(filename_buf, filename, sizeof(filename_buf)-1); - filename_buf[sizeof(filename_buf)-1] = '\0'; + strncpy(filename_buf, filename, sizeof(filename_buf) - 1); + filename_buf[sizeof(filename_buf) - 1] = '\0'; EXPECT_LE(0, dlt_daemon_applications_save(&daemon, filename_buf, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); @@ -668,40 +655,41 @@ TEST(t_dlt_daemon_applications_save, normal) } TEST(t_dlt_daemon_applications_save, abnormal) { -/* DltDaemon daemon; */ -/* const char * apid = "TEST"; */ -/* pid_t pid = 0; */ -/* const char * desc = "HELLO_TEST"; */ -/* DltDaemonApplication *app = NULL; */ -/* const char * filename = "/tmp/dlt-runtime.cfg"; */ + /* DltDaemon daemon; */ + /* const char * apid = "TEST"; */ + /* pid_t pid = 0; */ + /* const char * desc = "HELLO_TEST"; */ + /* DltDaemonApplication *app = NULL; */ + /* const char * filename = "/tmp/dlt-runtime.cfg"; */ /* Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, (char *) filename, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, (char *) filename, 0)); */ /* Verbose != 1 or 0, expect error */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, (char *) filename, 123456789)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, (char *) filename, 123456789)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Wrong path filename */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, (char *) "PATH_DONT_EXIST", 0)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, (char *) "PATH_DONT_EXIST", 0)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_applications_save, nullpointer) { DltDaemon daemon; - const char *filename = "/tmp/dlt-runtime.cfg"; + const char* filename = "/tmp/dlt-runtime.cfg"; /* NULL-Pointer */ EXPECT_GE(-1, dlt_daemon_applications_save(NULL, NULL, 0)); char filename_buf[256] = {0}; - strncpy(filename_buf, filename, sizeof(filename_buf)-1); - filename_buf[sizeof(filename_buf)-1] = '\0'; + strncpy(filename_buf, filename, sizeof(filename_buf) - 1); + filename_buf[sizeof(filename_buf) - 1] = '\0'; EXPECT_GE(-1, dlt_daemon_applications_save(NULL, filename_buf, 0)); EXPECT_GE(-1, dlt_daemon_applications_save(&daemon, NULL, 0)); } @@ -709,65 +697,65 @@ TEST(t_dlt_daemon_applications_save, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_applications_load */ TEST(t_dlt_daemon_applications_load, normal) { DltDaemon daemon; DltGateway gateway; char ecu[] = "ECU1"; - const char *filename = "/tmp/dlt-runtime.cfg"; + const char* filename = "/tmp/dlt-runtime.cfg"; /* Normal Use-Case, first execute t_dlt_daemon_applications_save !! */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); char filename_buf[256] = {0}; - strncpy(filename_buf, filename, sizeof(filename_buf)-1); - filename_buf[sizeof(filename_buf)-1] = '\0'; + strncpy(filename_buf, filename, sizeof(filename_buf) - 1); + filename_buf[sizeof(filename_buf) - 1] = '\0'; EXPECT_LE(0, dlt_daemon_applications_load(&daemon, filename_buf, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_applications_load, abnormal) { -/* DltDaemon daemon; */ -/* const char * apid = "TEST"; */ -/* pid_t pid = 0; */ -/* const char * desc = "HELLO_TEST"; */ -/* DltDaemonApplication *app = NULL; */ -/* const char * filename = "/tmp/dlt-runtime.cfg"; */ + /* DltDaemon daemon; */ + /* const char * apid = "TEST"; */ + /* pid_t pid = 0; */ + /* const char * desc = "HELLO_TEST"; */ + /* DltDaemonApplication *app = NULL; */ + /* const char * filename = "/tmp/dlt-runtime.cfg"; */ /* Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, (char *) filename, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, (char *) filename, 0)); */ /* Verbose != 1 or 0, expect error */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, (char *) filename, 123456789)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, (char *) filename, 123456789)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Wrong path filename */ -/* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, (char *) "PATH_DONT_EXIST", 0)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, (char *) "PATH_DONT_EXIST", 0)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_applications_load, nullpointer) { DltDaemon daemon; - const char *filename = "/tmp/dlt-runtime.cfg"; + const char* filename = "/tmp/dlt-runtime.cfg"; /* NULL-Pointer */ EXPECT_GE(-1, dlt_daemon_applications_load(NULL, NULL, 0)); char filename_buf[256] = {0}; - strncpy(filename_buf, filename, sizeof(filename_buf)-1); - filename_buf[sizeof(filename_buf)-1] = '\0'; + strncpy(filename_buf, filename, sizeof(filename_buf) - 1); + filename_buf[sizeof(filename_buf) - 1] = '\0'; EXPECT_GE(-1, dlt_daemon_applications_load(NULL, filename_buf, 0)); EXPECT_GE(-1, dlt_daemon_applications_load(&daemon, NULL, 0)); } @@ -775,53 +763,51 @@ TEST(t_dlt_daemon_applications_load, nullpointer) - /*##############################################################################################################################*/ /*##############################################################################################################################*/ /*##############################################################################################################################*/ - /* Begin Method: dlt_daemon_common::dlt_daemon_context_add */ TEST(t_dlt_daemon_context_add, normal) { -/* Log Level */ -/* 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 * / */ - -/* Trace Status */ -/* DLT_TRACE_STATUS_DEFAULT = -1, / **< Default trace status * / */ -/* DLT_TRACE_STATUS_OFF = 0x00, / **< Trace status: Off * / */ -/* DLT_TRACE_STATUS_ON = 0x01 / **< Trace status: On * / */ + /* Log Level */ + /* 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 * / */ + + /* Trace Status */ + /* DLT_TRACE_STATUS_DEFAULT = -1, / **< Default trace status * / */ + /* DLT_TRACE_STATUS_OFF = 0x00, / **< Trace status: Off * / */ + /* DLT_TRACE_STATUS_ON = 0x01 / **< Trace status: On * / */ DltDaemon daemon; DltGateway gateway; ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); /*printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ EXPECT_STREQ(apid, daecontext->apid); EXPECT_STREQ(ctid, daecontext->ctid); @@ -841,34 +827,26 @@ TEST(t_dlt_daemon_context_add, abnormal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Log Level dont exists */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); /* Log level out of valid range (-1 to 6), should return NULL */ int8_t invalid_log_level = 100; app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - invalid_log_level, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, invalid_log_level, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); /*printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ - EXPECT_EQ((DltDaemonContext *)0, daecontext); + EXPECT_EQ((DltDaemonContext*)0, daecontext); EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); @@ -877,93 +855,89 @@ TEST(t_dlt_daemon_context_add, abnormal) /* Trace Status out of valid range (-1 to 1), should return NULL */ int8_t invalid_trace_status = 100; app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - invalid_trace_status, - 0, - 0, - desc, - ecu, - 0); + daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, invalid_trace_status, 0, 0, desc, ecu, 0); /*printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ - EXPECT_EQ((DltDaemonContext *)0, daecontext); + EXPECT_EQ((DltDaemonContext*)0, daecontext); EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); /* Apid to long */ -/* char apid_tl[8] = "TO_LONG"; */ -/* app = dlt_daemon_application_add(&daemon, apid_tl, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid_tl,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ -/* EXPECT_STREQ(apid_tl, daecontext->apid); */ -/* EXPECT_STREQ(ctid, daecontext->ctid); */ -/* EXPECT_STREQ(desc, daecontext->context_description); */ -/* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ -/* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* char apid_tl[8] = "TO_LONG"; */ + /* app = dlt_daemon_application_add(&daemon, apid_tl, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid_tl,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); + */ + /* printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ + /* EXPECT_STREQ(apid_tl, daecontext->apid); */ + /* EXPECT_STREQ(ctid, daecontext->ctid); */ + /* EXPECT_STREQ(desc, daecontext->context_description); */ + /* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ + /* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Apid to short */ -/* char apid_ts[3] = "TS"; */ -/* app = dlt_daemon_application_add(&daemon, apid_ts, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid_ts,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ -/* EXPECT_STREQ(apid_ts, daecontext->apid); */ -/* EXPECT_STREQ(ctid, daecontext->ctid); */ -/* EXPECT_STREQ(desc, daecontext->context_description); */ -/* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ -/* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ -/* //EXPECT_EQ(4, strlen(apid_ts)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* char apid_ts[3] = "TS"; */ + /* app = dlt_daemon_application_add(&daemon, apid_ts, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid_ts,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); + */ + /* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ + /* EXPECT_STREQ(apid_ts, daecontext->apid); */ + /* EXPECT_STREQ(ctid, daecontext->ctid); */ + /* EXPECT_STREQ(desc, daecontext->context_description); */ + /* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ + /* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ + /* //EXPECT_EQ(4, strlen(apid_ts)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Ctid to long */ -/* char ctid_tl[8] = "TO_LONG"; */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid_tl,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ -/* EXPECT_STREQ(apid, daecontext->apid); */ -/* EXPECT_STREQ(ctid_tl, daecontext->ctid); */ -/* EXPECT_STREQ(desc, daecontext->context_description); */ -/* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ -/* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* char ctid_tl[8] = "TO_LONG"; */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid_tl,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); + */ + /* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ + /* EXPECT_STREQ(apid, daecontext->apid); */ + /* EXPECT_STREQ(ctid_tl, daecontext->ctid); */ + /* EXPECT_STREQ(desc, daecontext->context_description); */ + /* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ + /* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Ctid to short */ -/* char ctid_ts[4] = "TS"; */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid_ts,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ -/* EXPECT_STREQ(apid, daecontext->apid); */ -/* EXPECT_STREQ(ctid_ts, daecontext->ctid); */ -/* EXPECT_STREQ(desc, daecontext->context_description); */ -/* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ -/* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* char ctid_ts[4] = "TS"; */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid_ts,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); + */ + /* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ + /* EXPECT_STREQ(apid, daecontext->apid); */ + /* EXPECT_STREQ(ctid_ts, daecontext->ctid); */ + /* EXPECT_STREQ(desc, daecontext->context_description); */ + /* EXPECT_EQ(DLT_LOG_DEFAULT, daecontext->log_level); */ + /* EXPECT_EQ(DLT_TRACE_STATUS_DEFAULT, daecontext->trace_status); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Verbose != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,123456789); */ -/* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ -/* EXPECT_EQ((DltDaemonContext *) 0, daecontext); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = + * dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,123456789); */ + /* //printf("### CONTEXT: APID=%s\tCTID=%s\n", daecontext->apid,daecontext->ctid); */ + /* EXPECT_EQ((DltDaemonContext *) 0, daecontext); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_context_add, nullpointer) @@ -976,28 +950,28 @@ TEST(t_dlt_daemon_context_add, nullpointer) char desc[255] = "TEST dlt_daemon_context_add"; /* NULL-Pointer */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, NULL, NULL, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, NULL, ctid, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, NULL, ctid, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, apid, NULL, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, apid, NULL, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, apid, ctid, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(NULL, apid, ctid, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, NULL, NULL, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, NULL, NULL, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, NULL, ctid, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, NULL, ctid, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, apid, NULL, 0, 0, 0, 0, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, apid, NULL, 0, 0, 0, 0, desc, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_add(&daemon, apid, ctid, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, NULL, NULL, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, NULL, ctid, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, NULL, ctid, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, apid, NULL, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, apid, NULL, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, apid, ctid, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(NULL, apid, ctid, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, NULL, NULL, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, NULL, NULL, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, NULL, ctid, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, NULL, ctid, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, apid, NULL, 0, 0, 0, 0, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, apid, NULL, 0, 0, 0, 0, desc, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_add(&daemon, apid, ctid, 0, 0, 0, 0, NULL, NULL, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } /* End Method: dlt_daemon_common::dlt_daemon_context_add */ @@ -1012,30 +986,22 @@ TEST(t_dlt_daemon_context_del, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); @@ -1044,39 +1010,40 @@ TEST(t_dlt_daemon_context_del, normal) } TEST(t_dlt_daemon_context_del, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext; */ -/* DltDaemonApplication *app; */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext; */ + /* DltDaemonApplication *app; */ /* Context uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 0)); */ /* No application used */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 0)); */ -/* EXPECT_GE(-1, dlt_daemon_application_del(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ -/* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 0)); */ + /* EXPECT_GE(-1, dlt_daemon_application_del(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ + /* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ /* No contex added */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 0)); */ -/* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ -/* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 0)); */ + /* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ + /* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ /* Verbose != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 123456789)); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, 123456789)); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_context_del, nullpointer) { @@ -1093,7 +1060,6 @@ TEST(t_dlt_daemon_context_del, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_context_find */ TEST(t_dlt_daemon_context_find, normal) { @@ -1102,30 +1068,22 @@ TEST(t_dlt_daemon_context_find, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); EXPECT_STREQ(apid, daecontext->apid); EXPECT_STREQ(ctid, daecontext->ctid); EXPECT_STREQ(desc, daecontext->context_description); @@ -1144,35 +1102,27 @@ TEST(t_dlt_daemon_context_find, abnormal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Uninitialized */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, apid, ctid, ecu, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, apid, ctid, ecu, 0)); /* No apid */ char no_apid[1] = ""; app = dlt_daemon_application_add(&daemon, no_apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - no_apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, no_apid, ctid, ecu, 0)); + daecontext = + dlt_daemon_context_add(&daemon, no_apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, no_apid, ctid, ecu, 0)); EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_GE(-1, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); @@ -1181,46 +1131,30 @@ TEST(t_dlt_daemon_context_find, abnormal) /* No ctid */ char no_ctid[1] = ""; app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - no_ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, apid, no_ctid, ecu, 0)); + daecontext = + dlt_daemon_context_add(&daemon, apid, no_ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, apid, no_ctid, ecu, 0)); EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); /* No application added */ - daecontext = dlt_daemon_context_add(&daemon, - no_apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, no_apid, ctid, ecu, 0)); + daecontext = + dlt_daemon_context_add(&daemon, no_apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, no_apid, ctid, ecu, 0)); EXPECT_GE(-1, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); /* Verbose != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_EQ((DltDaemonContext *) 0 ,dlt_daemon_context_find(&daemon, apid, ctid, 123456789)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_EQ((DltDaemonContext *) 0 ,dlt_daemon_context_find(&daemon, apid, ctid, 123456789)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_context_find, nullpointer) @@ -1230,20 +1164,19 @@ TEST(t_dlt_daemon_context_find, nullpointer) ID4 ctid = "CON"; ID4 ecu = "ECU"; - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(NULL, NULL, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(NULL, NULL, ctid, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(NULL, apid, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(NULL, apid, ctid, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, NULL, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, NULL, ctid, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, apid, NULL, NULL, 0)); - EXPECT_EQ((DltDaemonContext *)0, dlt_daemon_context_find(&daemon, NULL, NULL, ecu, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(NULL, NULL, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(NULL, NULL, ctid, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(NULL, apid, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(NULL, apid, ctid, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, NULL, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, NULL, ctid, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, apid, NULL, NULL, 0)); + EXPECT_EQ((DltDaemonContext*)0, dlt_daemon_context_find(&daemon, NULL, NULL, ecu, 0)); } /* End Method: dlt_daemon_common::dlt_daemon_context_find */ - /* Begin Method: dlt_daemon_common::dlt_daemon_contexts_clear */ TEST(t_dlt_daemon_contexts_clear, normal) { @@ -1252,30 +1185,22 @@ TEST(t_dlt_daemon_contexts_clear, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, ecu, 0)); @@ -1284,25 +1209,26 @@ TEST(t_dlt_daemon_contexts_clear, normal) } TEST(t_dlt_daemon_contexts_clear, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext = NULL; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext = NULL; */ + /* DltDaemonApplication *app = NULL; */ /* No context added */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_clear(&daemon, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_clear(&daemon, 0)); */ /* Verbose != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 123456789)); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 123456789)); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_contexts_clear, nullpointer) { @@ -1313,7 +1239,6 @@ TEST(t_dlt_daemon_contexts_clear, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_contexts_invalidate_fd */ TEST(t_dlt_daemon_contexts_invalidate_fd, normal) { @@ -1322,30 +1247,22 @@ TEST(t_dlt_daemon_contexts_invalidate_fd, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); EXPECT_LE(0, dlt_daemon_contexts_invalidate_fd(&daemon, ecu, app->user_handle, 0)); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -1355,26 +1272,27 @@ TEST(t_dlt_daemon_contexts_invalidate_fd, normal) } TEST(t_dlt_daemon_contexts_invalidate_fd, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext = NULL; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext = NULL; */ + /* DltDaemonApplication *app = NULL; */ /* Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_invalidate_fd(&daemon, app->user_handle, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_invalidate_fd(&daemon, app->user_handle, 0)); */ /* Verbose != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_invalidate_fd(&daemon, app->user_handle, 123456789)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_invalidate_fd(&daemon, app->user_handle, 123456789)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_contexts_invalidate_fd, nullpointer) { @@ -1385,7 +1303,6 @@ TEST(t_dlt_daemon_contexts_invalidate_fd, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_contexts_save */ TEST(t_dlt_daemon_contexts_save, normal) { @@ -1394,31 +1311,23 @@ TEST(t_dlt_daemon_contexts_save, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; - const char *filename = "/tmp/dlt-runtime-context.cfg"; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; + const char* filename = "/tmp/dlt-runtime-context.cfg"; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); EXPECT_LE(0, dlt_daemon_contexts_save(&daemon, filename, 0)); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -1428,41 +1337,42 @@ TEST(t_dlt_daemon_contexts_save, normal) } TEST(t_dlt_daemon_contexts_save, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext = NULL; */ -/* DltDaemonApplication *app = NULL; */ -/* const char * filename = "/tmp/dlt-runtime-context.cfg"; */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext = NULL; */ + /* DltDaemonApplication *app = NULL; */ + /* const char * filename = "/tmp/dlt-runtime-context.cfg"; */ /* Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_save(&daemon, filename, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_save(&daemon, filename, 0)); */ /* Verbose != 1 or 0, expect error */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_save(&daemon, filename, 123456789)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_save(&daemon, filename, 123456789)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Wrong path filename */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_save(&daemon, (char *) "PATCH_NOT_EXISTS", 0)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_save(&daemon, (char *) "PATCH_NOT_EXISTS", 0)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_contexts_save, nullpointer) { DltDaemon daemon; - const char *filename = "/tmp/dlt-runtime-context.cfg"; + const char* filename = "/tmp/dlt-runtime-context.cfg"; /* NULL-Pointer */ EXPECT_GE(-1, dlt_daemon_contexts_save(NULL, NULL, 0)); @@ -1473,7 +1383,6 @@ TEST(t_dlt_daemon_contexts_save, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_contexts_load */ TEST(t_dlt_daemon_contexts_load, normal) { @@ -1482,31 +1391,23 @@ TEST(t_dlt_daemon_contexts_load, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; - const char *filename = "/tmp/dlt-runtime-context.cfg"; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; + const char* filename = "/tmp/dlt-runtime-context.cfg"; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 0, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); EXPECT_LE(0, dlt_daemon_contexts_load(&daemon, filename, 0)); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -1516,41 +1417,42 @@ TEST(t_dlt_daemon_contexts_load, normal) } TEST(t_dlt_daemon_contexts_load, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext = NULL; */ -/* DltDaemonApplication *app = NULL; */ -/* const char * filename = "/tmp/dlt-runtime-context.cfg"; */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext = NULL; */ + /* DltDaemonApplication *app = NULL; */ + /* const char * filename = "/tmp/dlt-runtime-context.cfg"; */ /* Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_load(&daemon, filename, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_load(&daemon, filename, 0)); */ /* Verbose != 1 or 0, expect error */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_load(&daemon, filename, 123456789)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_load(&daemon, filename, 123456789)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ /* Wrong path filename */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_contexts_load(&daemon, (char *) "PATCH_NOT_EXISTS", 0)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_contexts_load(&daemon, (char *) "PATCH_NOT_EXISTS", 0)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_contexts_load, nullpointer) { DltDaemon daemon; - const char *filename = "/tmp/dlt-runtime-context.cfg"; + const char* filename = "/tmp/dlt-runtime-context.cfg"; /* NULL-Pointer */ EXPECT_GE(-1, dlt_daemon_contexts_load(NULL, NULL, 0)); @@ -1561,15 +1463,12 @@ TEST(t_dlt_daemon_contexts_load, nullpointer) - - /*##############################################################################################################################*/ /*##############################################################################################################################*/ /*##############################################################################################################################*/ - /* Begin Method: dlt_daemon_common::dlt_daemon_user_send_all_log_state */ /* Can't test this Method, maybe a return value would be a better solution */ TEST(t_dlt_daemon_user_send_all_log_state, normal) @@ -1579,10 +1478,10 @@ TEST(t_dlt_daemon_user_send_all_log_state, normal) char ecu[] = "ECU1"; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); @@ -1590,7 +1489,8 @@ TEST(t_dlt_daemon_user_send_all_log_state, normal) EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_user_send_all_log_state, abnormal) -{} +{ +} TEST(t_dlt_daemon_user_send_all_log_state, nullpointer) { EXPECT_NO_FATAL_FAILURE(dlt_daemon_user_send_all_log_state(NULL, 0)); @@ -1599,7 +1499,6 @@ TEST(t_dlt_daemon_user_send_all_log_state, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_user_send_default_update */ /* Can't test this Method, maybe a return value would be a better solution */ TEST(t_dlt_daemon_user_send_default_update, normal) @@ -1609,10 +1508,10 @@ TEST(t_dlt_daemon_user_send_default_update, normal) char ecu[] = "ECU1"; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); @@ -1620,7 +1519,8 @@ TEST(t_dlt_daemon_user_send_default_update, normal) EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_user_send_default_update, abnormal) -{} +{ +} TEST(t_dlt_daemon_user_send_default_update, nullpointer) { EXPECT_NO_FATAL_FAILURE(dlt_daemon_user_send_default_update(NULL, 0)); @@ -1629,7 +1529,6 @@ TEST(t_dlt_daemon_user_send_default_update, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_user_send_log_level */ TEST(t_dlt_daemon_user_send_log_level, normal) { @@ -1638,30 +1537,22 @@ TEST(t_dlt_daemon_user_send_log_level, normal) ID4 apid = "TES"; ID4 ctid = "CON"; char desc[255] = "TEST dlt_daemon_context_add"; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 42; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, - apid, - ctid, - DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, - 0, - 1, - desc, - ecu, - 0); + daecontext = + dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 1, desc, ecu, 0); EXPECT_LE(0, dlt_daemon_user_send_log_level(&daemon, daecontext, 0)); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -1671,35 +1562,37 @@ TEST(t_dlt_daemon_user_send_log_level, normal) } TEST(t_dlt_daemon_user_send_log_level, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext = NULL; */ -/* DltDaemonApplication *app = NULL; */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext = NULL; */ + /* DltDaemonApplication *app = NULL; */ /* Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_user_send_log_level(&daemon, daecontext, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_user_send_log_level(&daemon, daecontext, 0)); */ /* File Handler <= 0 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,-1,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_user_send_log_level(&daemon, daecontext, 0)); */ -/* EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, 0)); */ -/* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ -/* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,-1,desc,0); + */ + /* EXPECT_GE(-1, dlt_daemon_user_send_log_level(&daemon, daecontext, 0)); */ + /* EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, 0)); */ + /* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ + /* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ /* Verbose != 0 or 1 */ -/* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,1,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_user_send_log_level(&daemon, daecontext, 123456789)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* app = dlt_daemon_application_add(&daemon, apid, 0, desc, 0); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,1,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_user_send_log_level(&daemon, daecontext, 123456789)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_user_send_log_level, nullpointer) { @@ -1715,85 +1608,88 @@ TEST(t_dlt_daemon_user_send_log_level, nullpointer) - /* Begin Method: dlt_daemon_common::dlt_daemon_user_send_log_state */ TEST(t_dlt_daemon_user_send_log_state, normal) { DltDaemon daemon; DltGateway gateway; -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext; */ -/* DltDaemonApplication *app; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext; */ + /* DltDaemonApplication *app; */ pid_t pid = 18166; char ecu[] = "ECU1"; char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE + 1]; snprintf(filename, DLT_DAEMON_COMMON_TEXTBUFSIZE, "%s/dlt%d", DLT_USER_DIR, pid); /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); -/* open(filename, O_RDWR |O_NONBLOCK); */ -/* dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); */ -/* app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); */ -/* //printf("### USERHANDLE=%i\n", app->user_handle); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(0, dlt_daemon_user_send_log_state(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, 0)); */ -/* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ -/* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ -/* EXPECT_LE(0, close(app->user_handle)); */ + /* open(filename, O_RDWR |O_NONBLOCK); */ + /* dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); */ + /* app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); */ + /* //printf("### USERHANDLE=%i\n", app->user_handle); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(0, dlt_daemon_user_send_log_state(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, 0)); */ + /* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ + /* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ + /* EXPECT_LE(0, close(app->user_handle)); */ EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } TEST(t_dlt_daemon_user_send_log_state, abnormal) { -/* DltDaemon daemon; */ -/* ID4 apid = "TES"; */ -/* ID4 ctid = "CON"; */ -/* char desc[255] = "TEST dlt_daemon_context_add"; */ -/* DltDaemonContext *daecontext = NULL; */ -/* DltDaemonApplication *app = NULL; */ -/* pid_t pid = 18166; */ -/* char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE+1]; */ -/* snprintf(filename,DLT_DAEMON_COMMON_TEXTBUFSIZE,"%s/dlt%d",DLT_USER_DIR,pid); */ + /* DltDaemon daemon; */ + /* ID4 apid = "TES"; */ + /* ID4 ctid = "CON"; */ + /* char desc[255] = "TEST dlt_daemon_context_add"; */ + /* DltDaemonContext *daecontext = NULL; */ + /* DltDaemonApplication *app = NULL; */ + /* pid_t pid = 18166; */ + /* char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE+1]; */ + /* snprintf(filename,DLT_DAEMON_COMMON_TEXTBUFSIZE,"%s/dlt%d",DLT_USER_DIR,pid); */ /*Uninitialized */ -/* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ -/* EXPECT_GE(-1, dlt_daemon_user_send_log_state(&daemon, app, 0)); */ + /* EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); */ + /* EXPECT_GE(-1, dlt_daemon_user_send_log_state(&daemon, app, 0)); */ /* No Pipe open */ /*open(filename, O_RDWR |O_NONBLOCK); */ -/* dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); */ -/* app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); */ + /* dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); */ + /* app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); */ /*printf("### USERHANDLE=%i\n", app->user_handle); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_user_send_log_state(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, 0)); */ -/* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ -/* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ -/* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ -/* EXPECT_LE(0, close(app->user_handle)); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_user_send_log_state(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, 0)); */ + /* EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, 0)); */ + /* EXPECT_LE(0, dlt_daemon_contexts_clear(&daemon, 0)); */ + /* EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, 0)); */ + /* EXPECT_LE(0, close(app->user_handle)); */ /* Verbose != 1 or 0 */ -/* open(filename, O_RDWR |O_NONBLOCK); */ -/* dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); */ -/* app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); */ -/* //printf("### USERHANDLE=%i\n", app->user_handle); */ -/* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ -/* EXPECT_GE(-1, dlt_daemon_user_send_log_state(&daemon, app, 123456789)); */ -/* dlt_daemon_context_del(&daemon, daecontext, 0); */ -/* dlt_daemon_application_del(&daemon, app, 0); */ -/* dlt_daemon_contexts_clear(&daemon, 0); */ -/* dlt_daemon_applications_clear(&daemon, 0); */ -/* close(app->user_handle); */ -/* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ + /* open(filename, O_RDWR |O_NONBLOCK); */ + /* dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, + * DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); */ + /* app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); */ + /* //printf("### USERHANDLE=%i\n", app->user_handle); */ + /* daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,0); */ + /* EXPECT_GE(-1, dlt_daemon_user_send_log_state(&daemon, app, 123456789)); */ + /* dlt_daemon_context_del(&daemon, daecontext, 0); */ + /* dlt_daemon_application_del(&daemon, app, 0); */ + /* dlt_daemon_contexts_clear(&daemon, 0); */ + /* dlt_daemon_applications_clear(&daemon, 0); */ + /* close(app->user_handle); */ + /* EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); */ } TEST(t_dlt_daemon_user_send_log_state, nullpointer) { @@ -1811,36 +1707,35 @@ TEST(t_dlt_daemon_user_send_log_state, nullpointer) TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, nullpointer) { int num_settings; - DltTraceLoadSettings *settings = NULL; + DltTraceLoadSettings* settings = NULL; DltDaemon daemon; - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - NULL, "APP1", "CTID", &settings, &num_settings, 0), - DLT_RETURN_WRONG_PARAMETER); - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - &daemon, NULL, "CTID", &settings, &num_settings, 0), - DLT_RETURN_WRONG_PARAMETER); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(NULL, "APP1", "CTID", &settings, &num_settings, 0), + DLT_RETURN_WRONG_PARAMETER); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(&daemon, NULL, "CTID", &settings, &num_settings, 0), + DLT_RETURN_WRONG_PARAMETER); } TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, empty_trace_settings) { int num_settings; - DltTraceLoadSettings *settings = NULL; + DltTraceLoadSettings* settings = NULL; DltDaemon daemon; daemon.preconfigured_trace_load_settings = NULL; - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - &daemon, "APP1", NULL, &settings, &num_settings, 0), - DLT_RETURN_OK); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(&daemon, "APP1", NULL, &settings, &num_settings, 0), + DLT_RETURN_OK); // test wrong trace load settings count - daemon.preconfigured_trace_load_settings = (DltTraceLoadSettings *)malloc( - sizeof(DltTraceLoadSettings)); + daemon.preconfigured_trace_load_settings = (DltTraceLoadSettings*)malloc(sizeof(DltTraceLoadSettings)); daemon.preconfigured_trace_load_settings_count = 0; - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - &daemon, "APP1", "CTID", &settings, &num_settings, 0), - DLT_RETURN_OK); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(&daemon, "APP1", "CTID", &settings, &num_settings, 0), + DLT_RETURN_OK); free(daemon.preconfigured_trace_load_settings); } @@ -1848,34 +1743,33 @@ TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, empty_trace_settings) TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, app_id_not_found) { int num_settings = 42; - DltTraceLoadSettings *settings = (DltTraceLoadSettings *)42; + DltTraceLoadSettings* settings = (DltTraceLoadSettings*)42; DltDaemon daemon; // test wrong trace load settings count - daemon.preconfigured_trace_load_settings = (DltTraceLoadSettings *)malloc( - sizeof(DltTraceLoadSettings)); - memset(daemon.preconfigured_trace_load_settings, 0, - sizeof(DltTraceLoadSettings)); + daemon.preconfigured_trace_load_settings = (DltTraceLoadSettings*)malloc(sizeof(DltTraceLoadSettings)); + memset(daemon.preconfigured_trace_load_settings, 0, sizeof(DltTraceLoadSettings)); strncpy(daemon.preconfigured_trace_load_settings[0].apid, "APP2", DLT_ID_SIZE); daemon.preconfigured_trace_load_settings_count = 1; - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - &daemon, "APP1", NULL, &settings, &num_settings, 0), - DLT_RETURN_OK); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(&daemon, "APP1", NULL, &settings, &num_settings, 0), + DLT_RETURN_OK); EXPECT_EQ(num_settings, 0); EXPECT_TRUE(settings == NULL); free(daemon.preconfigured_trace_load_settings); } -static void setup_trace_load_settings(DltDaemon &daemon) +static void setup_trace_load_settings(DltDaemon& daemon) { daemon.preconfigured_trace_load_settings_count = 7; - daemon.preconfigured_trace_load_settings = (DltTraceLoadSettings *)malloc( + daemon.preconfigured_trace_load_settings = + (DltTraceLoadSettings*)malloc(daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); + memset( + daemon.preconfigured_trace_load_settings, 0, daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); - memset(daemon.preconfigured_trace_load_settings, 0, - daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); strncpy(daemon.preconfigured_trace_load_settings[0].apid, "APP2", DLT_ID_SIZE); strncpy(daemon.preconfigured_trace_load_settings[0].ctid, "CTID", DLT_ID_SIZE); @@ -1909,25 +1803,24 @@ static void setup_trace_load_settings(DltDaemon &daemon) daemon.preconfigured_trace_load_settings[6].soft_limit = 555; daemon.preconfigured_trace_load_settings[6].hard_limit = 666; - qsort(daemon.preconfigured_trace_load_settings, daemon.preconfigured_trace_load_settings_count, - sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); + qsort( + daemon.preconfigured_trace_load_settings, daemon.preconfigured_trace_load_settings_count, + sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); } TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, search_with_context) { int num_settings = 42; - DltTraceLoadSettings *settings = NULL; + DltTraceLoadSettings* settings = NULL; DltDaemon daemon; setup_trace_load_settings(daemon); - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - &daemon, "APP1", "CTID", &settings, &num_settings, 0), - DLT_RETURN_OK); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(&daemon, "APP1", "CTID", &settings, &num_settings, 0), + DLT_RETURN_OK); EXPECT_EQ(num_settings, 1); - EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[3], - sizeof(DltTraceLoadSettings)), - 0); + EXPECT_EQ(memcmp(settings, &daemon.preconfigured_trace_load_settings[3], sizeof(DltTraceLoadSettings)), 0); free(settings); free(daemon.preconfigured_trace_load_settings); @@ -1936,19 +1829,17 @@ TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, search_with_context) TEST(t_dlt_daemon_find_preconfigured_trace_load_settings, search_with_app_id) { int num_settings = 42; - DltTraceLoadSettings *settings = NULL; + DltTraceLoadSettings* settings = NULL; DltDaemon daemon; setup_trace_load_settings(daemon); - EXPECT_EQ(dlt_daemon_find_preconfigured_trace_load_settings( - &daemon, "APP1", NULL, &settings, &num_settings, 0), - DLT_RETURN_OK); + EXPECT_EQ( + dlt_daemon_find_preconfigured_trace_load_settings(&daemon, "APP1", NULL, &settings, &num_settings, 0), + DLT_RETURN_OK); EXPECT_EQ(num_settings, 4); for (int i = 0; i < num_settings; i++) { - EXPECT_EQ(memcmp(&settings[i], - &daemon.preconfigured_trace_load_settings[i], - sizeof(DltTraceLoadSettings)),0); + EXPECT_EQ(memcmp(&settings[i], &daemon.preconfigured_trace_load_settings[i], sizeof(DltTraceLoadSettings)), 0); } free(settings); @@ -1959,39 +1850,33 @@ TEST(t_dlt_daemon_application_add, trace_load_settings_not_found) { DltDaemon daemon; DltGateway gateway; - const char *apid_const = "TEST"; + const char* apid_const = "TEST"; pid_t pid = 0; - const char *desc_const = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc_const = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 15; - EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_EQ(DLT_RETURN_OK, - strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid[DLT_ID_SIZE+1] = {0}; + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); + char apid[DLT_ID_SIZE + 1] = {0}; char desc[32] = {0}; strncpy(apid, apid_const, DLT_ID_SIZE); apid[DLT_ID_SIZE] = '\0'; - strncpy(desc, desc_const, sizeof(desc)-1); - desc[sizeof(desc)-1] = '\0'; - app = dlt_daemon_application_add(&daemon, apid, pid, desc, - fd, ecu, 0); + strncpy(desc, desc_const, sizeof(desc) - 1); + desc[sizeof(desc) - 1] = '\0'; + app = dlt_daemon_application_add(&daemon, apid, pid, desc, fd, ecu, 0); EXPECT_FALSE(app->trace_load_settings == NULL); EXPECT_EQ(app->trace_load_settings_count, 1); - EXPECT_EQ(app->trace_load_settings[0].soft_limit, - DLT_TRACE_LOAD_DAEMON_SOFT_LIMIT_DEFAULT); - EXPECT_EQ(app->trace_load_settings[0].hard_limit, - DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT); + EXPECT_EQ(app->trace_load_settings[0].soft_limit, DLT_TRACE_LOAD_DAEMON_SOFT_LIMIT_DEFAULT); + EXPECT_EQ(app->trace_load_settings[0].hard_limit, DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT); EXPECT_STREQ(app->trace_load_settings[0].apid, apid); - EXPECT_TRUE(app->trace_load_settings[0].ctid == NULL || - strlen(app->trace_load_settings[0].ctid) == 0); + EXPECT_TRUE(app->trace_load_settings[0].ctid == NULL || strlen(app->trace_load_settings[0].ctid) == 0); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); @@ -2005,41 +1890,40 @@ TEST(t_dlt_daemon_application_add, trace_load_settings_configured) { DltDaemon daemon; DltGateway gateway; - const char *apid_const = "APP1"; + const char* apid_const = "APP1"; pid_t pid = 0; - const char *desc_const = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc_const = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 15; - EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); // must be done after daemon init, else data is overwritten setup_trace_load_settings(daemon); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_EQ(DLT_RETURN_OK, - strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid[DLT_ID_SIZE+1] = {0}; + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); + char apid[DLT_ID_SIZE + 1] = {0}; char desc[32] = {0}; strncpy(apid, apid_const, DLT_ID_SIZE); apid[DLT_ID_SIZE] = '\0'; - strncpy(desc, desc_const, sizeof(desc)-1); - desc[sizeof(desc)-1] = '\0'; - app = dlt_daemon_application_add(&daemon, apid, pid, desc, - fd, ecu, 0); + strncpy(desc, desc_const, sizeof(desc) - 1); + desc[sizeof(desc) - 1] = '\0'; + app = dlt_daemon_application_add(&daemon, apid, pid, desc, fd, ecu, 0); EXPECT_FALSE(app->trace_load_settings == NULL); EXPECT_EQ(app->trace_load_settings_count, 4); for (uint32_t i = 0; i < app->trace_load_settings_count; i++) { - EXPECT_EQ(memcmp(&app->trace_load_settings[i], - &daemon.preconfigured_trace_load_settings[i], - sizeof(DltTraceLoadSettings)), 0); + EXPECT_EQ( + memcmp( + &app->trace_load_settings[i], &daemon.preconfigured_trace_load_settings[i], + sizeof(DltTraceLoadSettings)), + 0); } EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -2054,31 +1938,28 @@ TEST(t_dlt_daemon_user_send_trace_load_config, normal) { DltDaemon daemon; DltGateway gateway; - const char *apid_const = "APP1"; + const char* apid_const = "APP1"; pid_t pid = 0; - const char *desc_const = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + const char* desc_const = "HELLO_TEST"; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; int fd = 15; - EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_EQ(DLT_RETURN_OK, - strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); - char apid[DLT_ID_SIZE+1] = {0}; + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); + char apid[DLT_ID_SIZE + 1] = {0}; char desc[32] = {0}; strncpy(apid, apid_const, DLT_ID_SIZE); apid[DLT_ID_SIZE] = '\0'; - strncpy(desc, desc_const, sizeof(desc)-1); - desc[sizeof(desc)-1] = '\0'; - app = dlt_daemon_application_add(&daemon, apid, pid, desc, - fd, ecu, 0); + strncpy(desc, desc_const, sizeof(desc) - 1); + desc[sizeof(desc) - 1] = '\0'; + app = dlt_daemon_application_add(&daemon, apid, pid, desc, fd, ecu, 0); dlt_daemon_user_send_trace_load_config(&daemon, app, 0); dlt_daemon_application_del(&daemon, app, ecu, 0); @@ -2086,10 +1967,9 @@ TEST(t_dlt_daemon_user_send_trace_load_config, normal) strncpy(apid, apid_const, DLT_ID_SIZE); apid[DLT_ID_SIZE] = '\0'; - strncpy(desc, desc_const, sizeof(desc)-1); - desc[sizeof(desc)-1] = '\0'; - app = dlt_daemon_application_add(&daemon, apid, pid, desc, - fd, ecu, 0); + strncpy(desc, desc_const, sizeof(desc) - 1); + desc[sizeof(desc) - 1] = '\0'; + app = dlt_daemon_application_add(&daemon, apid, pid, desc, fd, ecu, 0); dlt_daemon_user_send_trace_load_config(&daemon, app, 0); dlt_daemon_application_del(&daemon, app, ecu, 0); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); @@ -2103,8 +1983,7 @@ TEST(t_dlt_daemon_user_send_trace_load_config, normal) - -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_daemon_common_v2.cpp b/tests/gtest_dlt_daemon_common_v2.cpp index bfc7a13a9..08e80209d 100644 --- a/tests/gtest_dlt_daemon_common_v2.cpp +++ b/tests/gtest_dlt_daemon_common_v2.cpp @@ -73,12 +73,12 @@ extern "C" { } #ifndef DLT_USER_DIR -# define DLT_USER_DIR "/tmp/dltpipes" +#define DLT_USER_DIR "/tmp/dltpipes" #endif /* Name of named pipe to DLT daemon */ #ifndef DLT_USER_FIFO -# define DLT_USER_FIFO "/tmp/dlt" +#define DLT_USER_FIFO "/tmp/dlt" #endif @@ -87,16 +87,14 @@ TEST(t_dlt_daemon_find_users_list_v2, normal_one_list) { DltDaemon daemon; DltGateway gateway; - DltDaemonRegisteredUsers *user_list; + DltDaemonRegisteredUsers* user_list; char ecu[] = "ECU1"; uint8_t eculen = (uint8_t)strlen(ecu); - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id_v2(daemon.ecuid2, ecu, eculen); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); @@ -126,16 +124,16 @@ TEST(t_dlt_daemon_application_add_v2, normal) uint8_t apidlen = (uint8_t)strlen(apid); pid_t pid = 0; char desc[] = "HELLO_TEST"; - DltDaemonApplication *app = NULL; + DltDaemonApplication* app = NULL; char ecu[] = "ECU1"; uint8_t eculen = (uint8_t)strlen(ecu); int fd = 15; /* Normal Use-Case */ - EXPECT_EQ(0, - dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); daemon.ecuid2len = eculen; memset(daemon.ecuid2, 0, sizeof(daemon.ecuid2)); dlt_set_id_v2(daemon.ecuid2, ecu, eculen); @@ -143,7 +141,8 @@ TEST(t_dlt_daemon_application_add_v2, normal) EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid2, daemon.user_list[0].ecuid2, eculen)); app = dlt_daemon_application_add_v2(&daemon, apidlen, apid, pid, desc, fd, eculen, ecu, 0); - // printf("### APP: APID=%s DESCR=%s NUMCONTEXT=%i PID=%i USERHANDLE=%i\n", app->apid2,app->application_description, app->num_contexts, app->pid, app->user_handle); + // printf("### APP: APID=%s DESCR=%s NUMCONTEXT=%i PID=%i USERHANDLE=%i\n", + // app->apid2,app->application_description, app->num_contexts, app->pid, app->user_handle); EXPECT_STREQ(apid, app->apid2); EXPECT_STREQ(desc, app->application_description); EXPECT_EQ(pid, app->pid); @@ -159,7 +158,7 @@ TEST(t_dlt_daemon_application_add_v2, normal) /*##############################################################################################################################*/ -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_daemon_event_handler.cpp b/tests/gtest_dlt_daemon_event_handler.cpp index 8e7f22d8c..bfff24b90 100644 --- a/tests/gtest_dlt_daemon_event_handler.cpp +++ b/tests/gtest_dlt_daemon_event_handler.cpp @@ -57,14 +57,13 @@ int connectServer(void); -extern "C" -{ - #include "dlt_daemon_event_handler.h" - #include "dlt_daemon_connection.h" - #include - #include - #include - #include +extern "C" { +#include "dlt_daemon_event_handler.h" +#include "dlt_daemon_connection.h" +#include +#include +#include +#include } /* Begin Method: dlt_daemon_event_handler::t_dlt_daemon_prepare_event_handling*/ @@ -88,9 +87,7 @@ TEST(t_dlt_daemon_handle_event, normal) DltDaemon daemon; EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&daemon_local.pEvent)); - EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_handle_event(&daemon_local.pEvent, - &daemon, - &daemon_local)); + EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_handle_event(&daemon_local.pEvent, &daemon, &daemon_local)); } TEST(t_dlt_daemon_handle_event, nullpointer) @@ -104,7 +101,7 @@ TEST(t_dlt_event_handler_find_connection, normal) int fd = 10; DltEventHandler ev = {}; DltConnection connections = {}; - DltConnection *ret = nullptr; + DltConnection* ret = nullptr; DltReceiver receiver = {}; receiver.fd = fd; @@ -120,16 +117,16 @@ TEST(t_dlt_event_handler_find_connection, normal) TEST(t_dlt_daemon_add_connection, normal) { DltEventHandler ev1 = {}; - DltConnection *head = nullptr; - DltConnection *connections1 = nullptr; + DltConnection* head = nullptr; + DltConnection* connections1 = nullptr; DltReceiver receiver = {}; - ev1.connections = (DltConnection *)malloc(sizeof(DltConnection)); - head = (DltConnection *)ev1.connections; + ev1.connections = (DltConnection*)malloc(sizeof(DltConnection)); + head = (DltConnection*)ev1.connections; ev1.connections->next = 0; ev1.connections->type = DLT_CONNECTION_CLIENT_MSG_SERIAL; - connections1 = (DltConnection *)malloc(sizeof(DltConnection)); + connections1 = (DltConnection*)malloc(sizeof(DltConnection)); connections1->next = 0; connections1->type = DLT_CONNECTION_GATEWAY; connections1->receiver = &receiver; @@ -137,7 +134,7 @@ TEST(t_dlt_daemon_add_connection, normal) EXPECT_EQ(DLT_CONNECTION_CLIENT_MSG_SERIAL, ev1.connections->type); dlt_daemon_add_connection(&ev1, connections1); - head = (DltConnection *)ev1.connections->next; + head = (DltConnection*)ev1.connections->next; EXPECT_EQ(DLT_CONNECTION_GATEWAY, head->type); @@ -150,18 +147,18 @@ TEST(t_dlt_daemon_add_connection, normal) TEST(t_dlt_daemon_remove_connection, normal) { DltEventHandler ev1; - DltConnection *head = nullptr; - DltConnection *connections1 = nullptr; + DltConnection* head = nullptr; + DltConnection* connections1 = nullptr; memset(&ev1, 0, sizeof(DltEventHandler)); - ev1.connections = (DltConnection *)malloc(sizeof(DltConnection)); - head = (DltConnection *)ev1.connections; + ev1.connections = (DltConnection*)malloc(sizeof(DltConnection)); + head = (DltConnection*)ev1.connections; memset(ev1.connections, 0, sizeof(DltConnection)); ev1.connections->next = 0; ev1.connections->type = DLT_CONNECTION_CLIENT_MSG_SERIAL; - connections1 = (DltConnection *)malloc(sizeof(DltConnection)); + connections1 = (DltConnection*)malloc(sizeof(DltConnection)); memset(connections1, 0, sizeof(DltConnection)); connections1->next = 0; connections1->type = DLT_CONNECTION_GATEWAY; @@ -171,7 +168,7 @@ TEST(t_dlt_daemon_remove_connection, normal) EXPECT_EQ(DLT_CONNECTION_CLIENT_MSG_SERIAL, ev1.connections->type); dlt_daemon_add_connection(&ev1, connections1); - head = (DltConnection *)ev1.connections->next; + head = (DltConnection*)ev1.connections->next; EXPECT_EQ(DLT_CONNECTION_GATEWAY, head->type); @@ -187,7 +184,7 @@ TEST(t_dlt_event_handler_cleanup_connections, normal) memset(&ev1, 0, sizeof(DltEventHandler)); memset(&receiver1, 0, sizeof(DltReceiver)); - ev1.connections = (DltConnection *)malloc(sizeof(DltConnection)); + ev1.connections = (DltConnection*)malloc(sizeof(DltConnection)); memset(ev1.connections, 0, sizeof(DltConnection)); ev1.connections->next = 0; ev1.connections->type = DLT_CONNECTION_GATEWAY; @@ -236,7 +233,7 @@ TEST(t_dlt_event_handler_register_connection, normal) DltDaemonLocal daemon_local; int mask = 0; DltEventHandler ev1; - DltConnection *connections1 = nullptr; + DltConnection* connections1 = nullptr; DltReceiver receiver; memset(&daemon_local, 0, sizeof(DltDaemonLocal)); @@ -245,17 +242,14 @@ TEST(t_dlt_event_handler_register_connection, normal) EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&ev1)); - connections1 = (DltConnection *)malloc(sizeof(DltConnection)); + connections1 = (DltConnection*)malloc(sizeof(DltConnection)); memset(connections1, 0, sizeof(DltConnection)); connections1->next = 0; connections1->type = DLT_CONNECTION_GATEWAY; connections1->receiver = &receiver; - ret = dlt_event_handler_register_connection(&ev1, - &daemon_local, - connections1, - mask); + ret = dlt_event_handler_register_connection(&ev1, &daemon_local, connections1, mask); EXPECT_EQ(DLT_RETURN_OK, ret); EXPECT_EQ(DLT_CONNECTION_GATEWAY, ev1.connections->type); @@ -276,7 +270,7 @@ TEST(t_dlt_event_handler_unregister_connection, normal) DltDaemonLocal daemon_local; int mask = 0; DltEventHandler ev1; - DltConnection *connections1 = nullptr; + DltConnection* connections1 = nullptr; DltReceiver receiver; memset(&daemon_local, 0, sizeof(DltDaemonLocal)); @@ -285,7 +279,7 @@ TEST(t_dlt_event_handler_unregister_connection, normal) EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&ev1)); - connections1 = (DltConnection *)malloc(sizeof(DltConnection)); + connections1 = (DltConnection*)malloc(sizeof(DltConnection)); memset(connections1, 0, sizeof(DltConnection)); connections1->next = 0; @@ -293,10 +287,7 @@ TEST(t_dlt_event_handler_unregister_connection, normal) connections1->receiver = &receiver; receiver.fd = 100; - ret = dlt_event_handler_register_connection(&ev1, - &daemon_local, - connections1, - mask); + ret = dlt_event_handler_register_connection(&ev1, &daemon_local, connections1, mask); EXPECT_EQ(DLT_RETURN_OK, ret); EXPECT_EQ(DLT_CONNECTION_GATEWAY, ev1.connections->type); @@ -315,19 +306,12 @@ TEST(t_dlt_connection_create, normal) memset(&daemon_local, 0, sizeof(DltDaemonLocal)); - EXPECT_EQ(DLT_RETURN_OK, - dlt_daemon_prepare_event_handling(&daemon_local.pEvent)); + EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&daemon_local.pEvent)); - ret = dlt_connection_create(&daemon_local, - &daemon_local.pEvent, - fd, - POLLIN, - DLT_CONNECTION_CLIENT_MSG_SERIAL); + ret = dlt_connection_create(&daemon_local, &daemon_local.pEvent, fd, POLLIN, DLT_CONNECTION_CLIENT_MSG_SERIAL); EXPECT_EQ(DLT_RETURN_OK, ret); - dlt_event_handler_unregister_connection(&daemon_local.pEvent, - &daemon_local, - fd); + dlt_event_handler_unregister_connection(&daemon_local.pEvent, &daemon_local, fd); free(daemon_local.pEvent.pfd); } @@ -335,13 +319,13 @@ TEST(t_dlt_connection_create, normal) /* Begin Method: dlt_daemon_connections::dlt_connection_destroy*/ TEST(t_dlt_connection_destroy, normal) { - DltConnection *to_destroy = (DltConnection *)malloc(sizeof(DltConnection)); + DltConnection* to_destroy = (DltConnection*)malloc(sizeof(DltConnection)); memset(to_destroy, 0, sizeof(DltConnection)); to_destroy->next = 0; to_destroy->type = DLT_CONNECTION_CLIENT_MSG_SERIAL; - to_destroy->receiver = (DltReceiver *)malloc(sizeof(DltReceiver)); + to_destroy->receiver = (DltReceiver*)malloc(sizeof(DltReceiver)); memset(to_destroy->receiver, 0, sizeof(DltReceiver)); to_destroy->receiver->fd = -1; @@ -357,7 +341,7 @@ TEST(t_dlt_connection_destroy_receiver, normal) memset(&to_destroy, 0, sizeof(DltConnection)); - to_destroy.receiver = (DltReceiver *)malloc(sizeof(DltReceiver)); + to_destroy.receiver = (DltReceiver*)malloc(sizeof(DltReceiver)); memset(to_destroy.receiver, 0, sizeof(DltReceiver)); to_destroy.receiver->fd = -1; @@ -370,14 +354,12 @@ TEST(t_dlt_connection_destroy_receiver, normal) TEST(t_dlt_connection_get_receiver, normal) { int fd = 10; - DltReceiver *ret; + DltReceiver* ret; DltDaemonLocal daemon_local; memset(&daemon_local, 0, sizeof(DltDaemonLocal)); - ret = dlt_connection_get_receiver(&daemon_local, - DLT_CONNECTION_CLIENT_MSG_TCP, - fd); + ret = dlt_connection_get_receiver(&daemon_local, DLT_CONNECTION_CLIENT_MSG_TCP, fd); ASSERT_NE(ret, nullptr); EXPECT_EQ(fd, ret->fd); @@ -386,9 +368,8 @@ TEST(t_dlt_connection_get_receiver, normal) /* Begin Method: dlt_daemon_connections::(t_dlt_connection_get_next*/ TEST(t_dlt_connection_get_next, normal) { - int type_mask = - (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL); - DltConnection *ret = nullptr; + int type_mask = (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL); + DltConnection* ret = nullptr; DltConnection node; DltConnection current; @@ -408,9 +389,8 @@ TEST(t_dlt_connection_get_next, normal) /* Begin Method: dlt_daemon_connections::(t_dlt_connection_get_next*/ TEST(t_dlt_connection_get_next, abnormal) { - int type_mask = - (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL); - DltConnection *ret; + int type_mask = (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL); + DltConnection* ret; DltConnection node; DltConnection current; @@ -433,7 +413,7 @@ TEST(t_dlt_connection_send, normal_1) int ret = 0; DltConnection conn; DltReceiver receiver; - void *data1 = nullptr; + void* data1 = nullptr; int size1 = 0; DltDaemonLocal daemon_local; @@ -446,12 +426,12 @@ TEST(t_dlt_connection_send, normal_1) conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_TCP; - daemon_local.msg.databuffer = (uint8_t *)malloc(sizeof(uint8_t)); + daemon_local.msg.databuffer = (uint8_t*)malloc(sizeof(uint8_t)); if (daemon_local.msg.databuffer == NULL) close(receiver.fd); - EXPECT_NE((uint8_t *)NULL, daemon_local.msg.databuffer); + EXPECT_NE((uint8_t*)NULL, daemon_local.msg.databuffer); memset(daemon_local.msg.databuffer, 1, sizeof(uint8_t)); daemon_local.msg.datasize = sizeof(uint8_t); @@ -480,9 +460,8 @@ TEST(t_dlt_connection_send, normal_2) conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_SERIAL; - ret = dlt_connection_send(&conn, - const_cast(static_cast(dltSerialHeader)), - sizeof(dltSerialHeader)); + ret = dlt_connection_send( + &conn, const_cast(static_cast(dltSerialHeader)), sizeof(dltSerialHeader)); EXPECT_EQ(DLT_RETURN_OK, ret); } @@ -500,9 +479,8 @@ TEST(t_dlt_connection_send, abnormal) conn.receiver = &receiver; conn.type = DLT_CONNECTION_TYPE_MAX; - ret = dlt_connection_send(&conn, - const_cast(static_cast(dltSerialHeader)), - sizeof(dltSerialHeader)); + ret = dlt_connection_send( + &conn, const_cast(static_cast(dltSerialHeader)), sizeof(dltSerialHeader)); EXPECT_EQ(DLT_RETURN_ERROR, ret); } @@ -510,8 +488,8 @@ TEST(t_dlt_connection_send, abnormal) TEST(t_dlt_connection_send_multiple, normal_1) { int ret = 0; - void *data1 = nullptr; - void *data2 = nullptr; + void* data1 = nullptr; + void* data2 = nullptr; int size1 = 0; int size2 = 0; DltConnection conn = {}; @@ -529,22 +507,20 @@ TEST(t_dlt_connection_send_multiple, normal_1) conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_TCP; - daemon_local.msg.headersize = sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - sizeof(DltStandardHeaderExtra) + - sizeof(DltExtendedHeader); + daemon_local.msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra) + + sizeof(DltExtendedHeader); memset(daemon_local.msg.headerbuffer, 0, daemon_local.msg.headersize); data1 = daemon_local.msg.headerbuffer + sizeof(DltStorageHeader); size1 = static_cast(daemon_local.msg.headersize - sizeof(DltStorageHeader)); - daemon_local.msg.databuffer = (uint8_t *)malloc(sizeof(uint8_t)); + daemon_local.msg.databuffer = (uint8_t*)malloc(sizeof(uint8_t)); if (daemon_local.msg.databuffer == NULL) close(receiver.fd); - EXPECT_NE((uint8_t *)NULL, daemon_local.msg.databuffer); + EXPECT_NE((uint8_t*)NULL, daemon_local.msg.databuffer); memset(daemon_local.msg.databuffer, 0, sizeof(uint8_t)); daemon_local.msg.datasize = sizeof(uint8_t); @@ -552,12 +528,7 @@ TEST(t_dlt_connection_send_multiple, normal_1) data2 = daemon_local.msg.databuffer; size2 = daemon_local.msg.datasize; - ret = dlt_connection_send_multiple(&conn, - data1, - size1, - data2, - size2, - 1); + ret = dlt_connection_send_multiple(&conn, data1, size1, data2, size2, 1); EXPECT_EQ(DLT_RETURN_OK, ret); @@ -568,8 +539,8 @@ TEST(t_dlt_connection_send_multiple, normal_1) TEST(t_dlt_connection_send_multiple, normal_2) { int ret = 0; - void *data1 = nullptr; - void *data2 = nullptr; + void* data1 = nullptr; + void* data2 = nullptr; int size1 = 0; int size2 = 0; DltConnection conn = {}; @@ -587,22 +558,20 @@ TEST(t_dlt_connection_send_multiple, normal_2) conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_TCP; - daemon_local.msg.headersize = sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - sizeof(DltStandardHeaderExtra) + - sizeof(DltExtendedHeader); + daemon_local.msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra) + + sizeof(DltExtendedHeader); memset(daemon_local.msg.headerbuffer, 0, daemon_local.msg.headersize); data1 = daemon_local.msg.headerbuffer + sizeof(DltStorageHeader); size1 = static_cast(daemon_local.msg.headersize - sizeof(DltStorageHeader)); - daemon_local.msg.databuffer = (uint8_t *)malloc(sizeof(uint8_t)); + daemon_local.msg.databuffer = (uint8_t*)malloc(sizeof(uint8_t)); if (daemon_local.msg.databuffer == NULL) close(receiver.fd); - EXPECT_NE((uint8_t *)NULL, daemon_local.msg.databuffer); + EXPECT_NE((uint8_t*)NULL, daemon_local.msg.databuffer); memset(daemon_local.msg.databuffer, 0, sizeof(uint8_t)); daemon_local.msg.datasize = sizeof(uint8_t); @@ -610,12 +579,7 @@ TEST(t_dlt_connection_send_multiple, normal_2) data2 = daemon_local.msg.databuffer; size2 = daemon_local.msg.datasize; - ret = dlt_connection_send_multiple(&conn, - data1, - size1, - data2, - size2, - 0); + ret = dlt_connection_send_multiple(&conn, data1, size1, data2, size2, 0); EXPECT_EQ(DLT_RETURN_OK, ret); @@ -626,8 +590,8 @@ TEST(t_dlt_connection_send_multiple, normal_2) TEST(t_dlt_connection_send_multiple, nullpointer) { int ret = 0; - void *data1 = nullptr; - void *data2 = nullptr; + void* data1 = nullptr; + void* data2 = nullptr; int size1 = 0; int size2 = 0; DltDaemonLocal daemon_local = {}; @@ -637,12 +601,7 @@ TEST(t_dlt_connection_send_multiple, nullpointer) data2 = daemon_local.msg.databuffer; size2 = daemon_local.msg.datasize; - ret = dlt_connection_send_multiple(NULL, - data1, - size1, - data2, - size2, - 0); + ret = dlt_connection_send_multiple(NULL, data1, size1, data2, size2, 0); EXPECT_EQ(DLT_RETURN_ERROR, ret); } @@ -651,22 +610,18 @@ int connectServer(void) { int sockfd = 0, portno = 0; struct sockaddr_in serv_addr; - struct hostent *server = nullptr; + struct hostent* server = nullptr; portno = 8080; sockfd = socket(AF_INET, SOCK_STREAM, 0); server = gethostbyname("127.0.0.1"); - memset((char *)&serv_addr, 0, sizeof(serv_addr)); + memset((char*)&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - memcpy((char *)&serv_addr.sin_addr.s_addr, - (char *)server->h_addr, - server->h_length); + memcpy((char*)&serv_addr.sin_addr.s_addr, (char*)server->h_addr, server->h_length); serv_addr.sin_port = htons(static_cast(portno)); - if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { - printf("Error: %s (%d) occured in connect socket\n", - strerror(errno), - errno); + if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { + printf("Error: %s (%d) occured in connect socket\n", strerror(errno), errno); close(sockfd); return -1; } @@ -676,7 +631,7 @@ int connectServer(void) #define GTEST_SOCKS_ACCEPTED 3 -int main(int argc, char **argv) +int main(int argc, char** argv) { pid_t cpid = fork(); @@ -699,25 +654,21 @@ int main(int argc, char **argv) return -1; } - memset((char *) &serv_addr, 0, sizeof(serv_addr)); - memset((char *) &cli_addr, 0, sizeof(cli_addr)); + memset((char*)&serv_addr, 0, sizeof(serv_addr)); + memset((char*)&cli_addr, 0, sizeof(cli_addr)); portno = 8080; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(static_cast(portno)); - if (setsockopt(sockfd, - SOL_SOCKET, - SO_REUSEADDR, - &optval, - sizeof(optval)) == -1) { + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { perror("setsockopt"); close(sockfd); exit(1); } - j = bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + j = bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); if (j == -1) { perror("Bind Error\n"); @@ -729,9 +680,7 @@ int main(int argc, char **argv) while (i) { clilen = sizeof(cli_addr); - newsockfd[i - 1] = accept(sockfd, - (struct sockaddr *)&cli_addr, - &clilen); + newsockfd[i - 1] = accept(sockfd, (struct sockaddr*)&cli_addr, &clilen); if (newsockfd[i - 1] == -1) { printf("Error in accept"); @@ -747,12 +696,10 @@ int main(int argc, char **argv) close(newsockfd[i]); close(sockfd); - } - else { - + } else { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = false; -/* ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; */ + /* ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; */ return RUN_ALL_TESTS(); } diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp index a07723e22..71eb4859a 100644 --- a/tests/gtest_dlt_daemon_gateway.cpp +++ b/tests/gtest_dlt_daemon_gateway.cpp @@ -57,8 +57,7 @@ #include #include -extern "C" -{ +extern "C" { #include "dlt_gateway.h" #include "dlt_gateway_internal.h" } @@ -102,9 +101,9 @@ TEST(t_dlt_gateway_send_control_message, Normal) DltPassiveControlMessage p_control_msgs; DltServiceSetLogLevel req; memset(&connections, 0, sizeof(DltGatewayConnection)); - memset(&p_control_msgs,0, sizeof(DltPassiveControlMessage)); - strcpy(req.apid,"LOG"); - strcpy(req.ctid,"TES"); + memset(&p_control_msgs, 0, sizeof(DltPassiveControlMessage)); + strcpy(req.apid, "LOG"); + strcpy(req.ctid, "TES"); req.log_level = 1; daemon_local.pGateway.connections = &connections; @@ -117,29 +116,33 @@ TEST(t_dlt_gateway_send_control_message, Normal) daemon_local.pEvent.connections->receiver = &receiver1; memset(daemon_local.flags.gatewayConfigFile, 0, DLT_DAEMON_FLAG_MAX); strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); - (void) dlt_gateway_init(&daemon_local, 0); + (void)dlt_gateway_init(&daemon_local, 0); daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_GET_LOG_INFO; daemon_local.pGateway.connections->p_control_msgs->type = CONTROL_MESSAGE_ON_DEMAND; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_gateway_send_control_message( + daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, NULL, 0)); daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_gateway_send_control_message( + daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, NULL, 0)); daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_gateway_send_control_message( + daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, NULL, 0)); daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_SET_LOG_LEVEL; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - (void*)&req, 0)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_gateway_send_control_message( + daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, (void*)&req, 0)); } TEST(t_dlt_gateway_send_control_message, nullpointer) @@ -149,23 +152,24 @@ TEST(t_dlt_gateway_send_control_message, nullpointer) DltConnection connections1; DltReceiver receiver1; DltPassiveControlMessage p_control_msgs; - memset(&daemon_local,0, sizeof(DltDaemonLocal)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); memset(&connections, 0, sizeof(DltGatewayConnection)); - memset(&p_control_msgs,0, sizeof(DltPassiveControlMessage)); + memset(&p_control_msgs, 0, sizeof(DltPassiveControlMessage)); daemon_local.pGateway.connections = &connections; daemon_local.pEvent.connections = &connections1; daemon_local.pGateway.connections->p_control_msgs = &p_control_msgs; daemon_local.pEvent.connections->next = NULL; daemon_local.pEvent.connections->receiver = &receiver1; - memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX); + memset(daemon_local.flags.gatewayConfigFile, 0, DLT_DAEMON_FLAG_MAX); strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_send_control_message(NULL, NULL, NULL, 0)); daemon_local.pGateway.connections->p_control_msgs->id = DLT_SERVICE_ID_SET_LOG_LEVEL; - EXPECT_EQ(DLT_RETURN_ERROR,dlt_gateway_send_control_message(daemon_local.pGateway.connections, - daemon_local.pGateway.connections->p_control_msgs, - NULL, 0)); + EXPECT_EQ( + DLT_RETURN_ERROR, + dlt_gateway_send_control_message( + daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_store_connection*/ @@ -206,7 +210,7 @@ TEST(t_dlt_gateway_store_connection, nullpointer) TEST(t_dlt_gateway_check_ip, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; #ifdef DLT_USE_IPv6 char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "::ffff:a71:6464"; #else @@ -226,7 +230,7 @@ TEST(t_dlt_gateway_check_ip, nullpointer) TEST(t_dlt_gateway_check_send_serial, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "134dltgatway"; con = &tmp; @@ -242,7 +246,7 @@ TEST(t_dlt_gateway_check_send_serial, nullpointer) TEST(t_dlt_gateway_allocate_control_messages, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; tmp.p_control_msgs = NULL; con = &tmp; EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_allocate_control_messages(con)); @@ -257,7 +261,7 @@ TEST(t_dlt_gateway_allocate_control_messages, nullpointer) TEST(t_dlt_gateway_check_control_messages, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1,2,3,4,5"; tmp.p_control_msgs = NULL; con = &tmp; @@ -273,7 +277,7 @@ TEST(t_dlt_gateway_check_control_messages, nullpointer) TEST(t_dlt_gateway_check_periodic_control_messages, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1:5,2:10"; tmp.p_control_msgs = NULL; con = &tmp; @@ -289,7 +293,7 @@ TEST(t_dlt_gateway_check_periodic_control_messages, nullpointer) TEST(t_dlt_gateway_check_port, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "3490"; con = &tmp; @@ -299,7 +303,7 @@ TEST(t_dlt_gateway_check_port, normal) TEST(t_dlt_gateway_check_port, abnormal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "9999999999"; con = &tmp; @@ -315,7 +319,7 @@ TEST(t_dlt_gateway_check_port, nullpointer) TEST(t_dlt_gateway_check_ecu, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "ECU2"; con = &tmp; @@ -331,7 +335,7 @@ TEST(t_dlt_gateway_check_ecu, nullpointer) TEST(t_dlt_gateway_check_connect_trigger, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "OnStartup"; con = &tmp; @@ -341,7 +345,7 @@ TEST(t_dlt_gateway_check_connect_trigger, normal) TEST(t_dlt_gateway_check_connect_trigger, abnormal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "wrong_parameter"; con = &tmp; @@ -357,7 +361,7 @@ TEST(t_dlt_gateway_check_connect_trigger, nullpointer) TEST(t_dlt_gateway_check_timeout, normal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "10"; con = &tmp; @@ -367,7 +371,7 @@ TEST(t_dlt_gateway_check_timeout, normal) TEST(t_dlt_gateway_check_timeout, abnormal) { DltGatewayConnection tmp; - DltGatewayConnection *con; + DltGatewayConnection* con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "-1"; con = &tmp; @@ -385,7 +389,7 @@ TEST(t_dlt_gateway_establish_connections, normal) char ip[] = "127.0.0.1"; int port = 3491; DltDaemonLocal daemon_local; - DltGateway *gateway = &daemon_local.pGateway; + DltGateway* gateway = &daemon_local.pGateway; DltGatewayConnection connections; gateway->num_connections = 1; gateway->connections = &connections; @@ -406,7 +410,7 @@ TEST(t_dlt_gateway_establish_connections, nullpointer) /* Begin Method: dlt_gateway::t_dlt_gateway_get_connection_receiver*/ TEST(t_dlt_gateway_get_connection_receiver, normal) { - DltReceiver *ret = NULL; + DltReceiver* ret = NULL; DltGateway gateway; DltGatewayConnection connections; memset(&gateway, 0, sizeof(DltGateway)); @@ -424,7 +428,7 @@ TEST(t_dlt_gateway_get_connection_receiver, normal) TEST(t_dlt_gateway_get_connection_receiver, abnormal) { - DltReceiver *ret = NULL; + DltReceiver* ret = NULL; DltGateway gateway; DltGatewayConnection connections; memset(&gateway, 0, sizeof(DltGateway)); @@ -441,7 +445,7 @@ TEST(t_dlt_gateway_get_connection_receiver, abnormal) TEST(t_dlt_gateway_get_connection_receiver, nullpointer) { - DltReceiver *ret; + DltReceiver* ret; ret = dlt_gateway_get_connection_receiver(NULL, 0); EXPECT_EQ(NULL, ret); @@ -460,9 +464,9 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) uint8_t status = 7; uint16_t count_app_ids = 1; uint16_t count_context_ids = 1; - const char *apid = "LOG"; - const char *ctid = "TEST"; - const char *com = "remo"; + const char* apid = "LOG"; + const char* ctid = "TEST"; + const char* com = "remo"; char app_description[] = "Test Application for Logging"; char context_description[] = "Test Context for Logging"; uint16_t len_app = 0; @@ -479,12 +483,10 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) ASSERT_EQ(DLT_RETURN_OK, ret); /* create response message */ - msg.datasize = static_cast(sizeof(DltServiceGetLogInfoResponse) + - sizeof(AppIDsType) + - sizeof(ContextIDsInfoType) + - strlen(app_description) + - strlen(context_description)); - msg.databuffer = (uint8_t *)malloc(msg.datasize); + msg.datasize = static_cast( + sizeof(DltServiceGetLogInfoResponse) + sizeof(AppIDsType) + sizeof(ContextIDsInfoType) + strlen(app_description) + + strlen(context_description)); + msg.databuffer = (uint8_t*)malloc(msg.datasize); msg.databuffersize = msg.datasize; memset(msg.databuffer, 0, msg.datasize); @@ -497,13 +499,13 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) memcpy(msg.databuffer + offset, &count_app_ids, sizeof(uint16_t)); offset += static_cast(sizeof(uint16_t)); - dlt_set_id((char *)(msg.databuffer + offset), apid); + dlt_set_id((char*)(msg.databuffer + offset), apid); offset += static_cast(sizeof(ID4)); memcpy(msg.databuffer + offset, &count_context_ids, sizeof(uint16_t)); offset += static_cast(sizeof(uint16_t)); - dlt_set_id((char *)(msg.databuffer + offset), ctid); + dlt_set_id((char*)(msg.databuffer + offset), ctid); offset += static_cast(sizeof(ID4)); memcpy(msg.databuffer + offset, &log_level, sizeof(int8_t)); @@ -526,12 +528,12 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) memcpy(msg.databuffer + offset, app_description, strlen(app_description)); offset += static_cast(strlen(app_description)); - dlt_set_id((char *)(msg.databuffer + offset), com); + dlt_set_id((char*)(msg.databuffer + offset), com); - msg.storageheader = (DltStorageHeader *)msg.headerbuffer; + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; dlt_set_storageheader(msg.storageheader, ""); - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; msg.standardheader->mcnt = 0; @@ -539,19 +541,16 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) msg.headerextra.tmsp = dlt_uptime(); dlt_message_set_extraparameters(&msg, 0); - msg.extendedheader = (DltExtendedHeader *)(msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); msg.extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE; msg.extendedheader->noar = 1; dlt_set_id(msg.extendedheader->apid, ""); dlt_set_id(msg.extendedheader->ctid, ""); - msg.headersize = static_cast(sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.headersize = static_cast( + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); len = static_cast(msg.headersize - sizeof(DltStorageHeader) + msg.datasize); msg.standardheader->len = DLT_HTOBE_16((uint16_t)len); @@ -613,8 +612,9 @@ TEST(t_dlt_gateway_process_gateway_timer, normal) daemon.storage_handle = &storage_handle; daemon_local.pEvent.connections->receiver->fd = -1; - EXPECT_EQ(DLT_RETURN_OK, - dlt_gateway_process_gateway_timer(&daemon, &daemon_local, daemon_local.pEvent.connections->receiver, 1)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_gateway_process_gateway_timer(&daemon, &daemon_local, daemon_local.pEvent.connections->receiver, 1)); } TEST(t_dlt_gateway_process_gateway_timer, nullpointer) @@ -635,11 +635,9 @@ TEST(t_dlt_gateway_process_on_demand_request, normal) connections.trigger = DLT_GATEWAY_ON_STARTUP; connections.ecuid = node_id; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_on_demand_request(&daemon_local.pGateway, - &daemon_local, - node_id, - conn_status, - 1)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_gateway_process_on_demand_request(&daemon_local.pGateway, &daemon_local, node_id, conn_status, 1)); } TEST(t_dlt_gateway_process_on_demand_request, abnormal) @@ -653,11 +651,9 @@ TEST(t_dlt_gateway_process_on_demand_request, abnormal) connections.status = DLT_GATEWAY_INITIALIZED; connections.ecuid = node_id; - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_process_on_demand_request(&daemon_local.pGateway, - &daemon_local, - node_id, - conn_status, - 0)); + EXPECT_EQ( + DLT_RETURN_ERROR, + dlt_gateway_process_on_demand_request(&daemon_local.pGateway, &daemon_local, node_id, conn_status, 0)); } TEST(t_dlt_gateway_process_on_demand_request, nullpointer) @@ -679,15 +675,9 @@ TEST(t_dlt_gateway_check_param, normal) DltGatewayConnection tmp; gateway.connections = &tmp; - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_param(&gateway, - &tmp, - GW_CONF_IP_ADDRESS, - value_1)); + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_param(&gateway, &tmp, GW_CONF_IP_ADDRESS, value_1)); - EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_param(&gateway, - &tmp, - GW_CONF_PORT, - value_2)); + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_param(&gateway, &tmp, GW_CONF_PORT, value_2)); } TEST(t_dlt_gateway_check_param, abnormal) @@ -701,10 +691,7 @@ TEST(t_dlt_gateway_check_param, abnormal) DltGatewayConnection tmp; gateway.connections = &tmp; - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_param(&gateway, - &tmp, - GW_CONF_PORT, - value_1)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_param(&gateway, &tmp, GW_CONF_PORT, value_1)); } TEST(t_dlt_gateway_check_param, nullpointer) @@ -730,10 +717,10 @@ TEST(t_dlt_gateway_configure, nullpointer) EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_configure(NULL, NULL, 0)); } -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); -/* ::testing::FLAGS_gtest_break_on_failure = true; */ -/* ::testing::FLAGS_gtest_filter = "t_dlt_gateway_process_passive_node_messages*"; */ + /* ::testing::FLAGS_gtest_break_on_failure = true; */ + /* ::testing::FLAGS_gtest_filter = "t_dlt_gateway_process_passive_node_messages*"; */ return RUN_ALL_TESTS(); } diff --git a/tests/gtest_dlt_daemon_multiple_files_logging.cpp b/tests/gtest_dlt_daemon_multiple_files_logging.cpp index dd48180b3..9e4bb49d1 100644 --- a/tests/gtest_dlt_daemon_multiple_files_logging.cpp +++ b/tests/gtest_dlt_daemon_multiple_files_logging.cpp @@ -28,8 +28,7 @@ int connectServer(void); -extern "C" -{ +extern "C" { #include "dlt_log.h" #include "dlt_common.h" #include @@ -113,7 +112,8 @@ TEST(t_dlt_logging_multiple_files_append_reinit, normal) verify_in_one_file(path, file_name, log1, log2); } -void configure(const char *path, const char* file_name, const bool enable_limit, const int file_size, const int max_files_size) +void configure( + const char* path, const char* file_name, const bool enable_limit, const int file_size, const int max_files_size) { char abs_file_path[PATH_MAX]; snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, file_name); @@ -138,7 +138,7 @@ void verify_multiple_files(const char* path, const char* file_name, const int fi int file_indices[100]; char filename[PATH_MAX + 1]; - struct dirent *dp; + struct dirent* dp; struct stat status; char file_name_copy[NAME_MAX + 1]; @@ -146,19 +146,17 @@ void verify_multiple_files(const char* path, const char* file_name, const int fi file_name_copy[NAME_MAX - 1] = '\0'; char filename_base[NAME_MAX]; EXPECT_TRUE(dlt_extract_base_name_without_ext(file_name_copy, filename_base, sizeof(filename_base))); - const char *filename_ext = get_filename_ext(file_name); + const char* filename_ext = get_filename_ext(file_name); EXPECT_TRUE(filename_ext); - DIR *dir = opendir(path); + DIR* dir = opendir(path); while ((dp = readdir(dir)) != NULL) { - if (strstr(dp->d_name, filename_base) && - strstr(dp->d_name, filename_ext)) { - + if (strstr(dp->d_name, filename_base) && strstr(dp->d_name, filename_ext)) { snprintf(filename, sizeof(filename), "%s/%s", path, dp->d_name); if (0 == stat(filename, &status)) { EXPECT_LE(status.st_size, file_size); - EXPECT_GE(status.st_size, file_size/2); + EXPECT_GE(status.st_size, file_size / 2); sum_size += static_cast(status.st_size); file_indices[num_files++] = get_file_index(filename); } else { @@ -171,10 +169,10 @@ void verify_multiple_files(const char* path, const char* file_name, const int fi EXPECT_GT(sum_size, 0); EXPECT_GT(num_files, 0); - //check that file indices are successive in ascending order + // check that file indices are successive in ascending order qsort(file_indices, num_files, sizeof(int), compare_int); int index = file_indices[0]; - for (int i=1; id_name, filename_base) && - strstr(dp->d_name, filename_ext)) { - + if (strstr(dp->d_name, filename_base) && strstr(dp->d_name, filename_ext)) { snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, dp->d_name); if (file_contains_strings(abs_file_path, log1, log2)) { @@ -227,20 +223,18 @@ void verify_in_one_file(const char* path, const char* file_name, const char* log bool file_contains_strings(const char* abs_file_path, const char* str1, const char* str2) { bool found = false; - FILE *file = fopen(abs_file_path, "r"); + FILE* file = fopen(abs_file_path, "r"); if (file != nullptr) { - fseek (file , 0 , SEEK_END); - long size = ftell (file); - rewind (file); + fseek(file, 0, SEEK_END); + long size = ftell(file); + rewind(file); - char* buffer = (char*) malloc(size); + char* buffer = (char*)malloc(size); long read_bytes = fread(buffer, 1, size, file); EXPECT_EQ(size, read_bytes); - if ((strstr(buffer, str1) != nullptr) && - (strstr(buffer, str2) != nullptr)) { - + if ((strstr(buffer, str1) != nullptr) && (strstr(buffer, str2) != nullptr)) { found = true; } @@ -252,25 +246,29 @@ bool file_contains_strings(const char* abs_file_path, const char* str1, const ch int get_file_index(char* file_name) { - char *dot = strrchr(file_name, '.'); + char* dot = strrchr(file_name, '.'); *dot = '\0'; - //start with the first zero - char *iterator = strchr(file_name, '0'); - do {} while (*(++iterator) == '0'); - //now iterator points to the first character after 0 + // start with the first zero + char* iterator = strchr(file_name, '0'); + do { + } while (*(++iterator) == '0'); + // now iterator points to the first character after 0 return atoi(iterator); } int compare_int(const void* a, const void* b) { - if (*((const int*)a) == *((const int*)b)) return 0; - else if (*((const int*)a) < *((const int*)b)) return -1; - else return 1; + if (*((const int*)a) == *((const int*)b)) + return 0; + else if (*((const int*)a) < *((const int*)b)) + return -1; + else + return 1; } -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp index 9bbe01f62..701d2a323 100644 --- a/tests/gtest_dlt_daemon_offline_log.cpp +++ b/tests/gtest_dlt_daemon_offline_log.cpp @@ -15,8 +15,7 @@ int connectServer(void); -extern "C" -{ +extern "C" { #include "dlt_offline_logstorage.h" #include "dlt_offline_logstorage_internal.h" #include "dlt_offline_logstorage_behavior.h" @@ -39,14 +38,14 @@ unsigned int g_logstorage_cache_max; /* Begin Method: dlt_logstorage::t_dlt_logstorage_list_add*/ TEST(t_dlt_logstorage_list_add, normal) { - DltLogStorageFilterList *list = NULL; - DltLogStorageFilterConfig *data = NULL; + DltLogStorageFilterList* list = NULL; + DltLogStorageFilterConfig* data = NULL; DltLogStorageUserConfig file_config; char path[] = "/tmp"; char key = 1; int num_keys = 1; - data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + data = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); @@ -60,11 +59,11 @@ TEST(t_dlt_logstorage_list_add, normal) /* Begin Method: dlt_logstorage::t_dlt_logstorage_list_add_config*/ TEST(t_dlt_logstorage_list_add_config, normal) { - DltLogStorageFilterConfig *data = NULL; - DltLogStorageFilterConfig *listdata = NULL; + DltLogStorageFilterConfig* data = NULL; + DltLogStorageFilterConfig* listdata = NULL; - data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); - listdata = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + data = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); + listdata = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if ((data != NULL) && (listdata != NULL)) { dlt_logstorage_list_add_config(data, &listdata); @@ -76,14 +75,14 @@ TEST(t_dlt_logstorage_list_add_config, normal) /* Begin Method: dlt_logstorage::t_dlt_logstorage_list_destroy*/ TEST(t_dlt_logstorage_list_destroy, normal) { - DltLogStorageFilterList *list = NULL; - DltLogStorageFilterConfig *data = NULL; + DltLogStorageFilterList* list = NULL; + DltLogStorageFilterConfig* data = NULL; DltLogStorageUserConfig file_config; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); char key = 1; int num_keys = 1; - data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + data = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); @@ -96,18 +95,18 @@ TEST(t_dlt_logstorage_list_destroy, normal) /* Begin Method: dlt_logstorage::t_dlt_logstorage_list_find*/ TEST(t_dlt_logstorage_list_find, normal) { - DltLogStorageFilterList *list = NULL; - DltLogStorageFilterConfig *data = NULL; + DltLogStorageFilterList* list = NULL; + DltLogStorageFilterConfig* data = NULL; int num_configs = 0; DltLogStorageUserConfig file_config; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); char key[] = ":1234:5678"; char apid[] = "1234"; char ctid[] = "5678"; int num_keys = 1; - DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + DltLogStorageFilterConfig* config[DLT_CONFIG_FILE_SECTIONS_MAX] = {0}; - data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + data = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { data->apids = strdup(apid); @@ -119,7 +118,7 @@ TEST(t_dlt_logstorage_list_find, normal) num_configs = dlt_logstorage_list_find(key, &list, config); EXPECT_EQ(1, num_configs); - EXPECT_NE((DltLogStorageFilterConfig *)NULL, config[0]); + EXPECT_NE((DltLogStorageFilterConfig*)NULL, config[0]); if (num_configs > 0) { EXPECT_STREQ(apid, config[0]->apids); @@ -135,13 +134,13 @@ TEST(t_dlt_logstorage_free, normal) { char key = 1; DltLogStorage handle; - DltLogStorageFilterConfig *data = NULL; + DltLogStorageFilterConfig* data = NULL; int reason = 0; handle.num_configs = 0; handle.config_list = NULL; int num_keys = 1; - data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + data = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); @@ -155,7 +154,7 @@ TEST(t_dlt_logstorage_free, normal) /* Begin Method: dlt_logstorage::t_dlt_logstorage_count_ids*/ TEST(t_dlt_logstorage_count_ids, normal) { - char const *str = "a,b,c,d"; + char const* str = "a,b,c,d"; EXPECT_EQ(4, dlt_logstorage_count_ids(str)); } @@ -187,7 +186,7 @@ TEST(t_dlt_logstorage_create_keys, normal) { DltLogStorageFilterConfig data; memset(&data, 0, sizeof(DltLogStorageFilterConfig)); - char *keys = NULL; + char* keys = NULL; int num_keys = 0; char apids[] = "1234"; char ctids[] = "5678"; @@ -204,7 +203,7 @@ TEST(t_dlt_logstorage_prepare_table, normal) DltLogStorage handle; DltLogStorageFilterConfig data; DltLogStorageUserConfig file_config; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); memset(&handle, 0, sizeof(DltLogStorage)); memset(&data, 0, sizeof(DltLogStorageFilterConfig)); char apids[] = "1234"; @@ -256,10 +255,10 @@ TEST(t_dlt_logstorage_filter_set_strategy, normal) /* Begin Method: dlt_logstorage::t_dlt_logstorage_read_list_of_names*/ TEST(t_dlt_logstorage_read_list_of_names, normal) { - char *namesPtr = NULL; + char* namesPtr = NULL; char value[] = "a,b,c,d"; - namesPtr = (char *)calloc (1, sizeof(char)); + namesPtr = (char*)calloc(1, sizeof(char)); if (namesPtr != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_list_of_names(&namesPtr, value)); @@ -279,7 +278,7 @@ TEST(t_dlt_logstorage_check_apids, normal) char value[] = "a,b,c,d"; DltLogStorageFilterConfig config; /* Initialize id pointer as NULL pointer for testing only */ - config.apids = (char *)calloc (1, sizeof(char)); + config.apids = (char*)calloc(1, sizeof(char)); if (config.apids != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_apids(&config, value)); @@ -299,7 +298,7 @@ TEST(t_dlt_logstorage_check_ctids, normal) char value[] = "a,b,c,d"; DltLogStorageFilterConfig config; /* Initialize id pointer as NULL pointer for testing only */ - config.ctids = (char *)calloc (1, sizeof(char)); + config.ctids = (char*)calloc(1, sizeof(char)); if (config.ctids != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_ctids(&config, value)); @@ -319,7 +318,7 @@ TEST(t_dlt_logstorage_store_config_excluded_apids, normal) char value[] = "a,b,c,d"; DltLogStorageFilterConfig config; /* Initialize id pointer as NULL pointer for testing only */ - config.excluded_apids = (char *)calloc (1, sizeof(char)); + config.excluded_apids = (char*)calloc(1, sizeof(char)); if (config.excluded_apids != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_config_excluded_apids(&config, value)); @@ -339,7 +338,7 @@ TEST(t_dlt_logstorage_store_config_excluded_ctids, normal) char value[] = "a,b,c,d"; DltLogStorageFilterConfig config; /* Initialize id pointer as NULL pointer for testing only */ - config.excluded_ctids = (char *)calloc (1, sizeof(char)); + config.excluded_ctids = (char*)calloc(1, sizeof(char)); if (config.excluded_ctids != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_config_excluded_ctids(&config, value)); @@ -392,7 +391,7 @@ TEST(t_dlt_logstorage_check_filename, normal) char value[] = "file_name"; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); - config.file_name = (char *)calloc (1, sizeof(char)); + config.file_name = (char*)calloc(1, sizeof(char)); if (config.file_name != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_filename(&config, value)); @@ -406,7 +405,7 @@ TEST(t_dlt_logstorage_check_filename, abnormal) char value[] = "../file_name"; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); - config.file_name = (char *)calloc (1, sizeof(char)); + config.file_name = (char*)calloc(1, sizeof(char)); if (config.file_name != NULL) { EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_filename(&config, value)); @@ -486,7 +485,7 @@ TEST(t_dlt_logstorage_check_ecuid, normal) char value[] = "213"; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); - config.ecuid = (char *)calloc (1, sizeof(char)); + config.ecuid = (char*)calloc(1, sizeof(char)); if (config.ecuid != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_ecuid(&config, value)); @@ -526,7 +525,7 @@ TEST(t_dlt_logstorage_store_filters, normal) memset(&handle, 0, sizeof(DltLogStorage)); DltLogStorageUserConfig file_config; memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); char config_file_name[] = "/tmp/dlt_logstorage.conf"; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = 0; @@ -548,7 +547,7 @@ TEST(t_dlt_logstorage_load_config, normal) { DltLogStorage handle; DltLogStorageUserConfig file_config; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = 0; handle.write_errors = 0; @@ -603,8 +602,8 @@ TEST(t_dlt_logstorage_device_disconnected, null) TEST(t_dlt_logstorage_get_loglevel_by_key, normal) { char arr[] = "abc"; - char *key = arr; - DltLogStorageFilterConfig *config = NULL; + char* key = arr; + DltLogStorageFilterConfig* config = NULL; DltLogStorage handle; handle.config_status = 0; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; @@ -613,7 +612,7 @@ TEST(t_dlt_logstorage_get_loglevel_by_key, normal) handle.newest_file_list = NULL; int num_keys = 1; - config = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); + config = (DltLogStorageFilterConfig*)calloc(1, sizeof(DltLogStorageFilterConfig)); if (config != NULL) { config->log_level = DLT_LOG_ERROR; @@ -647,7 +646,7 @@ TEST(t_dlt_logstorage_get_config, normal) char key0[] = ":1234:\000\000\000\000"; char key1[] = "::5678\000\000\000\000"; char key2[] = ":1234:5678"; - DltLogStorageFilterConfig *config[3] = { 0 }; + DltLogStorageFilterConfig* config[3] = {0}; DltLogStorage handle; memset(&handle, 0, sizeof(DltLogStorage)); handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; @@ -690,7 +689,7 @@ TEST(t_dlt_logstorage_filter, normal) char key0[] = ":1234:\000\000\000\000"; char key1[] = "::5678\000\000\000\000"; char key2[] = ":1234:5678"; - DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* config[DLT_CONFIG_FILE_SECTIONS] = {0}; DltLogStorage handle; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; @@ -712,7 +711,7 @@ TEST(t_dlt_logstorage_filter, normal) /* Filter on excluded application and context */ value.excluded_apids = apid; value.excluded_ctids = ctid; - DltLogStorageFilterConfig *neg_filter_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* neg_filter_config[DLT_CONFIG_FILE_SECTIONS] = {0}; handle.config_list = NULL; handle.newest_file_list = NULL; @@ -730,7 +729,7 @@ TEST(t_dlt_logstorage_filter, normal) /* Change excluded fields */ value.excluded_apids = t_apid; value.excluded_ctids = t_ctid; - DltLogStorageFilterConfig *t_neg_filter_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* t_neg_filter_config[DLT_CONFIG_FILE_SECTIONS] = {0}; handle.config_list = NULL; handle.newest_file_list = NULL; @@ -748,7 +747,7 @@ TEST(t_dlt_logstorage_filter, normal) /* Only filter on excluded contexts */ value.excluded_apids = NULL; value.excluded_ctids = ctid; - DltLogStorageFilterConfig *neg_filter_ctid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* neg_filter_ctid_only_config[DLT_CONFIG_FILE_SECTIONS] = {0}; handle.config_list = NULL; handle.newest_file_list = NULL; @@ -766,7 +765,7 @@ TEST(t_dlt_logstorage_filter, normal) /* Change excluded fields */ value.excluded_apids = NULL; value.excluded_ctids = t_ctid; - DltLogStorageFilterConfig *t_neg_filter_ctid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* t_neg_filter_ctid_only_config[DLT_CONFIG_FILE_SECTIONS] = {0}; handle.config_list = NULL; handle.newest_file_list = NULL; @@ -784,7 +783,7 @@ TEST(t_dlt_logstorage_filter, normal) /* Only filter on excluded applications */ value.excluded_apids = apid; value.excluded_ctids = NULL; - DltLogStorageFilterConfig *neg_filter_apid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* neg_filter_apid_only_config[DLT_CONFIG_FILE_SECTIONS] = {0}; handle.config_list = NULL; handle.newest_file_list = NULL; @@ -802,7 +801,7 @@ TEST(t_dlt_logstorage_filter, normal) /* Change excluded fields */ value.excluded_apids = t_apid; value.excluded_ctids = NULL; - DltLogStorageFilterConfig *t_neg_filter_apid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + DltLogStorageFilterConfig* t_neg_filter_apid_only_config[DLT_CONFIG_FILE_SECTIONS] = {0}; handle.config_list = NULL; handle.newest_file_list = NULL; @@ -820,7 +819,7 @@ TEST(t_dlt_logstorage_filter, normal) TEST(t_dlt_logstorage_filter, null) { - DltLogStorageFilterConfig *config[3] = { 0 }; + DltLogStorageFilterConfig* config[3] = {0}; int num = dlt_logstorage_filter(NULL, config, NULL, NULL, NULL, 0); EXPECT_EQ(DLT_RETURN_ERROR, num); } @@ -856,18 +855,16 @@ TEST(t_dlt_logstorage_write, normal) int log_level = 4; dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG); dlt_message_init(&msg, 0); - msg.storageheader = (DltStorageHeader *)msg.headerbuffer; + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; dlt_set_storageheader(msg.storageheader, ecuid); - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); - msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1|DLT_HTYP_UEH; + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1 | DLT_HTYP_UEH; msg.standardheader->mcnt = 0; dlt_message_set_extraparameters(&msg, 0); - msg.extendedheader = (DltExtendedHeader *)(msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); - msg.extendedheader->msin = (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | - (uint8_t)(((log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) | DLT_MSIN_VERB); + msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.extendedheader->msin = (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) + | (uint8_t)(((log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) | DLT_MSIN_VERB); msg.extendedheader->noar = 1; dlt_set_id(msg.extendedheader->apid, apid); dlt_set_id(msg.extendedheader->ctid, ctid); @@ -875,11 +872,11 @@ TEST(t_dlt_logstorage_write, normal) EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write(&handle, &uconfig, - (unsigned char*)&(userheader), sizeof(DltUserHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (int)(msg.headersize - sizeof(DltStorageHeader)), - data, size, &disable_nw)); + EXPECT_EQ( + DLT_RETURN_OK, dlt_logstorage_write( + &handle, &uconfig, (unsigned char*)&(userheader), sizeof(DltUserHeader), + msg.headerbuffer + sizeof(DltStorageHeader), + (int)(msg.headersize - sizeof(DltStorageHeader)), data, size, &disable_nw)); dlt_message_free(&msg, 0); } @@ -914,7 +911,7 @@ TEST(t_dlt_logstorage_write_v2, normal) DltMessageV2 msg; DltUserHeader userheader; - //int log_level = 4; + // int log_level = 4; dlt_user_set_userheader_v2(&userheader, DLT_USER_MESSAGE_LOG); dlt_message_init_v2(&msg, 0); size_t _hdrsz = 512; @@ -923,11 +920,11 @@ TEST(t_dlt_logstorage_write_v2, normal) msg.storageheadersizev2 = (int)sizeof(DltStorageHeaderV2); msg.baseheadersizev2 = (int)sizeof(DltBaseHeaderV2); msg.baseheaderextrasizev2 = 0; - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + msg.storageheadersizev2); - //msg.storageheaderv2 = (DltStorageHeaderV2 *)msg.headerbufferv2; - //dlt_set_storageheader_v2(&(msg.storageheaderv2), ecuid_len, ecuid); - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + sizeof(DltStorageHeaderV2)); - msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2|DLT_HTYP2_EH; + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + msg.storageheadersizev2); + // msg.storageheaderv2 = (DltStorageHeaderV2 *)msg.headerbufferv2; + // dlt_set_storageheader_v2(&(msg.storageheaderv2), ecuid_len, ecuid); + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + sizeof(DltStorageHeaderV2)); + msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2 | DLT_HTYP2_EH; msg.baseheaderv2->mcnt = 0; dlt_message_set_extraparameters_v2(&msg, 0); /*msg.extendedheaderv2 = (DltExtendedHeaderV2 *)(msg.headerbufferv2 + @@ -940,11 +937,11 @@ TEST(t_dlt_logstorage_write_v2, normal) EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write(&handle, &uconfig, - (unsigned char*)&(userheader), sizeof(DltUserHeader), - msg.headerbufferv2 + sizeof(DltStorageHeaderV2), - (int)(msg.headersizev2 - (int32_t)sizeof(DltStorageHeaderV2)), - data, size, &disable_nw)); + EXPECT_EQ( + DLT_RETURN_OK, dlt_logstorage_write( + &handle, &uconfig, (unsigned char*)&(userheader), sizeof(DltUserHeader), + msg.headerbufferv2 + sizeof(DltStorageHeaderV2), + (int)(msg.headersizev2 - (int32_t)sizeof(DltStorageHeaderV2)), data, size, &disable_nw)); dlt_message_free_v2(&msg, 0); } @@ -980,7 +977,7 @@ TEST(t_dlt_logstorage_sync_caches, normal) /* Begin Method: dlt_logstorage::t_dlt_logstorage_log_file_name*/ TEST(t_dlt_logstorage_log_file_name, normal) { - char log_file_name[DLT_MOUNT_PATH_MAX] = { '\0' }; + char log_file_name[DLT_MOUNT_PATH_MAX] = {'\0'}; DltLogStorageUserConfig file_config; memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); file_config.logfile_delimiter = '/'; @@ -1004,7 +1001,7 @@ TEST(t_dlt_logstorage_log_file_name, normal) TEST(t_dlt_logstorage_log_file_name, tmsp) { - char log_file_name[DLT_MOUNT_PATH_MAX] = { '\0' }; + char log_file_name[DLT_MOUNT_PATH_MAX] = {'\0'}; DltLogStorageUserConfig file_config; memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); file_config.logfile_delimiter = '_'; @@ -1017,7 +1014,7 @@ TEST(t_dlt_logstorage_log_file_name, tmsp) memset(&filter_config, 0, sizeof(filter_config)); filter_config.file_name = &name[0]; - dlt_logstorage_log_file_name(log_file_name, &file_config, &filter_config, "log", 8, 4); + dlt_logstorage_log_file_name(log_file_name, &file_config, &filter_config, "log", 8, 4); // log_04_20210810-094602.dlt std::regex r("log_04_\\d{8}-\\d{6}\\.dlt"); @@ -1058,10 +1055,10 @@ TEST(t_dlt_logstorage_log_file_name, null) TEST(t_dlt_logstorage_sort_file_name, normal) { DltLogStorageFileList *node1, *node2, *node3; - DltLogStorageFileList **head; - node1 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node2 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node3 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); + DltLogStorageFileList** head; + node1 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); + node2 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); + node3 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); if ((node1 != NULL) && (node2 != NULL) && (node3 != NULL)) { node1->next = node2; @@ -1108,13 +1105,12 @@ TEST(t_dlt_logstorage_sort_file_name, null) TEST(t_dlt_logstorage_rearrange_file_name, normal1) { DltLogStorageFileList *node1, *node2, *node3; - DltLogStorageFileList **head; - node1 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node2 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node3 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); + DltLogStorageFileList** head; + node1 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); + node2 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); + node3 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); if ((node1 != NULL) && (node2 != NULL) && (node3 != NULL)) { - node1->next = node2; node2->next = node3; node3->next = NULL; @@ -1155,13 +1151,12 @@ TEST(t_dlt_logstorage_rearrange_file_name, normal1) TEST(t_dlt_logstorage_rearrange_file_name, normal2) { DltLogStorageFileList *node1, *node2, *node3; - DltLogStorageFileList **head; - node1 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node2 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); - node3 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList)); + DltLogStorageFileList** head; + node1 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); + node2 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); + node3 = (DltLogStorageFileList*)calloc(1, sizeof(DltLogStorageFileList)); if ((node1 != NULL) && (node2 != NULL) && (node3 != NULL)) { - node1->next = node2; node2->next = node3; node3->next = NULL; @@ -1209,11 +1204,11 @@ TEST(t_dlt_logstorage_get_idx_of_log_file, normal) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; char name[] = "Test"; - char *file = const_cast("Test_002_20160509_191132.dlt"); + char* file = const_cast("Test_002_20160509_191132.dlt"); DltLogStorageFilterConfig filter_config; memset(&filter_config, 0, sizeof(filter_config)); @@ -1221,7 +1216,7 @@ TEST(t_dlt_logstorage_get_idx_of_log_file, normal) EXPECT_EQ(2, dlt_logstorage_get_idx_of_log_file(&file_config, &filter_config, file)); - char *gz_file = const_cast("Test_142_20160509_191132.dlt.gz"); + char* gz_file = const_cast("Test_142_20160509_191132.dlt.gz"); filter_config.gzip_compression = 1; EXPECT_EQ(142, dlt_logstorage_get_idx_of_log_file(&file_config, &filter_config, gz_file)); @@ -1236,10 +1231,10 @@ TEST(t_dlt_logstorage_storage_dir_info, normal) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; @@ -1262,10 +1257,10 @@ TEST(t_dlt_logstorage_open_log_file, normal) DltLogStorageUserConfig file_config; memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); file_config.logfile_timestamp = 0; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; @@ -1296,10 +1291,10 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal1) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; @@ -1325,10 +1320,10 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal2) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; @@ -1351,14 +1346,13 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal2) char dummy_file[100] = ""; sprintf(dummy_file, "%s/%s", path, newest_file_name.newest_file); int ret = 0; - FILE *fp = fopen(dummy_file, "w"); + FILE* fp = fopen(dummy_file, "w"); ret = ftruncate(fileno(fp), 1024); fclose(fp); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); - if (ret == 0) - { + if (ret == 0) { remove(dummy_file); } } @@ -1367,15 +1361,15 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal3) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; char ctids; - char *working_file_name = const_cast("Test_002_20160509_191132.dlt"); + char* working_file_name = const_cast("Test_002_20160509_191132.dlt"); config.apids = &apids; config.ctids = &ctids; config.file_name = const_cast("Test"); @@ -1394,14 +1388,13 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal3) char dummy_file[100] = ""; sprintf(dummy_file, "%s/%s", path, newest_file_name.newest_file); int ret = 0; - FILE *fp = fopen(dummy_file, "w"); + FILE* fp = fopen(dummy_file, "w"); ret = ftruncate(fileno(fp), 1024); fclose(fp); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); - if (ret == 0) - { + if (ret == 0) { remove(dummy_file); } } @@ -1416,10 +1409,10 @@ TEST(t_dlt_logstorage_write_on_msg, normal) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; @@ -1446,8 +1439,8 @@ TEST(t_dlt_logstorage_write_on_msg, normal) char tmp_file[100] = ""; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, &file_config, path, - data1, size, data2, size, data3, size)); + EXPECT_EQ( + DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, &file_config, path, data1, size, data2, size, data3, size)); sprintf(tmp_file, "%s/%s", path, config.working_file_name); remove(tmp_file); } @@ -1457,10 +1450,10 @@ TEST(t_dlt_logstorage_write_on_msg, gzip) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 191132; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); char apids; @@ -1485,8 +1478,8 @@ TEST(t_dlt_logstorage_write_on_msg, gzip) newest_file_name.next = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, &file_config, path, - data1, size, data2, size, data3, size)); + EXPECT_EQ( + DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, &file_config, path, data1, size, data2, size, data3, size)); } #endif @@ -1511,7 +1504,7 @@ TEST(t_dlt_logstorage_sync_on_msg, normal) config.log = NULL; config.working_file_name = NULL; config.wrap_id = 0; - char *path = NULL; + char* path = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_on_msg(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_MSG)); } @@ -1526,10 +1519,10 @@ TEST(t_dlt_logstorage_prepare_msg_cache, normal) { DltLogStorageUserConfig file_config; file_config.logfile_timestamp = 1; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 2; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; DltNewestFileName newest_info; memset(&newest_info, 0, sizeof(DltNewestFileName)); @@ -1572,14 +1565,15 @@ TEST(t_dlt_logstorage_write_msg_cache, normal) DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); DltLogStorageUserConfig file_config; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter)); if (config.cache != NULL) { config.file_size = 50; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, &file_config, path, - data1, size, data2, size, data3, size)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_logstorage_write_msg_cache(&config, &file_config, path, data1, size, data2, size, data3, size)); free(config.cache); config.cache = NULL; @@ -1629,12 +1623,10 @@ TEST(t_dlt_logstorage_update_all_contexts, normal) daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, &daemon_local, apid, 1, 1, ecu, 0)); @@ -1651,8 +1643,8 @@ TEST(t_dlt_logstorage_update_context, normal) { DltDaemon daemon; DltDaemonLocal daemon_local; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; memset(&daemon, 0, sizeof(DltDaemon)); memset(&daemon_local, 0, sizeof(DltDaemonLocal)); memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); @@ -1669,18 +1661,16 @@ TEST(t_dlt_logstorage_update_context, normal) char desc[255] = "TEST dlt_logstorage_update_context"; char ecu[] = "ECU1"; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); app = dlt_daemon_application_add(&daemon, apid, getpid(), desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, 0, app->user_handle, desc, daemon.ecuid, 0); - EXPECT_NE((DltDaemonContext *)(NULL), daecontext); + daecontext = dlt_daemon_context_add( + &daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, app->user_handle, desc, daemon.ecuid, 0); + EXPECT_NE((DltDaemonContext*)(NULL), daecontext); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context(&daemon, &daemon_local, apid, ctid, ecu, 1, 0)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context(&daemon, &daemon_local, apid, ctid, ecu, 0, 0)); } @@ -1695,8 +1685,8 @@ TEST(t_dlt_logstorage_update_context_loglevel, normal) { DltDaemon daemon; DltDaemonLocal daemon_local; - DltDaemonContext *daecontext = NULL; - DltDaemonApplication *app = NULL; + DltDaemonContext* daecontext = NULL; + DltDaemonApplication* app = NULL; memset(&daemon, 0, sizeof(DltDaemon)); memset(&daemon_local, 0, sizeof(DltDaemonLocal)); memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); @@ -1714,20 +1704,17 @@ TEST(t_dlt_logstorage_update_context_loglevel, normal) char desc[255] = "TEST dlt_logstorage_update_context_loglevel"; char ecu[] = "ECU1"; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); app = dlt_daemon_application_add(&daemon, apid, getpid(), desc, fd, ecu, 0); - daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, 0, app->user_handle, desc, daemon.ecuid, 0); - EXPECT_NE((DltDaemonContext *)(NULL), daecontext); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context_loglevel - (&daemon, &daemon_local, key, 1, 0)); + daecontext = dlt_daemon_context_add( + &daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, app->user_handle, desc, daemon.ecuid, 0); + EXPECT_NE((DltDaemonContext*)(NULL), daecontext); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context_loglevel(&daemon, &daemon_local, key, 1, 0)); } TEST(t_dlt_logstorage_update_context_loglevel, null) @@ -1751,12 +1738,10 @@ TEST(t_dlt_daemon_logstorage_reset_application_loglevel, normal) char ecu[] = "ECU1"; int device_index = 0; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(&daemon, &daemon_local, device_index, 1, 0)); @@ -1794,12 +1779,10 @@ TEST(t_dlt_daemon_logstorage_get_loglevel, normal) daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); @@ -1848,12 +1831,10 @@ TEST(t_dlt_daemon_logstorage_update_application_loglevel, normal) daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); @@ -1882,12 +1863,10 @@ TEST(t_dlt_daemon_logstorage_write, normal) char ecu[] = "ECU1"; DltLogStorage storage_handle; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); daemon.storage_handle = &storage_handle; @@ -1922,18 +1901,16 @@ TEST(t_dlt_daemon_logstorage_write, normal) int log_level = 4; dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG); dlt_message_init(&msg, 0); - msg.storageheader = (DltStorageHeader *)msg.headerbuffer; + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; dlt_set_storageheader(msg.storageheader, ecuid); - msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); - msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1|DLT_HTYP_UEH; + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1 | DLT_HTYP_UEH; msg.standardheader->mcnt = 0; dlt_message_set_extraparameters(&msg, 0); - msg.extendedheader = (DltExtendedHeader *)(msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); - msg.extendedheader->msin = (uint8_t)((DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | - ((log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) | DLT_MSIN_VERB); + msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); + msg.extendedheader->msin = (uint8_t)((DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) + | ((log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) | DLT_MSIN_VERB); msg.extendedheader->noar = 1; dlt_set_id(msg.extendedheader->apid, apid); dlt_set_id(msg.extendedheader->ctid, ctid); @@ -1941,11 +1918,11 @@ TEST(t_dlt_daemon_logstorage_write, normal) EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(daemon.storage_handle->config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_write(&daemon, &uconfig, - (unsigned char*)&(userheader), sizeof(DltUserHeader), - msg.headerbuffer + sizeof(DltStorageHeader), - (int)(msg.headersize - sizeof(DltStorageHeader)), - data, size)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_daemon_logstorage_write( + &daemon, &uconfig, (unsigned char*)&(userheader), sizeof(DltUserHeader), + msg.headerbuffer + sizeof(DltStorageHeader), (int)(msg.headersize - sizeof(DltStorageHeader)), data, size)); dlt_message_free(&msg, 0); } @@ -1960,12 +1937,10 @@ TEST(t_dlt_daemon_logstorage_write_v2, normal) int ecu_len = (int)strlen(ecu); DltLogStorage storage_handle; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id_v2(daemon.ecuid2, ecu, (uint8_t)ecu_len); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); daemon.storage_handle = &storage_handle; @@ -1998,7 +1973,7 @@ TEST(t_dlt_daemon_logstorage_write_v2, normal) DltMessageV2 msg; DltUserHeader userheader; - //int log_level = 4; + // int log_level = 4; dlt_user_set_userheader_v2(&userheader, DLT_USER_MESSAGE_LOG); dlt_message_init_v2(&msg, 0); size_t _hdrsz = 512; @@ -2007,28 +1982,28 @@ TEST(t_dlt_daemon_logstorage_write_v2, normal) msg.storageheadersizev2 = (int)sizeof(DltStorageHeaderV2); msg.baseheadersizev2 = (int)sizeof(DltBaseHeaderV2); msg.baseheaderextrasizev2 = 0; - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + msg.storageheadersizev2); - //msg.storageheaderv2 = (DltStorageHeaderV2 *)msg.headerbufferv2; - // dlt_set_storageheader_v2(&(msg.storageheaderv2), ecuid_len, ecuid); - msg.baseheaderv2 = (DltBaseHeaderV2 *)(msg.headerbufferv2 + sizeof(DltStorageHeaderV2)); - msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2|DLT_HTYP2_EH; + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + msg.storageheadersizev2); + // msg.storageheaderv2 = (DltStorageHeaderV2 *)msg.headerbufferv2; + // dlt_set_storageheader_v2(&(msg.storageheaderv2), ecuid_len, ecuid); + msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + sizeof(DltStorageHeaderV2)); + msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2 | DLT_HTYP2_EH; msg.baseheaderv2->mcnt = 0; dlt_message_set_extraparameters_v2(&msg, 0); /*msg.extendedheaderv2 = (DltExtendedHeaderV2 *)(msg.headerbufferv2 + sizeof(DltStorageHeaderV2) + sizeof(DltBaseHeaderV2) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.baseheaderv2.htyp2));*/ - //dlt_set_id_v2(&(msg.extendedheaderv2.apid), apid, apid_len); - //dlt_set_id_v2(&(msg.extendedheaderv2.ctid), ctid, ecuid_len); + // dlt_set_id_v2(&(msg.extendedheaderv2.apid), apid, apid_len); + // dlt_set_id_v2(&(msg.extendedheaderv2.ctid), ctid, ecuid_len); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(daemon.storage_handle->config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_write(&daemon, &uconfig, - (unsigned char*)&(userheader), sizeof(DltUserHeader), - msg.headerbufferv2 + sizeof(DltStorageHeaderV2), - (int)(msg.headersizev2 - (int32_t)sizeof(DltStorageHeaderV2)), - data, size)); + EXPECT_EQ( + DLT_RETURN_OK, dlt_daemon_logstorage_write( + &daemon, &uconfig, (unsigned char*)&(userheader), sizeof(DltUserHeader), + msg.headerbufferv2 + sizeof(DltStorageHeaderV2), + (int)(msg.headersizev2 - (int32_t)sizeof(DltStorageHeaderV2)), data, size)); dlt_message_free_v2(&msg, 0); } @@ -2052,12 +2027,10 @@ TEST(t_dlt_daemon_logstorage_setup_internal_storage, normal) char ecu[] = "ECU1"; char path[] = "/tmp"; - EXPECT_EQ(0, dlt_daemon_init(&daemon, - daemon_local.RingbufferMinSize, - daemon_local.RingbufferMaxSize, - daemon_local.RingbufferStepSize, - DLT_RUNTIME_DEFAULT_DIRECTORY, - DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + &daemon, daemon_local.RingbufferMinSize, daemon_local.RingbufferMaxSize, daemon_local.RingbufferStepSize, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); @@ -2144,18 +2117,18 @@ TEST(t_dlt_daemon_logstorage_get_device, normal) char path[] = "/tmp"; strncpy(daemon.storage_handle->device_mount_point, "/tmp", 5); - EXPECT_NE((DltLogStorage *)NULL, dlt_daemon_logstorage_get_device(&daemon, &daemon_local, path, 0)); + EXPECT_NE((DltLogStorage*)NULL, dlt_daemon_logstorage_get_device(&daemon, &daemon_local, path, 0)); } TEST(t_dlt_daemon_logstorage_get_device, null) { - EXPECT_EQ((DltLogStorage *)NULL, dlt_daemon_logstorage_get_device(NULL, NULL, NULL, 0)); + EXPECT_EQ((DltLogStorage*)NULL, dlt_daemon_logstorage_get_device(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_find_dlt_header*/ TEST(t_dlt_logstorage_find_dlt_header, normal) { - char data[] = { 'a', 'b', 'D', 'L', 'T', 0x01 }; + char data[] = {'a', 'b', 'D', 'L', 'T', 0x01}; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); config.cache = calloc(1, sizeof(data)); @@ -2170,7 +2143,7 @@ TEST(t_dlt_logstorage_find_dlt_header, normal) TEST(t_dlt_logstorage_find_dlt_header, null) { - char data[] = { 'N', 'o', 'H', 'e', 'a', 'd', 'e', 'r' }; + char data[] = {'N', 'o', 'H', 'e', 'a', 'd', 'e', 'r'}; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); config.cache = calloc(1, sizeof(data)); @@ -2186,7 +2159,7 @@ TEST(t_dlt_logstorage_find_dlt_header, null) /* Begin Method: dlt_logstorage::t_dlt_logstorage_find_last_dlt_header*/ TEST(t_dlt_logstorage_find_last_dlt_header, normal) { - char data[] = {'a','b','D','L','T',0x01}; + char data[] = {'a', 'b', 'D', 'L', 'T', 0x01}; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); config.cache = calloc(1, sizeof(data)); @@ -2202,12 +2175,11 @@ TEST(t_dlt_logstorage_find_last_dlt_header, normal) TEST(t_dlt_logstorage_find_last_dlt_header, null) { - char data[] = {'N','o','H','e','a','d','e','r'}; + char data[] = {'N', 'o', 'H', 'e', 'a', 'd', 'e', 'r'}; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); config.cache = calloc(1, sizeof(data)); - if (config.cache != NULL) - { + if (config.cache != NULL) { /* config.cache =(void *) "a,b,D,L,T,0x01"; */ memcpy(config.cache, data, sizeof(data)); EXPECT_EQ(-1, dlt_logstorage_find_last_dlt_header(config.cache, 0, sizeof(data))); @@ -2221,10 +2193,10 @@ TEST(t_dlt_logstorage_sync_to_file, normal) DltLogStorageUserConfig file_config; memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); file_config.logfile_timestamp = 0; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 6; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; DltNewestFileName newest_info; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); @@ -2242,41 +2214,42 @@ TEST(t_dlt_logstorage_sync_to_file, normal) config.file_size = 50; g_logstorage_cache_max = 16; unsigned int size = 10; - unsigned char data1[10] = {'a', 'b', 'D', 'L', 'T', 0x01 , 'c', 'd', 'e', 'f'}; + unsigned char data1[10] = {'a', 'b', 'D', 'L', 'T', 0x01, 'c', 'd', 'e', 'f'}; unsigned char data2[10] = "dlt_data1"; unsigned char data3[10] = "dlt_data2"; newest_info.wrap_id = 0; config.wrap_id = 0; - DltLogStorageCacheFooter *footer = NULL; + DltLogStorageCacheFooter* footer = NULL; config.cache = calloc(1, config.file_size + sizeof(DltLogStorageCacheFooter)); if (config.cache != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1, &newest_info)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, &file_config, path, - data1, size, data2, size, data3, size)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_logstorage_write_msg_cache(&config, &file_config, path, data1, size, data2, size, data3, size)); - footer = (DltLogStorageCacheFooter *)((uint8_t*)config.cache + config.file_size); + footer = (DltLogStorageCacheFooter*)((uint8_t*)config.cache + config.file_size); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_to_file(&config, &file_config, path, - footer, footer->last_sync_offset, footer->offset)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_logstorage_sync_to_file(&config, &file_config, path, footer, footer->last_sync_offset, footer->offset)); std::stringstream file_path; file_path << path << "/" << config.working_file_name; std::ifstream f(file_path.str()); - if (f.is_open()) - { + if (f.is_open()) { std::string line; EXPECT_TRUE(std::getline(f, line)); int idx = -2; // First 2 characters should not appear - for (auto i=2; i < 10; i++) - EXPECT_TRUE(line[i+idx] == data1[i]); + for (auto i = 2; i < 10; i++) + EXPECT_TRUE(line[i + idx] == data1[i]); idx += 10; - for (auto i=0; i < 10; i++) - EXPECT_TRUE(line[i+idx] == data2[i]); + for (auto i = 0; i < 10; i++) + EXPECT_TRUE(line[i + idx] == data2[i]); idx += 10; - for (auto i=0; i < 10; i++) - EXPECT_TRUE(line[i+idx] == data3[i]); + for (auto i = 0; i < 10; i++) + EXPECT_TRUE(line[i + idx] == data3[i]); f.close(); } free(config.cache); @@ -2289,7 +2262,6 @@ TEST(t_dlt_logstorage_sync_to_file, normal) TEST(t_dlt_logstorage_sync_to_file, null) { EXPECT_EQ(-1, dlt_logstorage_sync_to_file(NULL, NULL, NULL, NULL, 0, 1)); - } /* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_msg_cache*/ @@ -2298,10 +2270,10 @@ TEST(t_dlt_logstorage_sync_msg_cache, normal) DltLogStorageUserConfig file_config; memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); file_config.logfile_timestamp = 0; - file_config.logfile_delimiter = { '_' }; + file_config.logfile_delimiter = {'_'}; file_config.logfile_maxcounter = 8; file_config.logfile_counteridxlen = 2; - char *path = const_cast("/tmp"); + char* path = const_cast("/tmp"); DltLogStorageFilterConfig config; DltNewestFileName newest_info; @@ -2321,7 +2293,8 @@ TEST(t_dlt_logstorage_sync_msg_cache, normal) g_logstorage_cache_max = 16; unsigned int size = 10; - unsigned char data1[10] = {'a', 'b', 'D', 'L', 'T', 0x01 , 'c', 'd', 'e', 'f'};; + unsigned char data1[10] = {'a', 'b', 'D', 'L', 'T', 0x01, 'c', 'd', 'e', 'f'}; + ; unsigned char data2[10] = "dlt_dataB"; unsigned char data3[10] = "dlt_dataC"; @@ -2329,26 +2302,27 @@ TEST(t_dlt_logstorage_sync_msg_cache, normal) if (config.cache != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1, &newest_info)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, &file_config, path, data1, size, data2, size, data3, size)); - EXPECT_EQ(DLT_RETURN_OK, - dlt_logstorage_sync_msg_cache(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_DEMAND)); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_logstorage_write_msg_cache(&config, &file_config, path, data1, size, data2, size, data3, size)); + EXPECT_EQ( + DLT_RETURN_OK, dlt_logstorage_sync_msg_cache(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_DEMAND)); std::stringstream file_path; file_path << path << "/" << config.working_file_name; std::ifstream f(file_path.str()); - if (f.is_open()) - { + if (f.is_open()) { std::string line; EXPECT_TRUE(std::getline(f, line)); int idx = -2; // First 2 characters should not appear - for (auto i=2; i < 10; i++) - EXPECT_TRUE(line[i+idx] == data1[i]); + for (auto i = 2; i < 10; i++) + EXPECT_TRUE(line[i + idx] == data1[i]); idx += 10; - for (auto i=0; i < 10; i++) - EXPECT_TRUE(line[i+idx] == data2[i]); + for (auto i = 0; i < 10; i++) + EXPECT_TRUE(line[i + idx] == data2[i]); idx += 10; - for (auto i=0; i < 10; i++) - EXPECT_TRUE(line[i+idx] == data3[i]); + for (auto i = 0; i < 10; i++) + EXPECT_TRUE(line[i + idx] == data3[i]); f.close(); } free(config.cache); @@ -2368,18 +2342,16 @@ int connectServer(void) #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC int sockfd, portno; struct sockaddr_in serv_addr; - struct hostent *server; + struct hostent* server; portno = 8080; sockfd = socket(AF_INET, SOCK_STREAM, 0); server = gethostbyname("127.0.0.1"); - memset((char *) &serv_addr, 0, sizeof(serv_addr)); + memset((char*)&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - memcpy((char *)&serv_addr.sin_addr.s_addr, - (char *)server->h_addr, - server->h_length); + memcpy((char*)&serv_addr.sin_addr.s_addr, (char*)server->h_addr, server->h_length); serv_addr.sin_port = htons(portno); - if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { + if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { printf("Error: %s (%d) occured in connect socket\n", strerror(errno), errno); close(sockfd); return -1; @@ -2401,7 +2373,7 @@ int connectServer(void) #define GTEST_SOCKS_ACCEPTED 2 -int main(int argc, char **argv) +int main(int argc, char** argv) { #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC pid_t cpid; @@ -2426,7 +2398,7 @@ int main(int argc, char **argv) return -1; } - memset((char *) &serv_addr, 0, sizeof(serv_addr)); + memset((char*)&serv_addr, 0, sizeof(serv_addr)); portno = 8080; serv_addr.sin_family = AF_INET; @@ -2439,7 +2411,7 @@ int main(int argc, char **argv) exit(1); } - j = bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + j = bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); if (j == -1) { perror("Bind Error\n"); @@ -2451,7 +2423,7 @@ int main(int argc, char **argv) while (i) { clilen = sizeof(cli_addr); - newsockfd[i - 1] = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); + newsockfd[i - 1] = accept(sockfd, (struct sockaddr*)&cli_addr, &clilen); if (newsockfd[i - 1] == -1) { printf("Error in accept"); @@ -2467,12 +2439,11 @@ int main(int argc, char **argv) close(newsockfd[i]); close(sockfd); - } - else { + } else { #endif ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = false; -/* ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; */ + /* ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; */ return RUN_ALL_TESTS(); #ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC } diff --git a/tests/gtest_dlt_daemon_v2.cpp b/tests/gtest_dlt_daemon_v2.cpp index d1d338947..8319bdd66 100644 --- a/tests/gtest_dlt_daemon_v2.cpp +++ b/tests/gtest_dlt_daemon_v2.cpp @@ -58,8 +58,7 @@ #include #include -extern "C" -{ +extern "C" { #include "dlt-daemon.h" #include "dlt-daemon_cfg.h" #include "dlt_user_cfg.h" @@ -71,14 +70,15 @@ extern "C" const int _trace_load_send_size = 100; -static void init_daemon(DltDaemon* daemon, char* ecu) { +static void init_daemon(DltDaemon* daemon, char* ecu) +{ DltGateway gateway; strcpy(ecu, "ECU1"); - EXPECT_EQ(0, - dlt_daemon_init(daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF, 0, 0)); + EXPECT_EQ( + 0, dlt_daemon_init( + daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, + DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF, 0, 0)); dlt_set_id(daemon->ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(daemon, &gateway, 0, 0)); @@ -88,8 +88,10 @@ static void setup_trace_load_settings(DltDaemon& daemon) { daemon.preconfigured_trace_load_settings_count = 6; daemon.preconfigured_trace_load_settings = - (DltTraceLoadSettings *)malloc(daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); - memset(daemon.preconfigured_trace_load_settings, 0, daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); + (DltTraceLoadSettings*)malloc(daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); + memset( + daemon.preconfigured_trace_load_settings, 0, + daemon.preconfigured_trace_load_settings_count * sizeof(DltTraceLoadSettings)); // APP0 only has app id strcpy(daemon.preconfigured_trace_load_settings[0].apid, "APP0"); @@ -125,48 +127,51 @@ static void setup_trace_load_settings(DltDaemon& daemon) // APP3 is not configured at all, but will be added via application_add // to make sure we assign default value in that case - qsort(daemon.preconfigured_trace_load_settings, daemon.preconfigured_trace_load_settings_count, - sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); + qsort( + daemon.preconfigured_trace_load_settings, daemon.preconfigured_trace_load_settings_count, + sizeof(DltTraceLoadSettings), dlt_daemon_compare_trace_load_settings); } -TEST(t_trace_load_keep_message_v2, normal) { +TEST(t_trace_load_keep_message_v2, normal) +{ DltDaemon daemon; DltDaemonLocal daemon_local = {}; const int num_apps = 4; const char* app_ids[num_apps] = {"APP0", "APP1", "APP2", "APP3"}; - DltDaemonApplication *apps[num_apps] = {}; + DltDaemonApplication* apps[num_apps] = {}; char ecu[DLT_ID_SIZE] = {}; pid_t pid = 0; int fd = 15; - const char *desc = "HELLO_TEST"; + const char* desc = "HELLO_TEST"; const auto set_extended_header = [&daemon_local]() { - daemon_local.msg.extendedheader = (DltExtendedHeaderV2 *)(daemon_local.msg.headerbuffer + sizeof(DltStorageHeaderV2) + - sizeof(DltStandardHeaderV2)); + daemon_local.msg.extendedheader = + (DltExtendedHeaderV2*)(daemon_local.msg.headerbuffer + sizeof(DltStorageHeaderV2) + + sizeof(DltStandardHeaderV2)); memset(daemon_local.msg.extendedheader, 0, sizeof(DltExtendedHeaderV2)); }; const auto set_extended_header_log_level = [&daemon_local](unsigned int log_level) { - daemon_local.msg.extendedheader->msin = ((daemon_local.msg.extendedheader->msin) & ~DLT_MSIN_MTIN) | ((log_level) << DLT_MSIN_MTIN_SHIFT); + daemon_local.msg.extendedheader->msin = + ((daemon_local.msg.extendedheader->msin) & ~DLT_MSIN_MTIN) | ((log_level) << DLT_MSIN_MTIN_SHIFT); }; - const auto log_until_hard_limit_reached = [&daemon, &daemon_local] (DltDaemonApplication *app) { - while (trace_load_keep_message_v2(app, _trace_load_send_size, &daemon, &daemon_local, 0)); + const auto log_until_hard_limit_reached = [&daemon, &daemon_local](DltDaemonApplication* app) { + while (trace_load_keep_message_v2(app, _trace_load_send_size, &daemon, &daemon_local, 0)) + ; }; const auto check_debug_and_trace_can_log = [&](DltDaemonApplication* app) { // messages for debug and verbose logs are never dropped set_extended_header_log_level(DLT_LOG_VERBOSE); - EXPECT_TRUE(trace_load_keep_message_v2(app, - app->trace_load_settings->hard_limit * 10, - &daemon, &daemon_local, 0)); + EXPECT_TRUE( + trace_load_keep_message_v2(app, app->trace_load_settings->hard_limit * 10, &daemon, &daemon_local, 0)); set_extended_header_log_level(DLT_LOG_DEBUG); - EXPECT_TRUE(trace_load_keep_message_v2(app, - app->trace_load_settings->hard_limit * 10, - &daemon, &daemon_local, 0)); + EXPECT_TRUE( + trace_load_keep_message_v2(app, app->trace_load_settings->hard_limit * 10, &daemon, &daemon_local, 0)); set_extended_header_log_level(DLT_LOG_INFO); }; @@ -175,14 +180,14 @@ TEST(t_trace_load_keep_message_v2, normal) { setup_trace_load_settings_v2(daemon); for (int i = 0; i < num_apps; i++) { - apps[i] = dlt_daemon_application_add_v2(&daemon, (char *)app_ids[i], pid, (char *)desc, fd, ecu, 0); + apps[i] = dlt_daemon_application_add_v2(&daemon, (char*)app_ids[i], pid, (char*)desc, fd, ecu, 0); EXPECT_FALSE(apps[i]->trace_load_settings == NULL); } // messages without extended header will be kept daemon_local.msg.extendedheader = NULL; - EXPECT_TRUE(trace_load_keep_message_v2( - apps[0], apps[0]->trace_load_settings->soft_limit, &daemon, &daemon_local, 0)); + EXPECT_TRUE( + trace_load_keep_message_v2(apps[0], apps[0]->trace_load_settings->soft_limit, &daemon, &daemon_local, 0)); set_extended_header_v2(); check_debug_and_trace_can_log(apps[0]); @@ -224,8 +229,8 @@ TEST(t_trace_load_keep_message_v2, normal) { // Test not configured context memcpy(daemon_local.msg.extendedheader->ctid, "CTXX", DLT_ID_SIZE); EXPECT_EQ( - trace_load_keep_message_v2(apps[1], _trace_load_send_size, &daemon, &daemon_local, 0), - DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT != 0); + trace_load_keep_message_v2(apps[1], _trace_load_send_size, &daemon, &daemon_local, 0), + DLT_TRACE_LOAD_DAEMON_HARD_LIMIT_DEFAULT != 0); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -237,8 +242,7 @@ TEST(t_trace_load_keep_message_v2, normal) { - -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = true; diff --git a/tests/gtest_dlt_json_filter.cpp b/tests/gtest_dlt_json_filter.cpp index 6dc35e159..9ba637a29 100644 --- a/tests/gtest_dlt_json_filter.cpp +++ b/tests/gtest_dlt_json_filter.cpp @@ -3,10 +3,9 @@ #include #include -extern "C" -{ - #include "dlt-control-common.h" - #include "dlt-daemon.h" +extern "C" { +#include "dlt-control-common.h" +#include "dlt-daemon.h" } /* Begin Method: dlt_common::dlt_message_print_ascii with json filter*/ @@ -21,7 +20,7 @@ TEST(t_dlt_message_print_ascii_with_json_filter, normal) char openfile[114]; /* ignore returned value from getcwd */ - if (getcwd(pwd, 100) == NULL) {} + if (getcwd(pwd, 100) == NULL) { } char openfilter[117]; sprintf(openfile, "%s/testfile_extended.dlt", pwd); @@ -35,25 +34,25 @@ TEST(t_dlt_message_print_ascii_with_json_filter, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); - char tmp[DLT_ID_SIZE+1]; + char tmp[DLT_ID_SIZE + 1]; strncpy(tmp, filter.apid[0], DLT_ID_SIZE); tmp[DLT_ID_SIZE] = '\0'; - EXPECT_STREQ("LOG",tmp); - EXPECT_EQ(3,filter.log_level[0]); - EXPECT_EQ(0,filter.payload_min[0]); - EXPECT_EQ(INT32_MAX,filter.payload_max[0]); + EXPECT_STREQ("LOG", tmp); + EXPECT_EQ(3, filter.log_level[0]); + EXPECT_EQ(0, filter.payload_min[0]); + EXPECT_EQ(INT32_MAX, filter.payload_max[0]); strncpy(tmp, filter.apid[1], DLT_ID_SIZE); - EXPECT_STREQ("app",tmp); + EXPECT_STREQ("app", tmp); strncpy(tmp, filter.ctid[1], DLT_ID_SIZE); - EXPECT_STREQ("",tmp); + EXPECT_STREQ("", tmp); - EXPECT_EQ(0,filter.log_level[2]); - EXPECT_EQ(20,filter.payload_min[2]); - EXPECT_EQ(50,filter.payload_max[2]); + EXPECT_EQ(0, filter.log_level[2]); + EXPECT_EQ(20, filter.payload_min[2]); + EXPECT_EQ(50, filter.payload_max[2]); - while (dlt_file_read(&file, 0) >= 0) {} + while (dlt_file_read(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); @@ -79,7 +78,7 @@ TEST(t_dlt_message_print_ascii_with_json_filter_v2, normal) char openfile[114]; /* ignore returned value from getcwd */ - if (getcwd(pwd, 100) == NULL) {} + if (getcwd(pwd, 100) == NULL) { } char openfilter[117]; sprintf(openfile, "%s/testfile_extended.dlt", pwd); @@ -93,25 +92,25 @@ TEST(t_dlt_message_print_ascii_with_json_filter_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter_v2(&file, &filter, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open_v2(&file, openfile, 0)); - char tmp[DLT_ID_SIZE+1]; + char tmp[DLT_ID_SIZE + 1]; strncpy(tmp, filter.apid[0], DLT_ID_SIZE); tmp[DLT_ID_SIZE] = {}; - EXPECT_STREQ("LOG",tmp); - EXPECT_EQ(3,filter.log_level[0]); - EXPECT_EQ(0,filter.payload_min[0]); - EXPECT_EQ(INT32_MAX,filter.payload_max[0]); + EXPECT_STREQ("LOG", tmp); + EXPECT_EQ(3, filter.log_level[0]); + EXPECT_EQ(0, filter.payload_min[0]); + EXPECT_EQ(INT32_MAX, filter.payload_max[0]); strncpy(tmp, filter.apid[1], DLT_ID_SIZE); - EXPECT_STREQ("app",tmp); + EXPECT_STREQ("app", tmp); strncpy(tmp, filter.ctid[1], DLT_ID_SIZE); - EXPECT_STREQ("",tmp); + EXPECT_STREQ("", tmp); - EXPECT_EQ(0,filter.log_level[2]); - EXPECT_EQ(20,filter.payload_min[2]); - EXPECT_EQ(50,filter.payload_max[2]); + EXPECT_EQ(0, filter.log_level[2]); + EXPECT_EQ(20, filter.payload_min[2]); + EXPECT_EQ(50, filter.payload_max[2]); - while (dlt_file_read_v2(&file, 0) >= 0) {} + while (dlt_file_read_v2(&file, 0) >= 0) { } for (int i = 0; i < file.counter; i++) { EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0)); diff --git a/tests/gtest_dlt_shm.cpp b/tests/gtest_dlt_shm.cpp index 7260080b8..3fa8d07d0 100644 --- a/tests/gtest_dlt_shm.cpp +++ b/tests/gtest_dlt_shm.cpp @@ -1,13 +1,12 @@ #include -extern "C" -{ - #include "dlt_shm.h" +extern "C" { +#include "dlt_shm.h" } -DltShm *server_buf = (DltShm *)calloc(1, sizeof(DltShm)); -DltShm *client_buf = (DltShm *)calloc(1, sizeof(DltShm)); +DltShm* server_buf = (DltShm*)calloc(1, sizeof(DltShm)); +DltShm* client_buf = (DltShm*)calloc(1, sizeof(DltShm)); -char *dltShmNameTest = (char *)"dlt-shm-test"; +char* dltShmNameTest = (char*)"dlt-shm-test"; int size = 1000; /* Method: dlt_shm::t_dlt_shm_init_server */ @@ -58,7 +57,7 @@ TEST(t_dlt_shm_free_server, nullpointer) EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_shm_free_server(NULL, NULL)); } -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = false; diff --git a/tests/gtest_dlt_user.cpp b/tests/gtest_dlt_user.cpp index eb92defaf..35f93b76c 100644 --- a/tests/gtest_dlt_user.cpp +++ b/tests/gtest_dlt_user.cpp @@ -48,24 +48,20 @@ extern "C" { /* tested functions */ /* * int dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel); - * int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid); - * int dlt_user_log_write_finish(DltContextData *log); - * int dlt_user_log_write_bool(DltContextData *log, uint8_t data); - * int dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name); - * int dlt_user_log_write_float32(DltContextData *log, float32_t data); - * int dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit); - * int dlt_user_log_write_float64(DltContextData *log, double data); - * int dlt_user_log_write_float64_attr(DltContextData *log, double data, const char *name, const char *unit); - * int dlt_user_log_write_uint(DltContextData *log, unsigned int data); - * int dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit); - * int dlt_user_log_write_uint8(DltContextData *log, uint8_t data); - * int dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit); - * int dlt_user_log_write_uint16(DltContextData *log, uint16_t data); - * int dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit); - * int dlt_user_log_write_uint32(DltContextData *log, uint32_t data); - * int dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit); - * int dlt_user_log_write_uint64(DltContextData *log, uint64_t data); - * int dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit); + * int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t + * messageid); int dlt_user_log_write_finish(DltContextData *log); int dlt_user_log_write_bool(DltContextData *log, + * uint8_t data); int dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name); int + * dlt_user_log_write_float32(DltContextData *log, float32_t data); int dlt_user_log_write_float32_attr(DltContextData + * *log, float32_t data, const char *name, const char *unit); int dlt_user_log_write_float64(DltContextData *log, double + * data); int dlt_user_log_write_float64_attr(DltContextData *log, double data, const char *name, const char *unit); int + * dlt_user_log_write_uint(DltContextData *log, unsigned int data); int dlt_user_log_write_uint_attr(DltContextData + * *log, unsigned int data, const char *name, const char *unit); int dlt_user_log_write_uint8(DltContextData *log, + * uint8_t data); int dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char + * *unit); int dlt_user_log_write_uint16(DltContextData *log, uint16_t data); int + * dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit); int + * dlt_user_log_write_uint32(DltContextData *log, uint32_t data); int dlt_user_log_write_uint32_attr(DltContextData + * *log, uint32_t data, const char *name, const char *unit); int dlt_user_log_write_uint64(DltContextData *log, uint64_t + * data); int dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit); * int dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type); * int dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type); * int dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type); @@ -87,11 +83,11 @@ extern "C" { * int dlt_user_log_write_constant_string( DltContextData *log, const char *text); * int dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_sized_constant_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - * int dlt_user_log_write_utf8_string(DltContextData *log, const char *text); - * int dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); - * int dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); + * int dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char + * *name); int dlt_user_log_write_utf8_string(DltContextData *log, const char *text); int + * dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); int + * dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); int + * dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); * int dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text); * int dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text); @@ -99,7 +95,8 @@ extern "C" { * int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length); * int dlt_user_log_write_raw_attr(DltContextData *log,void *data,uint16_t length, const char *name); * int dlt_user_log_write_raw_formatted(DltContextData *log,void *data,uint16_t length,DltFormatType type); - * int dlt_user_log_write_raw_formatted_attr(DltContextData *log,void *data,uint16_t length,DltFormatType type, const char *name); + * int dlt_user_log_write_raw_formatted_attr(DltContextData *log,void *data,uint16_t length,DltFormatType type, const + * char *name); */ /* @@ -116,16 +113,19 @@ extern "C" { * int dlt_register_app(const char *apid, const char * description); * int dlt_unregister_app(void); * int dlt_register_context(DltContext *handle, const char *contextid, const char * description); - * int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus); - * int dlt_unregister_context(DltContext *handle); - * int dlt_register_injection_callback(DltContext *handle, uint32_t service_id, int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)); - * int dlt_register_log_level_changed_callback(DltContext *handle, void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE],uint8_t log_level, uint8_t trace_status)); + * int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int + * tracestatus); int dlt_unregister_context(DltContext *handle); int dlt_register_injection_callback(DltContext *handle, + * uint32_t service_id, int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)); int + * dlt_register_log_level_changed_callback(DltContext *handle, void (*dlt_log_level_changed_callback)(char + * context_id[DLT_ID_SIZE],uint8_t log_level, uint8_t trace_status)); */ /* - * int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload); - * int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate); - * int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload); + * int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, + * uint16_t payload_len, void *payload); int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType + * nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate); int + * dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void + * *header, uint16_t payload_len, void *payload); */ /* @@ -138,7 +138,7 @@ extern "C" { * int dlt_nonverbose_mode(void); */ -static const char *STR_TRUNCATED_MESSAGE = "... <>"; +static const char* STR_TRUNCATED_MESSAGE = "... <>"; /*/////////////////////////////////////// */ /* start initial dlt */ @@ -222,8 +222,9 @@ TEST(t_dlt_user_log_write_start, startstartfinish) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start startstartfinish")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start startstartfinish")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* shouldn't it return -1, because it is already started? */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); */ @@ -240,8 +241,8 @@ TEST(t_dlt_user_log_write_start, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start nullpointer")); /* NULL's */ EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_start(NULL, &contextData, DLT_LOG_DEFAULT)); /*EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_finish(&contextData)); */ @@ -318,16 +319,20 @@ TEST(t_dlt_user_log_write_start_id, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id abnormal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id abnormal")); /* undefined values for DltLogLevelType */ /* shouldn't it return -1? */ /* TODO: messageid = 0; */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)-100, messageid)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)-10, messageid)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)10, messageid)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)100, messageid)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)-100, + * messageid)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)-10, + * messageid)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)10, + * messageid)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, (DltLogLevelType)100, + * messageid)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -342,13 +347,15 @@ TEST(t_dlt_user_log_write_start_id, startstartfinish) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id startstartfinish")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id startstartfinish")); messageid = 0; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); /* shouldn't it return -1, because it is already started? */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, + * messageid)); */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); @@ -364,8 +371,8 @@ TEST(t_dlt_user_log_write_start_id, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id nullpointer")); /* NULL's */ messageid = 0; @@ -489,8 +496,8 @@ TEST(t_dlt_user_log_write_bool, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool nullpointer")); /* NULL */ data = true; @@ -509,7 +516,8 @@ TEST(t_dlt_user_log_write_bool_attr, normal) uint8_t data; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); data = true; @@ -563,8 +571,8 @@ TEST(t_dlt_user_log_write_float32, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float32 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float32 nullpointer")); /* NULL */ data = 1.; @@ -583,7 +591,8 @@ TEST(t_dlt_user_log_write_float32_attr, normal) float32_t data; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float32_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float32_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); data = 3.141592653589793238f; @@ -641,8 +650,8 @@ TEST(t_dlt_user_log_write_float64, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float64 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float64 nullpointer")); /* NULL */ data = 1.; @@ -661,7 +670,8 @@ TEST(t_dlt_user_log_write_float64_attr, normal) double data; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float64_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_float64_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); data = 3.14159265358979323846; @@ -734,8 +744,8 @@ TEST(t_dlt_user_log_write_uint, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint nullpointer")); /* NULL */ data = 1; @@ -754,7 +764,8 @@ TEST(t_dlt_user_log_write_uint_attr, normal) unsigned int data; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); data = 42; @@ -806,8 +817,8 @@ TEST(t_dlt_user_log_write_uint8, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8 nullpointer")); /* NULL */ data = 1; @@ -825,7 +836,8 @@ TEST(t_dlt_user_log_write_uint8_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); uint8_t data = 0xaa; @@ -877,8 +889,8 @@ TEST(t_dlt_user_log_write_uint16, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16 nullpointer")); /* NULL */ data = 1; @@ -896,7 +908,8 @@ TEST(t_dlt_user_log_write_uint16_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); uint16_t data = 0xaa55; @@ -948,8 +961,8 @@ TEST(t_dlt_user_log_write_uint32, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32 nullpointer")); /* NULL */ data = 1; @@ -967,7 +980,8 @@ TEST(t_dlt_user_log_write_uint32_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); uint32_t data = 0xaabbccdd; @@ -1019,8 +1033,8 @@ TEST(t_dlt_user_log_write_uint64, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64 nullpointer")); /* NULL */ data = 1; @@ -1038,7 +1052,8 @@ TEST(t_dlt_user_log_write_uint64_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); uint64_t data = 0x11223344aabbccddULL; @@ -1066,8 +1081,9 @@ TEST(t_dlt_user_log_write_uint8_formatted, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_formatted normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_formatted normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -1110,8 +1126,9 @@ TEST(t_dlt_user_log_write_uint8_formatted, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_formatted abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_formatted abnormal")); /* abnormal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -1134,8 +1151,9 @@ TEST(t_dlt_user_log_write_uint8_formatted, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_formatted nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint8_formatted nullpointer")); /* NULL */ data = 1; @@ -1162,8 +1180,9 @@ TEST(t_dlt_user_log_write_uint16_formatted, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_formatted normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_formatted normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -1206,13 +1225,15 @@ TEST(t_dlt_user_log_write_uint16_formatted, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_formatted abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_formatted abnormal")); /* abnormal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* TODO: data = 1; */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint16_formatted(&contextData, data, (DltFormatType)-100)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint16_formatted(&contextData, data, (DltFormatType)-100)); + */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint16_formatted(&contextData, data, (DltFormatType)-10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint16_formatted(&contextData, data, (DltFormatType)10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint16_formatted(&contextData, data, (DltFormatType)100)); */ @@ -1230,8 +1251,9 @@ TEST(t_dlt_user_log_write_uint16_formatted, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_formatted nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint16_formatted nullpointer")); /* NULL */ data = 1; @@ -1258,8 +1280,9 @@ TEST(t_dlt_user_log_write_uint32_formatted, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_formatted normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_formatted normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -1302,13 +1325,15 @@ TEST(t_dlt_user_log_write_uint32_formatted, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_formatted abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_formatted abnormal")); /* abnormal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* TODO: data = 1; */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint32_formatted(&contextData, data, (DltFormatType)-100)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint32_formatted(&contextData, data, (DltFormatType)-100)); + */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint32_formatted(&contextData, data, (DltFormatType)-10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint32_formatted(&contextData, data, (DltFormatType)10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint32_formatted(&contextData, data, (DltFormatType)100)); */ @@ -1326,8 +1351,9 @@ TEST(t_dlt_user_log_write_uint32_formatted, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_formatted nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint32_formatted nullpointer")); /* NULL */ data = 1; @@ -1354,8 +1380,9 @@ TEST(t_dlt_user_log_write_uint64_formatted, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_formatted normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_formatted normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -1398,13 +1425,15 @@ TEST(t_dlt_user_log_write_uint64_formatted, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_formatted abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_formatted abnormal")); /* abnormal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* TODO: data = 1; */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint64_formatted(&contextData, data, (DltFormatType)-100)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint64_formatted(&contextData, data, (DltFormatType)-100)); + */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint64_formatted(&contextData, data, (DltFormatType)-10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint64_formatted(&contextData, data, (DltFormatType)10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_uint64_formatted(&contextData, data, (DltFormatType)100)); */ @@ -1422,8 +1451,9 @@ TEST(t_dlt_user_log_write_uint64_formatted, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_formatted nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_uint64_formatted nullpointer")); /* NULL */ data = 1; @@ -1552,8 +1582,8 @@ TEST(t_dlt_user_log_write_int8, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int8 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int8 nullpointer")); /* NULL */ data = 1; @@ -1571,7 +1601,8 @@ TEST(t_dlt_user_log_write_int8_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int8_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int8_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); int8_t data = static_cast(0xaa); @@ -1627,8 +1658,8 @@ TEST(t_dlt_user_log_write_int16, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int16 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int16 nullpointer")); /* NULL */ data = 1; @@ -1646,7 +1677,8 @@ TEST(t_dlt_user_log_write_int16_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int16_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int16_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); int16_t data = static_cast(0xaa55); @@ -1702,8 +1734,8 @@ TEST(t_dlt_user_log_write_int32, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int32 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int32 nullpointer")); /* NULL */ data = 1; @@ -1721,7 +1753,8 @@ TEST(t_dlt_user_log_write_int32_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int32_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int32_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); int32_t data = 0xffeeddcc; @@ -1777,8 +1810,8 @@ TEST(t_dlt_user_log_write_int64, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int64 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int64 nullpointer")); /* NULL */ data = 1; @@ -1796,7 +1829,8 @@ TEST(t_dlt_user_log_write_int64_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int64_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_int64_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); int64_t data = 0xffeeddcc44332211LL; @@ -1825,9 +1859,9 @@ TEST(t_dlt_user_log_write_string, normal) /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_string(&contextData, text1)); - const char *text2 = ""; + const char* text2 = ""; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_string(&contextData, text2)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -1851,22 +1885,25 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th uint16_t send_message_length = 0; uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; - char *message = NULL; - char *expected_message = NULL; + char* message = NULL; + char* expected_message = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string normal_dlt_log_msg_truncated_because_exceed_the_buffer_length_in_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_string " + "normal_dlt_log_msg_truncated_because_exceed_the_buffer_length_in_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* Create the message exceed buffer length 10 bytes */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -1880,12 +1917,13 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '#'; } @@ -1893,7 +1931,7 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -1921,24 +1959,27 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th uint16_t send_message_length = 0; uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; - char *message = NULL; - char *expected_message = NULL; + char* message = NULL; + char* expected_message = NULL; dlt_nonverbose_mode(); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string normal_dlt_log_msg_truncated_because_exceed_the_buffer_length_in_non_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_string " + "normal_dlt_log_msg_truncated_because_exceed_the_buffer_length_in_non_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* Create the message exceed buffer length 10 bytes */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -1952,12 +1993,13 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '#'; } @@ -1965,7 +2007,7 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -1987,7 +2029,9 @@ TEST(t_dlt_user_log_write_string, normal_dlt_log_msg_truncated_because_exceed_th * the end of received message. * Note: dlt_init() will be called after testcase is finished to restore environment for other test cases */ -TEST(t_dlt_user_log_write_string, normal_message_truncated_because_exceed_buffer_length_and_reduce_msg_buf_len_by_env_variable) +TEST( + t_dlt_user_log_write_string, + normal_message_truncated_because_exceed_buffer_length_and_reduce_msg_buf_len_by_env_variable) { DltContext context; DltContextData contextData; @@ -1996,13 +2040,14 @@ TEST(t_dlt_user_log_write_string, normal_message_truncated_because_exceed_buffer uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t user_message_after_truncated_size = 0; - const char *message = "$$$$###############################################"; - char *expected_message = NULL; + const char* message = "$$$$###############################################"; + char* expected_message = NULL; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable * to simulate use case the dlt user buffer size only available 4 bytes for store user message. - * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user message + 1 byte NULL terminator. + * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user + * message + 1 byte NULL terminator. */ user_message_after_truncated_size = 4; EXPECT_EQ(DLT_RETURN_OK, dlt_free()); @@ -2010,7 +2055,12 @@ TEST(t_dlt_user_log_write_string, normal_message_truncated_because_exceed_buffer EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string normal_message_truncated_because_exceed_buffer_length_and_reduce_msg_buf_len_by_env_variable")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_string " + "normal_message_truncated_because_exceed_buffer_length_and_reduce_msg_buf_len_by_env_variable")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2026,17 +2076,21 @@ TEST(t_dlt_user_log_write_string, normal_message_truncated_because_exceed_buffer /* Create the expected message */ expected_message_length = static_cast(user_message_after_truncated_size + str_truncate_message_length); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; for (index = 0; index < fill_len; index++) { expected_message[index] = '$'; } /* Use memcpy for the truncated message, but ensure we do not overflow and always null-terminate */ - if (str_truncate_message_length > 0 && (user_message_after_truncated_size + str_truncate_message_length) <= expected_message_length) { - memcpy(expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length - 1); + if (str_truncate_message_length > 0 + && (user_message_after_truncated_size + str_truncate_message_length) <= expected_message_length) { + memcpy( + expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, + str_truncate_message_length - 1); expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; } else if ((user_message_after_truncated_size + str_truncate_message_length - 1) < expected_message_length) { /* fallback: copy as much as possible, then null-terminate */ @@ -2046,7 +2100,7 @@ TEST(t_dlt_user_log_write_string, normal_message_truncated_because_exceed_buffer } else if (expected_message_length > 0) { expected_message[expected_message_length - 1] = '\0'; } - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -2060,9 +2114,9 @@ TEST(t_dlt_user_log_write_string, normal_message_truncated_because_exceed_buffer } /** - * Set DLT_USER_ENV_LOG_MSG_BUF_LEN to 35 bytes and send a message which has the length exceed DLT_USER_ENV_LOG_MSG_BUF_LEN - * Expectation: dlt_user_log_write_string() will be returned DLT_RETURN_USER_BUFFER_FULL because the DLT_USER_ENV_LOG_MSG_BUF_LEN - * does not have enough space to store truncate message STR_TRUNCATED_MESSAGE + * Set DLT_USER_ENV_LOG_MSG_BUF_LEN to 35 bytes and send a message which has the length exceed + * DLT_USER_ENV_LOG_MSG_BUF_LEN Expectation: dlt_user_log_write_string() will be returned DLT_RETURN_USER_BUFFER_FULL + * because the DLT_USER_ENV_LOG_MSG_BUF_LEN does not have enough space to store truncate message STR_TRUNCATED_MESSAGE * Note: dlt_init() will be called after testcase is finished to restore environment for other test cases */ TEST(t_dlt_user_log_write_string, normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_does_not_enough_space_for_truncated_message) @@ -2070,19 +2124,23 @@ TEST(t_dlt_user_log_write_string, normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_does_not_e DltContext context; DltContextData contextData; uint16_t package_description_size = 0; - const char *message = "################################################################################"; + const char* message = "################################################################################"; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable - * to simulate use case the dlt user buffer size not enough minimum space to store data even the truncate notice message. - * Note: The minimum buffer to store the truncate notice message is 42 bytes. + * to simulate use case the dlt user buffer size not enough minimum space to store data even the truncate notice + * message. Note: The minimum buffer to store the truncate notice message is 42 bytes. */ EXPECT_EQ(DLT_RETURN_OK, dlt_free()); setenv(DLT_USER_ENV_LOG_MSG_BUF_LEN, "35", 1); EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_does_not_enough_space_for_truncated_message")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_string " + "normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_does_not_enough_space_for_truncated_message")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2094,7 +2152,7 @@ TEST(t_dlt_user_log_write_string, normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_does_not_e * package_description_size = Type info (32 bits) + Description of data payload of type string (16 bits) */ package_description_size = sizeof(uint32_t) + sizeof(uint16_t); - ASSERT_STREQ("", (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ("", (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); @@ -2107,29 +2165,32 @@ TEST(t_dlt_user_log_write_string, normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_does_not_e } /** - * Set DLT_USER_ENV_LOG_MSG_BUF_LEN to 42 bytes and send a message which has the length exceed DLT_USER_ENV_LOG_MSG_BUF_LEN - * Expectation: dlt_user_log_write_string() will be returned DLT_RETURN_USER_BUFFER_FULL and - * receive message will be STR_TRUNCATED_MESSAGE - * Note: dlt_init() will be called after testcase is finished to restore environment for other test cases + * Set DLT_USER_ENV_LOG_MSG_BUF_LEN to 42 bytes and send a message which has the length exceed + * DLT_USER_ENV_LOG_MSG_BUF_LEN Expectation: dlt_user_log_write_string() will be returned DLT_RETURN_USER_BUFFER_FULL + * and receive message will be STR_TRUNCATED_MESSAGE Note: dlt_init() will be called after testcase is finished to + * restore environment for other test cases */ TEST(t_dlt_user_log_write_string, normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_fix_truncate_message) { DltContext context; DltContextData contextData; uint16_t package_description_size = 0; - const char *message = "################################################################################"; + const char* message = "################################################################################"; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable * to simulate use case the dlt user buffer size just fixed to truncate message STR_TRUNCATED_MESSAGE - * Note: 42 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 1 byte NULL terminator. + * Note: 42 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 1 byte NULL + * terminator. */ EXPECT_EQ(DLT_RETURN_OK, dlt_free()); setenv(DLT_USER_ENV_LOG_MSG_BUF_LEN, "42", 1); EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_fix_truncate_message")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_fix_truncate_message")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2141,7 +2202,7 @@ TEST(t_dlt_user_log_write_string, normal_DLT_USER_ENV_LOG_MSG_BUF_LEN_fix_trunca * package_description_size = Type info (32 bits) + Description of data payload of type string (16 bits) */ package_description_size = sizeof(uint32_t) + sizeof(uint16_t); - ASSERT_STREQ(STR_TRUNCATED_MESSAGE, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(STR_TRUNCATED_MESSAGE, (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); @@ -2159,11 +2220,11 @@ TEST(t_dlt_user_log_write_string, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string nullpointer")); /* NULL */ - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_string(NULL, text1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_string(NULL, NULL)); @@ -2183,13 +2244,13 @@ TEST(t_dlt_user_log_write_sized_string, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_string normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_string normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); const char text1[] = "TheQuickBrownFox"; - const char *arg1_start = strchr(text1, 'Q'); + const char* arg1_start = strchr(text1, 'Q'); const size_t arg1_len = 5; /* from the above string, send only the substring "Quick" */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_string(&contextData, arg1_start, arg1_len)); @@ -2209,14 +2270,15 @@ TEST(t_dlt_user_log_write_constant_string, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string(&contextData, text1)); - const char *text2 = ""; + const char* text2 = ""; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_string(&contextData, text2)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -2230,7 +2292,9 @@ TEST(t_dlt_user_log_write_constant_string, normal) * message will be truncated and appended STR_TRUNCATED_MESSAGE at * the end of received message. */ -TEST(t_dlt_user_log_write_constant_string, normal_too_long_message_is_truncated_and_appended_notice_message_in_verbose_mode) +TEST( + t_dlt_user_log_write_constant_string, + normal_too_long_message_is_truncated_and_appended_notice_message_in_verbose_mode) { DltContext context; DltContextData contextData; @@ -2240,11 +2304,15 @@ TEST(t_dlt_user_log_write_constant_string, normal_too_long_message_is_truncated_ uint16_t send_message_length = 0; uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; - char *message = NULL; - char *expected_message = NULL; + char* message = NULL; + char* expected_message = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string normal_too_long_message_is_truncated_and_appended_notice_message_in_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_constant_string " + "normal_too_long_message_is_truncated_and_appended_notice_message_in_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2258,29 +2326,29 @@ TEST(t_dlt_user_log_write_constant_string, normal_too_long_message_is_truncated_ /* Create the message exceed DLT_USER_ENV_LOG_MSG_BUF_LEN 10 bytes */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length); /* Fill the safe region with '#' and append the truncated message */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; memset(expected_message, '#', fill_len); strncpy(expected_message + fill_len, STR_TRUNCATED_MESSAGE, str_truncate_message_length); expected_message[fill_len + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_constant_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -2300,12 +2368,15 @@ TEST(t_dlt_user_log_write_constant_string, normal_do_nothing_in_non_verbose_mode { DltContext context; DltContextData contextData; - const char *message = "message"; + const char* message = "message"; dlt_nonverbose_mode(); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string normal_do_nothing_in_non_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string normal_do_nothing_in_non_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2325,11 +2396,12 @@ TEST(t_dlt_user_log_write_constant_string, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string nullpointer")); /* NULL */ - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_constant_string(NULL, text1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_constant_string(NULL, NULL)); @@ -2349,13 +2421,14 @@ TEST(t_dlt_user_log_write_sized_constant_string, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_string normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_string normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); const char text1[] = "TheQuickBrownFox"; - const char *arg1_start = strchr(text1, 'Q'); + const char* arg1_start = strchr(text1, 'Q'); const size_t arg1_len = 5; /* from the above string, send only the substring "Quick" */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_string(&contextData, arg1_start, arg1_len)); @@ -2375,14 +2448,14 @@ TEST(t_dlt_user_log_write_utf8_string, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_utf8_string(&contextData, text1)); - const char *text2 = ""; + const char* text2 = ""; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_utf8_string(&contextData, text2)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -2406,22 +2479,26 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1byte_in uint16_t send_message_length = 0; uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; - char *message = NULL; - char *expected_message = NULL; + char* message = NULL; + char* expected_message = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_1byte_in_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_1byte_in_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message exceed buffer length 10 bytes which have '$' character (utf-8 1 byte) right before truncate position */ + /* Create the message exceed buffer length 10 bytes which have '$' character (utf-8 1 byte) right before truncate + * position */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -2439,7 +2516,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1byte_in /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length); @@ -2451,7 +2528,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1byte_in expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -2479,24 +2556,28 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1byte_in uint16_t send_message_length = 0; uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; - char *message = NULL; - char *expected_message = NULL; + char* message = NULL; + char* expected_message = NULL; dlt_nonverbose_mode(); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_1byte_in_non_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_1byte_in_non_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message exceed buffer length 10 bytes which have '$' character (utf-8 1 byte) right before truncate position */ + /* Create the message exceed buffer length 10 bytes which have '$' character (utf-8 1 byte) right before truncate + * position */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -2515,12 +2596,11 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1byte_in /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length); - for (index = 0; index < (user_message_after_truncated_size - 1); index++) - { + for (index = 0; index < (user_message_after_truncated_size - 1); index++) { expected_message[index] = '#'; } expected_message[user_message_after_truncated_size - 1] = '$'; @@ -2528,7 +2608,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1byte_in expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -2559,13 +2639,14 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1bytes_a uint16_t expected_message_length = 0; uint16_t str_truncate_message_length = 0; uint16_t user_message_after_truncated_size = 0; - const char *message = "$$$$###############################################"; - char *expected_message = NULL; + const char* message = "$$$$###############################################"; + char* expected_message = NULL; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable * to simulate use case the dlt user buffer size only available 4 bytes for store user message. - * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user message + 1 byte NULL terminator. + * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user + * message + 1 byte NULL terminator. */ user_message_after_truncated_size = 4; EXPECT_EQ(DLT_RETURN_OK, dlt_free()); @@ -2573,7 +2654,11 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1bytes_a EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_1bytes_and_reduce_msg_buf_len_by_env_variable")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string " + "normal_message_truncated_at_utf8_1bytes_and_reduce_msg_buf_len_by_env_variable")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2589,19 +2674,19 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_1bytes_a /* Create the expected message */ expected_message_length = static_cast(user_message_after_truncated_size + str_truncate_message_length); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '$'; } strncpy(expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -2632,23 +2717,27 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_i uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *utf8_2byte_character = "¢"; - char *message = NULL; - char *expected_message = NULL; + const char* utf8_2byte_character = "¢"; + char* message = NULL; + char* expected_message = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_2bytes_in_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_2bytes_in_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message contain the '¢' (2 bytes utf-8 character) and last byte of this character is exceed buffer length */ + /* Create the message contain the '¢' (2 bytes utf-8 character) and last byte of this character is exceed buffer + * length */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -2665,17 +2754,21 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_i */ str_truncate_message_length = static_cast(strlen(STR_TRUNCATED_MESSAGE) + 1); remaining_byte_truncated_utf8_character = 1; - index = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length - remaining_byte_truncated_utf8_character); + index = static_cast( + DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length + - remaining_byte_truncated_utf8_character); memcpy(message + index, utf8_2byte_character, strlen(utf8_2byte_character)); /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = static_cast( + expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; for (index = 0; index < fill_len; index++) { expected_message[index] = '#'; } @@ -2683,7 +2776,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_i expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -2713,25 +2806,29 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_i uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *utf8_2byte_character = "¢"; - char *message = NULL; - char *expected_message = NULL; + const char* utf8_2byte_character = "¢"; + char* message = NULL; + char* expected_message = NULL; dlt_nonverbose_mode(); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_2bytes_in_non_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_2bytes_in_non_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message contain the '¢' (2 bytes utf-8 character) and last byte of this character is exceed buffer length */ + /* Create the message contain the '¢' (2 bytes utf-8 character) and last byte of this character is exceed buffer + * length */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -2748,17 +2845,21 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_i */ str_truncate_message_length = static_cast(strlen(STR_TRUNCATED_MESSAGE) + 1); remaining_byte_truncated_utf8_character = 1; - index = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length - remaining_byte_truncated_utf8_character); + index = static_cast( + DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length + - remaining_byte_truncated_utf8_character); memcpy(message + index, utf8_2byte_character, strlen(utf8_2byte_character)); /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(DLT_USER_BUF_MAX_SIZE)); + expected_message = (char*)(malloc(DLT_USER_BUF_MAX_SIZE)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = static_cast( + expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; for (index = 0; index < fill_len; index++) { expected_message[index] = '#'; } @@ -2766,7 +2867,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_i expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -2799,13 +2900,14 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_a uint16_t package_description_size = 0; uint16_t user_message_after_truncated_size = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *message = "$$$¢###############################################"; - char *expected_message = NULL; + const char* message = "$$$¢###############################################"; + char* expected_message = NULL; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable * to simulate use case the dlt user buffer size only available 4 bytes for store user message. - * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user message + 1 byte NULL terminator. + * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user + * message + 1 byte NULL terminator. */ user_message_after_truncated_size = 4; EXPECT_EQ(DLT_RETURN_OK, dlt_free()); @@ -2813,7 +2915,11 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_a EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_2bytes_and_reduce_msg_buf_len_by_env_variable")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string " + "normal_message_truncated_at_utf8_2bytes_and_reduce_msg_buf_len_by_env_variable")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -2829,21 +2935,23 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_2bytes_a /* Create the expected message */ remaining_byte_truncated_utf8_character = 1; - expected_message_length = static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character + str_truncate_message_length); - expected_message = (char *)(malloc(expected_message_length)); + expected_message_length = static_cast( + user_message_after_truncated_size - remaining_byte_truncated_utf8_character + str_truncate_message_length); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = + static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '$'; } strncpy(expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -2875,23 +2983,27 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_i uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *utf8_3byte_character = "€"; - char *message = NULL; - char *expected_message = NULL; + const char* utf8_3byte_character = "€"; + char* message = NULL; + char* expected_message = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_3bytes_in_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_3bytes_in_verbose_mode")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message contain the '€' (3 bytes utf-8 character) and last byte of this character is exceed buffer length */ + /* Create the message contain the '€' (3 bytes utf-8 character) and last byte of this character is exceed buffer + * length */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -2908,35 +3020,40 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_i */ str_truncate_message_length = static_cast(strlen(STR_TRUNCATED_MESSAGE) + 1); remaining_byte_truncated_utf8_character = 2; - index = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length - remaining_byte_truncated_utf8_character); + index = static_cast( + DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length + - remaining_byte_truncated_utf8_character); /* Ensure we do not overflow the buffer when copying utf8_3byte_character */ size_t max_utf8_copy = send_message_length - index - 1; /* leave space for null-terminator */ size_t utf8_len = strlen(utf8_3byte_character); - if (utf8_len > max_utf8_copy) utf8_len = max_utf8_copy; + if (utf8_len > max_utf8_copy) + utf8_len = max_utf8_copy; memcpy(message + index, utf8_3byte_character, utf8_len); message[send_message_length - 1] = '\0'; /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); if (expected_message != NULL) { memset(expected_message, 0, expected_message_length); } ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = static_cast( + expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '#'; } /* Use memcpy for the truncated message, then null-terminate */ - memcpy(expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length - 1); + memcpy( + expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length - 1); expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -2966,25 +3083,29 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_i uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *utf8_3byte_character = "€"; - char *message = NULL; - char *expected_message = NULL; + const char* utf8_3byte_character = "€"; + char* message = NULL; + char* expected_message = NULL; dlt_nonverbose_mode(); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_3bytes_in_non_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_3bytes_in_non_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message contain the '€' (3 bytes utf-8 character) and last byte of this character is exceed buffer length */ + /* Create the message contain the '€' (3 bytes utf-8 character) and last byte of this character is exceed buffer + * length */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -3001,19 +3122,22 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_i */ str_truncate_message_length = static_cast(strlen(STR_TRUNCATED_MESSAGE) + 1); remaining_byte_truncated_utf8_character = 2; - index = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length - remaining_byte_truncated_utf8_character); + index = static_cast( + DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length + - remaining_byte_truncated_utf8_character); memcpy(message + index, utf8_3byte_character, strlen(utf8_3byte_character)); /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = static_cast( + expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '#'; } /* Use memcpy for the truncated message, but ensure we do not overflow and always null-terminate */ @@ -3029,7 +3153,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_i } EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -3062,13 +3186,14 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_a uint16_t package_description_size = 0; uint16_t user_message_after_truncated_size = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *message = "$$€###############################################"; - char *expected_message = NULL; + const char* message = "$$€###############################################"; + char* expected_message = NULL; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable * to simulate use case the dlt user buffer size only available 4 bytes for store user message. - * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user message + 1 byte NULL terminator. + * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user + * message + 1 byte NULL terminator. */ user_message_after_truncated_size = 4; EXPECT_EQ(DLT_RETURN_OK, dlt_free()); @@ -3076,7 +3201,11 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_a EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_3bytes_and_reduce_msg_buf_len_by_env_variable")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string " + "normal_message_truncated_at_utf8_3bytes_and_reduce_msg_buf_len_by_env_variable")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -3092,20 +3221,22 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_3bytes_a /* Create the expected message */ remaining_byte_truncated_utf8_character = 2; - expected_message_length = static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character + str_truncate_message_length); - expected_message = (char *)(malloc(expected_message_length)); + expected_message_length = static_cast( + user_message_after_truncated_size - remaining_byte_truncated_utf8_character + str_truncate_message_length); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = + static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '$'; } memcpy(expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -3137,22 +3268,26 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_i uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - char *message = NULL; - char *expected_message = NULL; + char* message = NULL; + char* expected_message = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_4bytes_in_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_4bytes_in_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message contain the '𐍈' (4 bytes utf-8 character) and last byte of this character is exceed buffer length */ + /* Create the message contain the '𐍈' (4 bytes utf-8 character) and last byte of this character is exceed buffer + * length */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -3169,25 +3304,29 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_i */ str_truncate_message_length = static_cast(strlen(STR_TRUNCATED_MESSAGE) + 1); remaining_byte_truncated_utf8_character = 3; - const char *utf8_4byte_character = "𐍈"; - index = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length - remaining_byte_truncated_utf8_character); + const char* utf8_4byte_character = "𐍈"; + index = static_cast( + DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length + - remaining_byte_truncated_utf8_character); /* Ensure we do not overflow the buffer when copying utf8_4byte_character */ size_t max_utf8_copy = send_message_length - index - 1; /* leave space for null-terminator */ size_t utf8_len = strlen(utf8_4byte_character); - if (utf8_len > max_utf8_copy) utf8_len = max_utf8_copy; + if (utf8_len > max_utf8_copy) + utf8_len = max_utf8_copy; memcpy(message + index, utf8_4byte_character, utf8_len); message[send_message_length - 1] = '\0'; /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = static_cast( + expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '#'; } /* Use memcpy for the truncated message, but ensure we do not overflow and always null-terminate */ @@ -3203,7 +3342,7 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_i } EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -3233,25 +3372,29 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_i uint16_t str_truncate_message_length = 0; uint16_t expected_message_length = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *utf8_4byte_character = "𐍈"; - char *message = NULL; - char *expected_message = NULL; + const char* utf8_4byte_character = "𐍈"; + char* message = NULL; + char* expected_message = NULL; dlt_nonverbose_mode(); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_4bytes_in_non_verbose_mode")); + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_4bytes_in_non_verbose_mode")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); - /* Create the message contain the '𐍈' (4 bytes utf-8 character) and last byte of this character is exceed buffer length */ + /* Create the message contain the '𐍈' (4 bytes utf-8 character) and last byte of this character is exceed buffer + * length */ send_message_length = DLT_USER_BUF_MAX_SIZE + 10; - message = (char *)(malloc(send_message_length)); + message = (char*)(malloc(send_message_length)); ASSERT_TRUE(message != NULL) << "Failed to allocate memory."; - for (index = 0; index < send_message_length; index++) - { + for (index = 0; index < send_message_length; index++) { message[index] = '#'; } message[send_message_length - 1] = '\0'; @@ -3268,26 +3411,29 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_i */ str_truncate_message_length = static_cast(strlen(STR_TRUNCATED_MESSAGE) + 1); remaining_byte_truncated_utf8_character = 3; - index = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length - remaining_byte_truncated_utf8_character); + index = static_cast( + DLT_USER_BUF_MAX_SIZE - package_description_size - str_truncate_message_length + - remaining_byte_truncated_utf8_character); memcpy(message + index, utf8_4byte_character, strlen(utf8_4byte_character)); /* Create the expected message */ expected_message_length = static_cast(DLT_USER_BUF_MAX_SIZE - package_description_size); - expected_message = (char *)(malloc(expected_message_length)); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; - user_message_after_truncated_size = static_cast(expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); + user_message_after_truncated_size = static_cast( + expected_message_length - str_truncate_message_length - remaining_byte_truncated_utf8_character); /* Ensure we do not write past the allocated buffer */ - size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : expected_message_length; - for (index = 0; index < fill_len && index < expected_message_length; index++) - { + size_t fill_len = user_message_after_truncated_size < expected_message_length ? user_message_after_truncated_size : + expected_message_length; + for (index = 0; index < fill_len && index < expected_message_length; index++) { expected_message[index] = '#'; } strncpy(expected_message + user_message_after_truncated_size, STR_TRUNCATED_MESSAGE, str_truncate_message_length); expected_message[user_message_after_truncated_size + str_truncate_message_length - 1] = '\0'; EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, dlt_user_log_write_utf8_string(&contextData, message)); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); free(message); message = NULL; @@ -3319,13 +3465,14 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_a uint16_t package_description_size = 0; uint16_t user_message_after_truncated_size = 0; uint16_t remaining_byte_truncated_utf8_character = 0; - const char *message = "$𐍈###############################################"; - char *expected_message = NULL; + const char* message = "$𐍈###############################################"; + char* expected_message = NULL; /** * Re-initialize the dlt with dlt user buffer size from DLT_USER_ENV_LOG_MSG_BUF_LEN environment variable * to simulate use case the dlt user buffer size only available 4 bytes for store user message. - * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user message + 1 byte NULL terminator. + * Note: 46 bytes = package_description_size (6 bytes) + str_truncated_message_length (35 bytes) + 4 bytes user + * message + 1 byte NULL terminator. */ user_message_after_truncated_size = 4; EXPECT_EQ(DLT_RETURN_OK, dlt_free()); @@ -3333,7 +3480,11 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_a EXPECT_EQ(DLT_RETURN_OK, dlt_init()); EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string normal_message_truncated_at_utf8_4bytes_and_reduce_msg_buf_len_by_env_variable")); + EXPECT_EQ( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", + "dlt_user.c t_dlt_user_log_write_utf8_string " + "normal_message_truncated_at_utf8_4bytes_and_reduce_msg_buf_len_by_env_variable")); /* Normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -3349,14 +3500,15 @@ TEST(t_dlt_user_log_write_utf8_string, normal_message_truncated_at_utf8_4bytes_a /* Create the expected message */ remaining_byte_truncated_utf8_character = 3; - expected_message_length = static_cast(user_message_after_truncated_size - remaining_byte_truncated_utf8_character + str_truncate_message_length); - expected_message = (char *)(malloc(expected_message_length)); + expected_message_length = static_cast( + user_message_after_truncated_size - remaining_byte_truncated_utf8_character + str_truncate_message_length); + expected_message = (char*)(malloc(expected_message_length)); ASSERT_TRUE(expected_message != NULL) << "Failed to allocate memory."; expected_message[0] = '$'; strncpy(expected_message + 1, STR_TRUNCATED_MESSAGE, str_truncate_message_length); - ASSERT_STREQ(expected_message, (char *)(contextData.buffer + package_description_size)); + ASSERT_STREQ(expected_message, (char*)(contextData.buffer + package_description_size)); EXPECT_EQ(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -3376,11 +3528,12 @@ TEST(t_dlt_user_log_write_utf8_string, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string nullpointer")); /* NULL */ - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_utf8_string(NULL, text1)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_utf8_string(NULL, NULL)); @@ -3400,8 +3553,9 @@ TEST(t_dlt_user_log_write_sized_utf8_string, partial_string) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -3422,11 +3576,12 @@ TEST(t_dlt_user_log_write_sized_utf8_string, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string nullpointer")); /* NULL */ - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_sized_utf8_string(NULL, text1, 5)); EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_sized_utf8_string(NULL, NULL, 5)); @@ -3445,10 +3600,11 @@ TEST(t_dlt_user_log_write_constant_utf8_string, verbose) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string verbose")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string verbose")); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, text1)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -3463,10 +3619,11 @@ TEST(t_dlt_user_log_write_constant_utf8_string, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nullpointer")); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_TRUE, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(NULL, text1)); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(NULL, NULL)); @@ -3485,10 +3642,11 @@ TEST(t_dlt_user_log_write_constant_utf8_string, nonverbose) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nonverbose")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nonverbose")); - const char *text2 = "test2"; + const char* text2 = "test2"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, text2)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -3507,10 +3665,11 @@ TEST(t_dlt_user_log_write_sized_constant_utf8_string, verbose) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string verbose")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string verbose")); - const char *text1 = "test1text"; + const char* text1 = "test1text"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, text1, 5)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -3525,10 +3684,11 @@ TEST(t_dlt_user_log_write_sized_constant_utf8_string, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nullpointer")); - const char *text1 = "test1text"; + const char* text1 = "test1text"; EXPECT_LE(DLT_RETURN_TRUE, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(NULL, text1, 5)); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(NULL, NULL, 5)); @@ -3547,13 +3707,16 @@ TEST(t_dlt_user_log_write_sized_constant_utf8_string, nonverbose) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nonverbose")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nonverbose")); - const char *text2 = "test2text"; + const char* text2 = "test2text"; size_t text2len = 5; // only use a (non-null-terminated) substring EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); - EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, text2, static_cast(text2len))); + EXPECT_LE( + DLT_RETURN_OK, + dlt_user_log_write_sized_constant_utf8_string(&contextData, text2, static_cast(text2len))); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); @@ -3570,7 +3733,8 @@ TEST(t_dlt_user_log_write_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_string_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456"; @@ -3591,7 +3755,9 @@ TEST(t_dlt_user_log_write_sized_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_string_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456789"; @@ -3612,7 +3778,9 @@ TEST(t_dlt_user_log_write_constant_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_string_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456"; @@ -3633,7 +3801,9 @@ TEST(t_dlt_user_log_write_sized_constant_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_string_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456789"; @@ -3654,7 +3824,9 @@ TEST(t_dlt_user_log_write_utf8_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_utf8_string_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456"; @@ -3675,7 +3847,9 @@ TEST(t_dlt_user_log_write_sized_utf8_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_utf8_string_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456789"; @@ -3696,10 +3870,11 @@ TEST(t_dlt_user_log_write_constant_utf8_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr normal")); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(&contextData, text1, "name")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -3714,10 +3889,11 @@ TEST(t_dlt_user_log_write_constant_utf8_string_attr, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr nullpointer")); - const char *text1 = "test1"; + const char* text1 = "test1"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(NULL, text1, "name")); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(NULL, NULL, "name")); @@ -3736,10 +3912,11 @@ TEST(t_dlt_user_log_write_sized_constant_utf8_string_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context( + &context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr normal")); - const char *text1 = "test1text"; + const char* text1 = "test1text"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(&contextData, text1, 5, "name")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); @@ -3754,10 +3931,12 @@ TEST(t_dlt_user_log_write_sized_constant_utf8_string_attr, nullpointer) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context( + &context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr nullpointer")); - const char *text1 = "test1text"; + const char* text1 = "test1text"; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(NULL, text1, 5, "name")); EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(NULL, NULL, 5, "name")); @@ -3846,8 +4025,8 @@ TEST(t_dlt_user_log_write_raw_formatted, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted normal")); /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -3880,26 +4059,28 @@ TEST(t_dlt_user_log_write_raw_formatted, abnormal) uint16_t length = DLT_USER_BUF_MAX_SIZE + 10; - char *buffer = new char[length]; + char* buffer = new char[length]; memset(buffer, '\000', length); for (int i = 0; i < length; i++) buffer[i] = 'X'; EXPECT_EQ(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_EQ(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted abnormal")); - - EXPECT_EQ(DLT_RETURN_USER_BUFFER_FULL, - dlt_user_log_write_raw_formatted(&contextData, buffer, length, DLT_FORMAT_DEFAULT)); - -/* undefined values for DltFormatType */ -/* shouldn't it return -1? */ -/* char text1[6] = "test1"; */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)-100)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)-10)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)10)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)100)); */ + EXPECT_EQ( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted abnormal")); + + EXPECT_EQ( + DLT_RETURN_USER_BUFFER_FULL, + dlt_user_log_write_raw_formatted(&contextData, buffer, length, DLT_FORMAT_DEFAULT)); + + /* undefined values for DltFormatType */ + /* shouldn't it return -1? */ + /* char text1[6] = "test1"; */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)-100)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)-10)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)10)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_raw_formatted(&contextData, text1, 6, (DltFormatType)100)); */ EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -3913,8 +4094,9 @@ TEST(t_dlt_user_log_write_raw_formatted, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted nullpointer")); /* NULL */ char text1[6] = "test1"; @@ -3937,7 +4119,9 @@ TEST(t_dlt_user_log_write_raw_formatted_attr, normal) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted_attr normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_raw_formatted_attr normal")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); char data[] = "123456"; @@ -4041,7 +4225,7 @@ TEST(t_dlt_log_string, abnormal) EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_log_string abnormal")); uint16_t length = DLT_USER_BUF_MAX_SIZE + 10; - char *buffer = new char[length]; + char* buffer = new char[length]; memset(buffer, '\000', length); for (int i = 0; i < length - 1; i++) @@ -4131,7 +4315,7 @@ TEST(t_dlt_log_string_int, abnormal) EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_log_string_int abnormal")); uint16_t length = DLT_USER_BUF_MAX_SIZE + 10; - char *buffer = new char[length]; + char* buffer = new char[length]; memset(buffer, '\000', length); for (int i = 0; i < length - 1; i++) @@ -4223,7 +4407,7 @@ TEST(t_dlt_log_string_uint, abnormal) EXPECT_EQ(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_log_string_uint abnormal")); uint16_t length = DLT_USER_BUF_MAX_SIZE + 10; - char *buffer = new char[length]; + char* buffer = new char[length]; memset(buffer, '\000', DLT_USER_BUF_MAX_SIZE + 10); for (int i = 0; i < length - 1; i++) @@ -4459,7 +4643,7 @@ TEST(t_dlt_log_raw, abnormal) uint16_t length = DLT_USER_BUF_MAX_SIZE + 10; - char *buffer = new char[length]; + char* buffer = new char[length]; memset(buffer, '\000', length); for (int i = 0; i < length; i++) @@ -4469,7 +4653,7 @@ TEST(t_dlt_log_raw, abnormal) /* undefined values for DltLogLevelType */ /* shouldn't it return -1? */ -/* char data[5] = "test"; */ + /* char data[5] = "test"; */ /* TODO: uint16_t length = 4; */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, (DltLogLevelType)-100, data, length)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, (DltLogLevelType)-10, data, length)); */ @@ -4480,8 +4664,8 @@ TEST(t_dlt_log_raw, abnormal) /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, DLT_LOG_DEFAULT, data, 0)); */ /* negative length */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, DLT_LOG_DEFAULT, data, -1)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, DLT_LOG_DEFAULT, data, -100)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, DLT_LOG_DEFAULT, data, -1)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_log_raw(&context, DLT_LOG_DEFAULT, data, -100)); */ EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_EQ(DLT_RETURN_OK, dlt_unregister_app()); @@ -4529,8 +4713,6 @@ TEST(t_dlt_log_marker, normal) /* t_dlt_register_app */ TEST(t_dlt_register_app, normal) { - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("T", "dlt_user.c tests")); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TU", "dlt_user.c tests")); @@ -4543,8 +4725,6 @@ TEST(t_dlt_register_app, normal) TEST(t_dlt_register_app, abnormal) { - - EXPECT_GE(DLT_RETURN_ERROR, dlt_register_app("", "dlt_user.c tests")); EXPECT_GE(DLT_RETURN_ERROR, dlt_unregister_app()); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_app("TUSR1", "dlt_user.c tests")); */ @@ -4558,19 +4738,14 @@ TEST(t_dlt_register_app, abnormal) TEST(t_dlt_register_app, nullpointer) { - - EXPECT_GE(DLT_RETURN_ERROR, dlt_register_app(NULL, NULL)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_app(NULL, "dlt_user.c tests")); - } /*/////////////////////////////////////// */ /* t_dlt_unregister_app */ TEST(t_dlt_unregister_app, normal) { - - EXPECT_LE(DLT_RETURN_OK, dlt_register_app("T", "dlt_user.c tests")); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TU", "dlt_user.c tests")); @@ -4583,8 +4758,6 @@ TEST(t_dlt_unregister_app, normal) TEST(t_dlt_unregister_app, abnormal) { - - EXPECT_GE(DLT_RETURN_ERROR, dlt_unregister_app()); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_app("", "dlt_user.c tests")); EXPECT_GE(DLT_RETURN_ERROR, dlt_unregister_app()); @@ -4635,10 +4808,14 @@ TEST(t_dlt_register_context, abnormal) /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST1234567890", "1")); */ EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context normal")); - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context + * normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context + * normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context + * normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_context + * normal")); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", NULL)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); @@ -4672,76 +4849,76 @@ TEST(t_dlt_register_context_ll_ts, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_OFF, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_FATAL, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_FATAL, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_ERROR, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_ERROR, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_WARN, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_WARN, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_DEBUG, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_DEBUG, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_VERBOSE, - DLT_TRACE_STATUS_OFF)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_VERBOSE, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_OFF, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_FATAL, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_FATAL, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_ERROR, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_ERROR, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_WARN, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_WARN, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_INFO, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_INFO, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_DEBUG, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_DEBUG, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_VERBOSE, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); } @@ -4756,55 +4933,72 @@ TEST(t_dlt_register_context_ll_ts, abnormal) EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts(&context, "", "d", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "T", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "T", "", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts(&context, "", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1", "", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1", "1", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1", "1", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1234567890", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1234567890", "", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1234567890", "1", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_OFF, - DLT_TRACE_STATUS_ON)); - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST1234567890", "1", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ + + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); /* DLT_LOG_DEFAULT and DLT_TRACE_STATUS_DEFAULT not allowed */ /* TODO: Why not? */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_OFF)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_OFF)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_DEFAULT)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_DEFAULT)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ /* abnormal values for loglevel and tracestatus */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", -3, - DLT_TRACE_STATUS_OFF)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", -3, DLT_TRACE_STATUS_OFF)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", 100, - DLT_TRACE_STATUS_OFF)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", 100, DLT_TRACE_STATUS_OFF)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_OFF, -3)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, -3)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", - DLT_LOG_OFF, 100)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, 100)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts(&context, "TEST", NULL, DLT_LOG_OFF, + * DLT_TRACE_STATUS_OFF)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); } @@ -4817,14 +5011,16 @@ TEST(t_dlt_register_context_ll_ts, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_register_context_ll_ts(&context, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, - DLT_TRACE_STATUS_OFF)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_register_context_ll_ts( + &context, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts(&context, NULL, NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts(NULL, "TEST", NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_register_context_ll_ts(NULL, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, - DLT_TRACE_STATUS_OFF)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_register_context_ll_ts( + NULL, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts(NULL, NULL, NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -4869,10 +5065,14 @@ TEST(t_dlt_unregister_context, abnormal) /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST1234567890", "1")); */ EXPECT_LE(DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context normal")); - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context + * normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context + * normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context + * normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_unregister_context + * normal")); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context(&context, "TEST", NULL)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); @@ -4899,7 +5099,7 @@ TEST(t_dlt_unregister_context, nullpointer) /*/////////////////////////////////////// */ /* t_dlt_register_injection_callback */ -int dlt_user_injection_callback(uint32_t /*service_id*/, void */*data*/, uint32_t /*length*/) +int dlt_user_injection_callback(uint32_t /*service_id*/, void* /*data*/, uint32_t /*length*/) { return 0; } @@ -4912,23 +5112,24 @@ TEST(t_dlt_register_injection_callback, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_injection_callback normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_injection_callback normal")); /* TODO: service_id = 0x123; */ - /* TODO: EXPECT_LE(DLT_RETURN_OK,dlt_register_injection_callback(&context, service_id, dlt_user_injection_callback)); */ + /* TODO: EXPECT_LE(DLT_RETURN_OK,dlt_register_injection_callback(&context, service_id, + * dlt_user_injection_callback)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); - } /*/////////////////////////////////////// */ /* t_dlt_register_log_level_changed_callback */ -void dlt_user_log_level_changed_callback(char /*context_id*/[DLT_ID_SIZE], uint8_t /*log_level*/, - uint8_t /*trace_status*/) -{} +void dlt_user_log_level_changed_callback( + char /*context_id*/[DLT_ID_SIZE], uint8_t /*log_level*/, uint8_t /*trace_status*/) +{ +} TEST(t_dlt_register_log_level_changed_callback, normal) { @@ -4937,14 +5138,14 @@ TEST(t_dlt_register_log_level_changed_callback, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_log_level_changed_callback normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_register_log_level_changed_callback normal")); EXPECT_LE(DLT_RETURN_OK, dlt_register_log_level_changed_callback(&context, dlt_user_log_level_changed_callback)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); - } #ifdef DLT_NETWORK_TRACE_ENABLE @@ -5001,13 +5202,18 @@ TEST(t_dlt_user_trace_network, abnormal) /* data length = 0. Does this make sense? */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, DLT_NW_TRACE_IPC, 0, header, 32, payload)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, DLT_NW_TRACE_CAN, 0, header, 0, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, payload)); + */ /* invalid DltNetworkTraceType value */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)-100, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)-10, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)10, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)100, 16, header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)-100, 16, header, 32, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)-10, 16, header, 32, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)10, 16, header, 32, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network(&context, (DltNetworkTraceType)100, 16, header, 32, + * payload)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -5051,8 +5257,8 @@ TEST(t_dlt_user_trace_network_truncated, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated normal")); char header[16]; @@ -5066,10 +5272,10 @@ TEST(t_dlt_user_trace_network_truncated, normal) EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 16, header, 32, payload, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 16, header, 32, payload, 1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 32, payload, -1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_MOST, 16, header, 32, payload, 10)); + EXPECT_LE( + DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 32, payload, -1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_MOST, 16, header, 32, payload, 10)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -5082,8 +5288,9 @@ TEST(t_dlt_user_trace_network_truncated, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated abnormal")); /* TODO: char header[16]; */ /* TODO: for(char i = 0; i < 16; ++i) */ @@ -5097,15 +5304,22 @@ TEST(t_dlt_user_trace_network_truncated, abnormal) /* TODO: } */ /* data length = 0. Does this make sense? */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 0, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 0, header, 0, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 0, header, 32, + * payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 0, header, 0, + * payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, + * payload, 0)); */ /* invalid DltNetworkTraceType value */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-100, 16, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-10, 16, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)10, 16, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)100, 16, header, 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-100, 16, + * header, 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-10, 16, header, + * 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)10, 16, header, + * 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)100, 16, header, + * 32, payload, 0)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -5118,8 +5332,9 @@ TEST(t_dlt_user_trace_network_truncated, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated nullpointer")); char header[16]; @@ -5133,10 +5348,12 @@ TEST(t_dlt_user_trace_network_truncated, nullpointer) /* what to expect when giving in NULL pointer? */ EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 16, NULL, 32, payload, 0)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL, 0)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL, 0)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, + dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL, 0)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, + dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -5152,8 +5369,8 @@ TEST(t_dlt_user_trace_network_segmented, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented normal")); char header[16]; @@ -5181,8 +5398,9 @@ TEST(t_dlt_user_trace_network_segmented, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented abnormal")); /* TODO: char header[16]; */ /* TODO: for(char i = 0; i < 16; ++i) */ @@ -5196,15 +5414,22 @@ TEST(t_dlt_user_trace_network_segmented, abnormal) /* TODO: } */ /* data length = 0. Does this make sense? */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_IPC, 0, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_CAN, 0, header, 0, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_IPC, 0, header, 32, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_CAN, 0, header, 0, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, + * payload)); */ /* invalid DltNetworkTraceType value */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)-100, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)-10, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)10, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)100, 16, header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)-100, 16, + * header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)-10, 16, header, + * 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)10, 16, header, + * 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented(&context, (DltNetworkTraceType)100, 16, header, + * 32, payload)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -5217,8 +5442,9 @@ TEST(t_dlt_user_trace_network_segmented, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented nullpointer")); char header[16]; @@ -5232,10 +5458,11 @@ TEST(t_dlt_user_trace_network_segmented, nullpointer) /* what to expect when giving in NULL pointer? */ EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_IPC, 16, NULL, 32, payload)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, + dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); @@ -5246,27 +5473,19 @@ TEST(t_dlt_user_trace_network_segmented, nullpointer) /* t_dlt_set_log_mode */ TEST(t_dlt_set_log_mode, normal) { - - - EXPECT_LE(DLT_RETURN_OK, dlt_set_log_mode(DLT_USER_MODE_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_set_log_mode(DLT_USER_MODE_EXTERNAL)); EXPECT_LE(DLT_RETURN_OK, dlt_set_log_mode(DLT_USER_MODE_INTERNAL)); EXPECT_LE(DLT_RETURN_OK, dlt_set_log_mode(DLT_USER_MODE_BOTH)); - } TEST(t_dlt_set_log_mode, abnormal) { - - - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_set_log_mode(DLT_USER_MODE_UNDEFINED)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_set_log_mode((DltUserLogMode)-100)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_set_log_mode((DltUserLogMode)-10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_set_log_mode((DltUserLogMode)10)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_set_log_mode((DltUserLogMode)100)); */ - } @@ -5284,9 +5503,7 @@ TEST(t_dlt_get_log_state, normal) /* t_dlt_verbose_mode */ TEST(t_dlt_verbose_mode, normal) { - EXPECT_LE(DLT_RETURN_OK, dlt_verbose_mode()); - } @@ -5294,11 +5511,7 @@ TEST(t_dlt_verbose_mode, normal) /* t_dlt_nonverbose_mode */ TEST(t_dlt_nonverbose_mode, normal) { - - - EXPECT_LE(DLT_RETURN_OK, dlt_nonverbose_mode()); - } /*/////////////////////////////////////// */ @@ -5314,10 +5527,10 @@ TEST(t_dlt_user_is_logLevel_enabled, normal) { DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_ll_ts(&context, "ILLE", - "t_dlt_user_is_logLevel_enabled context", - DLT_LOG_INFO, - -2)); /* DLT_USER_TRACE_STATUS_NOT_SET */ + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts( + &context, "ILLE", "t_dlt_user_is_logLevel_enabled context", DLT_LOG_INFO, + -2)); /* DLT_USER_TRACE_STATUS_NOT_SET */ EXPECT_LE(DLT_RETURN_TRUE, dlt_user_is_logLevel_enabled(&context, DLT_LOG_FATAL)); EXPECT_LE(DLT_RETURN_TRUE, dlt_user_is_logLevel_enabled(&context, DLT_LOG_ERROR)); @@ -5349,11 +5562,11 @@ struct ShutdownWhileInitParams { pthread_cond_t dlt_free_done = PTHREAD_COND_INITIALIZER; pthread_mutex_t dlt_free_mtx = PTHREAD_MUTEX_INITIALIZER; bool has_error = false; - }; -void* dlt_free_call_and_deadlock_detection(void *arg) { - auto *params = static_cast(arg); +void* dlt_free_call_and_deadlock_detection(void* arg) +{ + auto* params = static_cast(arg); // allow thread to be canceled int old_thread_type; @@ -5368,14 +5581,14 @@ void* dlt_free_call_and_deadlock_detection(void *arg) { return nullptr; } -void *dlt_free_thread(void *arg) { - auto *params = static_cast(arg); +void* dlt_free_thread(void* arg) +{ + auto* params = static_cast(arg); while (std::chrono::steady_clock::now() < params->stop_time && !params->has_error) { - // pthread cond_timedwait expects an absolute time to wait - struct timespec abs_time{}; + struct timespec abs_time { }; clock_gettime(CLOCK_REALTIME, &abs_time); - abs_time.tv_sec += 3; // wait at most 3 seconds + abs_time.tv_sec += 3; // wait at most 3 seconds pthread_t dlt_free_deadlock_detection_thread_id; @@ -5398,11 +5611,12 @@ void *dlt_free_thread(void *arg) { return nullptr; } -TEST(t_dlt_user_shutdown_while_init_is_running, normal) { +TEST(t_dlt_user_shutdown_while_init_is_running, normal) +{ const auto max_runtime = std::chrono::seconds(5); const auto stop_time = std::chrono::steady_clock::now() + max_runtime; - struct ShutdownWhileInitParams args{}; + struct ShutdownWhileInitParams args { }; args.stop_time = stop_time; pthread_t dlt_free_thread_id; @@ -5438,7 +5652,7 @@ TEST(t_dlt_user_run_into_trace_limit, normal) auto loadExceededReceived = false; - for (int i = 0; i < DLT_TRACE_LOAD_CLIENT_HARD_LIMIT_DEFAULT;++i) { + for (int i = 0; i < DLT_TRACE_LOAD_CLIENT_HARD_LIMIT_DEFAULT; ++i) { /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); data = 0; @@ -5469,7 +5683,7 @@ TEST(t_dlt_user_run_into_trace_limit, normal) /*/////////////////////////////////////// */ /* main */ -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); dlt_set_resend_timeout_atexit(0); diff --git a/tests/gtest_dlt_user_v2.cpp b/tests/gtest_dlt_user_v2.cpp index 57c4f8f66..b0f6daeaf 100644 --- a/tests/gtest_dlt_user_v2.cpp +++ b/tests/gtest_dlt_user_v2.cpp @@ -71,28 +71,24 @@ extern "C" { /* DO FAIL! */ -//TBD: Update +// TBD: Update /* tested functions */ /* * int dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel); - * int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid); - * int dlt_user_log_write_finish(DltContextData *log); - * int dlt_user_log_write_bool(DltContextData *log, uint8_t data); - * int dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name); - * int dlt_user_log_write_float32(DltContextData *log, float32_t data); - * int dlt_user_log_write_float32_attr(DltContextData *log, float32_t data, const char *name, const char *unit); - * int dlt_user_log_write_float64(DltContextData *log, double data); - * int dlt_user_log_write_float64_attr(DltContextData *log, double data, const char *name, const char *unit); - * int dlt_user_log_write_uint(DltContextData *log, unsigned int data); - * int dlt_user_log_write_uint_attr(DltContextData *log, unsigned int data, const char *name, const char *unit); - * int dlt_user_log_write_uint8(DltContextData *log, uint8_t data); - * int dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char *unit); - * int dlt_user_log_write_uint16(DltContextData *log, uint16_t data); - * int dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit); - * int dlt_user_log_write_uint32(DltContextData *log, uint32_t data); - * int dlt_user_log_write_uint32_attr(DltContextData *log, uint32_t data, const char *name, const char *unit); - * int dlt_user_log_write_uint64(DltContextData *log, uint64_t data); - * int dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit); + * int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t + * messageid); int dlt_user_log_write_finish(DltContextData *log); int dlt_user_log_write_bool(DltContextData *log, + * uint8_t data); int dlt_user_log_write_bool_attr(DltContextData *log, uint8_t data, const char *name); int + * dlt_user_log_write_float32(DltContextData *log, float32_t data); int dlt_user_log_write_float32_attr(DltContextData + * *log, float32_t data, const char *name, const char *unit); int dlt_user_log_write_float64(DltContextData *log, double + * data); int dlt_user_log_write_float64_attr(DltContextData *log, double data, const char *name, const char *unit); int + * dlt_user_log_write_uint(DltContextData *log, unsigned int data); int dlt_user_log_write_uint_attr(DltContextData + * *log, unsigned int data, const char *name, const char *unit); int dlt_user_log_write_uint8(DltContextData *log, + * uint8_t data); int dlt_user_log_write_uint8_attr(DltContextData *log, uint8_t data, const char *name, const char + * *unit); int dlt_user_log_write_uint16(DltContextData *log, uint16_t data); int + * dlt_user_log_write_uint16_attr(DltContextData *log, uint16_t data, const char *name, const char *unit); int + * dlt_user_log_write_uint32(DltContextData *log, uint32_t data); int dlt_user_log_write_uint32_attr(DltContextData + * *log, uint32_t data, const char *name, const char *unit); int dlt_user_log_write_uint64(DltContextData *log, uint64_t + * data); int dlt_user_log_write_uint64_attr(DltContextData *log, uint64_t data, const char *name, const char *unit); * int dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type); * int dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type); * int dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type); @@ -114,11 +110,11 @@ extern "C" { * int dlt_user_log_write_constant_string( DltContextData *log, const char *text); * int dlt_user_log_write_constant_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_sized_constant_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); - * int dlt_user_log_write_utf8_string(DltContextData *log, const char *text); - * int dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); - * int dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); - * int dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); + * int dlt_user_log_write_sized_constant_string_attr(DltContextData *log, const char *text, uint16_t length, const char + * *name); int dlt_user_log_write_utf8_string(DltContextData *log, const char *text); int + * dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); int + * dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); int + * dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); * int dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text); * int dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text); @@ -126,7 +122,8 @@ extern "C" { * int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length); * int dlt_user_log_write_raw_attr(DltContextData *log,void *data,uint16_t length, const char *name); * int dlt_user_log_write_raw_formatted(DltContextData *log,void *data,uint16_t length,DltFormatType type); - * int dlt_user_log_write_raw_formatted_attr(DltContextData *log,void *data,uint16_t length,DltFormatType type, const char *name); + * int dlt_user_log_write_raw_formatted_attr(DltContextData *log,void *data,uint16_t length,DltFormatType type, const + * char *name); */ /* @@ -143,16 +140,19 @@ extern "C" { * int dlt_register_app(const char *apid, const char * description); * int dlt_unregister_app(void); * int dlt_register_context(DltContext *handle, const char *contextid, const char * description); - * int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus); - * int dlt_unregister_context(DltContext *handle); - * int dlt_register_injection_callback(DltContext *handle, uint32_t service_id, int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)); - * int dlt_register_log_level_changed_callback(DltContext *handle, void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE],uint8_t log_level, uint8_t trace_status)); + * int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int + * tracestatus); int dlt_unregister_context(DltContext *handle); int dlt_register_injection_callback(DltContext *handle, + * uint32_t service_id, int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)); int + * dlt_register_log_level_changed_callback(DltContext *handle, void (*dlt_log_level_changed_callback)(char + * context_id[DLT_ID_SIZE],uint8_t log_level, uint8_t trace_status)); */ /* - * int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload); - * int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate); - * int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload); + * int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, + * uint16_t payload_len, void *payload); int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType + * nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate); int + * dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void + * *header, uint16_t payload_len, void *payload); */ /* @@ -220,8 +220,9 @@ TEST(t_dlt_user_log_write_start_v2, startstartfinish) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start startstartfinish")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start startstartfinish")); EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); /* shouldn't it return -1, because it is already started? */ /* EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); */ @@ -238,8 +239,8 @@ TEST(t_dlt_user_log_write_start_v2, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start nullpointer")); /* NULL's */ EXPECT_GE(DLT_RETURN_ERROR, dlt_user_log_write_start(NULL, &contextData, DLT_LOG_DEFAULT)); /*EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_finish_v2(&contextData)); */ @@ -262,7 +263,8 @@ TEST(t_dlt_user_log_write_start_id_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id normal")); /* the defined enum values for log level */ messageid = 0; @@ -316,13 +318,15 @@ TEST(t_dlt_user_log_write_start_id_v2, startstartfinish) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id startstartfinish")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id startstartfinish")); messageid = 0; EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, messageid)); /* shouldn't it return -1, because it is already started? */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id_v2(&context, &contextData, DLT_LOG_DEFAULT, messageid)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_start_id_v2(&context, &contextData, DLT_LOG_DEFAULT, + * messageid)); */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish_v2(&contextData)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); @@ -338,8 +342,9 @@ TEST(t_dlt_user_log_write_start_id_v2, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id_v2 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_start_id_v2 nullpointer")); /* NULL's */ messageid = 0; @@ -367,7 +372,8 @@ TEST(t_dlt_user_log_write_finish_v2, finish) /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_finish_v2(&contextData)); */ EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_finish_v2 finish")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_finish_v2 finish")); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_log_write_finish_v2(&contextData)); */ /* finish with start and initialized context */ @@ -389,7 +395,8 @@ TEST(t_dlt_user_log_write_finish_v2, finish_with_timestamp) DltContextData contextData; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_finish_v2 finish")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_finish_v2 finish")); /* finish with start and initialized context */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -435,7 +442,8 @@ TEST(t_dlt_user_log_write_bool_v2, abnormal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool abnormal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool abnormal")); /* abnormal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); @@ -459,8 +467,8 @@ TEST(t_dlt_user_log_write_bool_v2, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_log_write_bool nullpointer")); /* NULL */ data = true; @@ -480,76 +488,76 @@ TEST(t_dlt_register_context_ll_ts_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_OFF, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_FATAL, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_ERROR, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_WARN, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_INFO, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_DEBUG, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_VERBOSE, - DLT_TRACE_STATUS_OFF)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_OFF, - DLT_TRACE_STATUS_ON)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_FATAL, - DLT_TRACE_STATUS_ON)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_ERROR, - DLT_TRACE_STATUS_ON)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_WARN, - DLT_TRACE_STATUS_ON)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_INFO, - DLT_TRACE_STATUS_ON)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_DEBUG, - DLT_TRACE_STATUS_ON)); - EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_VERBOSE, - DLT_TRACE_STATUS_ON)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_FATAL, + DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_ERROR, + DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_WARN, DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_DEBUG, + DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_VERBOSE, + DLT_TRACE_STATUS_OFF)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_FATAL, DLT_TRACE_STATUS_ON)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_ERROR, DLT_TRACE_STATUS_ON)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_WARN, DLT_TRACE_STATUS_ON)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_INFO, DLT_TRACE_STATUS_ON)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_DEBUG, DLT_TRACE_STATUS_ON)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_VERBOSE, + DLT_TRACE_STATUS_ON)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); } @@ -563,55 +571,72 @@ TEST(t_dlt_register_context_ll_ts_v2, abnormal) EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts_v2(&context, "", "d", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "T", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "T", "", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts_v2(&context, "", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1", "", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1", "1", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1", "1", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1234567890", "", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1234567890", "", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1234567890", "1", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_OFF, - DLT_TRACE_STATUS_ON)); - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST1234567890", "1", DLT_LOG_OFF, + * DLT_TRACE_STATUS_ON)); */ + + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_ON)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); /* DLT_LOG_DEFAULT and DLT_TRACE_STATUS_DEFAULT not allowed */ /* TODO: Why not? */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_OFF)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_OFF)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ -/* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_DEFAULT)); */ + /* EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c + * t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_DEFAULT)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ /* abnormal values for loglevel and tracestatus */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", -3, - DLT_TRACE_STATUS_OFF)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", -3, DLT_TRACE_STATUS_OFF)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", 100, - DLT_TRACE_STATUS_OFF)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", 100, DLT_TRACE_STATUS_OFF)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_OFF, -3)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_OFF, -3)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, - dlt_register_context_ll_ts_v2(&context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", - DLT_LOG_OFF, 100)); + EXPECT_EQ( + DLT_RETURN_WRONG_PARAMETER, + dlt_register_context_ll_ts_v2( + &context, "TEST", "dlt_user.c t_dlt_register_context_ll_ts_v2 normal", DLT_LOG_OFF, 100)); /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_ll_ts_v2(&context, "TEST", NULL, DLT_LOG_OFF, + * DLT_TRACE_STATUS_OFF)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); } @@ -622,14 +647,16 @@ TEST(t_dlt_register_context_ll_ts_v2, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_register_context_ll_ts_v2(&context, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, - DLT_TRACE_STATUS_OFF)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_register_context_ll_ts_v2( + &context, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts_v2(&context, NULL, NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts_v2(NULL, "TEST", NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); - EXPECT_GE(DLT_RETURN_ERROR, - dlt_register_context_ll_ts_v2(NULL, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, - DLT_TRACE_STATUS_OFF)); + EXPECT_GE( + DLT_RETURN_ERROR, + dlt_register_context_ll_ts_v2( + NULL, NULL, "dlt_user.c t_dlt_register_context_ll_ts normal", DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_ll_ts_v2(NULL, NULL, NULL, DLT_LOG_OFF, DLT_TRACE_STATUS_OFF)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -643,7 +670,8 @@ TEST(t_dlt_unregister_context_v2, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -669,11 +697,16 @@ TEST(t_dlt_unregister_context_v2, abnormal) /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_unregister_context_v2(&context)); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST1234567890", "1")); */ - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); */ + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_unregister_context_v2 normal")); + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c + * t_dlt_unregister_context_v2 normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c + * t_dlt_unregister_context_v2 normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c + * t_dlt_unregister_context_v2 normal")); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", "dlt_user.c + * t_dlt_unregister_context_v2 normal")); */ /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_register_context_v2(&context, "TEST", NULL)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); @@ -687,7 +720,8 @@ TEST(t_dlt_unregister_context_v2, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_v2(&context, NULL, "dlt_user.c t_dlt_unregister_context_v2 normal")); + EXPECT_GE( + DLT_RETURN_ERROR, dlt_register_context_v2(&context, NULL, "dlt_user.c t_dlt_unregister_context_v2 normal")); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_v2(&context, NULL, NULL)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_v2(NULL, "TEST", NULL)); EXPECT_GE(DLT_RETURN_ERROR, dlt_register_context_v2(NULL, NULL, "dlt_user.c t_dlt_unregister_context_v2 normal")); @@ -704,7 +738,8 @@ TEST(t_dlt_user_trace_network, nullpointer) DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network nullpointer")); char header[16]; @@ -734,8 +769,9 @@ TEST(t_dlt_user_trace_network_truncated, normal) EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated normal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated normal")); char header[16]; @@ -749,10 +785,10 @@ TEST(t_dlt_user_trace_network_truncated, normal) EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 16, header, 32, payload, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 16, header, 32, payload, 1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 32, payload, -1)); - EXPECT_LE(DLT_RETURN_OK, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_MOST, 16, header, 32, payload, 10)); + EXPECT_LE( + DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 32, payload, -1)); + EXPECT_LE( + DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_MOST, 16, header, 32, payload, 10)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -764,8 +800,9 @@ TEST(t_dlt_user_trace_network_truncated, abnormal) DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated abnormal")); /* TODO: char header[16]; */ /* TODO: for(char i = 0; i < 16; ++i) */ @@ -779,15 +816,22 @@ TEST(t_dlt_user_trace_network_truncated, abnormal) /* TODO: } */ /* data length = 0. Does this make sense? */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 0, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 0, header, 0, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 0, header, 32, + * payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 0, header, 0, + * payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, + * payload, 0)); */ /* invalid DltNetworkTraceType value */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-100, 16, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-10, 16, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)10, 16, header, 32, payload, 0)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)100, 16, header, 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-100, 16, + * header, 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)-10, 16, header, + * 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)10, 16, header, + * 32, payload, 0)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_truncated(&context, (DltNetworkTraceType)100, 16, header, + * 32, payload, 0)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -799,8 +843,9 @@ TEST(t_dlt_user_trace_network_truncated, nullpointer) DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_truncated nullpointer")); char header[16]; @@ -814,10 +859,12 @@ TEST(t_dlt_user_trace_network_truncated, nullpointer) /* what to expect when giving in NULL pointer? */ EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_IPC, 16, NULL, 32, payload, 0)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL, 0)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL, 0)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, + dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL, 0)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, + dlt_user_trace_network_truncated(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -828,8 +875,9 @@ TEST(t_dlt_user_trace_network_segmented, abnormal) DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented_v2 abnormal")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented_v2 abnormal")); /* TODO: char header[16]; */ /* TODO: for(char i = 0; i < 16; ++i) */ @@ -843,15 +891,22 @@ TEST(t_dlt_user_trace_network_segmented, abnormal) /* TODO: } */ /* data length = 0. Does this make sense? */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, DLT_NW_TRACE_IPC, 0, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, DLT_NW_TRACE_CAN, 0, header, 0, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, DLT_NW_TRACE_FLEXRAY, 16, header, 0, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, DLT_NW_TRACE_IPC, 0, header, 32, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, DLT_NW_TRACE_CAN, 0, header, 0, + * payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, DLT_NW_TRACE_FLEXRAY, 16, header, + * 0, payload)); */ /* invalid DltNetworkTraceType value */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)-100, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)-10, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)10, 16, header, 32, payload)); */ - /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)100, 16, header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)-100, 16, + * header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)-10, 16, + * header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)10, 16, + * header, 32, payload)); */ + /* TODO: EXPECT_GE(DLT_RETURN_ERROR,dlt_user_trace_network_segmented_v2(&context, (DltNetworkTraceType)100, 16, + * header, 32, payload)); */ EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -862,8 +917,9 @@ TEST(t_dlt_user_trace_network_segmented, nullpointer) DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, - dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented_v2 nullpointer")); + EXPECT_LE( + DLT_RETURN_OK, + dlt_register_context_v2(&context, "TEST", "dlt_user.c t_dlt_user_trace_network_segmented_v2 nullpointer")); char header[16]; @@ -877,10 +933,11 @@ TEST(t_dlt_user_trace_network_segmented, nullpointer) /* what to expect when giving in NULL pointer? */ EXPECT_LE(DLT_RETURN_OK, dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_IPC, 16, NULL, 32, payload)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL)); - EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, - dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_CAN, 16, header, 32, NULL)); + EXPECT_LE( + DLT_RETURN_WRONG_PARAMETER, + dlt_user_trace_network_segmented(&context, DLT_NW_TRACE_FLEXRAY, 16, NULL, 32, NULL)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context_v2(&context)); EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app_v2()); @@ -893,10 +950,10 @@ TEST(t_dlt_user_is_logLevel_enabled, normal) { DltContext context; EXPECT_LE(DLT_RETURN_OK, dlt_register_app_v2("TUSR", "dlt_user.c tests")); - EXPECT_LE(DLT_RETURN_OK, dlt_register_context_ll_ts_v2(&context, "ILLE", - "t_dlt_user_is_logLevel_enabled context", - DLT_LOG_INFO, - -2)); /* DLT_USER_TRACE_STATUS_NOT_SET */ + EXPECT_LE( + DLT_RETURN_OK, dlt_register_context_ll_ts_v2( + &context, "ILLE", "t_dlt_user_is_logLevel_enabled context", DLT_LOG_INFO, + -2)); /* DLT_USER_TRACE_STATUS_NOT_SET */ EXPECT_LE(DLT_RETURN_TRUE, dlt_user_is_logLevel_enabled(&context, DLT_LOG_FATAL)); EXPECT_LE(DLT_RETURN_TRUE, dlt_user_is_logLevel_enabled(&context, DLT_LOG_ERROR)); @@ -926,7 +983,7 @@ TEST(t_dlt_user_run_into_trace_limit, normal) auto loadExceededReceived = false; - for (int i = 0; i < DLT_TRACE_LOAD_CLIENT_HARD_LIMIT_DEFAULT;++i) { + for (int i = 0; i < DLT_TRACE_LOAD_CLIENT_HARD_LIMIT_DEFAULT; ++i) { /* normal values */ EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); data = 0; @@ -957,7 +1014,7 @@ TEST(t_dlt_user_run_into_trace_limit, normal) /*/////////////////////////////////////// */ /* main */ -int main(int argc, char **argv) +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); /* Reduce atexit resend wait during unit tests to avoid long teardown delays */ diff --git a/tests/mod_system_logger/mod_system_logger.c b/tests/mod_system_logger/mod_system_logger.c index 61c732ccc..493373e0f 100644 --- a/tests/mod_system_logger/mod_system_logger.c +++ b/tests/mod_system_logger/mod_system_logger.c @@ -4,7 +4,7 @@ int i; -static int system_proc_show(struct seq_file *m, void *v) +static int system_proc_show(struct seq_file* m, void* v) { for (i = 0; i < 1000; i++) seq_printf(m, "Test Systemlogger %i\n", i); @@ -12,7 +12,7 @@ static int system_proc_show(struct seq_file *m, void *v) return 0; } -static int system_proc_open(struct inode *inode, struct file *file) +static int system_proc_open(struct inode* inode, struct file* file) { return single_open(file, system_proc_show, NULL); }