update on dbus
authorChristian Mueller <christian@lmuc329619u.(none)>
Fri, 5 Aug 2011 08:51:38 +0000 (10:51 +0200)
committerChristian Mueller <christian@lmuc329619u.(none)>
Fri, 5 Aug 2011 08:51:38 +0000 (10:51 +0200)
21 files changed:
AudioManagerDaemon/CommandHandler.cpp
AudioManagerDaemon/commandInterface.h
AudioManagerDaemon/main.cpp
PluginCommandInterfaceDbus/CMakeLists.txt
PluginCommandInterfaceDbus/CommandDbusReceive.cpp
PluginCommandInterfaceDbus/CommandDbusReceive.h
PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
PluginCommandInterfaceDbus/DBUSMessageHandler.h
PluginCommandInterfaceDbus/DBUSTypes.h [deleted file]
PluginCommandInterfaceDbus/DbusInterface.cpp
PluginCommandInterfaceDbus/DbusInterface.h
PluginCommandInterfaceDbus/headers.h
PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
PluginRoutingInterfaceDbus/AudiomanagerInterface.h
PluginRoutingInterfaceDbus/CMakeLists.txt
PluginRoutingInterfaceDbus/DBUSIntrospection.cpp [deleted file]
PluginRoutingInterfaceDbus/DBUSIntrospection.h [deleted file]
PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
PluginRoutingInterfaceDbus/DBUSMessageHandler.h
PluginRoutingInterfaceDbus/DBUSTypes.h [deleted file]
PluginRoutingInterfaceDbus/headers.h

index 96cf8ed..7a7719f 100644 (file)
@@ -60,7 +60,7 @@ void CommandHandler::loadPlugins(){
         }
 
 
-        CommandPlugin->startupInterface(m_receiver);
+        CommandPlugin->startupInterface(m_receiver,m_core->returnDbusHandler());
                DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Routing Plugin"));
         m_interfaceList.push_back(CommandPlugin);
     }
index daef4ca..f95d207 100644 (file)
@@ -55,7 +55,7 @@ public:
 \r
 class CommandSendInterface {\r
 public:\r
-       virtual void startupInterface(CommandReceiveInterface * action)=0;\r
+       virtual void startupInterface(CommandReceiveInterface * action,  dbusRoothandler* dbushandler)=0;\r
        virtual void stop()=0;\r
        /**\r
         * Callback that is called when the number of connections change\r
index ea6d5f5..2531e15 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
        core.registerHookEngine(&hookhandler);
        core.registerReceiver(&breceiver);
        core.registerDbusRootHandler(&dbushandler);
-       //core.registerCommandInterfa email whenever you are availce(&commandIface);
+//     core.registerCommandInterface(&commandIface);
        router.registerDatabasehandler(&dhandler);
        //commandIface.registerDatabasehandler(&dhandler);
 
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
        DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("load bus plugins"));
        bushandler.load_Bus_plugins();
        bushandler.StartupInterfaces();
-//     chandler.loadPlugins();
+       chandler.loadPlugins();
        DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Init phase is over, everything up and running"));
 
        DBusConnection* con=dbushandler.returnConnection();
index a1d7209..62d4dc1 100644 (file)
@@ -37,7 +37,6 @@ INCLUDE_DIRECTORIES(
 SET(PLUGINDBUS_SRCS_CXX
        CommandDbusReceive.cpp
     DbusInterface.cpp 
-    DBUSIntrospection.cpp
     DBUSMessageHandler.cpp
     DbusSend.cpp
 )
index 4269bbe..e4d4bbb 100644 (file)
@@ -43,9 +43,9 @@ static MethodTable manager_methods[] =
 {
        { "connect",                    "uu",           "u",            &CommandDbusReceive::connect },
        { "disconnect",                         "uu",           "u",            &CommandDbusReceive::disconnect },
-       { "getListConnections",     "",                 "a{ii}",        &CommandDbusReceive::getListConnections },
-       { "getListSinks",               "",             "a{si}",        &CommandDbusReceive::getListSinks },
-       { "getListSources",             "",             "a{si}",        &CommandDbusReceive::getListSources },
+       { "getListConnections",     "",                 "a(ii)",        &CommandDbusReceive::getListConnections },
+       { "getListSinks",               "",             "a(si)",        &CommandDbusReceive::getListSinks },
+       { "getListSources",             "",             "a(si)",        &CommandDbusReceive::getListSources },
        { "interruptRequest",           "ss",           "u",            &CommandDbusReceive::interruptRequest },
        { "interruptResume",            "s",            "u",            &CommandDbusReceive::interruptResume },
        { "setVolume",                  "ss",       "u",                &CommandDbusReceive::setVolume },
@@ -59,25 +59,24 @@ static SignalTable manager_signals[] = {
        { "",                           ""}
 };
 
+static DBusObjectPathVTable vtable =
+{
+       NULL,CommandDbusReceive::receive_callback,NULL, NULL, NULL, NULL
+};
+
+
 
-CommandDbusReceive::CommandDbusReceive(CommandReceiveInterface* r_interface): m_audioman(r_interface),m_running(false) {
+CommandDbusReceive::CommandDbusReceive(CommandReceiveInterface* r_interface, dbusRoothandler* roothandler): m_audioman(r_interface),m_Introspection(new DBUSIntrospection(manager_methods, manager_signals,std::string(MY_NODE))),m_roothandler(roothandler) {
 }
 
 bool CommandDbusReceive::startup_interface() {
        DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Starting up dbus connector"));
-
-    g_pDbusMessage = new DBUSMessageHandler();
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("create thread"));
-    this->m_running = true;
-    pthread_create(&m_currentThread, NULL, CommandDbusReceive::run, this);
-       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Started dbus connector"));
+    g_pDbusMessage = new DBUSMessageHandler(&vtable,m_roothandler->returnConnection(),this);
     return true;
 }
 
 void CommandDbusReceive::stop() {
        DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Stopped dbus communication"));
-    this->m_running = false;
-    pthread_join(m_currentThread, NULL);
     delete g_pDbusMessage;
 }
 
@@ -175,52 +174,34 @@ void CommandDbusReceive::emitSignalNumberofSourcesChanged() {
 }
 
 DBusHandlerResult CommandDbusReceive::receive_callback (DBusConnection *conn,DBusMessage *msg,void *user_data) {
-       (void) user_data;
+       m_reference=(CommandDbusReceive*) user_data;
        DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("message received"));
 
-       const char *member = dbus_message_get_member(msg);
-       const char *iface = dbus_message_get_interface(msg);
-       bool found=false;
-       int i = 0;
+    string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
 
        if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
-               DBUSIntrospection introspectionString(manager_methods,manager_signals);
-               introspectionString.process(conn, msg); 'a'
-               g_pDbusMessage->setConnection(conn);
-               dbus_connection_pop_message(conn);
+               m_reference->m_Introspection->process(conn,msg);
                return DBUS_HANDLER_RESULT_HANDLED;
-       } else if (strcmp(DBUS_SERVICE_PREFIX,iface)==0) {
-
-               while (!found && strcmp(manager_methods[i].name, "") != 0) {
-                       if (strcmp(manager_methods[i].name, member) == 0)
-                       {
-                               MethodTable entry = manager_methods[i];
-                               DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("got call for method:"),DLT_STRING(entry.name));
-                               CallBackMethod m = entry.function;
-                               (m_reference->*m)(conn, msg);
-                               found = true;
-                       }
-                       i++;
+       }
+
+       bool found=false;
+       int i = 0;
+
+       const char *n = dbus_message_get_member(msg);
+       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("got call for method:"),DLT_STRING(n));
+       while (!found && strcmp(manager_methods[i].name, "") != 0) {
+               if (dbus_message_is_method_call(msg,DBUS_SERVICE_SERVICE,manager_methods[i].name)) {
+                       MethodTable entry = manager_methods[i];
+                       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("got call for method:"),DLT_STRING(entry.name));
+                       CallBackMethod m = entry.function;
+                       (m_reference->*m)(conn, msg);
+                       found=true;
+                       return DBUS_HANDLER_RESULT_HANDLED;
                }
-               return DBUS_HANDLER_RESULT_HANDLED;
-       } else {
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+               i++;
        }
-}
 
-void* CommandDbusReceive::run(void * arg)
-{
-       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Main loop running"));
-    m_reference = (CommandDbusReceive*) arg;
-    DBusConnection* conn = g_pDbusMessage->getConnection();
-    if (!dbus_connection_add_filter(conn, (DBusHandleMessageFunction)&m_reference->receive_callback, NULL,NULL)) {
-       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("failing filter thread"));
-    }
-    while (m_reference->m_running && dbus_connection_read_write_dispatch(conn, -1))
-    {
-       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Dispatching Most message..."));
-    }
-
-       DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread"));
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
+
index f8daa7e..72b43b7 100644 (file)
 
 #include "headers.h"
 
+class DBUSIntrospection;
+
 class CommandDbusReceive {
 
 public:
-       CommandDbusReceive(CommandReceiveInterface* r_interface);
+       CommandDbusReceive(CommandReceiveInterface* r_interface, dbusRoothandler* roothandler);
 
        bool startup_interface();
        void stop();
+    static DBusHandlerResult receive_callback (DBusConnection *,DBusMessage *,void *);
 
-       static DBusHandlerResult receive_callback (DBusConnection *connection,DBusMessage *message,void *user_data);
        void connect(DBusConnection* conn, DBusMessage* msg);
        void disconnect(DBusConnection* conn, DBusMessage* msg);
        void getListConnections(DBusConnection* conn, DBusMessage* msg);
@@ -50,11 +52,10 @@ public:
        void emitSignalNumberofSourcesChanged();
 
 private:
-       static void* run(void * threadid);
-    pthread_t m_currentThread;
     static CommandDbusReceive* m_reference;
     CommandReceiveInterface* m_audioman;
-       bool m_running;
+       DBUSIntrospection* m_Introspection;
+    dbusRoothandler* m_roothandler;
 };
 
 #endif /* DBUSINTERFACE_H_ */
index a796f28..7c4f39a 100644 (file)
@@ -3,37 +3,19 @@
 #include "headers.h"
 #include <stdlib.h>
 
-DBUSMessageHandler::DBUSMessageHandler()
+DBUSMessageHandler::DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference)
 : m_MessageIter()
 , m_pReply(0)
 , m_serial(0)
