From 2d849dd0b5b1558e92cd0f2cd6dbc556950d631d Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Wed, 3 Aug 2011 12:37:16 +0200 Subject: Dbus restructured --- .../AudiomanagerInterface.cpp | 95 +++++++++------------- PluginRoutingInterfaceDbus/AudiomanagerInterface.h | 11 ++- PluginRoutingInterfaceDbus/CMakeLists.txt | 10 +-- PluginRoutingInterfaceDbus/DBUSIntrospection.cpp | 13 +-- PluginRoutingInterfaceDbus/DBUSIntrospection.h | 3 +- PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp | 41 +++------- PluginRoutingInterfaceDbus/DBUSMessageHandler.h | 8 +- PluginRoutingInterfaceDbus/DbusInterface.cpp | 33 ++++---- PluginRoutingInterfaceDbus/DbusInterface.h | 9 +- PluginRoutingInterfaceDbus/headers.h | 4 +- 10 files changed, 100 insertions(+), 127 deletions(-) (limited to 'PluginRoutingInterfaceDbus') diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp index 4810d89..bdfbdd4 100644 --- a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp +++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp @@ -52,19 +52,22 @@ static SignalTable manager_signals[] = { { "", ""} }; +static DBusObjectPathVTable _vtable = +{ + NULL,AudioManagerInterface::receive_callback,NULL, NULL, NULL, NULL +}; + + -AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interface) : m_audioman(r_interface),m_running(false) { +AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interface, dbusRoothandler* roothandler) : m_audioman(r_interface),m_Introspection(new DBUSIntrospection(manager_methods, manager_signals,std::string(MY_NODE))),m_roothandler(roothandler) { } 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); - DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Started dbus connector")); + g_pDbusMessage = new DBUSMessageHandler(&_vtable,m_roothandler->returnConnection(),this); + return true; } @@ -72,8 +75,6 @@ void AudioManagerInterface::stop() { DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopped dbus connector")); - this->m_running = false; - pthread_join(m_currentThread, NULL); delete g_pDbusMessage; } @@ -118,7 +119,7 @@ void AudioManagerInterface::registerDomain(DBusConnection* conn, DBusMessage* ms 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); + domain_t domain=m_reference->m_audioman->registerDomain(name, busname, node, earlymode); g_pDbusMessage->initReply(msg); g_pDbusMessage->appendUInt(domain); g_pDbusMessage->closeReply(); @@ -140,57 +141,37 @@ void AudioManagerInterface::registerGateway(DBusConnection* conn, DBusMessage* m emit_systemReady(); } void AudioManagerInterface::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); + g_pDbusMessage->sendSignal("signal_systemReady"); } -void* AudioManagerInterface::run(void * arg) -{ - DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Main loop running")); - m_reference = (AudioManagerInterface*) arg; - DBusMessage* msg = 0; - DBusConnection* conn = g_pDbusMessage->getConnection(); - while (m_reference->m_running && dbus_connection_read_write_dispatch(conn, -1)) - { - 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++; - } +DBusHandlerResult AudioManagerInterface::receive_callback(DBusConnection *conn, DBusMessage *msg, void *user_data){ + m_reference=(AudioManagerInterface*) user_data; + DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("message received")); + + string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE); + + if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { + m_reference->m_Introspection->process(conn,msg); + return DBUS_HANDLER_RESULT_HANDLED; + } + + bool found=false; + int i = 0; + + 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(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; + return DBUS_HANDLER_RESULT_HANDLED; } - dbus_connection_flush(conn); - dbus_message_unref(msg); - msg = NULL; - } + i++; + } - DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread")); - return 0; + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } + + diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.h b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h index ffa0148..a56975c 100644 --- a/PluginRoutingInterfaceDbus/AudiomanagerInterface.h +++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h @@ -26,14 +26,18 @@ #define DBUSINTERFACE_H_ #include "headers.h" +#include "DBUSIntrospection.h" + +class DBUSIntrospection; class AudioManagerInterface { public: - AudioManagerInterface(RoutingReceiveInterface* r_interface); + AudioManagerInterface(RoutingReceiveInterface* r_interface,dbusRoothandler* roothandler); bool startup_interface(); void stop(); + static DBusHandlerResult receive_callback (DBusConnection *,DBusMessage *,void *); void peekDomain(DBusConnection* conn, DBusMessage* msg); void registerDomain(DBusConnection* conn, DBusMessage* msg); @@ -43,11 +47,10 @@ public: void emit_systemReady(); private: - static void* run(void * threadid); - pthread_t m_currentThread; static AudioManagerInterface* m_reference; RoutingReceiveInterface* m_audioman; - bool m_running; + DBUSIntrospection* m_Introspection; + dbusRoothandler* m_roothandler; }; #endif /* DBUSINTERFACE_H_ */ diff --git a/PluginRoutingInterfaceDbus/CMakeLists.txt b/PluginRoutingInterfaceDbus/CMakeLists.txt index 827d309..4880da1 100644 --- a/PluginRoutingInterfaceDbus/CMakeLists.txt +++ b/PluginRoutingInterfaceDbus/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.6) -PROJECT(PluginCommandInterfaceDbus) +PROJECT(PluginRoutingInterfaceDbus) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xlinker -export-dynamic") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") @@ -12,7 +12,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}") set(STD_INCLUDE_DIRS "/usr/include") set(EXECUTABLE_OUTPUT_PATH ../../bin/) set(LIBRARY_OUTPUT_PATH ../plugins/routing) -set(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../doc/DBusPlugin) +set(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../doc/RoutingDBusPlugin) find_package (Threads) FIND_PACKAGE(DBUS REQUIRED) @@ -35,16 +35,16 @@ INCLUDE_DIRECTORIES( # all source files go here SET(PLUGINDBUS_SRCS_CXX + AudiomanagerInterface.cpp DbusInterface.cpp DBUSIntrospection.cpp DBUSMessageHandler.cpp - AudiomanagerInterface.cpp DbusSend.cpp ) -add_library(PluginCommandInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX}) +add_library(PluginRoutingInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX}) -TARGET_LINK_LIBRARIES(PluginCommandInterfaceDbus +TARGET_LINK_LIBRARIES(PluginRoutingInterfaceDbus ${DLT_LIBRARIES} ${DBUS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp index fabd2dd..20d682a 100644 --- a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp +++ b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp @@ -19,11 +19,14 @@ #include "DBUSIntrospection.h" #include #include + +DLT_IMPORT_CONTEXT(DBusCommandPlugin); + using std::stringstream; -DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable) -: m_methodTable(methodTable), m_signalTable(signalTable) +DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable,std::string nodename) +: m_methodTable(methodTable), m_signalTable(signalTable), m_nodename(nodename) { generateString(); } @@ -33,13 +36,13 @@ void DBUSIntrospection::generateString() DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!")); addHeader(); - openNode(""); + openNode(m_nodename); openInterface("org.freedesktop.DBus.Introspectable"); openMethod("Introspect"); addArgument("data", "out", "s"); closeMethod(); closeInterface(); - openInterface(DBUS_SERVICE_PREFIX); + openInterface(DBUS_SERVICE_SERVICE); int index = 0; @@ -87,7 +90,7 @@ void DBUSIntrospection::openMethod(string methodname) } void DBUSIntrospection::addSignal(string signalname) { - m_introspectionString<<" \n"; + m_introspectionString<<" \n"; } void DBUSIntrospection::addArgument(string argname, string direction, string type) diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.h b/PluginRoutingInterfaceDbus/DBUSIntrospection.h index 753dc0e..64636dd 100644 --- a/PluginRoutingInterfaceDbus/DBUSIntrospection.h +++ b/PluginRoutingInterfaceDbus/DBUSIntrospection.h @@ -32,7 +32,7 @@ using std::string; class DBUSIntrospection { public: - DBUSIntrospection(MethodTable* table, SignalTable* stable); + DBUSIntrospection(MethodTable* table, SignalTable* stable,std::string nodename); void process(DBusConnection* conn, DBusMessage* msg); private: @@ -59,6 +59,7 @@ private: stringstream m_introspectionString; MethodTable* m_methodTable; SignalTable* m_signalTable; + std::string m_nodename; }; diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp index a77c012..51d69dc 100644 --- a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp +++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp @@ -3,37 +3,19 @@ #include "headers.h" #include -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(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Connection error")); - dbus_error_free(&m_err); - } - if (NULL == m_pConnection) - { - 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); - if (dbus_error_is_set(&m_err)) - { - DLT_LOG(DBusPlugin,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(DBusPlugin,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(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Registering of node"), DLT_STRING(MY_NODE),DLT_STRING("failed")); + } } DBUSMessageHandler::~DBUSMessageHandler() @@ -45,14 +27,14 @@ DBUSMessageHandler::~DBUSMessageHandler() { DLT_LOG(DBusPlugin,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(DBusPlugin,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) @@ -283,12 +265,11 @@ void DBUSMessageHandler::appendArrayOfUInt(unsigned int length, unsigned int *ID dbus_message_iter_close_container(&m_MessageIter, &arrayIter); } -void DBUSMessageHandler::sendSignal(const char* name, const char* signal) { +void DBUSMessageHandler::sendSignal(const char* signalname) { dbus_uint32_t serial = 0; DBusMessage* msg; - DBusMessageIter args; - msg = dbus_message_new_signal(DBUS_SERVICE_PREFIX, signal, name); + msg =dbus_message_new_signal(DBUS_SERVICE_ROOT,DBUS_SERVICE_SERVICE,signalname); if (NULL == msg) { diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.h b/PluginRoutingInterfaceDbus/DBUSMessageHandler.h index ad685df..8ef0b3d 100644 --- a/PluginRoutingInterfaceDbus/DBUSMessageHandler.h +++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.h @@ -27,7 +27,7 @@ class DBUSMessageHandler { public: - DBUSMessageHandler(); + DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference); ~DBUSMessageHandler(); void setConnection(DBusConnection* conn); @@ -53,7 +53,7 @@ public: void appendDouble(double toAppend); void appendArrayOfUInt(unsigned int length, unsigned int *IDs); - void sendSignal(const char* name,const char* signal); + void sendSignal(const char* signalname); private: DBusMessageIter m_MessageIter; @@ -74,10 +74,6 @@ inline DBusConnection* DBUSMessageHandler::getConnection() return m_pConnection; } -void DBUSMessageHandler::appendArrayOfStringString(std::list list) -{ -} - #endif // _DBUSMESSAGEWRAPPER_H_ diff --git a/PluginRoutingInterfaceDbus/DbusInterface.cpp b/PluginRoutingInterfaceDbus/DbusInterface.cpp index 822b35c..38e2b15 100644 --- a/PluginRoutingInterfaceDbus/DbusInterface.cpp +++ b/PluginRoutingInterfaceDbus/DbusInterface.cpp @@ -38,7 +38,7 @@ DLT_DECLARE_CONTEXT(DBusPlugin) DbusInterface::DbusInterface(): m_busname(DBUS_BUSNAME), m_path(DBUS_PATH) { DLT_REGISTER_APP("DBusPlugin", "DBusPlugin"); - DLT_REGISTER_CONTEXT(DBusPlugin, "Plugin", "Dbus Plugin"); + DLT_REGISTER_CONTEXT(DBusPlugin, "DPlugin", "Dbus Plugin"); DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("The DBus Plugin is started")); } @@ -46,11 +46,12 @@ DbusInterface::~DbusInterface() { delete m_DbusInterface; } -void DbusInterface::startup_interface(RoutingReceiveInterface* audioman) { +void DbusInterface::startup_interface(RoutingReceiveInterface* audioman,dbusRoothandler* dbushandler) { m_audioman = audioman; - m_DbusInterface = new AudioManagerInterface(audioman); + m_rootHandler = dbushandler; + m_DbusInterface = new AudioManagerInterface(audioman,dbushandler); m_DbusInterface->startup_interface(); - + m_rootHandler->registerNode(MY_NODE); DBusError err; dbus_error_init(&err); @@ -164,17 +165,19 @@ genError_t DbusInterface::unmuteSink(sink_t sinkID) { */ } -genError_t DbusInterface::asyncConnect(source_t source, sink_t sink, connection_t con_ID) { - /** - * \todo implement - */ -} - -genError_t DbusInterface::asyncDisconnect(connection_t connection_ID){ - /** - * \todo implement - */ -} +//genError_t DbusInterface::asyncConnect(source_t source, sink_t sink, connection_t con_ID) { +// /** +// * \todo implement +// */ +// return GEN_OK; +//} +// +//genError_t DbusInterface::asyncDisconnect(connection_t connection_ID){ +// /** +// * \todo implement +// */ +// return GEN_OK; +//} //That is the actual implementation of the Factory Class returning the real sendInterface diff --git a/PluginRoutingInterfaceDbus/DbusInterface.h b/PluginRoutingInterfaceDbus/DbusInterface.h index 7de8cc8..b356378 100644 --- a/PluginRoutingInterfaceDbus/DbusInterface.h +++ b/PluginRoutingInterfaceDbus/DbusInterface.h @@ -28,6 +28,8 @@ #include "headers.h" #include "routinginterface.h" +class RoutingSendInterface; + /**Implementation of the interface * */ @@ -37,7 +39,7 @@ public: DbusInterface(); virtual ~DbusInterface(); - void startup_interface(RoutingReceiveInterface * audioman); + void startup_interface(RoutingReceiveInterface * audioman, dbusRoothandler* dbushandler); void return_BusName(char * BusName); genError_t connect(source_t source, sink_t sink, connection_t connID); genError_t disconnect(connection_t connectionID); @@ -47,14 +49,15 @@ public: genError_t muteSink(sink_t sinkID); genError_t unmuteSource(source_t sourceID); genError_t unmuteSink(sink_t sinkID); - genError_t asyncConnect(source_t source, sink_t sink, connection_t con_ID); - virtual genError_t asyncDisconnect(connection_t connection_ID); +// genError_t asyncConnect(source_t source, sink_t sink, connection_t con_ID); +// genError_t asyncDisconnect(connection_t connection_ID); void system_ready(); private: RoutingReceiveInterface *m_audioman; AudioManagerInterface* m_DbusInterface; DBusConnection* m_conn; + dbusRoothandler* m_rootHandler; char* m_busname; char* m_path; diff --git a/PluginRoutingInterfaceDbus/headers.h b/PluginRoutingInterfaceDbus/headers.h index 54e3b25..dbb6f3c 100644 --- a/PluginRoutingInterfaceDbus/headers.h +++ b/PluginRoutingInterfaceDbus/headers.h @@ -11,6 +11,7 @@ #include #include #include "routinginterface.h" +#include "dbusRoothandler.h" #include "AudiomanagerInterface.h" #include "DbusSend.h" #include "DBUSMessageHandler.h" @@ -22,7 +23,8 @@ #define DBUS_BUSNAME "org.genivi.command" #define DBUS_PATH "/pulse" -const char DBUS_SERVICE_PREFIX[] = "org.genivi.audiomanagerCommand\0"; + +const char MY_NODE[]="routinginterface\0"; DLT_IMPORT_CONTEXT(DBusPlugin); -- cgit v1.2.1