First implementation of DLT DBus adapter.
authorAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Fri, 6 Jun 2014 10:44:27 +0000 (12:44 +0200)
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Wed, 11 Jun 2014 12:16:57 +0000 (14:16 +0200)
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
CMakeLists.txt
src/CMakeLists.txt
src/dbus/CMakeLists.txt [new file with mode: 0644]
src/dbus/dlt-dbus.c [new file with mode: 0644]
src/dbus/dlt-dbus.conf [new file with mode: 0644]
src/dbus/dlt-dbus.h [new file with mode: 0644]
systemd/CMakeLists.txt
systemd/dlt-dbus.service.cmake [new file with mode: 0755]

index 79f303f..e40f5ff 100644 (file)
@@ -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 )\r
 option(WITH_DLTTEST                      "Set to ON to build with modifications to test User-Daemon communication with corrupt messages" OFF)\r
 option(WITH_DLT_SHM_ENABLE    "EXPERIMENTAL! Set to ON to use shared memory as IPC. EXPERIMENTAL!"               OFF )\r
-option(WTIH_DLT_ADAPTOR       "Set ton ON to build src/adaptor binaries"                                         ON)\r
-option(WITH_DLT_CONSOLE       "Set ton ON to build src/console binaries"                                         ON)\r
-option(WITH_DLT_EXAMPLES      "Set ton ON to build src/examples binaries"                                        ON)\r
-option(WITH_DLT_SYSTEM        "Set ton ON to build src/system binaries"                                          ON)\r
-option(WITH_DLT_TESTS         "Set ton ON to build src/test binaries"                                            ON)\r
+option(WTIH_DLT_ADAPTOR       "Set to ON to build src/adaptor binaries"                                         ON)\r
+option(WITH_DLT_CONSOLE       "Set to ON to build src/console binaries"                                         ON)\r
+option(WITH_DLT_EXAMPLES      "Set to ON to build src/examples binaries"                                        ON)\r
+option(WITH_DLT_SYSTEM        "Set to ON to build src/system binaries"                                          ON)\r
+option(WITH_DLT_DBUS          "Set to ON to build src/dbus binaries"                                            ON)\r
+option(WITH_DLT_TESTS         "Set to ON to build src/test binaries"                                            ON)\r
 # RPM settings\r
 set( GENIVI_RPM_RELEASE "1")#${DLT_REVISION}")\r
 set( LICENSE "Mozilla Public License Version 2.0" )\r
@@ -74,6 +75,11 @@ set( LICENSE "Mozilla Public License Version 2.0" )
 find_package(Threads REQUIRED)\r
 find_package(ZLIB REQUIRED)\r
 \r
+find_package(PkgConfig)\r
+if(WITH_DLT_DBUS)\r
+  pkg_check_modules(DBUS REQUIRED dbus-1)\r
+endif(WITH_DLT_DBUS)\r
+\r
 include_directories( \r
     ${CMAKE_SOURCE_DIR}/\r
     ${CMAKE_SOURCE_DIR}/include/dlt\r
@@ -150,6 +156,7 @@ message( STATUS "WTIH_DLT_ADAPTOR = ${WTIH_DLT_ADAPTOR}")
 message( STATUS "WITH_DLT_CONSOLE = ${WITH_DLT_CONSOLE}")\r
 message( STATUS "WITH_DLT_EXAMPLES = ${WITH_DLT_EXAMPLES}")\r
 message( STATUS "WITH_DLT_SYSTEM = ${WITH_DLT_SYSTEM}")\r
+message( STATUS "WITH_DLT_DBUS = ${WITH_DLT_DBUS}")\r
 message( STATUS "WITH_DLT_TESTS = ${WITH_DLT_TESTS}")\r
 message( STATUS "WITH_DLT_SHM_ENABLE = ${WITH_DLT_SHM_ENABLE}" )\r
 message( STATUS "WITH_DLTTEST = ${WITH_DLTTEST}" )\r
index a288381..52291f8 100644 (file)
@@ -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 (file)
index 0000000..4d26358
--- /dev/null
@@ -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 (file)
index 0000000..53eb94c
--- /dev/null
@@ -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 (file)
index 0000000..29ec241
--- /dev/null
@@ -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 (file)
index 0000000..da93f7b
--- /dev/null
@@ -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_ */
index 38ab7c2..a9838e4 100644 (file)
@@ -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 (executable)
index 0000000..2727c2d
--- /dev/null
@@ -0,0 +1,32 @@
+#######\r
+# Dlt - Diagnostic Log and Trace\r
+# @licence make begin@\r
+#\r
+# Copyright (C) 2011-2012, BMW AG - Alexander Wenzel <alexander.aw.wenzel@bmw.de>\r
+# \r
+# Contributions are licensed to the GENIVI Alliance under one or more\r
+# Contribution License Agreements.\r
+# \r
+# This Source Code Form is subject to the terms of the\r
+# Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with\r
+# this file, You can obtain one at http://mozilla.org/MPL/2.0/.\r
+#\r
+# @licence end@\r
+########\r
+\r
+[Unit]\r
+Description=GENIVI DLT DBus. Application to forward DBus messages to DLT.\r
+Documentation=man:dlt-dbus(1) man:dlt-dbus.conf(5)\r
+Wants=dlt.service\r
+\r
+[Service]\r
+Type=Simple\r
+User=root\r
+ExecStart=@CMAKE_INSTALL_PREFIX@/bin/dlt-dbus\r
+WatchdogSec=@DLT_WatchdogSec@\r
+NotifyAccess=main\r
+LimitCORE=infinity\r
+\r
+[Install]\r
+WantedBy=basic.target\r
+\r