-, m_pConnection(0)
+, m_pConnection(conn)
 {
     dbus_error_init(&m_err);
 
-    // connect to the bus and check for errors
-    m_pConnection = dbus_bus_get(DBUS_BUS_SESSION, &m_err);
-    if (dbus_error_is_set(&m_err))
-    {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Connection error"));
-        dbus_error_free(&m_err);
-    }
-    if (NULL == m_pConnection)
-    {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Connection is null"));
-        exit(1);
-    }
-    int ret = dbus_bus_request_name(m_pConnection,DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_REPLACE_EXISTING, &m_err);
-    if (dbus_error_is_set(&m_err))
-    {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Name Error"),DLT_STRING(m_err.message));
-        dbus_error_free(&m_err);
-    }
-    if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
-    {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicatorNot Primary Owner"), DLT_INT(ret));
-        exit(1);
-    }
+    string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
+       dbus_bool_t b=dbus_connection_register_object_path(m_pConnection, nodeString.c_str(), vtable, reference);
+       if(!b) {
+               DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("Registering of node"), DLT_STRING(MY_NODE),DLT_STRING("failed"));
+       }
 }
 
 DBUSMessageHandler::~DBUSMessageHandler()
@@ -43,23 +25,23 @@ DBUSMessageHandler::~DBUSMessageHandler()
     bool errorset = dbus_error_is_set(&err);
     if (errorset)
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
     }
-    dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_PREFIX, &err);
+    dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_SERVICE, &err);
     errorset = dbus_error_is_set(&err);
     if (errorset)
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
     }
     dbus_error_init(&err);
-    dbus_bus_release_name(m_pConnection, DBUS_SERVICE_PREFIX, &err);
+    dbus_bus_release_name(m_pConnection, DBUS_SERVICE_SERVICE, &err);
 }
 
 void DBUSMessageHandler::initReceive(DBusMessage* msg)
 {
     if (!dbus_message_iter_init(msg, &m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS Message has no arguments!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS Message has no arguments!"));
     }
 }
 
@@ -75,10 +57,10 @@ void DBUSMessageHandler::closeReply()
     // send the reply && flush the connection
     if (!dbus_connection_send(m_pConnection, m_pReply, &m_serial))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
     dbus_connection_flush(m_pConnection);
 
     // free the reply
@@ -92,10 +74,10 @@ void DBUSMessageHandler::ReplyError(DBusMessage* msg, const char* errorname, con
     // send the reply && flush the connection
     if (!dbus_connection_send(m_pConnection, m_pReply, &m_serial))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
     dbus_connection_flush(m_pConnection);
 
     // free the reply
@@ -105,9 +87,10 @@ void DBUSMessageHandler::ReplyError(DBusMessage* msg, const char* errorname, con
 char* DBUSMessageHandler::getString()
 {
     char* param;
+
     if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
     }
     else
     {
@@ -123,7 +106,7 @@ dbus_bool_t DBUSMessageHandler::getBool()
 
     if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no bool!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no bool!"));
     }
     else
     {
@@ -139,7 +122,7 @@ char DBUSMessageHandler::getByte()
 
     if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no byte!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no byte!"));
     }
     else
     {
@@ -155,7 +138,7 @@ dbus_uint32_t DBUSMessageHandler::getUInt()
 
     if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no uint32_t!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no uint32_t!"));
     }
     else
     {
@@ -171,7 +154,7 @@ double DBUSMessageHandler::getDouble()
 
     if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no double!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no double!"));
     }
     else
     {
@@ -185,7 +168,7 @@ void DBUSMessageHandler::getArrayOfUInt(int* pLength, unsigned int** ppArray)
 {
     if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
         return;
     }
 
@@ -206,7 +189,7 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
 {
     if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
         return;
     }
 
@@ -217,7 +200,7 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
     {
         if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&arrayIter))
         {
-               DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
+               DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
         }
         char* param;
         dbus_message_iter_get_basic(&arrayIter, &param);
@@ -240,7 +223,7 @@ void DBUSMessageHandler::append(bool toAppend)
        dbus_bool_t mybool=toAppend;
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BOOLEAN, &mybool))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
@@ -249,7 +232,7 @@ void DBUSMessageHandler::append(dbus_uint32_t toAppend)
 {
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_UINT32, &toAppend))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
@@ -258,7 +241,7 @@ void DBUSMessageHandler::append(double toAppend)
 {
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_DOUBLE, &toAppend))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
@@ -267,7 +250,7 @@ void DBUSMessageHandler::append(char toAppend)
 {
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BYTE, &toAppend))
     {
-       DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
@@ -287,16 +270,17 @@ void DBUSMessageHandler::sendSignal(const char* signalname) {
        dbus_uint32_t serial = 0;
        DBusMessage* msg;
 
-       msg =dbus_message_new_signal(DBUS_SERVICE_PREFIX_PATH,DBUS_SERVICE_PREFIX,signalname);
+    string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
+       msg =dbus_message_new_signal(nodeString.c_str(),DBUS_SERVICE_SERVICE,signalname);
 
        if (NULL == msg)
        {
-               DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("Message null!"));
+               DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("Message null!"));
                this->~DBUSMessageHandler();
        }
 
        if (!dbus_connection_send(m_pConnection, msg, &serial)) {
-               DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+               DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
                this->~DBUSMessageHandler();
        }
 
