summaryrefslogtreecommitdiff
path: root/PluginRoutingInterfaceDbus
diff options
context:
space:
mode:
authorChristian Mueller <christian@lmuc329619u.(none)>2011-08-05 10:51:38 +0200
committerChristian Mueller <christian@lmuc329619u.(none)>2011-08-05 10:51:38 +0200
commit9826492b0066d47cfa9ba68d6efe737cc3c317a3 (patch)
tree7cedfad495aeddb24a9a363ee1692c4bf4c186fb /PluginRoutingInterfaceDbus
parent2d849dd0b5b1558e92cd0f2cd6dbc556950d631d (diff)
downloadaudiomanager-9826492b0066d47cfa9ba68d6efe737cc3c317a3.tar.gz
update on dbus
Diffstat (limited to 'PluginRoutingInterfaceDbus')
-rw-r--r--PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp29
-rw-r--r--PluginRoutingInterfaceDbus/AudiomanagerInterface.h1
-rw-r--r--PluginRoutingInterfaceDbus/CMakeLists.txt1
-rw-r--r--PluginRoutingInterfaceDbus/DBUSIntrospection.cpp208
-rw-r--r--PluginRoutingInterfaceDbus/DBUSIntrospection.h66
-rw-r--r--PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp324
-rw-r--r--PluginRoutingInterfaceDbus/DBUSMessageHandler.h78
-rw-r--r--PluginRoutingInterfaceDbus/DBUSTypes.h41
-rw-r--r--PluginRoutingInterfaceDbus/headers.h2
9 files changed, 369 insertions, 381 deletions
diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
index bdfbdd4..650486c 100644
--- a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
+++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
@@ -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();
}
diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.h b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
index a56975c..3411bd3 100644
--- a/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
+++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
@@ -26,7 +26,6 @@
#define DBUSINTERFACE_H_
#include "headers.h"
-#include "DBUSIntrospection.h"
class DBUSIntrospection;
diff --git a/PluginRoutingInterfaceDbus/CMakeLists.txt b/PluginRoutingInterfaceDbus/CMakeLists.txt
index 4880da1..c9e80ea 100644
--- a/PluginRoutingInterfaceDbus/CMakeLists.txt
+++ b/PluginRoutingInterfaceDbus/CMakeLists.txt
@@ -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
index 20d682a..0000000
--- a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
+++ /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
index 64636dd..0000000
--- a/PluginRoutingInterfaceDbus/DBUSIntrospection.h
+++ /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_
diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
index 51d69dc..7c4f39a 100644
--- a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
+++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
@@ -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);
+}
+
+
+
+
+
+
diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.h b/PluginRoutingInterfaceDbus/DBUSMessageHandler.h
index 8ef0b3d..a7f0d4a 100644
--- a/PluginRoutingInterfaceDbus/DBUSMessageHandler.h
+++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.h
@@ -21,8 +21,32 @@
#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
index 2f6d0ef..0000000
--- a/PluginRoutingInterfaceDbus/DBUSTypes.h
+++ /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_
diff --git a/PluginRoutingInterfaceDbus/headers.h b/PluginRoutingInterfaceDbus/headers.h
index dbb6f3c..9f49ce4 100644
--- a/PluginRoutingInterfaceDbus/headers.h
+++ b/PluginRoutingInterfaceDbus/headers.h
@@ -15,10 +15,8 @@
#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"