diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-06-06 12:44:27 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2014-06-11 14:16:57 +0200 |
commit | e561fd5d5e2564dcb6d5e4358ac7d3b917016ebb (patch) | |
tree | f0388e9af4323f0441c4b578631f68c0a2cc1f80 | |
parent | 9a91fe28c05c54f7428325b0290a29c28966ae56 (diff) | |
download | DLT-daemon-e561fd5d5e2564dcb6d5e4358ac7d3b917016ebb.tar.gz |
First implementation of DLT DBus adapter.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r-- | CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/dbus/CMakeLists.txt | 35 | ||||
-rw-r--r-- | src/dbus/dlt-dbus.c | 168 | ||||
-rw-r--r-- | src/dbus/dlt-dbus.conf | 10 | ||||
-rw-r--r-- | src/dbus/dlt-dbus.h | 27 | ||||
-rw-r--r-- | systemd/CMakeLists.txt | 9 | ||||
-rwxr-xr-x | systemd/dlt-dbus.service.cmake | 32 |
8 files changed, 297 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 79f303f..e40f5ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,11 +61,12 @@ option(WITH_TESTSCRIPTS "Set to ON to run CMakeLists.txt in testscripts" option(WITH_GPROF "Set -pg to compile flags" OFF )
option(WITH_DLTTEST "Set to ON to build with modifications to test User-Daemon communication with corrupt messages" OFF)
option(WITH_DLT_SHM_ENABLE "EXPERIMENTAL! Set to ON to use shared memory as IPC. EXPERIMENTAL!" OFF )
-option(WTIH_DLT_ADAPTOR "Set ton ON to build src/adaptor binaries" ON)
-option(WITH_DLT_CONSOLE "Set ton ON to build src/console binaries" ON)
-option(WITH_DLT_EXAMPLES "Set ton ON to build src/examples binaries" ON)
-option(WITH_DLT_SYSTEM "Set ton ON to build src/system binaries" ON)
-option(WITH_DLT_TESTS "Set ton ON to build src/test binaries" ON)
+option(WTIH_DLT_ADAPTOR "Set to ON to build src/adaptor binaries" ON)
+option(WITH_DLT_CONSOLE "Set to ON to build src/console binaries" ON)
+option(WITH_DLT_EXAMPLES "Set to ON to build src/examples binaries" ON)
+option(WITH_DLT_SYSTEM "Set to ON to build src/system binaries" ON)
+option(WITH_DLT_DBUS "Set to ON to build src/dbus binaries" ON)
+option(WITH_DLT_TESTS "Set to ON to build src/test binaries" ON)
# RPM settings
set( GENIVI_RPM_RELEASE "1")#${DLT_REVISION}")
set( LICENSE "Mozilla Public License Version 2.0" )
@@ -74,6 +75,11 @@ set( LICENSE "Mozilla Public License Version 2.0" ) find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
+find_package(PkgConfig)
+if(WITH_DLT_DBUS)
+ pkg_check_modules(DBUS REQUIRED dbus-1)
+endif(WITH_DLT_DBUS)
+
include_directories(
${CMAKE_SOURCE_DIR}/
${CMAKE_SOURCE_DIR}/include/dlt
@@ -150,6 +156,7 @@ message( STATUS "WTIH_DLT_ADAPTOR = ${WTIH_DLT_ADAPTOR}") message( STATUS "WITH_DLT_CONSOLE = ${WITH_DLT_CONSOLE}")
message( STATUS "WITH_DLT_EXAMPLES = ${WITH_DLT_EXAMPLES}")
message( STATUS "WITH_DLT_SYSTEM = ${WITH_DLT_SYSTEM}")
+message( STATUS "WITH_DLT_DBUS = ${WITH_DLT_DBUS}")
message( STATUS "WITH_DLT_TESTS = ${WITH_DLT_TESTS}")
message( STATUS "WITH_DLT_SHM_ENABLE = ${WITH_DLT_SHM_ENABLE}" )
message( STATUS "WITH_DLTTEST = ${WITH_DLTTEST}" )
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a288381..52291f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,3 +36,7 @@ endif( WITH_DLT_TESTS ) if( WITH_DLT_SYSTEM ) add_subdirectory( system ) endif( WITH_DLT_SYSTEM ) + +if( WITH_DLT_DBUS ) + add_subdirectory( dbus ) +endif( WITH_DLT_DBUS ) diff --git a/src/dbus/CMakeLists.txt b/src/dbus/CMakeLists.txt new file mode 100644 index 0000000..4d26358 --- /dev/null +++ b/src/dbus/CMakeLists.txt @@ -0,0 +1,35 @@ +####### +# Dlt - Diagnostic Log and Trace +# @licence make begin@ +# +# Copyright (C) 2011-2014, BMW AG - Alexander Wenzel <alexander.aw.wenzel@bmw.de> +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# 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/. +# +# @licence end@ +######## + +include_directories( + ${CMAKE_SOURCE_DIR}/ + ${CMAKE_SOURCE_DIR}/include/dlt + ${DBUS_INCLUDE_DIRS} +) + +set(dlt_dbus_SRCS dlt-dbus.c) +add_executable(dlt-dbus ${dlt_dbus_SRCS}) +target_link_libraries(dlt-dbus dlt ${DBUS_LIBRARIES}) + +set_target_properties(dlt-dbus PROPERTIES LINKER_LANGUAGE C) + +install(TARGETS dlt-dbus + RUNTIME DESTINATION bin + COMPONENT base) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dlt-dbus.conf + DESTINATION /etc + COMPONENT base) diff --git a/src/dbus/dlt-dbus.c b/src/dbus/dlt-dbus.c new file mode 100644 index 0000000..53eb94c --- /dev/null +++ b/src/dbus/dlt-dbus.c @@ -0,0 +1,168 @@ +/** + * @licence app begin@ + * Copyright (C) 2014 BMW AG + * + * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Alexander Wenzel <alexander.wenzel@bmw.de> + * + * \file dlt-dbus.c + * For further information see http://www.genivi.org/. + * @licence end@ + */ + +#include "dlt-dbus.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dbus/dbus.h> +#include <sys/time.h> +#include <dlt.h> + +#include <time.h> + +#ifdef USE_EAVESDROP + #define EAVESDROPPING_RULE "eavesdrop=true," +#else + #define EAVESDROPPING_RULE "" +#endif + +DLT_DECLARE_CONTEXT(dbusContext); + +static char dbus_message_buffer[DBUS_MAXIMUM_MESSAGE_LENGTH]; + +static const char* +type_to_name (int message_type) +{ + switch (message_type) + { + case DBUS_MESSAGE_TYPE_SIGNAL: + return "signal"; + case DBUS_MESSAGE_TYPE_METHOD_CALL: + return "method call"; + case DBUS_MESSAGE_TYPE_METHOD_RETURN: + return "method return"; + case DBUS_MESSAGE_TYPE_ERROR: + return "error"; + default: + return "(unknown message type)"; + } +} + +static DBusHandlerResult +filter_func (DBusConnection *con, + DBusMessage *message, + void *data) +{ + DBusMessageIter iter; + const char *sender; + const char *destination; + char **buf; + int message_type; + char *log_message; + int log_type; + int len_p; + + buf = (char**)&dbus_message_buffer; + if (!dbus_message_marshal(message, + buf, + &len_p)) + { + fprintf (stderr, "Failed to serialize DBus message!\n"); + return DBUS_HANDLER_RESULT_HANDLED; + } + //DLT_LOG (dbusContext, DLT_LOG_INFO, DLT_STRING("dbus message"), DLT_RAW ((void *)*buf, len_p)); + DLT_TRACE_NETWORK_SEGMENTED(dbusContext,DLT_NW_TRACE_IPC,0,0,len_p,(void *)*buf); + + if (dbus_message_is_signal (message, + DBUS_INTERFACE_LOCAL, + "Disconnected")) + { + DLT_UNREGISTER_CONTEXT (dbusContext); + DLT_UNREGISTER_APP (); + exit (0); + } + + + /* Conceptually we want this to be + * DBUS_HANDLER_RESULT_NOT_YET_HANDLED, but this raises + * some problems. See bug 1719. + */ + return DBUS_HANDLER_RESULT_HANDLED; +} + +int main (int argc, char *argv[]) +{ + /* DLT initialisation */ + DLT_REGISTER_APP ("IPC0", "DBus Logging"); + DLT_REGISTER_CONTEXT(dbusContext, "ALL", "DBus Context for Logging"); + + DBusConnection *connection; + DBusError error; + DBusBusType type = DBUS_BUS_SESSION; + //DBusBusType type = DBUS_BUS_SYSTEM; + + dbus_error_init (&error); + + connection = dbus_bus_get (type, &error); + if (NULL == connection) + { + fprintf (stderr, "Failed to open connection to %s: %s\n", + DBUS_BUS_SYSTEM, + error.message); + dbus_error_free (&error); + exit (1); + } + + dbus_bus_add_match (connection, + EAVESDROPPING_RULE "type='signal'", + &error); + if (dbus_error_is_set (&error)) + goto fail; + dbus_bus_add_match (connection, + EAVESDROPPING_RULE "type='method_call'", + &error); + if (dbus_error_is_set (&error)) + goto fail; + dbus_bus_add_match (connection, + EAVESDROPPING_RULE "type='method_return'", + &error); + if (dbus_error_is_set (&error)) + goto fail; + dbus_bus_add_match (connection, + EAVESDROPPING_RULE "type='error'", + &error); + if (dbus_error_is_set (&error)) + goto fail; + + if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) { + fprintf (stderr, "Couldn't add filter!\n"); + exit (1); + } + + while (dbus_connection_read_write_dispatch(connection, -1)) + ; + + DLT_UNREGISTER_CONTEXT (dbusContext); + DLT_UNREGISTER_APP (); + exit(1); + +fail: + + /* fail */ + fprintf (stderr, "Error: %s\n", error.message); + DLT_UNREGISTER_CONTEXT (dbusContext); + DLT_UNREGISTER_APP (); + exit(1); + +} diff --git a/src/dbus/dlt-dbus.conf b/src/dbus/dlt-dbus.conf new file mode 100644 index 0000000..29ec241 --- /dev/null +++ b/src/dbus/dlt-dbus.conf @@ -0,0 +1,10 @@ +# Configuration file of DLT dbus forwarder +# + +######################################################################## +# General configuration +######################################################################## + +# The application Id used for the System manager (Default: SYS) +ApplicationId = DBUS + diff --git a/src/dbus/dlt-dbus.h b/src/dbus/dlt-dbus.h new file mode 100644 index 0000000..da93f7b --- /dev/null +++ b/src/dbus/dlt-dbus.h @@ -0,0 +1,27 @@ +/** + * @licence app begin@ + * Copyright (C) 2014 BMW AG + * + * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \author Alexander Wenzel <alexander.wenzel@bmw.de> + * + * \file dlt-dbus.c + * For further information see http://www.genivi.org/. + * @licence end@ + */ + +#ifndef DLT_DBUS_H_ +#define DLT_DBUS_H_ + + + +#endif /* DLT_DBUS_H_ */ diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index 38ab7c2..a9838e4 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -32,6 +32,11 @@ if(WITH_SYSTEMD) configure_file(${CMAKE_SOURCE_DIR}/systemd/dlt-system.service.cmake ${PROJECT_BINARY_DIR}/systemd/dlt-system.service) message( STATUS "Configured systemd unit file:dlt-system.service" ) + if(WITH_DLT_DBUS) + configure_file(${CMAKE_SOURCE_DIR}/systemd/dlt-dbus.service.cmake ${PROJECT_BINARY_DIR}/systemd/dlt-dbus.service) + message( STATUS "Configured systemd unit file:dlt-dbus.service" ) + endif(WITH_DLT_DBUS) + configure_file(${CMAKE_SOURCE_DIR}/systemd/dlt-receive.service.cmake ${PROJECT_BINARY_DIR}/systemd/dlt-receive.service) message( STATUS "Configured systemd unit file:dlt-receive.service" ) @@ -50,6 +55,10 @@ if(WITH_SYSTEMD) install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt-system.service DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt-receive.service DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) + if(WITH_DLT_DBUS) + install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt-dbus.service DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) + endif(WITH_DLT_DBUS) + if(WITH_DLT_EXAMPLES) install(FILES ${PROJECT_BINARY_DIR}/systemd/dlt-example-user.service DESTINATION ${SYSTEMD_CONFIGURATIONS_FILES_DIR} ) endif(WITH_DLT_EXAMPLES) diff --git a/systemd/dlt-dbus.service.cmake b/systemd/dlt-dbus.service.cmake new file mode 100755 index 0000000..2727c2d --- /dev/null +++ b/systemd/dlt-dbus.service.cmake @@ -0,0 +1,32 @@ +#######
+# Dlt - Diagnostic Log and Trace
+# @licence make begin@
+#
+# Copyright (C) 2011-2012, BMW AG - Alexander Wenzel <alexander.aw.wenzel@bmw.de>
+#
+# Contributions are licensed to the GENIVI Alliance under one or more
+# Contribution License Agreements.
+#
+# 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/.
+#
+# @licence end@
+########
+
+[Unit]
+Description=GENIVI DLT DBus. Application to forward DBus messages to DLT.
+Documentation=man:dlt-dbus(1) man:dlt-dbus.conf(5)
+Wants=dlt.service
+
+[Service]
+Type=Simple
+User=root
+ExecStart=@CMAKE_INSTALL_PREFIX@/bin/dlt-dbus
+WatchdogSec=@DLT_WatchdogSec@
+NotifyAccess=main
+LimitCORE=infinity
+
+[Install]
+WantedBy=basic.target
+
|