summaryrefslogtreecommitdiff
path: root/PluginRoutingInterfaceDbus
diff options
context:
space:
mode:
authorChristian Mueller <christian@lmuc329619u.(none)>2011-07-22 19:44:13 +0200
committerChristian Mueller <christian@lmuc329619u.(none)>2011-07-22 19:44:13 +0200
commit2feaef3bb5f91af43573155106c73143597bdf3e (patch)
treefd59b301174e9d0a1e6821feb3a3ccdf84ff7ee8 /PluginRoutingInterfaceDbus
parenta34ffa9cf03c0685ee4751efb16eca8267e533c3 (diff)
downloadaudiomanager-2feaef3bb5f91af43573155106c73143597bdf3e.tar.gz
- daily commit
- dbus working smooth now, implemented signal handling - changed worker thread for dbus to wait for dbus events not to wakeup every 50 ms
Diffstat (limited to 'PluginRoutingInterfaceDbus')
-rw-r--r--PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp168
-rw-r--r--PluginRoutingInterfaceDbus/AudiomanagerInterface.h6
-rw-r--r--PluginRoutingInterfaceDbus/DBUSIntrospection.cpp46
-rw-r--r--PluginRoutingInterfaceDbus/DBUSIntrospection.h6
-rw-r--r--PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp2
-rw-r--r--PluginRoutingInterfaceDbus/DBUSTypes.h5
-rw-r--r--PluginRoutingInterfaceDbus/DbusInterface.cpp2
7 files changed, 152 insertions, 83 deletions
diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
index 29fe480..0cccdb7 100644
--- a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
+++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
@@ -25,20 +25,34 @@
#include "headers.h"
#include <iostream>
#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <errno.h>
class AudioManagerInterface;
+
AudioManagerInterface* AudioManagerInterface::m_reference = NULL;
static DBUSMessageHandler* g_pDbusMessage;
static MethodTable manager_methods[] =
{
- { "registerSource", "sss", "u", &AudioManagerInterface::registerSource },
- { "peekDomain", "s", "u", &AudioManagerInterface::peekDomain },
- { "", "", "", 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[] = {
+ { "signal_systemReady", ""},
+ { "", ""}
};
+
AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interface) : m_audioman(r_interface),m_running(false) {
}
@@ -47,7 +61,6 @@ bool AudioManagerInterface::startup_interface()
DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Starting up dbus connector"));
g_pDbusMessage = new DBUSMessageHandler();
-
DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("create thread"));
this->m_running = true;
pthread_create(&m_currentThread, NULL, AudioManagerInterface::run, this);
@@ -56,6 +69,7 @@ bool AudioManagerInterface::startup_interface()
}
void AudioManagerInterface::stop()
+
{
DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopped dbus connector"));
this->m_running = false;
@@ -84,19 +98,56 @@ void AudioManagerInterface::registerSource(DBusConnection* conn, DBusMessage* ms
g_pDbusMessage->appendUInt(source);
g_pDbusMessage->closeReply();
}
-void AudioManagerInterface::registerSink(const char* &name, const char* &sinkclass, const char* &domain) {
- m_audioman->registerSink((char*)name, (char*)sinkclass, (char*)domain);
+void AudioManagerInterface::registerSink(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ char* name = g_pDbusMessage->getString();
+ char* audioclass = g_pDbusMessage->getString();
+ char* domain = g_pDbusMessage->getString();
+ sink_t sink=m_audioman->registerSink(name, audioclass, domain);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->appendUInt(sink);
+ g_pDbusMessage->closeReply();
}
-void AudioManagerInterface::registerDomain(const char* &name, const char* &node, bool earlymode) {
+
+void AudioManagerInterface::registerDomain(DBusConnection* conn, DBusMessage* msg) {
char busname[40];
strcpy(busname, BUS_NAME);
- m_audioman->registerDomain((char*)name, busname, (char*)node, earlymode);
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ char* name = g_pDbusMessage->getString();
+ char* node = g_pDbusMessage->getString();
+ bool earlymode = g_pDbusMessage->getString();
+ domain_t domain=m_audioman->registerDomain(name, busname, node, earlymode);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->appendUInt(domain);
+ g_pDbusMessage->closeReply();
+
}
-void AudioManagerInterface::registerGateway(const char* &name, const char* &sink, const char* &source, const char* &domainSource, const char* &domainSink, const char* &controlDomain) {
- m_audioman->registerGateway((char*)name, (char*)sink, (char*)source, (char*)domainSource, (char*)domainSink, (char*)controlDomain);
+void AudioManagerInterface::registerGateway(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ char* name = g_pDbusMessage->getString();
+ char* sink = g_pDbusMessage->getString();
+ char* source = g_pDbusMessage->getString();
+ char* domainSource = g_pDbusMessage->getString();
+ char* domainSink = g_pDbusMessage->getString();
+ 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->closeReply();
+ emit_systemReady();
}
void AudioManagerInterface::emit_systemReady() {
- m_reference->emit_systemReady();
+ DBusMessage* msg;
+ DBusConnection* conn = g_pDbusMessage->getConnection();
+ dbus_uint32_t serial = 0;
+ msg =dbus_message_new_signal("/org/genivi/audiomanager/RoutingInterface",DBUS_SERVICE_PREFIX,"signal_systemReady");
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("error while sending signal system ready on dbus"));
+ }
+ dbus_connection_flush(conn);
}
void* AudioManagerInterface::run(void * arg)
@@ -105,66 +156,43 @@ void* AudioManagerInterface::run(void * arg)
// pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
// pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
m_reference = (AudioManagerInterface*) arg;
- while (m_reference->m_running)
+ DBusMessage* msg = 0;
+ DBusConnection* conn = g_pDbusMessage->getConnection();
+ while (m_reference->m_running && dbus_connection_read_write_dispatch(conn, -1))
{
- // pthread_testcancel();
- DBusMessage* msg = 0;
- DBusConnection* conn = g_pDbusMessage->getConnection();
- dbus_connection_read_write(conn, 50);
- msg = dbus_connection_pop_message(conn);
- if (msg)
- {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("message received"));
- const char *n = dbus_message_get_member(msg);
- bool found = false;
- int i = 0;
-
- while (!found && strcmp(manager_methods[i].name, "") != 0)
- {
- if (n && strcmp(manager_methods[i].name, n) == 0)
- {
- MethodTable entry = manager_methods[i];
- DLT_LOG(DBusPlugin, 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++;
- }
-
- if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
- {
-
- DBUSIntrospection introspectionString(manager_methods);
- introspectionString.process(conn, msg);
- g_pDbusMessage->setConnection(conn);
- found = true; // TODO: always true
- }
-
- if (!found)
- {
- DBusMessage* reply = dbus_message_new_method_return(msg);
- uint serial = 0;
- // send the reply && flush the connection
- if (!dbus_connection_send(conn, reply, &serial))
- {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
- }
- dbus_connection_flush(conn);
- // free the reply
- dbus_message_unref(reply);
- reply = NULL;
- }
- if (msg)
- {
- dbus_connection_flush(conn);
- dbus_message_unref(msg);
- msg = NULL;
- }
- } else {
- /* put thread in sleep mode for 500 useconds due to safe cpu performance */
- //usleep(500);
- }
+ msg = dbus_connection_pop_message(conn);
+ DLT_LOG(DBusPlugin, 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;
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
+ DBUSIntrospection introspectionString(manager_methods,manager_signals);
+ introspectionString.process(conn, msg);
+ g_pDbusMessage->setConnection(conn);
+ } 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(DBusPlugin, 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++;
+ }
+ } else if (dbus_message_is_signal(msg, DBUS_INTERFACE_DBUS, "NameAcquired")) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Got Signal Name Aquired"));
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(msg);
+ msg = NULL;
}
DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread"));
diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.h b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
index 1e22c18..ffa0148 100644
--- a/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
+++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
@@ -36,9 +36,9 @@ public:
void stop();
void peekDomain(DBusConnection* conn, DBusMessage* msg);
- void registerDomain(const char* &name, const char* &node, bool earlymode);
- void registerGateway(const char* &name, const char* &sink, const char* &source, const char* &domainSource, const char* &domainSink, const char* &controlDomain);
- void registerSink(const char* &name, const char* &sinkclass, const char* &domain);
+ void registerDomain(DBusConnection* conn, DBusMessage* msg);
+ void registerGateway(DBusConnection* conn, DBusMessage* msg);
+ void registerSink(DBusConnection* conn, DBusMessage* msg);
void registerSource(DBusConnection* conn, DBusMessage* msg);
void emit_systemReady();
diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
index 313a71e..fabd2dd 100644
--- a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
+++ b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
@@ -22,10 +22,8 @@
using std::stringstream;
-
-
-DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable)
-: m_methodTable(methodTable)
+DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable)
+: m_methodTable(methodTable), m_signalTable(signalTable)
{
generateString();
}
@@ -35,7 +33,7 @@ void DBUSIntrospection::generateString()
DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
addHeader();
- openNode(DBUS_SERVICE_PREFIX);
+ openNode("");
openInterface("org.freedesktop.DBus.Introspectable");
openMethod("Introspect");
addArgument("data", "out", "s");
@@ -52,10 +50,18 @@ void DBUSIntrospection::generateString()
++index;
}
+ index=0;
+ if (m_signalTable) {
+ while (strcmp(m_signalTable[index].name, "") != 0)
+ {
+ SignalTable entry = m_signalTable[index];
+ addEntry(entry);
+ ++index;
+ }
+ }
closeInterface();
-
closeNode();
- //LOG_DEBUG("DBUSCommunicator", "generated introspection data");
+
}
void DBUSIntrospection::addHeader(void)
@@ -80,6 +86,10 @@ 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=\""
@@ -141,6 +151,28 @@ void DBUSIntrospection::addEntry(MethodTable entry)
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;
diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.h b/PluginRoutingInterfaceDbus/DBUSIntrospection.h
index 95ba9f1..753dc0e 100644
--- a/PluginRoutingInterfaceDbus/DBUSIntrospection.h
+++ b/PluginRoutingInterfaceDbus/DBUSIntrospection.h
@@ -32,7 +32,7 @@ using std::string;
class DBUSIntrospection
{
public:
- DBUSIntrospection(MethodTable* table);
+ DBUSIntrospection(MethodTable* table, SignalTable* stable);
void process(DBusConnection* conn, DBusMessage* msg);
private:
@@ -41,6 +41,7 @@ private:
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);
@@ -51,10 +52,13 @@ private:
void openMethod(string methodname);
void closeMethod(void);
+ void addSignal(string signalname);
+
private:
stringstream m_introspectionString;
MethodTable* m_methodTable;
+ SignalTable* m_signalTable;
};
diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
index 401fa32..a77c012 100644
--- a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
+++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
@@ -23,7 +23,7 @@ DBUSMessageHandler::DBUSMessageHandler()
DLT_LOG(DBusPlugin,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);
+ 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(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Name Error"),DLT_STRING(m_err.message));
diff --git a/PluginRoutingInterfaceDbus/DBUSTypes.h b/PluginRoutingInterfaceDbus/DBUSTypes.h
index 862f20b..2f6d0ef 100644
--- a/PluginRoutingInterfaceDbus/DBUSTypes.h
+++ b/PluginRoutingInterfaceDbus/DBUSTypes.h
@@ -33,4 +33,9 @@ struct MethodTable
CallBackMethod function;
};
+struct SignalTable {
+ const char* name;
+ const char* signature;
+};
+
#endif // _DBUSTYPES_H_
diff --git a/PluginRoutingInterfaceDbus/DbusInterface.cpp b/PluginRoutingInterfaceDbus/DbusInterface.cpp
index 56a8563..878d556 100644
--- a/PluginRoutingInterfaceDbus/DbusInterface.cpp
+++ b/PluginRoutingInterfaceDbus/DbusInterface.cpp
@@ -78,7 +78,7 @@ connection_t DbusInterface::connect(source_t source, sink_t sink, connection_t c
}
void DbusInterface::system_ready() {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Plugin ready"));
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Plugin got ready"));
m_DbusInterface->emit_systemReady();
}