@@ -354,7 +338,215 @@ void DBUSMessageHandler::append(std::list<SourceType> list){
 
 
 
+DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable,std::string nodename)
+: m_methodTable(methodTable), m_signalTable(signalTable), m_nodename(nodename)
+{
+    generateString();
+}
+
+void DBUSIntrospection::generateString()
+{
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
+
+    addHeader();
+    openNode(m_nodename);
+    openInterface("org.freedesktop.DBus.Introspectable");
+    openMethod("Introspect");
+    addArgument("data", "out", "s");
+    closeMethod();
+    closeInterface();
+    openInterface(DBUS_SERVICE_SERVICE);
+
+    int index = 0;
+
+    while (strcmp(m_methodTable[index].name, "") != 0)
+    {
+        MethodTable entry = m_methodTable[index];
+        addEntry(entry);
+        ++index;
+    }
+
+    index=0;
+    if (m_signalTable) {
+        while (strcmp(m_signalTable[index].name, "") != 0)
+        {
+            SignalTable entry = m_signalTable[index];
+            addEntry(entry);
+            ++index;
+        }
+    }
+    closeInterface();
+    closeNode();
+
+}
+
+void DBUSIntrospection::addHeader(void)
+{
+    m_introspectionString << "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS"
+        << "Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/"
+        << "dbus/1.0/introspect.dtd\"> \n";
+}
+
+void DBUSIntrospection::openNode(string nodename)
+{
+    m_introspectionString << "<node name=\"" << nodename << "\">  \n";
+}
+
+void DBUSIntrospection::openInterface(string interfacename)
+{
+    m_introspectionString << "<interface name=\"" << interfacename << "\">  \n";
+}
+
+void DBUSIntrospection::openMethod(string methodname)
+{
+    m_introspectionString << "<method name=\"" << methodname << "\">  \n";
+}
+
+void DBUSIntrospection::openSignal(string signalname) {
+       m_introspectionString<<"<signal name=\"" << signalname << "\">  \n";
+}
+
+void DBUSIntrospection::addArgument(string argname, string direction, string type)
+{
+    m_introspectionString << "<arg name=\"" << argname << "\" direction=\""
+        << direction << "\" type=\"" << type << "\"/>  \n";
+}
+
+
+void DBUSIntrospection::addSignalArgument(string argname, string type){
+    m_introspectionString << "<arg name=\"" << argname << "\" type=\"" << type << "\"/>  \n";
+}
+
+void DBUSIntrospection::closeMethod(void)
+{
+    m_introspectionString << "</method>  \n";
+}
+
+void DBUSIntrospection::closeInterface(void)
+{
+    m_introspectionString << "</interface>  \n";
+}
+
+void DBUSIntrospection::closeNode(void)
+{
+    m_introspectionString << "</node>  \n";
+}
+
+void DBUSIntrospection::closeSignal(void){
+       m_introspectionString<<"</signal>  \n";
+}
+
+void DBUSIntrospection::addEntry(MethodTable entry)
+{
+    string methodName = entry.name;
+    string parameterArray = entry.signature;
+    string returnValueArray = string(entry.reply);
+
+    openMethod(methodName);
+
+    for(uint parameterIndex = 0; parameterIndex < parameterArray.length(); ++parameterIndex)
+    {
+        switch (parameterArray.at(parameterIndex))
+        {
+                       case 'a':
+                       if (parameterArray.at(parameterIndex+1)=='(') {
+                               int size=parameterArray.find((')'),parameterIndex);
+                               addArgument("","in",parameterArray.substr(parameterIndex,size+1));
+                               parameterIndex+=size;
+                       } else {
+                               addArgument("","in", parameterArray.substr(parameterIndex,2));
+                               parameterIndex+=2;
+                       }
+                       break;
+               default:
+                       addArgument("","in", parameterArray.substr(parameterIndex,1));
+                       break;
+        }
+    }
+
+
+    for(uint returnValueIndex = 0; returnValueIndex < returnValueArray.length(); ++returnValueIndex)
+    {
+        switch (returnValueArray.at(returnValueIndex))
+        {
+                       case 'a':
+                       if (returnValueArray.at(returnValueIndex+1)=='(') {
+                               int size=returnValueArray.find((')'),returnValueIndex);
+                               addArgument("","out",returnValueArray.substr(returnValueIndex,size+1));
+                               returnValueIndex+=size;
+                       } else {
+                               addArgument("","out", returnValueArray.substr(returnValueIndex,2));
+                               returnValueIndex+=2;
+                       }
+                       break;
+               default:
+                       addArgument("","out", returnValueArray.substr(returnValueIndex,1));
+                       break;
+        }
+    }
+
+    closeMethod();
+}
 
+void DBUSIntrospection::addEntry(SignalTable entry)
+{
+    string methodName = entry.name;
+    string parameterArray = entry.signature;
+
+    openSignal(methodName);
+
+    for(uint parameterIndex = 0; parameterIndex < parameterArray.length(); ++parameterIndex)
+    {
+        switch (parameterArray.at(parameterIndex))
+        {
+            case 'a':
+                if (parameterArray.at(parameterIndex+1)=='{') {
+                       int size=parameterArray.find(('}'),parameterIndex);
+                       addSignalArgument("",parameterArray.substr(parameterIndex,size+1));
+                       parameterIndex+=size;
+                } else {
+                       parameterIndex++;
+                    addSignalArgument("", "a" + parameterArray.at(parameterIndex));
+                }
+                break;
+            default:
+               addSignalArgument("", parameterArray.substr(parameterIndex,1));
+                break;
+        }
+    }
+
+    closeSignal();
+}
+
+void DBUSIntrospection::process(DBusConnection* conn, DBusMessage* msg)
+{
+    DBusMessage * reply;
+    DBusMessageIter args;
+    dbus_uint32_t serial = 0;
+
+    // create a reply from the message
+    reply = dbus_message_new_method_return(msg);
+
+    string introspect = m_introspectionString.str();
+    const char* string = introspect.c_str();
+
+    // add the arguments to the reply
+    dbus_message_iter_init_append(reply, &args);
+    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string))
+    {
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+    }
+
+    // send the reply && flush the connection
+    if (!dbus_connection_send(conn, reply, &serial))
+    {
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+    }
+    dbus_connection_flush(conn);
+
+    // free the reply
+    dbus_message_unref(reply);
+}
 
 
 
