diff options
author | Lutz Helwing <lutz_helwing@mentor.com> | 2015-07-15 14:14:19 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2015-10-07 10:40:33 +0200 |
commit | 1236195e9b93aeb6bfa625956fa027f96003756d (patch) | |
tree | 07b08c892a486f9f97c1674e0d253099eb3388f3 /src/dbus/dlt-dbus.c | |
parent | 033a69218af3490f6be409f66f350c1568655f61 (diff) | |
download | DLT-daemon-1236195e9b93aeb6bfa625956fa027f96003756d.tar.gz |
DLT daemon improvement - dlt_init()-check
DLT daemon improvement - parameter value range check
Adapt unit tests to check for enum return values
Changed C version to gnu99 and C++ version to gnu++0c
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src/dbus/dlt-dbus.c')
-rw-r--r-- | src/dbus/dlt-dbus.c | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/src/dbus/dlt-dbus.c b/src/dbus/dlt-dbus.c index 2b99a4e..f85252f 100644 --- a/src/dbus/dlt-dbus.c +++ b/src/dbus/dlt-dbus.c @@ -80,96 +80,96 @@ filter_func (DBusConnection *con, int main (int argc, char *argv[]) { - DltDBusCliOptions options; - DltDBusConfiguration config; - - DBusConnection *connection; - DBusError error; - DBusBusType type; - - int num; - - if(read_command_line(&options, argc, argv) < 0) - { - fprintf(stderr, "Failed to read command line!\n"); - return -1; - } - - if(read_configuration_file(&config, options.ConfigurationFileName) < 0) - { - fprintf(stderr, "Failed to read configuration file!\n"); - return -1; - } - - // register application - if(options.ApplicationId) - DLT_REGISTER_APP (options.ApplicationId, "DBus Logging"); - else - DLT_REGISTER_APP (config.ApplicationId, "DBus Logging"); - - // register context - DLT_REGISTER_CONTEXT_LL_TS(dbusContext, config.DBus.ContextId, "DBus Context for Logging",DLT_LOG_INFO,DLT_TRACE_STATUS_ON); - DLT_REGISTER_CONTEXT(dbusLog, "Log", "DBus Context for Logging Generic information"); - - // initialise error handler - dbus_error_init (&error); - - // set DBus bus type - if(options.BusType) - type = (DBusBusType) atoi(options.BusType); - else - type = (DBusBusType) atoi(config.DBus.BusType); - - // get connection - connection = dbus_bus_get (type, &error); - - if(type==0) - DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("BusType"),DLT_STRING("Session Bus")); - else if(type==1) - DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("BusType"),DLT_STRING("System Bus")); - else - DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("BusType"),DLT_INT(type)); - - if (NULL == connection) - { - fprintf (stderr, "Failed to open connection to %d: %s\n", - DBUS_BUS_SYSTEM, - error.message); - dbus_error_free (&error); - exit (1); - } - - for(num=0;num<config.DBus.FilterCount;num++) - { - dbus_bus_add_match (connection, - config.DBus.FilterMatch[num], - &error); - printf("Added FilterMatch: %s\n",config.DBus.FilterMatch[num]); - DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("FilterMatch"),DLT_UINT(num+1),DLT_STRING(config.DBus.FilterMatch[num])); - 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_CONTEXT (dbusLog); - DLT_UNREGISTER_APP (); - exit(1); + DltDBusCliOptions options; + DltDBusConfiguration config; + + DBusConnection *connection; + DBusError error; + DBusBusType type; + + int num; + + if(read_command_line(&options, argc, argv) < 0) + { + fprintf(stderr, "Failed to read command line!\n"); + return -1; + } + + if(read_configuration_file(&config, options.ConfigurationFileName) < 0) + { + fprintf(stderr, "Failed to read configuration file!\n"); + return -1; + } + + // register application + if(options.ApplicationId) + DLT_REGISTER_APP (options.ApplicationId, "DBus Logging"); + else + DLT_REGISTER_APP (config.ApplicationId, "DBus Logging"); + + // register context + DLT_REGISTER_CONTEXT_LL_TS(dbusContext, config.DBus.ContextId, "DBus Context for Logging",DLT_LOG_INFO,DLT_TRACE_STATUS_ON); + DLT_REGISTER_CONTEXT(dbusLog, "Log", "DBus Context for Logging Generic information"); + + // initialise error handler + dbus_error_init (&error); + + // set DBus bus type + if(options.BusType) + type = (DBusBusType) atoi(options.BusType); + else + type = (DBusBusType) atoi(config.DBus.BusType); + + // get connection + connection = dbus_bus_get (type, &error); + + if(type==0) + DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("BusType"),DLT_STRING("Session Bus")); + else if(type==1) + DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("BusType"),DLT_STRING("System Bus")); + else + DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("BusType"),DLT_INT(type)); + + if (NULL == connection) + { + fprintf (stderr, "Failed to open connection to %d: %s\n", + DBUS_BUS_SYSTEM, + error.message); + dbus_error_free (&error); + exit (1); + } + + for(num=0;num<config.DBus.FilterCount;num++) + { + dbus_bus_add_match (connection, + config.DBus.FilterMatch[num], + &error); + printf("Added FilterMatch: %s\n",config.DBus.FilterMatch[num]); + DLT_LOG(dbusLog,DLT_LOG_INFO,DLT_STRING("FilterMatch"),DLT_UINT(num+1),DLT_STRING(config.DBus.FilterMatch[num])); + 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_CONTEXT (dbusLog); + DLT_UNREGISTER_APP (); + exit(1); fail: - /* fail */ - fprintf (stderr, "Error: %s\n", error.message); - DLT_UNREGISTER_CONTEXT (dbusContext); - DLT_UNREGISTER_CONTEXT (dbusLog); - DLT_UNREGISTER_APP (); - exit(1); + /* fail */ + fprintf (stderr, "Error: %s\n", error.message); + DLT_UNREGISTER_CONTEXT (dbusContext); + DLT_UNREGISTER_CONTEXT (dbusLog); + DLT_UNREGISTER_APP (); + exit(1); } |