summaryrefslogtreecommitdiff
path: root/PluginCommandInterfaceDbus
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 /PluginCommandInterfaceDbus
parent2d849dd0b5b1558e92cd0f2cd6dbc556950d631d (diff)
downloadaudiomanager-9826492b0066d47cfa9ba68d6efe737cc3c317a3.tar.gz
update on dbus
Diffstat (limited to 'PluginCommandInterfaceDbus')
-rw-r--r--PluginCommandInterfaceDbus/CMakeLists.txt1
-rw-r--r--PluginCommandInterfaceDbus/CommandDbusReceive.cpp83
-rw-r--r--PluginCommandInterfaceDbus/CommandDbusReceive.h11
-rw-r--r--PluginCommandInterfaceDbus/DBUSMessageHandler.cpp290
-rw-r--r--PluginCommandInterfaceDbus/DBUSMessageHandler.h69
-rw-r--r--PluginCommandInterfaceDbus/DBUSTypes.h39
-rw-r--r--PluginCommandInterfaceDbus/DbusInterface.cpp8
-rw-r--r--PluginCommandInterfaceDbus/DbusInterface.h5
-rw-r--r--PluginCommandInterfaceDbus/headers.h10
9 files changed, 344 insertions, 172 deletions
diff --git a/PluginCommandInterfaceDbus/CMakeLists.txt b/PluginCommandInterfaceDbus/CMakeLists.txt
index a1d7209..62d4dc1 100644
--- a/PluginCommandInterfaceDbus/CMakeLists.txt
+++ b/PluginCommandInterfaceDbus/CMakeLists.txt
@@ -37,7 +37,6 @@ INCLUDE_DIRECTORIES(
SET(PLUGINDBUS_SRCS_CXX
CommandDbusReceive.cpp
DbusInterface.cpp
- DBUSIntrospection.cpp
DBUSMessageHandler.cpp
DbusSend.cpp
)
diff --git a/PluginCommandInterfaceDbus/CommandDbusReceive.cpp b/PluginCommandInterfaceDbus/CommandDbusReceive.cpp
index 4269bbe..e4d4bbb 100644
--- a/PluginCommandInterfaceDbus/CommandDbusReceive.cpp
+++ b/PluginCommandInterfaceDbus/CommandDbusReceive.cpp
@@ -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;
}
+
diff --git a/PluginCommandInterfaceDbus/CommandDbusReceive.h b/PluginCommandInterfaceDbus/CommandDbusReceive.h
index f8daa7e..72b43b7 100644
--- a/PluginCommandInterfaceDbus/CommandDbusReceive.h
+++ b/PluginCommandInterfaceDbus/CommandDbusReceive.h
@@ -27,15 +27,17 @@
#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_ */
diff --git a/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp b/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
index a796f28..7c4f39a 100644
--- a/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
+++ b/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
@@ -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);
+}
diff --git a/PluginCommandInterfaceDbus/DBUSMessageHandler.h b/PluginCommandInterfaceDbus/DBUSMessageHandler.h
index 0ec6d3a..819b8f2 100644
--- a/PluginCommandInterfaceDbus/DBUSMessageHandler.h
+++ b/PluginCommandInterfaceDbus/DBUSMessageHandler.h
@@ -21,24 +21,44 @@
#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
index 0f8474c..0000000
--- a/PluginCommandInterfaceDbus/DBUSTypes.h
+++ /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_
diff --git a/PluginCommandInterfaceDbus/DbusInterface.cpp b/PluginCommandInterfaceDbus/DbusInterface.cpp
index a83a549..c37ada2 100644
--- a/PluginCommandInterfaceDbus/DbusInterface.cpp
+++ b/PluginCommandInterfaceDbus/DbusInterface.cpp
@@ -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);
diff --git a/PluginCommandInterfaceDbus/DbusInterface.h b/PluginCommandInterfaceDbus/DbusInterface.h
index 83a04b8..b4c5a45 100644
--- a/PluginCommandInterfaceDbus/DbusInterface.h
+++ b/PluginCommandInterfaceDbus/DbusInterface.h
@@ -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;
};
diff --git a/PluginCommandInterfaceDbus/headers.h b/PluginCommandInterfaceDbus/headers.h
index 062675f..078dfdc 100644
--- a/PluginCommandInterfaceDbus/headers.h
+++ b/PluginCommandInterfaceDbus/headers.h
@@ -15,17 +15,11 @@
#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);