index 0ec6d3a..819b8f2 100644 (file)
 #define _DBUSMESSAGEHANDLER_H_
 
 #include <vector>
+#include <sstream>
+using std::stringstream;
+
 #include <string>
+using std::string;
+
 #include "headers.h"
+#include <dbus/dbus.h>
+
+#define DLT_CONTEXT DBusCommandPlugin
+
+typedef void (CommandDbusReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
+
+struct MethodTable
+{
+    const char *name;
+    const char *signature;
+    const char *reply;
+    CallBackMethod function;
+};
+
+struct SignalTable {
+       const char* name;
+       const char* signature;
+};
+
 
 class DBUSMessageHandler
 {
 public:
-    DBUSMessageHandler();
+       DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference);
     ~DBUSMessageHandler();
 
-    void setConnection(DBusConnection* conn);
-    DBusConnection* getConnection();
-
     void initReceive(DBusMessage* msg);
     void initReply(DBusMessage* msg);
     void closeReply();
     void ReplyError(DBusMessage* msg, const char* errorname, const char* errorMsg);
 
-
     dbus_uint32_t getUInt();
     char getByte();
     dbus_bool_t getBool();
@@ -66,15 +86,38 @@ private:
     DBusError m_err;
 };
 
-
-inline void DBUSMessageHandler::setConnection(DBusConnection* conn)
+class DBUSIntrospection
 {
-    m_pConnection = conn;
-}
+public:
+    DBUSIntrospection(MethodTable* table, SignalTable* stable,std::string nodename);
+    void process(DBusConnection* conn, DBusMessage* msg);
 
-inline DBusConnection* DBUSMessageHandler::getConnection()
-{
-    return m_pConnection;
-}
+private:
+    void generateString(void);
+
+    void addHeader(void);
+    void addArgument(string argname, string direction, string type);
+    void addSignalArgument(string argname, string type);
+    void addEntry(MethodTable entry);
+    void addEntry(SignalTable entry);
+
+    void openNode(string nodename);
+    void closeNode(void);
+
+    void openInterface(string interfacename);
+    void closeInterface(void);
+
+    void openMethod(string methodname);
+    void closeMethod(void);
+
+    void openSignal(string signalname);
+    void closeSignal(void);
+
+private:
+    stringstream m_introspectionString;
+    MethodTable* m_methodTable;
+    SignalTable* m_signalTable;
+    std::string m_nodename;
+};
 
 #endif // _DBUSMESSAGEWRAPPER_H_
