summaryrefslogtreecommitdiff
path: root/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp')
-rw-r--r--PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp324
1 files changed, 295 insertions, 29 deletions
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);
+}
+
+
+
+
+
+