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 /src | |
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>
Diffstat (limited to 'src')
-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 |
5 files changed, 244 insertions, 0 deletions
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_ */ |