diff --git a/PluginCommandInterfaceDbus/DBUSTypes.h b/PluginCommandInterfaceDbus/DBUSTypes.h
deleted file mode 100644 (file)
index 0f8474c..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/***************************************************************************
- *
- * Copyright 2010,2011 BMW Car IT GmbH
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ****************************************************************************/
-#ifndef _DBUSTYPES_H_
-#define _DBUSTYPES_H_
-
-#include "headers.h"
-
-typedef void (CommandDbusReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
-
-struct MethodTable
-{
-    const char *name;
-    const char *signature;
-    const char *reply;
-    CallBackMethod function;
-};
-
-struct SignalTable {
-       const char* name;
-       const char* signature;
-};
-
-#endif // _DBUSTYPES_H_
index a83a549..c37ada2 100644 (file)
@@ -35,7 +35,7 @@
 
 DLT_DECLARE_CONTEXT(DBusCommandPlugin)
 
-DbusCommandInterface::DbusCommandInterface() : m_busname(DBUS_BUSNAME), m_path(DBUS_PATH) {
+DbusCommandInterface::DbusCommandInterface() {
 
        DLT_REGISTER_APP("DBusCommandPlugin", "DBusCommandPlugin");
        DLT_REGISTER_CONTEXT(DBusCommandPlugin, "PluginCommand", "DBusCommandPlugin");
@@ -46,10 +46,12 @@ DbusCommandInterface::~DbusCommandInterface() {
        delete m_DbusInterface;
 }
 
-void DbusCommandInterface::startupInterface(CommandReceiveInterface* iface) {
+void DbusCommandInterface::startupInterface(CommandReceiveInterface* iface,  dbusRoothandler* dbushandler) {
        m_audioman = iface;
-       m_DbusInterface = new CommandDbusReceive(iface);
+       m_rootHandler = dbushandler;
+       m_DbusInterface = new CommandDbusReceive(iface,dbushandler);
        m_DbusInterface->startup_interface();
+       m_rootHandler->registerNode(MY_NODE);
 
        DBusError err;
     dbus_error_init(&err);
index 83a04b8..b4c5a45 100644 (file)
@@ -44,15 +44,14 @@ public:
        void cbConnectionChanged();
        void cbNumberOfSinksChanged();
        void cbNumberOfSourcesChanged();
-       void startupInterface(CommandReceiveInterface* iface);
+       void startupInterface(CommandReceiveInterface* iface,dbusRoothandler* dbushandler);
        void stop();
 
 private:
        CommandReceiveInterface *m_audioman;
        CommandDbusReceive* m_DbusInterface;
        DBusConnection* m_conn;
-       char* m_busname;
-       char* m_path;
+       dbusRoothandler* m_rootHandler;
 
 };
 
index 062675f..078dfdc 100644 (file)
 #include "commandInterface.h"
 #include "DbusSend.h"
 #include "DBUSMessageHandler.h"
-#include "DBUSIntrospection.h"
+#include "dbusRoothandler.h"
 #include "DbusInterface.h"
-#include "DBUSTypes.h"
 
 
-#define BUS_NAME "DBUS"
-#define DBUS_BUSNAME "org.genivi.pulse"
-#define DBUS_PATH "/pulse"
-
-const char DBUS_SERVICE_PREFIX[] = "org.bla.audiomanagerCommand\0";
-const char DBUS_SERVICE_PREFIX_PATH[] = "/org/bla/audiomanagerCommand\0";
+const char MY_NODE[]="commandinterface\0";
 
 DLT_IMPORT_CONTEXT(DBusCommandPlugin);
 
index bdfbdd4..650486c 100644 (file)
@@ -39,12 +39,12 @@ static DBUSMessageHandler* g_pDbusMessage;
 
 static MethodTable manager_methods[] =
 {
-       { "peekDomain",        "s",    "u",     &AudioManagerInterface::peekDomain },
-       { "registerSource",    "sss",  "u",     &AudioManagerInterface::registerSource },
-       { "registerSink",      "sss",    "u",   &AudioManagerInterface::registerSink },
-       { "registerDomain",    "sssb",   "u",   &AudioManagerInterface::registerDomain },
-       { "registerGateway",      "sssss",    "u",      &AudioManagerInterface::registerGateway },
-       { "",                  "",      "",     NULL }
+       { "peekDomain",        "s",             "u",            &AudioManagerInterface::peekDomain },
+       { "registerSource",    "sss",           "u",            &AudioManagerInterface::registerSource },
+       { "registerSink",      "sss",           "u",            &AudioManagerInterface::registerSink },
+       { "registerDomain",    "sssb",          "u",            &AudioManagerInterface::registerDomain },
+       { "registerGateway",   "sssss",         "u",            &AudioManagerInterface::registerGateway },
+       { "",                  "",              "",     NULL }
 };
 
 static SignalTable manager_signals[] = {
@@ -52,7 +52,7 @@ static SignalTable manager_signals[] = {
        { "",                           ""}
 };
 
-static DBusObjectPathVTable _vtable =
+static DBusObjectPathVTable vtable =
 {
        NULL,AudioManagerInterface::receive_callback,NULL, NULL, NULL, NULL
 };
@@ -65,14 +65,11 @@ AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interfac
 bool AudioManagerInterface::startup_interface()
 {
        DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Starting up dbus connector"));
-
-    g_pDbusMessage = new DBUSMessageHandler(&_vtable,m_roothandler->returnConnection(),this);
-
+    g_pDbusMessage = new DBUSMessageHandler(&vtable,m_roothandler->returnConnection(),this);
     return true;
 }
 
 void AudioManagerInterface::stop()
-
 {
        DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopped dbus connector"));
     delete g_pDbusMessage;
@@ -84,7 +81,7 @@ void AudioManagerInterface::peekDomain(DBusConnection* conn, DBusMessage* msg) {
        char* name = g_pDbusMessage->getString();
        domain_t domain = m_audioman->peekDomain(name);
        g_pDbusMessage->initReply(msg);
-       g_pDbusMessage->appendUInt(domain);
+       g_pDbusMessage->append((dbus_uint32_t)domain);
        g_pDbusMessage->closeReply();
 }
 
@@ -96,7 +93,7 @@ void AudioManagerInterface::registerSource(DBusConnection* conn, DBusMessage* ms
        char* domain = g_pDbusMessage->getString();
        source_t source=m_audioman->registerSource(name, audioclass, domain);
        g_pDbusMessage->initReply(msg);
-       g_pDbusMessage->appendUInt(source);
+       g_pDbusMessage->append((dbus_uint32_t)source);
        g_pDbusMessage->closeReply();
 }
 void AudioManagerInterface::registerSink(DBusConnection* conn, DBusMessage* msg) {
@@ -107,7 +104,7 @@ void AudioManagerInterface::registerSink(DBusConnection* conn, DBusMessage* msg)
        char* domain = g_pDbusMessage->getString();
        sink_t sink=m_audioman->registerSink(name, audioclass, domain);
        g_pDbusMessage->initReply(msg);
-       g_pDbusMessage->appendUInt(sink);
+       g_pDbusMessage->append((dbus_uint32_t)sink);
        g_pDbusMessage->closeReply();
 }
 
@@ -121,7 +118,7 @@ void AudioManagerInterface::registerDomain(DBusConnection* conn, DBusMessage* ms
        bool earlymode = g_pDbusMessage->getString();
        domain_t domain=m_reference->m_audioman->registerDomain(name, busname, node, earlymode);
        g_pDbusMessage->initReply(msg);
-       g_pDbusMessage->appendUInt(domain);
+       g_pDbusMessage->append((dbus_uint32_t)domain);
        g_pDbusMessage->closeReply();
 
 }
@@ -136,7 +133,7 @@ void AudioManagerInterface::registerGateway(DBusConnection* conn, DBusMessage* m
        char* controlDomain = g_pDbusMessage->getString();
        domain_t domain=m_audioman->registerGateway(name, sink, source, domainSource, domainSink, controlDomain);
        g_pDbusMessage->initReply(msg);
-       g_pDbusMessage->appendUInt(domain);
+       g_pDbusMessage->append((dbus_uint32_t)domain);
        g_pDbusMessage->closeReply();
        emit_systemReady();
 }
index a56975c..3411bd3 100644 (file)
@@ -26,7 +26,6 @@
 #define DBUSINTERFACE_H_
 
 #include "headers.h"
-#include "DBUSIntrospection.h"
 
 class DBUSIntrospection;
 
index 4880da1..c9e80ea 100644 (file)
@@ -37,7 +37,6 @@ INCLUDE_DIRECTORIES(
 SET(PLUGINDBUS_SRCS_CXX
        AudiomanagerInterface.cpp
     DbusInterface.cpp 
-    DBUSIntrospection.cpp
     DBUSMessageHandler.cpp
     DbusSend.cpp
 )
diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
deleted file mode 100644 (file)
index 20d682a..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/***************************************************************************
- *
- * Copyright 2010,2011 BMW Car IT GmbH
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ****************************************************************************/
-#include "DBUSIntrospection.h"
-#include <string.h>
-#include <sstream>
-
-DLT_IMPORT_CONTEXT(DBusCommandPlugin);
-
-using std::stringstream;
-
-
-DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable,std::string nodename)
-: m_methodTable(methodTable), m_signalTable(signalTable), m_nodename(nodename)
-{
-    generateString();
-}
-
-void DBUSIntrospection::generateString()
-{
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
-
-    addHeader();
-    openNode(m_nodename);
-    openInterface("org.freedesktop.DBus.Introspectable");
-    openMethod("Introspect");
-    addArgument("data", "out", "s");
-    closeMethod();
-    closeInterface();
-    openInterface(DBUS_SERVICE_SERVICE);
-
-    int index = 0;
-
-    while (strcmp(m_methodTable[index].name, "") != 0)
-    {
-        MethodTable entry = m_methodTable[index];
-        addEntry(entry);
-        ++index;
-    }
-
-    index=0;
-    if (m_signalTable) {
-        while (strcmp(m_signalTable[index].name, "") != 0)
-        {
-            SignalTable entry = m_signalTable[index];
-            addEntry(entry);
-            ++index;
-        }
-    }
-    closeInterface();
-    closeNode();
-
-}
-
-void DBUSIntrospection::addHeader(void)
-{
-    m_introspectionString << "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS"
-        << "Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/"
-        << "dbus/1.0/introspect.dtd\"> \n";
-}
-
-void DBUSIntrospection::openNode(string nodename)
-{
-    m_introspectionString << "<node name=\"" << nodename << "\">  \n";
-}
-
-void DBUSIntrospection::openInterface(string interfacename)
-{
-    m_introspectionString << "<interface name=\"" << interfacename << "\">  \n";
-}
-
-void DBUSIntrospection::openMethod(string methodname)
-{
-    m_introspectionString << "<method name=\"" << methodname << "\">  \n";
-}
-
-void DBUSIntrospection::addSignal(string signalname) {
-       m_introspectionString<<"<signal name=\"" << signalname << "\"/>  \n";
-}
-
-void DBUSIntrospection::addArgument(string argname, string direction, string type)
-{
-    m_introspectionString << "<arg name=\"" << argname << "\" direction=\""
-        << direction << "\" type=\"" << type << "\"/>  \n";
-}
-
-void DBUSIntrospection::closeMethod(void)
-{
-    m_introspectionString << "</method>  \n";
-}
-
-void DBUSIntrospection::closeInterface(void)
-{
-    m_introspectionString << "</interface>  \n";
-}
-
-void DBUSIntrospection::closeNode(void)
-{
-    m_introspectionString << "</node>  \n";
-}
-
-
-void DBUSIntrospection::addEntry(MethodTable entry)
-{
-    string methodName = entry.name;
-    string parameterArray = entry.signature;
-    string returnValueArray = string(entry.reply);
-
-    openMethod(methodName);
-
-    for(uint parameterIndex = 0; parameterIndex < parameterArray.length(); ++parameterIndex)
-    {
-        switch (parameterArray.at(parameterIndex))
-        {
-            case 'a':
-                parameterIndex++;
-                addArgument("", "in", "a" + parameterArray.at(parameterIndex));
-                break;
-            default:
-                addArgument("param", "in", parameterArray.substr(parameterIndex,1));
-                break;
-        }
-    }
-
-    for(uint returnValueIndex = 0; returnValueIndex < returnValueArray.length(); ++returnValueIndex)
-    {
-        switch (returnValueArray.at(returnValueIndex))
-        {
-            case 'a':
-                returnValueIndex++;
-                addArgument("", "out", "a" + returnValueArray.at(returnValueIndex));
-                break;
-            default:
-                addArgument("param", "out", returnValueArray.substr(returnValueIndex,1));
-                break;
-        }
-    }
-
-    closeMethod();
-}
-
-void DBUSIntrospection::addEntry(SignalTable entry)
-{
-    string methodName = entry.name;
-    string parameterArray = entry.signature;
-
-    addSignal(methodName);
-
-    for(uint parameterIndex = 0; parameterIndex < parameterArray.length(); ++parameterIndex)
-    {
-        switch (parameterArray.at(parameterIndex))
-        {
-            case 'a':
-                parameterIndex++;
-                addArgument("", "in", "a" + parameterArray.at(parameterIndex));
-                break;
-            default:
-                addArgument("param", "in", parameterArray.substr(parameterIndex,1));
-                break;
-        }
-    }
-}
-
-void DBUSIntrospection::process(DBusConnection* conn, DBusMessage* msg)
-{
-    DBusMessage * reply;
-    DBusMessageIter args;
-    dbus_uint32_t serial = 0;
-
-    // create a reply from the message
-    reply = dbus_message_new_method_return(msg);
-
-    string introspect = m_introspectionString.str();
-    const char* string = introspect.c_str();
-
-    // add the arguments to the reply
-    dbus_message_iter_init_append(reply, &args);
-    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string))
-    {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
-    }
-
-    // send the reply && flush the connection
-    if (!dbus_connection_send(conn, reply, &serial))
-    {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
-    }
-    dbus_connection_flush(conn);
-
-    // free the reply
-    dbus_message_unref(reply);
-}
-
diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.h b/PluginRoutingInterfaceDbus/DBUSIntrospection.h
deleted file mode 100644 (file)
index 64636dd..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/***************************************************************************
- *
- * Copyright 2010,2011 BMW Car IT GmbH
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ****************************************************************************/
-
-#ifndef _DBUSINTROSPECTION_H_
-#define _DBUSINTROSPECTION_H_
-
-#include <sstream>
-using std::stringstream;
-
-#include <string>
-using std::string;
-
-#include "DBUSTypes.h"
-#include <dbus/dbus.h>
-
-class DBUSIntrospection
-{
-public:
-    DBUSIntrospection(MethodTable* table, SignalTable* stable,std::string nodename);
-    void process(DBusConnection* conn, DBusMessage* msg);
-
-private:
-    void generateString(void);
-
-    void addHeader(void);
-    void addArgument(string argname, string direction, string type);
-    void addEntry(MethodTable entry);
-    void addEntry(SignalTable entry);
-
-    void openNode(string nodename);
-    void closeNode(void);
-
-    void openInterface(string interfacename);
-    void closeInterface(void);
-
-    void openMethod(string methodname);
-    void closeMethod(void);
-
-    void addSignal(string signalname);
-
-
-private:
-    stringstream m_introspectionString;
-    MethodTable* m_methodTable;
-    SignalTable* m_signalTable;
-    std::string m_nodename;
-};
-
-
-#endif // _DBUSINTROSPECTION_H_
index 51d69dc..7c4f39a 100644 (file)
@@ -14,7 +14,7 @@ DBUSMessageHandler::DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnect
     string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
        dbus_bool_t b=dbus_connection_register_object_path(m_pConnection, nodeString.c_str(), vtable, reference);
        if(!b) {
-               DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Registering of node"), DLT_STRING(MY_NODE),DLT_STRING("failed"));
+               DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("Registering of node"), DLT_STRING(MY_NODE),DLT_STRING("failed"));
        }
 }
 
@@ -25,13 +25,13 @@ DBUSMessageHandler::~DBUSMessageHandler()
     bool errorset = dbus_error_is_set(&err);
     if (errorset)
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
     }
     dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_SERVICE, &err);
     errorset = dbus_error_is_set(&err);
     if (errorset)
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
     }
     dbus_error_init(&err);
     dbus_bus_release_name(m_pConnection, DBUS_SERVICE_SERVICE, &err);
