summaryrefslogtreecommitdiff
path: root/PluginRoutingInterfaceDbus
diff options
context:
space:
mode:
Diffstat (limited to 'PluginRoutingInterfaceDbus')
-rw-r--r--PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp173
-rw-r--r--PluginRoutingInterfaceDbus/AudiomanagerInterface.h (renamed from PluginRoutingInterfaceDbus/DBusInterface.h)41
-rw-r--r--PluginRoutingInterfaceDbus/CMakeLists.txt78
-rw-r--r--PluginRoutingInterfaceDbus/DBUSIntrospection.cpp173
-rw-r--r--PluginRoutingInterfaceDbus/DBUSIntrospection.h61
-rw-r--r--PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp308
-rw-r--r--PluginRoutingInterfaceDbus/DBUSMessageHandler.h77
-rw-r--r--PluginRoutingInterfaceDbus/DBUSTypes.h36
-rw-r--r--PluginRoutingInterfaceDbus/DBusInterface.cpp97
-rw-r--r--PluginRoutingInterfaceDbus/DbusInterface.cpp153
-rw-r--r--PluginRoutingInterfaceDbus/DbusInterface.h (renamed from PluginRoutingInterfaceDbus/RoutingSend.h)40
-rw-r--r--PluginRoutingInterfaceDbus/DbusSend.cpp112
-rw-r--r--PluginRoutingInterfaceDbus/DbusSend.h28
-rw-r--r--PluginRoutingInterfaceDbus/FindDBUS.cmake45
-rw-r--r--PluginRoutingInterfaceDbus/RoutingSend.cpp133
-rw-r--r--PluginRoutingInterfaceDbus/headers.h29
16 files changed, 1255 insertions, 329 deletions
diff --git a/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
new file mode 100644
index 0000000..29fe480
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.cpp
@@ -0,0 +1,173 @@
+/**
+ *
+ * Copyright (C) 2011, BMW AG
+ *
+ * PluginDBus
+ *
+ * \file DBusInterface.cpp
+ *
+ * \date 20.05.2011
+ * \author Christian Müller (christian.ei.mueller@bmw.de)
+ *
+ * \section License
+ * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
+ * Copyright (C) 2011, BMW AG – Christian Müller Christian.ei.mueller@bmw.de
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
+ * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
+ * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
+ * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
+ * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
+ * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
+ */
+
+#include "headers.h"
+#include <iostream>
+#include <string.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 }
+};
+
+AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interface) : m_audioman(r_interface),m_running(false) {
+}
+
+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"));
+ return true;
+}
+
+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;
+}
+
+void AudioManagerInterface::peekDomain(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ char* name = g_pDbusMessage->getString();
+ domain_t domain = m_audioman->peekDomain(name);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->appendUInt(domain);
+ g_pDbusMessage->closeReply();
+}
+
+void AudioManagerInterface::registerSource(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();
+ source_t source=m_audioman->registerSource(name, audioclass, domain);
+ g_pDbusMessage->initReply(msg);
+ 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::registerDomain(const char* &name, const char* &node, bool earlymode) {
+ char busname[40];
+ strcpy(busname, BUS_NAME);
+ m_audioman->registerDomain((char*)name, busname, (char*)node, earlymode);
+}
+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::emit_systemReady() {
+ m_reference->emit_systemReady();
+}
+
+void* AudioManagerInterface::run(void * arg)
+{
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Main loop running"));
+ // pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
+ // pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ m_reference = (AudioManagerInterface*) arg;
+ while (m_reference->m_running)
+ {
+ // 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);
+ }
+ }
+
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread"));
+ return 0;
+}
+
diff --git a/PluginRoutingInterfaceDbus/DBusInterface.h b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
index e094ae5..1e22c18 100644
--- a/PluginRoutingInterfaceDbus/DBusInterface.h
+++ b/PluginRoutingInterfaceDbus/AudiomanagerInterface.h
@@ -25,32 +25,29 @@
#ifndef DBUSINTERFACE_H_
#define DBUSINTERFACE_H_
-#include "DBusInterfaceAdaptor.h"
-#include "routinginterface.h"
+#include "headers.h"
+
+class AudioManagerInterface {
-class DBusInterface: public QObject {
- Q_OBJECT
public:
- DBusInterface(QObject *parent = 0);
- void setReceiverInterface(RoutingReceiveInterface* r_interface);
- void emitSystemReady();
-
-public Q_SLOTS: // METHODS
- int peekDomain(const QString &name);
- int
- registerDomain(const QString &name, const QString &node, bool earlymode);
- int registerGateway(const QString &name, const QString &sink,
- const QString &source, const QString &domainSource,
- const QString &domainSink, const QString &controlDomain);
- int registerSink(const QString &name, const QString &sinkclass,
- const QString &domain);
- int registerSource(const QString &name, const QString &audioclass,
- const QString &domain);
-Q_SIGNALS: // SIGNALS
- void signal_systemReady();
+ AudioManagerInterface(RoutingReceiveInterface* r_interface);
+
+ bool startup_interface();
+ 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 registerSource(DBusConnection* conn, DBusMessage* msg);
+ void emit_systemReady();
private:
- RoutingReceiveInterface* audiomanager;
+ static void* run(void * threadid);
+ pthread_t m_currentThread;
+ static AudioManagerInterface* m_reference;
+ RoutingReceiveInterface* m_audioman;
+ bool m_running;
};
#endif /* DBUSINTERFACE_H_ */
diff --git a/PluginRoutingInterfaceDbus/CMakeLists.txt b/PluginRoutingInterfaceDbus/CMakeLists.txt
index 54f8e86..cfac03b 100644
--- a/PluginRoutingInterfaceDbus/CMakeLists.txt
+++ b/PluginRoutingInterfaceDbus/CMakeLists.txt
@@ -1,79 +1,55 @@
cmake_minimum_required(VERSION 2.6)
-PROJECT(AudioManagerDeamon)
+PROJECT(PluginRoutingInterfaceDbus)
-set(CMAKE_CXX_FLAGS "-g -pipe -fPIC -Wall -W -D_REENTRANT")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xlinker -export-dynamic")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
+set(CMAKE_CXX_FLAGS "-g -pipe -g -Wall -W -D_REENTRANT")
+
+
+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)
-set(DBUS_FOLDER ${CMAKE_SOURCE_DIR}/../dbusInterfaces)
+set(LIBRARY_OUTPUT_PATH ../plugins/routing)
set(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../doc/DBusPlugin)
-set(DOCUMENT $ENV{gendoc})
-cmake_policy(SET CMP0015 NEW)
+find_package (Threads)
+FIND_PACKAGE(DBUS REQUIRED)
+FIND_PACKAGE(PkgConfig)
+pkg_check_modules(DLT REQUIRED automotive-dlt)
-file(MAKE_DIRECTORY ${DOC_OUTPUT_PATH})
-FIND_PACKAGE(Qt4 REQUIRED)
+set(DOCUMENT $ENV{gendoc})
+
+file(MAKE_DIRECTORY ${DOC_OUTPUT_PATH})
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${STD_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
- ${DBUS_FOLDER}
+ ${DBUS_INCLUDE_DIR}
+ ${DBUS_ARCH_INCLUDE_DIR}
../AudioManagerDaemon
)
-# add Qt modules here, the include will setup QT_LIBRARIES
-
-# defines for QL Plugins
-ADD_DEFINITIONS(${QT_DEFINITIONS})
-ADD_DEFINITIONS(-DQT_STATICPLUGIN)
-ADD_DEFINITIONS(-DQT_PLUGIN)
-ADD_DEFINITIONS(-DQT_SHARED)
-
-
-INCLUDE(${QT_USE_FILE})
-
# all source files go here
SET(PLUGINDBUS_SRCS_CXX
- DBusInterface.cpp
- RoutingSend.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/DBusSend.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/DBusInterfaceAdaptor.cpp
-)
-
-# every header that contains QT stuff like Q_OBJECT .... and must be mocced
-SET(PLUGINDBUS_MOC_SRCS
- DBusInterface.h
- RoutingSend.h
- ${CMAKE_CURRENT_BINARY_DIR}/DBusSend.h
- ${CMAKE_CURRENT_BINARY_DIR}/DBusInterfaceAdaptor.h
+ DbusInterface.cpp
+ DBUSIntrospection.cpp
+ DBUSMessageHandler.cpp
+ AudiomanagerInterface.cpp
+ DbusSend.cpp
)
-#now take the headers, moc them and append the resulting moc files to the sources
-QT4_WRAP_CPP(PLUGINDBUS_SRCS_CXX ${PLUGINDBUS_MOC_SRCS})
+add_library(PluginRoutingInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX})
-add_library(RoutingPlugin ${PLUGINDBUS_SRCS_CXX})
-
-TARGET_LINK_LIBRARIES(RoutingPlugin
- ${QT_LIBRARIES}
-)
-
-add_custom_command(
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DBusInterfaceAdaptor.h ${CMAKE_CURRENT_BINARY_DIR}/DBusInterfaceAdaptor.cpp
- COMMAND qdbusxml2cpp ARGS -c DBusInterfaceAdaptor -a DBusInterfaceAdaptor.h:DBusInterfaceAdaptor.cpp ${DBUS_FOLDER}/DBusReceive.xml
- MAIN_DEPENDENCY ${DBUS_FOLDER}/DBusReceive.xml
+TARGET_LINK_LIBRARIES(PluginRoutingInterfaceDbus
+ ${DLT_LIBRARIES}
+ ${DBUS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
)
-add_custom_command(
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DBusSend.h ${CMAKE_CURRENT_BINARY_DIR}/DBusSend.cpp
- COMMAND qdbusxml2cpp ARGS -v -c DBusSend -p DBusSend.h:DBusSend.cpp ${DBUS_FOLDER}/DBusSend.xml
- MAIN_DEPENDENCY ${DBUS_FOLDER}/DBusSend.xml
-)
#add a target to generate API documentation with Doxygen
find_package(Doxygen)
diff --git a/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
new file mode 100644
index 0000000..313a71e
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DBUSIntrospection.cpp
@@ -0,0 +1,173 @@
+/***************************************************************************
+ *
+ * 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>
+using std::stringstream;
+
+
+
+
+DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable)
+: m_methodTable(methodTable)
+{
+ generateString();
+}
+
+void DBUSIntrospection::generateString()
+{
+ DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
+
+ addHeader();
+ openNode(DBUS_SERVICE_PREFIX);
+ openInterface("org.freedesktop.DBus.Introspectable");
+ openMethod("Introspect");
+ addArgument("data", "out", "s");
+ closeMethod();
+ closeInterface();
+ openInterface(DBUS_SERVICE_PREFIX);
+
+ int index = 0;
+
+ while (strcmp(m_methodTable[index].name, "") != 0)
+ {
+ MethodTable entry = m_methodTable[index];
+ addEntry(entry);
+ ++index;
+ }
+
+ closeInterface();
+
+ closeNode();
+ //LOG_DEBUG("DBUSCommunicator", "generated introspection data");
+}
+
+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::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::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
new file mode 100644
index 0000000..95ba9f1
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DBUSIntrospection.h
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *
+ * 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);
+ 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 openNode(string nodename);
+ void closeNode(void);
+
+ void openInterface(string interfacename);
+ void closeInterface(void);
+
+ void openMethod(string methodname);
+ void closeMethod(void);
+
+
+private:
+ stringstream m_introspectionString;
+ MethodTable* m_methodTable;
+};
+
+
+#endif // _DBUSINTROSPECTION_H_
diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
new file mode 100644
index 0000000..401fa32
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.cpp
@@ -0,0 +1,308 @@
+
+
+#include "headers.h"
+#include <stdlib.h>
+
+DBUSMessageHandler::DBUSMessageHandler()
+: m_MessageIter()
+, m_pReply(0)
+, m_serial(0)
+, m_pConnection(0)
+{
+ 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);
+ }
+}
+
+DBUSMessageHandler::~DBUSMessageHandler()
+{
+ DBusError err;
+ dbus_error_init(&err);
+ bool errorset = dbus_error_is_set(&err);
+ if (errorset)
+ {
+ DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
+ }
+ dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_PREFIX, &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);
+}
+
+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!"));
+ }
+}
+
+void DBUSMessageHandler::initReply(DBusMessage* msg)
+{
+ // create a reply from the message
+ m_pReply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(m_pReply, &m_MessageIter);
+}
+
+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!"));
+ exit(1);
+ }
+ DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
+ dbus_connection_flush(m_pConnection);
+
+ // free the reply
+ dbus_message_unref(m_pReply);
+ m_pReply = NULL;
+}
+
+void DBUSMessageHandler::ReplyError(DBusMessage* msg, const char* errorname, const char* errorMsg)
+{
+ m_pReply = dbus_message_new_error(msg, errorname, errorMsg);
+ // 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!"));
+ exit(1);
+ }
+ DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
+ dbus_connection_flush(m_pConnection);
+
+ // free the reply
+ dbus_message_unref(m_pReply);
+}
+
+char* DBUSMessageHandler::getString()
+{
+ char* param;
+
+ 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!"));
+ }
+ else
+ {
+ dbus_message_iter_get_basic(&m_MessageIter, &param);
+ dbus_message_iter_next(&m_MessageIter);
+ }
+ return param;
+}
+
+dbus_bool_t DBUSMessageHandler::getBool()
+{
+ dbus_bool_t boolparam;
+
+ 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!"));
+ }
+ else
+ {
+ dbus_message_iter_get_basic(&m_MessageIter, &boolparam);
+ dbus_message_iter_next(&m_MessageIter);
+ }
+ return boolparam;
+}
+
+char DBUSMessageHandler::getByte()
+{
+ char param;
+
+ 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!"));
+ }
+ else
+ {
+ dbus_message_iter_get_basic(&m_MessageIter, &param);
+ dbus_message_iter_next(&m_MessageIter);
+ }
+ return param;
+}
+
+dbus_uint32_t DBUSMessageHandler::getUInt()
+{
+ dbus_uint32_t param;
+
+ 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!"));
+ }
+ else
+ {
+ dbus_message_iter_get_basic(&m_MessageIter, &param);
+ dbus_message_iter_next(&m_MessageIter);
+ }
+ return param;
+}
+
+double DBUSMessageHandler::getDouble()
+{
+ double param;
+
+ 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!"));
+ }
+ else
+ {
+ dbus_message_iter_get_basic(&m_MessageIter, &param);
+ dbus_message_iter_next(&m_MessageIter);
+ }
+ return param;
+}
+
+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!"));
+ return;
+ }
+
+ DBusMessageIter arrayIter;
+ dbus_message_iter_recurse(&m_MessageIter, &arrayIter);
+
+ uint* localArray;
+ dbus_message_iter_get_fixed_array(&arrayIter, &localArray, pLength);
+
+ *ppArray = new uint[*pLength];
+ for (int i = 0; i < *pLength; i++)
+ {
+ (*ppArray)[i] = localArray[i];
+ }
+}
+
+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!"));
+ return;
+ }
+
+ DBusMessageIter arrayIter;
+ dbus_message_iter_recurse(&m_MessageIter, &arrayIter);
+ bool hasNext = true;
+ while (hasNext)
+ {
+ 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!"));
+ }
+ char* param;
+ dbus_message_iter_get_basic(&arrayIter, &param);
+
+ stringVector->push_back(std::string(param));
+
+ if (dbus_message_iter_has_next(&arrayIter))
+ {
+ dbus_message_iter_next(&arrayIter);
+ }
+ else
+ {
+ hasNext = false;
+ }
+ }
+}
+
+void DBUSMessageHandler::appendBool(dbus_bool_t toAppend)
+{
+ if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BOOLEAN, &toAppend))
+ {
+ DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ exit(1);
+ }
+}
+
+void DBUSMessageHandler::appendUInt(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!"));
+ exit(1);
+ }
+}
+
+void DBUSMessageHandler::appendDouble(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!"));
+ exit(1);
+ }
+}
+
+void DBUSMessageHandler::appendByte(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!"));
+ exit(1);
+ }
+}
+
+void DBUSMessageHandler::appendArrayOfUInt(unsigned int length, unsigned int *IDs)
+{
+ DBusMessageIter arrayIter;
+ dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "u", &arrayIter);
+ for(unsigned int i = 0; i < length; i++)
+ {
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &IDs[i]);
+ }
+ dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
+}
+
+void DBUSMessageHandler::sendSignal(const char* name, const char* signal) {
+ dbus_uint32_t serial = 0;
+ DBusMessage* msg;
+ DBusMessageIter args;
+
+ msg = dbus_message_new_signal(DBUS_SERVICE_PREFIX, signal, name);
+
+ if (NULL == msg)
+ {
+ DLT_LOG(DBusPlugin,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!"));
+ this->~DBUSMessageHandler();
+ }
+
+ dbus_connection_flush(m_pConnection);
+
+ // free the message
+ dbus_message_unref(msg);
+}
diff --git a/PluginRoutingInterfaceDbus/DBUSMessageHandler.h b/PluginRoutingInterfaceDbus/DBUSMessageHandler.h
new file mode 100644
index 0000000..6d0d935
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DBUSMessageHandler.h
@@ -0,0 +1,77 @@
+/***************************************************************************
+ *
+ * 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 _DBUSMESSAGEHANDLER_H_
+#define _DBUSMESSAGEHANDLER_H_
+
+#include <vector>
+#include <string>
+#include "headers.h"
+
+class DBUSMessageHandler
+{
+public:
+ DBUSMessageHandler();
+ ~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();
+ double getDouble();
+ char* getString();
+ 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 sendSignal(const char* name,const char* signal);
+
+private:
+ DBusMessageIter m_MessageIter;
+ DBusMessage* m_pReply;
+ dbus_uint32_t m_serial;
+ DBusConnection* m_pConnection;
+ DBusError m_err;
+};
+
+
+inline void DBUSMessageHandler::setConnection(DBusConnection* conn)
+{
+ m_pConnection = conn;
+}
+
+inline DBusConnection* DBUSMessageHandler::getConnection()
+{
+ return m_pConnection;
+}
+
+#endif // _DBUSMESSAGEWRAPPER_H_
diff --git a/PluginRoutingInterfaceDbus/DBUSTypes.h b/PluginRoutingInterfaceDbus/DBUSTypes.h
new file mode 100644
index 0000000..862f20b
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DBUSTypes.h
@@ -0,0 +1,36 @@
+/***************************************************************************
+ *
+ * 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;
+};
+
+#endif // _DBUSTYPES_H_
diff --git a/PluginRoutingInterfaceDbus/DBusInterface.cpp b/PluginRoutingInterfaceDbus/DBusInterface.cpp
deleted file mode 100644
index cf4b8f4..0000000
--- a/PluginRoutingInterfaceDbus/DBusInterface.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- *
- * Copyright (C) 2011, BMW AG
- *
- * PluginDBus
- *
- * \file DBusInterface.cpp
- *
- * \date 20.05.2011
- * \author Christian Müller (christian.ei.mueller@bmw.de)
- *
- * \section License
- * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
- * Copyright (C) 2011, BMW AG – Christian Müller Christian.ei.mueller@bmw.de
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
- * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
- * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
- * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
- * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
- * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
- */
-
-#include "DBusInterface.h"
-#include "qstring.h"
-#include "RoutingSend.h"
-#include <iostream>
-
-using namespace std;
-
-DBusInterface::DBusInterface(QObject* parent) {
- (void) parent;
-}
-
-void DBusInterface::setReceiverInterface(RoutingReceiveInterface* r_interface) {
- audiomanager = r_interface;
-}
-
-int DBusInterface::peekDomain(const QString &name) {
- QByteArray b_name = name.toAscii();
- char * c_name = b_name.data();
- return audiomanager->peekDomain(c_name);
-}
-
-int DBusInterface::registerSource(const QString &name,
- const QString &audioclass, const QString &domain) {
- QByteArray b_name = name.toAscii();
- QByteArray b_audioclass = audioclass.toAscii();
- QByteArray b_domain = domain.toAscii();
- char * c_name = b_name.data();
- char * c_audioclass = b_audioclass.data();
- char * c_domain = b_domain.data();
- return audiomanager->registerSource(c_name, c_audioclass, c_domain);
-}
-int DBusInterface::registerSink(const QString &name, const QString &sinkclass,
- const QString &domain) {
- QByteArray b_name = name.toAscii();
- QByteArray b_sinkclass = sinkclass.toAscii();
- QByteArray b_domain = domain.toAscii();
- char * c_name = b_name.data();
- char * c_sinkclass = b_sinkclass.data();
- char * c_domain = b_domain.data();
- return audiomanager->registerSink(c_name, c_sinkclass, c_domain);
-}
-int DBusInterface::registerDomain(const QString &name, const QString &node,
- bool earlymode) {
- QByteArray b_name = name.toAscii();
- QByteArray b_nodeame = node.toAscii();
- char* c_name = b_name.data();
- char* c_nodename = b_nodeame.data();
- char c_busname[20];
- strcpy(c_busname, BUS_NAME);
- return audiomanager->registerDomain(c_name, c_busname, c_nodename,
- earlymode);
-}
-int DBusInterface::registerGateway(const QString &name, const QString &sink,
- const QString &source, const QString &domainSource,
- const QString &domainSink, const QString &controlDomain) {
- QByteArray b_name = name.toAscii();
- QByteArray b_sink = sink.toAscii();
- QByteArray b_source = source.toAscii();
- QByteArray b_domainSource = domainSource.toAscii();
- QByteArray b_domainSink = domainSink.toAscii();
- QByteArray b_controlDomain = controlDomain.toAscii();
- char* c_name = b_name.data();
- char* c_sink = b_sink.data();
- char* c_source = b_source.data();
- char* c_domainSource = b_domainSource.data();
- char* c_domainSink = b_domainSink.data();
- char* c_controlDomain = b_controlDomain.data();
- return audiomanager->registerGateway(c_name, c_sink, c_source,
- c_domainSource, c_domainSink, c_controlDomain);
-}
-void DBusInterface::emitSystemReady() {
- emit signal_systemReady();
-}
diff --git a/PluginRoutingInterfaceDbus/DbusInterface.cpp b/PluginRoutingInterfaceDbus/DbusInterface.cpp
new file mode 100644
index 0000000..56a8563
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DbusInterface.cpp
@@ -0,0 +1,153 @@
+/**
+ *
+ * Copyright (C) 2011, BMW AG
+ *
+ * PluginDBus
+ *
+ * \file RoutingSend.cpp
+ *
+ * \date 20.05.2011
+ * \author Christian Müller (christian.ei.mueller@bmw.de)
+ *
+ * \section License
+ * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
+ * Copyright (C) 2011, BMW AG – Christian Müller Christian.ei.mueller@bmw.de
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
+ * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
+ * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
+ * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
+ * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
+ * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
+ */
+
+
+#include "headers.h"
+#include "routinginterface.h"
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+#include <sstream>
+
+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_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("The DBus Plugin is started"));
+}
+
+DbusInterface::~DbusInterface() {
+ delete m_DbusInterface;
+}
+
+void DbusInterface::startup_interface(RoutingReceiveInterface* audioman) {
+ m_audioman = audioman;
+ m_DbusInterface = new AudioManagerInterface(audioman);
+ m_DbusInterface->startup_interface();
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ m_conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Could not connect to DBUS for sending, Error: "), DLT_STRING(err.message));
+ dbus_error_free(&err);
+ }
+
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Interface started "));
+}
+
+void DbusInterface::return_BusName(char* BusName) {
+ strcpy(BusName, BUS_NAME);
+}
+
+connection_t DbusInterface::connect(source_t source, sink_t sink, connection_t connID) {
+ int reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path, "connect");
+ send.appendInteger(source);
+ send.appendInteger(sink);
+ send.appendInteger(connID);
+ send.sendReply(&reply);
+ return (connection_t) reply;
+}
+
+void DbusInterface::system_ready() {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Plugin ready"));
+ m_DbusInterface->emit_systemReady();
+}
+
+bool DbusInterface::disconnect(connection_t connectionID) {
+ bool reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"disconnect");
+ send.appendInteger(connectionID);
+ send.sendReply(&reply);
+ return reply;
+}
+
+volume_t DbusInterface::setSinkVolume(volume_t volume, sink_t sink) {
+ int reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"setSinkVolume");
+ send.appendInteger(volume);
+ send.appendInteger(sink);
+ send.sendReply(&reply);
+ return (volume_t) reply;
+}
+
+volume_t DbusInterface::setSourceVolume(volume_t volume, source_t source) {
+ int reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"setSourceVolume");
+ send.appendInteger(volume);
+ send.appendInteger(source);
+ send.sendReply(&reply);
+ return (volume_t) reply;
+}
+
+bool DbusInterface::muteSource(source_t sourceID) {
+ bool reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"muteSource");
+ send.appendInteger(sourceID);
+ send.sendReply(&reply);
+ return reply;
+}
+
+bool DbusInterface::muteSink(sink_t sinkID) {
+ bool reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"muteSink");
+ send.appendInteger(sinkID);
+ send.sendReply(&reply);
+ return reply;
+}
+
+bool DbusInterface::unmuteSource(source_t sourceID) {
+ bool reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"unmuteSource");
+ send.appendInteger(sourceID);
+ send.sendReply(&reply);
+ return reply;
+}
+
+bool DbusInterface::unmuteSink(sink_t sinkID) {
+ bool reply;
+ DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"unmuteSink");
+ send.appendInteger(sinkID);
+ send.sendReply(&reply);
+ return reply;
+}
+
+//That is the actual implementation of the Factory Class returning the real sendInterface
+
+extern "C" RoutingSendInterface* PluginRoutingInterfaceDbusFactory() {
+ return new DbusInterface();
+}
+
+extern "C" void destroyRoutingPluginInterfaceDbus(RoutingSendInterface* iface) {
+ delete iface;
+}
+
+
diff --git a/PluginRoutingInterfaceDbus/RoutingSend.h b/PluginRoutingInterfaceDbus/DbusInterface.h
index 508614e..9f7b7f5 100644
--- a/PluginRoutingInterfaceDbus/RoutingSend.h
+++ b/PluginRoutingInterfaceDbus/DbusInterface.h
@@ -25,22 +25,19 @@
#ifndef BUS_INTERFACE_H_
#define BUS_INTERFACE_H_
+#include "headers.h"
#include "routinginterface.h"
-#include "DBusInterface.h"
-#include "DBusSend.h"
-#include "dlt/dlt.h"
-#include <qplugin.h>
-
-#define BUS_NAME "DBUS"
/**Implementation of the interface
*
*/
-class RoutingSend: public RoutingSendInterface {
- Q_OBJECT
+class DbusInterface: public RoutingSendInterface {
+
public:
- RoutingSend();
- void startup_interface(RoutingReceiveInterface * audioman);
+ DbusInterface();
+ virtual ~DbusInterface();
+
+ void startup_interface(RoutingReceiveInterface * audioman);
void return_BusName(char * BusName);
connection_t connect(source_t source, sink_t sink, connection_t connID);
bool disconnect(connection_t connectionID);
@@ -50,25 +47,16 @@ public:
bool muteSink(sink_t sinkID);
bool unmuteSource(source_t sourceID);
bool unmuteSink(sink_t sinkID);
-
-public slots:
- virtual void slot_system_ready();
+ void system_ready();
private:
- RoutingReceiveInterface *audiomanager;
- DBusInterface* receiver;
- QDBusConnection m_connection;
- DBusSend m_sender;
-};
-
-//That is the actual implementation of the Factory Class returning the real sendInterface
+ RoutingReceiveInterface *m_audioman;
+ AudioManagerInterface* m_DbusInterface;
+ DBusConnection* m_conn;
+ char* m_busname;
+ char* m_path;
-class SampleRoutingInterfaceFactory: public QObject,
- public RoutingInterfaceFactory {
- Q_OBJECT
- Q_INTERFACES(RoutingInterfaceFactory)
-public:
- RoutingSendInterface* returnInstance();
};
+
#endif /* BUS_INTERFACE_H_ */
diff --git a/PluginRoutingInterfaceDbus/DbusSend.cpp b/PluginRoutingInterfaceDbus/DbusSend.cpp
new file mode 100644
index 0000000..7183a95
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DbusSend.cpp
@@ -0,0 +1,112 @@
+/*
+ * DbusSend.cpp
+ *
+ * Created on: Jul 20, 2011
+ * Author: christian
+ */
+
+#include "DbusSend.h"
+
+DbusSend::DbusSend (DBusConnection* conn, const char* bus_name,const char* path, const char* interface, const char* method) : m_conn(conn) {
+ m_msg=dbus_message_new_method_call(bus_name,path,interface,method);
+ if (NULL == m_msg) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Error while creating DBus message"));
+ this->~DbusSend();
+ }
+}
+
+DbusSend::~DbusSend() {
+ // TODO Auto-generated destructor stub
+}
+
+void DbusSend::appendString(char* string) {
+ dbus_message_iter_init_append(m_msg, &m_args);
+ if (!dbus_message_iter_append_basic(&m_args, DBUS_TYPE_STRING, string)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
+ this->~DbusSend();
+ }
+}
+
+void DbusSend::appendInteger(int integer) {
+ dbus_message_iter_init_append(m_msg, &m_args);
+ if (!dbus_message_iter_append_basic(&m_args, DBUS_TYPE_INT32, &integer)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
+ this->~DbusSend();
+ }
+
+}
+
+void DbusSend::sendReply(bool* reply) {
+
+ DBusPendingCall* pending;
+ DBusMessageIter args;
+ if (!dbus_connection_send_with_reply (m_conn, m_msg, &pending, -1)) { // -1 is default timeout
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
+ this->~DbusSend();
+ }
+
+ if (NULL == pending) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Pending Call Null"));
+ this->~DbusSend();
+ }
+ dbus_connection_flush(m_conn);
+ dbus_message_unref(m_msg);
+ dbus_pending_call_block(pending);
+
+ DBusMessage* msg=dbus_pending_call_steal_reply(pending);
+
+ if (NULL == msg) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBUS reply NULL"));
+ this->~DbusSend();
+ }
+
+ dbus_pending_call_unref(pending);
+
+ if (!dbus_message_iter_init(msg, &args)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBUS Message without arguments"));
+ } else if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&args)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Argument not boolean"));
+ } else {
+ dbus_message_iter_get_basic(&args, reply);
+ }
+
+ dbus_message_unref(msg);
+}
+
+void DbusSend::sendReply(int* reply) {
+
+ DBusPendingCall* pending;
+ DBusMessageIter args;
+ if (!dbus_connection_send_with_reply (m_conn, m_msg, &pending, -1)) { // -1 is default timeout
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
+ this->~DbusSend();
+ }
+
+ if (NULL == pending) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Pending Call Null"));
+ this->~DbusSend();
+ }
+ dbus_connection_flush(m_conn);
+ dbus_message_unref(m_msg);
+ dbus_pending_call_block(pending);
+
+ DBusMessage* msg=dbus_pending_call_steal_reply(pending);
+
+ if (NULL == msg) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBUS reply NULL"));
+ this->~DbusSend();
+ }
+
+ dbus_pending_call_unref(pending);
+
+ if (!dbus_message_iter_init(msg, &args)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBUS Message without arguments"));
+ } else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Argument not integer"));
+ } else {
+ dbus_message_iter_get_basic(&args, reply);
+ }
+
+ dbus_message_unref(msg);
+}
+
diff --git a/PluginRoutingInterfaceDbus/DbusSend.h b/PluginRoutingInterfaceDbus/DbusSend.h
new file mode 100644
index 0000000..bfb565d
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/DbusSend.h
@@ -0,0 +1,28 @@
+/*
+ * DbusSend.h
+ *
+ * Created on: Jul 20, 2011
+ * Author: christian
+ */
+
+#ifndef DBUSSEND_H_
+#define DBUSSEND_H_
+
+#include "headers.h"
+
+class DbusSend {
+public:
+ DbusSend(DBusConnection* conn, const char* bus_name,const char* path, const char* interface, const char* method);
+ virtual ~DbusSend();
+ void appendString(char* string);
+ void appendInteger(int integer);
+ void sendReply(bool* reply);
+ void sendReply(int* reply);
+
+private:
+ DBusMessage* m_msg;
+ DBusMessageIter m_args;
+ DBusConnection* m_conn;
+};
+
+#endif /* DBUSSEND_H_ */
diff --git a/PluginRoutingInterfaceDbus/FindDBUS.cmake b/PluginRoutingInterfaceDbus/FindDBUS.cmake
new file mode 100644
index 0000000..48bc348
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/FindDBUS.cmake
@@ -0,0 +1,45 @@
+############################################################################
+#
+# 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.
+#
+############################################################################
+
+FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h
+/usr/include/dbus-1.0
+)
+
+FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h
+/usr/lib/dbus-1.0/include
+)
+
+FIND_LIBRARY(DBUS_LIBRARY
+NAMES dbus-1
+PATHS /lib
+)
+
+SET( DBUS_FOUND "NO" )
+IF(DBUS_LIBRARY)
+ SET( DBUS_FOUND "YES" )
+ message(STATUS "Found DBUS libs: ${DBUS_LIBRARY}")
+ message(STATUS "Found DBUS includes: ${DBUS_INCLUDE_DIR}")
+ message(STATUS "Found DBUS arch dependent includes: ${DBUS_ARCH_INCLUDE_DIR}")
+ENDIF(DBUS_LIBRARY)
+
+MARK_AS_ADVANCED(
+ DBUS_INCLUDE_DIR
+ DBUS_ARCH_INCLUDE_DIR
+ DBUS_LIBRARY
+)
diff --git a/PluginRoutingInterfaceDbus/RoutingSend.cpp b/PluginRoutingInterfaceDbus/RoutingSend.cpp
deleted file mode 100644
index d568f85..0000000
--- a/PluginRoutingInterfaceDbus/RoutingSend.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- *
- * Copyright (C) 2011, BMW AG
- *
- * PluginDBus
- *
- * \file RoutingSend.cpp
- *
- * \date 20.05.2011
- * \author Christian Müller (christian.ei.mueller@bmw.de)
- *
- * \section License
- * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
- * Copyright (C) 2011, BMW AG – Christian Müller Christian.ei.mueller@bmw.de
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
- * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
- * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
- * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
- * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
- * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
- */
-
-#include "RoutingSend.h"
-#include "DBusInterface.h"
-using namespace std;
-
-DLT_DECLARE_CONTEXT( DBusPlugin);
-
-RoutingSend::RoutingSend() :
- m_connection(QDBusConnection::sessionBus()),
- m_sender("org.genivi.pulse", "/pulse", m_connection) {
- DLT_REGISTER_APP("DBusPlugin", "DBusPlugin");
- DLT_REGISTER_CONTEXT(DBusPlugin, "Main", "Main Context");
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("The DBus Plugin is started"));
-}
-
-void RoutingSend::startup_interface(RoutingReceiveInterface* audioman) {
- audiomanager = audioman;
-
- DBusInterface* dbInterface = new DBusInterface;
- receiver = dbInterface;
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Interface started "));
-
- new DBusInterfaceAdaptor(dbInterface);
- // sender = new DBusSend();
- dbInterface->setReceiverInterface(audiomanager);
-
- QString Servicename = "com.Genivi.routinginterface";
- m_connection.registerService(Servicename);
- if (m_connection.isConnected()) {
- if (m_connection.registerObject(
- "/Hello",
- dbInterface,
- (QDBusConnection::ExportAdaptors
- | QDBusConnection::ExportAllSignals))) {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO,
- DLT_STRING("Registered DBus succsessfully"));
- } else {
- DLT_LOG(DBusPlugin, DLT_LOG_ERROR,
- DLT_STRING("Registered DBus succsessfully"));
- }
- }
-
- //
-}
-
-void RoutingSend::return_BusName(char* BusName) {
- strcpy(BusName, BUS_NAME);
-}
-
-connection_t RoutingSend::connect(source_t source, sink_t sink,
- connection_t connID) {
- QDBusPendingReply<int> pendingCall = m_sender.connect((int) source,
- (int) sink, (int) connID);
- pendingCall.waitForFinished();
- return (connection_t) pendingCall.value();
-}
-
-void RoutingSend::slot_system_ready() {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Plugin ready"));
- receiver->emitSystemReady();
-}
-
-bool RoutingSend::disconnect(connection_t connectionID) {
- if (m_sender.disconnect((int) connectionID) < 0) {
- return true;
- }
- return false;
-}
-
-volume_t RoutingSend::setSinkVolume(volume_t volume, sink_t sink) {
- return (volume_t) m_sender.setSinkVolume((int) volume, (int) sink);
-}
-
-volume_t RoutingSend::setSourceVolume(volume_t volume, source_t source) {
- return (volume_t) m_sender.setSourceVolume((int) volume, (int) source);
-}
-
-bool RoutingSend::muteSource(source_t sourceID) {
- if (m_sender.muteSource((int) sourceID) < 0) {
- return true;
- }
- return false;
-}
-
-bool RoutingSend::muteSink(sink_t sinkID) {
- if (m_sender.muteSink((int) sinkID) < 0) {
- return true;
- }
- return false;
-}
-
-bool RoutingSend::unmuteSource(source_t sourceID) {
- if (m_sender.unmuteSource((int) sourceID) < 0) {
- return true;
- }
- return false;
-}
-
-bool RoutingSend::unmuteSink(sink_t sinkID) {
- if (m_sender.unmuteSink((int) sinkID) < 0) {
- return true;
- }
- return false;
-}
-
-RoutingSendInterface* SampleRoutingInterfaceFactory::returnInstance() {
- return new RoutingSend();
-}
-
-Q_EXPORT_PLUGIN2(RoutingPlugin, SampleRoutingInterfaceFactory);
diff --git a/PluginRoutingInterfaceDbus/headers.h b/PluginRoutingInterfaceDbus/headers.h
new file mode 100644
index 0000000..15652e9
--- /dev/null
+++ b/PluginRoutingInterfaceDbus/headers.h
@@ -0,0 +1,29 @@
+/*
+ * headers.h
+ *
+ * Created on: Jul 21, 2011
+ * Author: christian
+ */
+
+#ifndef HEADERS_H_
+#define HEADERS_H_
+
+#include <dbus/dbus.h>
+#include <dlt/dlt.h>
+#include "routinginterface.h"
+#include "AudiomanagerInterface.h"
+#include "DbusSend.h"
+#include "DBUSMessageHandler.h"
+#include "DBUSIntrospection.h"
+#include "DbusInterface.h"
+
+
+#define BUS_NAME "DBUS"
+#define DBUS_BUSNAME "org.genivi.pulse"
+#define DBUS_PATH "/pulse"
+
+DLT_IMPORT_CONTEXT(DBusPlugin);
+const char DBUS_SERVICE_PREFIX[] = "org.genivi.audiomanager\0";
+
+
+#endif /* HEADERS_H_ */