From f4325524cb5acdddbe26d32fab49aeed1d7f0b23 Mon Sep 17 00:00:00 2001 From: Felix Herrmann Date: Tue, 10 Dec 2019 16:29:45 +0100 Subject: Android: Enable Android build Signed-off-by: Felix Herrmann Signed-off-by: KHANH LUONG HONG DUY --- Android.bp | 154 +++++++++++++++++++++++++++++++++++++++++++ include/dlt/dlt_user.h | 7 +- src/console/dlt-receive.c | 12 +++- src/lib/dlt_user.c | 36 ++++++++-- src/shared/dlt_common.c | 7 +- util/create_dlt_version_h.py | 81 +++++++++++++++++++++++ 6 files changed, 287 insertions(+), 10 deletions(-) create mode 100644 Android.bp create mode 100755 util/create_dlt_version_h.py diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..b50115a --- /dev/null +++ b/Android.bp @@ -0,0 +1,154 @@ +/** + * Copyright (C) 2019 Advanced Driver Information Technology. + * This code is developed by Advanced Driver Information Technology. + * Copyright of Advanced Driver Information Technology, Bosch and DENSO. + * + * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * For further information see http://www.genivi.org/. + */ + +cc_defaults { + name: "dlt_defaults", + vendor: true, + + local_include_dirs: [ + "include/dlt", + ], + + generated_headers: ["dlt_version_header"], + + cflags: [ + "-DDLT_USE_UNIX_SOCKET_IPC", + "-DCONFIGURATION_FILES_DIR=\"/vendor/etc\"", + "-DDLT_USER_IPC_PATH=\"/data/local/tmp\"", + ] + [ + "-Wno-unused-parameter", + "-W", + "-Wall", + ], +} + +// Generate dlt_version.h without Cmake +genrule { + name: "dlt_version_header", + tool_files: ["util/create_dlt_version_h.py"], + srcs: [ + "CMakeLists.txt", + "cmake/dlt_version.h.cmake", + ], + cmd: "$(location util/create_dlt_version_h.py) $(in) $(out)", + out: ["dlt_version.h"], +} + +cc_binary { + + name: "dlt-daemon", + defaults: ["dlt_defaults"], + + /* + init_rc: [ + "src/daemon/dlt-daemon.rc", + ], + */ + + local_include_dirs: [ + "src/daemon", + "src/gateway", + "src/lib", + "src/shared", + "src/offlinelogstorage", + ], + + srcs: [ + "src/daemon/dlt-daemon.c", + "src/daemon/dlt_daemon_client.c", + "src/daemon/dlt_daemon_common.c", + "src/daemon/dlt_daemon_connection.c", + "src/daemon/dlt_daemon_event_handler.c", + "src/daemon/dlt_daemon_filter.c", + "src/daemon/dlt_daemon_offline_logstorage.c", + "src/daemon/dlt_daemon_serial.c", + "src/daemon/dlt_daemon_socket.c", + "src/daemon/dlt_daemon_unix_socket.c", + "src/gateway/dlt_gateway.c", + "src/lib/dlt_client.c", + "src/shared/dlt_common.c", + "src/shared/dlt_config_file_parser.c", + "src/shared/dlt_offline_trace.c", + "src/shared/dlt_protocol.c", + "src/shared/dlt_user_shared.c", + "src/offlinelogstorage/dlt_offline_logstorage.c", + "src/offlinelogstorage/dlt_offline_logstorage_behavior.c", + ], + + shared_libs: [ + "libc", + "libutils", + "libcutils", + ], +} + +cc_library_shared { + name: "libdlt", + defaults: ["dlt_defaults"], + + local_include_dirs: [ + "src/lib", + "src/shared", + ], + + export_include_dirs: [ + "include/dlt", + ], + + export_generated_headers: ["dlt_version_header"], + + srcs: [ + "src/lib/dlt_client.c", + "src/lib/dlt_env_ll.c", + "src/lib/dlt_filetransfer.c", + "src/lib/dlt_user.c", + "src/shared/dlt_common.c", + "src/shared/dlt_protocol.c", + "src/shared/dlt_user_shared.c", + ], +} + +cc_binary { + + name: "dlt-example-user", + defaults: ["dlt_defaults"], + + srcs: [ + "src/examples/dlt-example-user.c", + ], + + shared_libs: [ + "libc", + "libdlt", + ], +} + +cc_binary { + + name: "dlt-receive", + defaults: ["dlt_defaults"], + + srcs: [ + "src/console/dlt-receive.c", + ], + + shared_libs: [ + "libc", + "libdlt", + ], +} + +// vim: ft=python diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 0533346..97aa911 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -73,7 +73,11 @@ * \addtogroup userapi \{ */ + +#ifndef __ANDROID_API__ # include +#endif + # include # if !defined (__WIN32__) @@ -193,10 +197,11 @@ typedef struct char appID[DLT_ID_SIZE]; /**< Application ID */ int dlt_log_handle; /**< Handle to fifo of dlt daemon */ int dlt_user_handle; /**< Handle to own fifo */ +#ifndef __ANDROID_API__ mqd_t dlt_segmented_queue_read_handle; /**< Handle message queue */ mqd_t dlt_segmented_queue_write_handle; /**< Handle message queue */ pthread_t dlt_segmented_nwt_handle; /**< thread handle of segmented sending */ - +#endif int8_t dlt_is_file; /**< Target of logging: 1 to file, 0 to daemon */ dlt_ll_ts_type *dlt_ll_ts; /** [MAX_DLT_LL_TS_ENTRIES]; < Internal management struct for all diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index 9424711..24280ee 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -205,7 +205,11 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) /* if (file_already_exists) */ glob_t outer; - if (glob(dltdata->ovalue, GLOB_TILDE | GLOB_NOSORT, NULL, &outer) == 0) { + if (glob(dltdata->ovalue, +#ifndef __ANDROID_API__ + GLOB_TILDE | +#endif + GLOB_NOSORT, NULL, &outer) == 0) { if (dltdata->vflag) { dlt_vlog(LOG_INFO, "File %s already exists, need to rename first\n", dltdata->ovalue); } @@ -223,7 +227,11 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) * foo.1000.dlt * foo.11.dlt */ - if (glob(pattern, GLOB_TILDE | GLOB_NOSORT, NULL, &inner) == 0) { + if (glob(pattern, +#ifndef __ANDROID_API__ + GLOB_TILDE | +#endif + GLOB_NOSORT, NULL, &inner) == 0) { /* search for the highest number used */ size_t i; diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index edb4ae0..be00a76 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -160,8 +160,10 @@ static DltReturnValue dlt_user_print_msg(DltMessage *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); +#ifndef __ANDROID_API__ 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_out_error_handling(void *ptr1, size_t len1, void *ptr2, @@ -400,11 +402,13 @@ DltReturnValue dlt_init(void) #endif +#ifndef __ANDROID_API__ /* These will be lazy initialized only when needed */ dlt_user.dlt_segmented_queue_read_handle = -1; dlt_user.dlt_segmented_queue_write_handle = -1; pthread_cond_init(&mq_init_condition, NULL); +#endif if (dlt_start_threads() < 0) { dlt_user_initialised = false; @@ -455,6 +459,7 @@ DltReturnValue dlt_init_file(const char *name) return DLT_RETURN_OK; } +#ifndef __ANDROID_API__ DltReturnValue dlt_init_message_queue(void) { dlt_lock_mutex(&mq_mutex); @@ -519,6 +524,7 @@ DltReturnValue dlt_init_message_queue(void) dlt_unlock_mutex(&mq_mutex); return DLT_RETURN_OK; } +#endif /*__ANDROID_API__*/ DltReturnValue dlt_init_common(void) { @@ -934,6 +940,7 @@ DltReturnValue dlt_free(void) dlt_env_free_ll_set(&dlt_user.initial_ll_set); DLT_SEM_FREE(); +#ifndef __ANDROID_API__ char queue_name[NAME_MAX]; snprintf(queue_name, NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid()); @@ -955,6 +962,7 @@ DltReturnValue dlt_free(void) dlt_user.dlt_segmented_queue_read_handle = DLT_FD_INIT; pthread_cond_destroy(&mq_init_condition); +#endif /* ifndef __ANDROID_API__ */ sem_destroy(&dlt_mutex); /* allow the user app to do dlt_init() again. */ @@ -1491,6 +1499,8 @@ int dlt_get_log_state() DltReturnValue dlt_set_log_mode(DltUserLogMode mode) { + DLT_UNUSED(mode); + /* forbid dlt usage in child after fork */ if (g_dlt_is_child) return DLT_RETURN_ERROR; @@ -2892,7 +2902,7 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han return DLT_RETURN_OK; } - +#ifndef __ANDROID_API__ void dlt_user_trace_network_segmented_thread(void *unused) { /* Unused on purpose. */ @@ -3192,6 +3202,7 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, return DLT_RETURN_OK; } +#endif /*__ANDROID_API__*/ DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text) { @@ -4622,26 +4633,39 @@ int dlt_start_threads() dlt_log(LOG_CRIT, "Can't start segmented thread!\n"); return -1; } - return 0; } void dlt_stop_threads() { int dlt_housekeeperthread_result = 0; - int dlt_segmented_nwt_result = 0; int joined = 0; if (dlt_housekeeperthread_handle) { /* do not ignore return value */ +#ifndef __ANDROID_API__ dlt_housekeeperthread_result = pthread_cancel(dlt_housekeeperthread_handle); +#else + dlt_lock_mutex(&mq_mutex); + dlt_housekeeperthread_result = pthread_kill(dlt_housekeeperthread_handle, SIGKILL); + dlt_user_cleanup_handler(NULL); +#endif + if (dlt_housekeeperthread_result != 0) dlt_vlog(LOG_ERR, - "ERROR pthread_cancel(dlt_housekeeperthread_handle): %s\n", + "ERROR %s(dlt_housekeeperthread_handle): %s\n", +#ifndef __ANDROID_API__ + "pthread_cancel", +#else + "pthread_kill", +#endif strerror(dlt_housekeeperthread_result)); } +#ifndef __ANDROID_API__ + int dlt_segmented_nwt_result = 0; + if (dlt_user.dlt_segmented_nwt_handle) { dlt_lock_mutex(&mq_mutex); pthread_cond_signal(&mq_init_condition); @@ -4654,7 +4678,7 @@ void dlt_stop_threads() "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", strerror(dlt_segmented_nwt_result)); } - +#endif /* ifndef __ANDROID_API__ */ /* make sure that the threads really finished working */ if ((dlt_housekeeperthread_result == 0) && dlt_housekeeperthread_handle) { joined = pthread_join(dlt_housekeeperthread_handle, NULL); @@ -4667,6 +4691,7 @@ void dlt_stop_threads() dlt_housekeeperthread_handle = 0; /* set to invalid */ } +#ifndef __ANDROID_API__ if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle) { joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); @@ -4677,6 +4702,7 @@ void dlt_stop_threads() dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */ } +#endif /* ifndef __ANDROID_API__ */ } static void dlt_fork_child_fork_handler() diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index d2471ee..642d43d 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2064,7 +2064,7 @@ int dlt_receiver_check_and_get(DltReceiver *receiver, unsigned int flags) { unsigned int min_size = to_get; - char *src = NULL; + uint8_t *src = NULL; if (flags & DLT_RCV_SKIP_HEADER) min_size += sizeof(DltUserHeader); @@ -2075,7 +2075,7 @@ int dlt_receiver_check_and_get(DltReceiver *receiver, !dest) return DLT_RETURN_WRONG_PARAMETER; - src = receiver->buf; + src = (uint8_t *)receiver->buf; if (flags & DLT_RCV_SKIP_HEADER) src += sizeof(DltUserHeader); @@ -3048,8 +3048,11 @@ void dlt_get_version(char *buf, size_t size) _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE, _DLT_PACKAGE_REVISION, +/* Clang does not like these macros, because they are not reproducable */ +#pragma clang diagnostic ignored "-Wdate-time" __DATE__, __TIME__, +#pragma clang diagnostic error "-Wdate-time" _DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, diff --git a/util/create_dlt_version_h.py b/util/create_dlt_version_h.py new file mode 100755 index 0000000..2b685b7 --- /dev/null +++ b/util/create_dlt_version_h.py @@ -0,0 +1,81 @@ +#!/usr/bin/python3 +# This software has been developed by Advanced Driver Information Technology. +# Copyright(c) 2019 Advanced Driver Information Technology GmbH, +# Advanced Driver Information Technology Corporation, Robert Bosch GmbH, +# Robert Bosch Car Multimedia GmbH and DENSO Corporation. +# +# This file is part of GENIVI Project DLT - Diagnostic Log and Trace. +# +# This Source Code Form is subject to the terms of the +# Mozilla Public License (MPL), v. 2.0. +# If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# For further information see http://www.genivi.org/. +import pathlib +import argparse +import re + + +# CMake variables without references to other vars +determined_vars = {} + + +# Resolves variable reverences from CMakeLists e.g.: +# ${DLT_MAJOR_VERSION}.${DLT_MINOR_VERSION} +# -> 2.${DLT_MINOR_VERSION} +def resolve_variables(undetermined_vars): + for key, val in undetermined_vars.items(): + m = re.search('\$\{(?P\w+)\}', val) + if m: + if m.group('var_name') in determined_vars: + yield key, val.replace(m.group(0), determined_vars[m.group('var_name')]) + continue + yield key, val + else: + determined_vars[key] = val + + +def main(cmake_file, header_in_file, header_out_file): + cmakelists = pathlib.Path(cmake_file) + header_in = pathlib.Path(header_in_file) + header_out = pathlib.Path(header_out_file) + + src = cmakelists.open().read() + undetermined_vars = {} + + # Find all cmake variable assignments + for match in re.finditer('set\s*\(\s*(?P\w+)\s*(?P\S+)\s*\)', src): + key = match.group('key') + val = match.group('value') + if '${' not in val: + determined_vars[key] = val + else: + undetermined_vars[key] = val + + # Try to resolve all variables referencing other vars e.g.: + # set(DLT_VERSION ${DLT_MAJOR_VERSION}.${DLT_MINOR_VERSION}.${DLT_PATCH_LEVEL}) + no_changes = 5 + def_len = len(undetermined_vars) + while no_changes > 0: + undetermined_vars = dict(resolve_variables(undetermined_vars)) + if len(undetermined_vars) == def_len: + no_changes -= 1 + else: + def_len = len(undetermined_vars) + no_changes = 5 + + header_out.parent.mkdir(parents=True, exist_ok=True) + with header_in.open() as hi, header_out.open('w') as ho: + for line in hi: + text, _ = re.subn('@(?P\w+)@', lambda x: determined_vars.get(x.group('var_name'), "NONE"), line) + ho.write(text) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('cmakelists') + parser.add_argument('header_in') + parser.add_argument('header_out') + args = parser.parse_args() + main(args.cmakelists, args.header_in, args.header_out) -- cgit v1.2.1