@@ -41,7 +41,7 @@ void DBUSMessageHandler::initReceive(DBusMessage* msg)
 {
     if (!dbus_message_iter_init(msg, &m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS Message has no arguments!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS Message has no arguments!"));
     }
 }
 
@@ -57,10 +57,10 @@ void DBUSMessageHandler::closeReply()
     // send the reply && flush the connection
     if (!dbus_connection_send(m_pConnection, m_pReply, &m_serial))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
     dbus_connection_flush(m_pConnection);
 
     // free the reply
@@ -74,10 +74,10 @@ void DBUSMessageHandler::ReplyError(DBusMessage* msg, const char* errorname, con
     // send the reply && flush the connection
     if (!dbus_connection_send(m_pConnection, m_pReply, &m_serial))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
     dbus_connection_flush(m_pConnection);
 
     // free the reply
@@ -90,7 +90,7 @@ char* DBUSMessageHandler::getString()
 
     if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
     }
     else
     {
@@ -106,7 +106,7 @@ dbus_bool_t DBUSMessageHandler::getBool()
 
     if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no bool!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no bool!"));
     }
     else
     {
@@ -122,7 +122,7 @@ char DBUSMessageHandler::getByte()
 
     if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no byte!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no byte!"));
     }
     else
     {
@@ -138,7 +138,7 @@ dbus_uint32_t DBUSMessageHandler::getUInt()
 
     if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no uint32_t!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no uint32_t!"));
     }
     else
     {
@@ -154,7 +154,7 @@ double DBUSMessageHandler::getDouble()
 
     if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no double!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no double!"));
     }
     else
     {
@@ -168,7 +168,7 @@ void DBUSMessageHandler::getArrayOfUInt(int* pLength, unsigned int** ppArray)
 {
     if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
         return;
     }
 
@@ -189,7 +189,7 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
 {
     if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&m_MessageIter))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
         return;
     }
 
@@ -200,7 +200,7 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
     {
         if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&arrayIter))
         {
-               DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
+               DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
         }
         char* param;
         dbus_message_iter_get_basic(&arrayIter, &param);
@@ -218,43 +218,44 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
     }
 }
 
-void DBUSMessageHandler::appendBool(dbus_bool_t toAppend)
+void DBUSMessageHandler::append(bool toAppend)
 {
-    if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BOOLEAN, &toAppend))
+       dbus_bool_t mybool=toAppend;
+    if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BOOLEAN, &mybool))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
 
-void DBUSMessageHandler::appendUInt(dbus_uint32_t toAppend)
+void DBUSMessageHandler::append(dbus_uint32_t toAppend)
 {
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_UINT32, &toAppend))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
 
-void DBUSMessageHandler::appendDouble(double toAppend)
+void DBUSMessageHandler::append(double toAppend)
 {
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_DOUBLE, &toAppend))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
 
-void DBUSMessageHandler::appendByte(char toAppend)
+void DBUSMessageHandler::append(char toAppend)
 {
     if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BYTE, &toAppend))
     {
-       DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
         exit(1);
     }
 }
 
-void DBUSMessageHandler::appendArrayOfUInt(unsigned int length, unsigned int *IDs)
+void DBUSMessageHandler::append(unsigned int length, unsigned int *IDs)
 {
     DBusMessageIter arrayIter;
     dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "u", &arrayIter);
@@ -269,16 +270,17 @@ void DBUSMessageHandler::sendSignal(const char* signalname) {
        dbus_uint32_t serial = 0;
        DBusMessage* msg;
 
-       msg =dbus_message_new_signal(DBUS_SERVICE_ROOT,DBUS_SERVICE_SERVICE,signalname);
+    string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
+       msg =dbus_message_new_signal(nodeString.c_str(),DBUS_SERVICE_SERVICE,signalname);
 
        if (NULL == msg)
        {
-               DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Message null!"));
+               DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("Message null!"));
                this->~DBUSMessageHandler();
        }
 
        if (!dbus_connection_send(m_pConnection, msg, &serial)) {
-               DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+               DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
                this->~DBUSMessageHandler();
        }
 
@@ -287,3 +289,267 @@ void DBUSMessageHandler::sendSignal(const char* signalname) {
        // free the message
        dbus_message_unref(msg);
 }
+
+void DBUSMessageHandler::append(std::list<ConnectionType> list){
+    DBusMessageIter arrayIter;
+    dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "uu", &arrayIter);
+
+    std::list<ConnectionType>::iterator Ilist;
+    std::list<ConnectionType>::iterator Ibegin=list.begin();
+    std::list<ConnectionType>::iterator Iend=list.end();
+    for(Ilist=Ibegin;Ilist!=Iend; Ilist++)
+    {
+        dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->Sink_ID);
+        dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->Source_ID);
+    }
+    dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
+}
+
+void DBUSMessageHandler::append(std::list<SinkType> list){
+    DBusMessageIter arrayIter;
+    dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "su", &arrayIter);
+
+    std::list<SinkType>::iterator Ilist;
+    std::list<SinkType>::iterator Ibegin=list.begin();
+    std::list<SinkType>::iterator Iend=list.end();
+    for(Ilist=Ibegin;Ilist!=Iend; Ilist++)
+    {
+        dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->name);
+        dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->ID);
+    }
+    dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
+
+}
+
+void DBUSMessageHandler::append(std::list<SourceType> list){
+    DBusMessageIter arrayIter;
+    dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "su", &arrayIter);
+
+    std::list<SourceType>::iterator Ilist;
+    std::list<SourceType>::iterator Ibegin=list.begin();
+    std::list<SourceType>::iterator Iend=list.end();
+    for(Ilist=Ibegin;Ilist!=Iend; Ilist++)
+    {
+        dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->name);
+        dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->ID);
+    }
+    dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
+}
+
+
+
+DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable,std::string nodename)
+: m_methodTable(methodTable), m_signalTable(signalTable), m_nodename(nodename)
+{
+    generateString();
+}
+
+void DBUSIntrospection::generateString()
+{
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
+
+    addHeader();
+    openNode(m_nodename);
+    openInterface("org.freedesktop.DBus.Introspectable");
+    openMethod("Introspect");
+    addArgument("data", "out", "s");
+    closeMethod();
+    closeInterface();
+    openInterface(DBUS_SERVICE_SERVICE);
+
+    int index = 0;
+
+    while (strcmp(m_methodTable[index].name, "") != 0)
+    {
+        MethodTable entry = m_methodTable[index];
+        addEntry(entry);
+        ++index;
+    }
+
+    index=0;
+    if (m_signalTable) {
+        while (strcmp(m_signalTable[index].name, "") != 0)
+        {
+            SignalTable entry = m_signalTable[index];
+            addEntry(entry);
+            ++index;
+        }
+    }
+    closeInterface();
+    closeNode();
+
+}
+
+void DBUSIntrospection::addHeader(void)
+{
+    m_introspectionString << "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS"
+        << "Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/"
+        << "dbus/1.0/introspect.dtd\"> \n";
+}
+
+void DBUSIntrospection::openNode(string nodename)
+{
+    m_introspectionString << "<node name=\"" << nodename << "\">  \n";
+}
+
+void DBUSIntrospection::openInterface(string interfacename)
+{
+    m_introspectionString << "<interface name=\"" << interfacename << "\">  \n";
+}
+
+void DBUSIntrospection::openMethod(string methodname)
+{
+    m_introspectionString << "<method name=\"" << methodname << "\">  \n";
+}
+
+void DBUSIntrospection::openSignal(string signalname) {
+       m_introspectionString<<"<signal name=\"" << signalname << "\">  \n";
+}
+
+void DBUSIntrospection::addArgument(string argname, string direction, string type)
+{
+    m_introspectionString << "<arg name=\"" << argname << "\" direction=\""
+        << direction << "\" type=\"" << type << "\"/>  \n";
+}
+
+
+void DBUSIntrospection::addSignalArgument(string argname, string type){
+    m_introspectionString << "<arg name=\"" << argname << "\" type=\"" << type << "\"/>  \n";
+}
+
+void DBUSIntrospection::closeMethod(void)
+{
+    m_introspectionString << "</method>  \n";
+}
+
+void DBUSIntrospection::closeInterface(void)
+{
+    m_introspectionString << "</interface>  \n";
+}
+
+void DBUSIntrospection::closeNode(void)
+{
+    m_introspectionString << "</node>  \n";
+}
+
+void DBUSIntrospection::closeSignal(void){
+       m_introspectionString<<"</signal>  \n";
+}
+
+void DBUSIntrospection::addEntry(MethodTable entry)
+{
+    string methodName = entry.name;
+    string parameterArray = entry.signature;
+    string returnValueArray = string(entry.reply);
+
+    openMethod(methodName);
+
+    for(uint parameterIndex = 0; parameterIndex < parameterArray.length(); ++parameterIndex)
+    {
+        switch (parameterArray.at(parameterIndex))
+        {
+                       case 'a':
+                       if (parameterArray.at(parameterIndex+1)=='(') {
+                               int size=parameterArray.find((')'),parameterIndex);
+                               addArgument("","in",parameterArray.substr(parameterIndex,size+1));
+                               parameterIndex+=size;
+                       } else {
+                               addArgument("","in", parameterArray.substr(parameterIndex,2));
+                               parameterIndex+=2;
+                       }
+                       break;
+               default:
+                       addArgument("","in", parameterArray.substr(parameterIndex,1));
+                       break;
+        }
+    }
+
+
+    for(uint returnValueIndex = 0; returnValueIndex < returnValueArray.length(); ++returnValueIndex)
+    {
+        switch (returnValueArray.at(returnValueIndex))
+        {
+                       case 'a':
+                       if (returnValueArray.at(returnValueIndex+1)=='(') {
+                               int size=returnValueArray.find((')'),returnValueIndex);
+                               addArgument("","out",returnValueArray.substr(returnValueIndex,size+1));
+                               returnValueIndex+=size;
+                       } else {
+                               addArgument("","out", returnValueArray.substr(returnValueIndex,2));
+                               returnValueIndex+=2;
+                       }
+                       break;
+               default:
+                       addArgument("","out", returnValueArray.substr(returnValueIndex,1));
+                       break;
+        }
+    }
+
+    closeMethod();
+}
+
+void DBUSIntrospection::addEntry(SignalTable entry)
+{
+    string methodName = entry.name;
+    string parameterArray = entry.signature;
+
+    openSignal(methodName);
+
+    for(uint parameterIndex = 0; parameterIndex < parameterArray.length(); ++parameterIndex)
+    {
+        switch (parameterArray.at(parameterIndex))
+        {
+            case 'a':
+                if (parameterArray.at(parameterIndex+1)=='{') {
+                       int size=parameterArray.find(('}'),parameterIndex);
+                       addSignalArgument("",parameterArray.substr(parameterIndex,size+1));
+                       parameterIndex+=size;
+                } else {
+                       parameterIndex++;
+                    addSignalArgument("", "a" + parameterArray.at(parameterIndex));
+                }
+                break;
+            default:
+               addSignalArgument("", parameterArray.substr(parameterIndex,1));
+                break;
+        }
+    }
+
+    closeSignal();
+}
+
+void DBUSIntrospection::process(DBusConnection* conn, DBusMessage* msg)
+{
+    DBusMessage * reply;
+    DBusMessageIter args;
+    dbus_uint32_t serial = 0;
+
+    // create a reply from the message
+    reply = dbus_message_new_method_return(msg);
+
+    string introspect = m_introspectionString.str();
+    const char* string = introspect.c_str();
+
+    // add the arguments to the reply
+    dbus_message_iter_init_append(reply, &args);
+    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string))
+    {
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+    }
+
+    // send the reply && flush the connection
+    if (!dbus_connection_send(conn, reply, &serial))
+    {
+       DLT_LOG(DLT_CONTEXT,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+    }
+    dbus_connection_flush(conn);
+
+    // free the reply
+    dbus_message_unref(reply);
+}
+
+
+
+
+
+
index 8ef0b3d..a7f0d4a 100644 (file)
 #define _DBUSMESSAGEHANDLER_H_
 
 #include <vector>
+#include <sstream>
+using std::stringstream;
+
 #include <string>
+using std::string;
+
 #include "headers.h"
+#include <dbus/dbus.h>
+
+#define DLT_CONTEXT DBusPlugin
+
+typedef void (AudioManagerInterface::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
+
+struct MethodTable
+{
+    const char *name;
+    const char *signature;
+    const char *reply;
+    CallBackMethod function;
+};
+
+struct SignalTable {
+       const char* name;
+       const char* signature;
+};
+
 
 class DBUSMessageHandler
 {
@@ -30,15 +54,11 @@ public:
        DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference);
     ~DBUSMessageHandler();
 
-    void setConnection(DBusConnection* conn);
-    DBusConnection* getConnection();
-
     void initReceive(DBusMessage* msg);
     void initReply(DBusMessage* msg);
     void closeReply();
     void ReplyError(DBusMessage* msg, const char* errorname, const char* errorMsg);
 
-
     dbus_uint32_t getUInt();
     char getByte();
     dbus_bool_t getBool();
@@ -47,11 +67,14 @@ public:
     void getArrayOfUInt(int* length, unsigned int** array);
     void getArrayOfString(std::vector<std::string>* uniforms);
 
-    void appendUInt(dbus_uint32_t toAppend);
-    void appendByte(char toAppend);
-    void appendBool(dbus_bool_t toAppend);
-    void appendDouble(double toAppend);
-    void appendArrayOfUInt(unsigned int length, unsigned int *IDs);
+    void append(dbus_uint32_t toAppend);
+    void append(char toAppend);
+    void append(bool toAppend);
+    void append(double toAppend);
+    void append(unsigned int length, unsigned int *IDs);
+    void append(std::list<SourceType> list);
+    void append(std::list<ConnectionType> list);
+    void append(std::list<SinkType> list);
 
     void sendSignal(const char* signalname);
 
@@ -63,17 +86,38 @@ private:
     DBusError m_err;
 };
 
-
-inline void DBUSMessageHandler::setConnection(DBusConnection* conn)
+class DBUSIntrospection
 {
-    m_pConnection = conn;
-}
+public:
+    DBUSIntrospection(MethodTable* table, SignalTable* stable,std::string nodename);
+    void process(DBusConnection* conn, DBusMessage* msg);
 
-inline DBusConnection* DBUSMessageHandler::getConnection()
-{
-    return m_pConnection;
-}
+private:
+    void generateString(void);
+
+    void addHeader(void);
+    void addArgument(string argname, string direction, string type);
+    void addSignalArgument(string argname, string type);
+    void addEntry(MethodTable entry);
+    void addEntry(SignalTable entry);
 
+    void openNode(string nodename);
+    void closeNode(void);
 
+    void openInterface(string interfacename);
+    void closeInterface(void);
+
+    void openMethod(string methodname);
+    void closeMethod(void);
+
+    void openSignal(string signalname);
+    void closeSignal(void);
+
+private:
+    stringstream m_introspectionString;
+    MethodTable* m_methodTable;
+    SignalTable* m_signalTable;
+    std::string m_nodename;
+};
 
 #endif // _DBUSMESSAGEWRAPPER_H_
diff --git a/PluginRoutingInterfaceDbus/DBUSTypes.h b/PluginRoutingInterfaceDbus/DBUSTypes.h
deleted file mode 100644 (file)
index 2f6d0ef..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/***************************************************************************
- *
- * Copyright 2010,2011 BMW Car IT GmbH
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ****************************************************************************/
-#ifndef _DBUSTYPES_H_
-#define _DBUSTYPES_H_
-
-#include "headers.h"
-
-class AudioManagerInterface;
-
-typedef void (AudioManagerInterface::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
-
-struct MethodTable
-{
-    const char *name;
-    const char *signature;
-    const char *reply;
-    CallBackMethod function;
-};
-
-struct SignalTable {
-       const char* name;
-       const char* signature;
-};
-
-#endif // _DBUSTYPES_H_
index dbb6f3c..9f49ce4 100644 (file)
 #include "AudiomanagerInterface.h"
 #include "DbusSend.h"
 #include "DBUSMessageHandler.h"
-#include "DBUSIntrospection.h"
 #include "DbusInterface.h"
 
-
 #define BUS_NAME "DBUS"
 #define DBUS_BUSNAME "org.genivi.command"
 #define DBUS_PATH "/pulse"