summaryrefslogtreecommitdiff
path: root/PluginCommandInterfaceDbus
diff options
context:
space:
mode:
authorChristian Mueller <christian@lmuc329619u.(none)>2011-08-03 12:37:16 +0200
committerChristian Mueller <christian@lmuc329619u.(none)>2011-08-03 12:37:16 +0200
commit2d849dd0b5b1558e92cd0f2cd6dbc556950d631d (patch)
tree7b0bf4fda11eaae332f0b932990c1808875dc7e2 /PluginCommandInterfaceDbus
parentdf88fefdd7df890aaf2a3206483678851cffc5c5 (diff)
downloadaudiomanager-2d849dd0b5b1558e92cd0f2cd6dbc556950d631d.tar.gz
Dbus restructured
Diffstat (limited to 'PluginCommandInterfaceDbus')
-rw-r--r--PluginCommandInterfaceDbus/CMakeLists.txt12
-rw-r--r--PluginCommandInterfaceDbus/CommandDbusReceive.cpp226
-rw-r--r--PluginCommandInterfaceDbus/CommandDbusReceive.h (renamed from PluginCommandInterfaceDbus/CommandReceive.h)14
-rw-r--r--PluginCommandInterfaceDbus/CommandReceive.cpp179
-rw-r--r--PluginCommandInterfaceDbus/DBUSIntrospection.cpp205
-rw-r--r--PluginCommandInterfaceDbus/DBUSIntrospection.h65
-rw-r--r--PluginCommandInterfaceDbus/DBUSMessageHandler.cpp118
-rw-r--r--PluginCommandInterfaceDbus/DBUSMessageHandler.h28
-rw-r--r--PluginCommandInterfaceDbus/DBUSTypes.h4
-rw-r--r--PluginCommandInterfaceDbus/DbusInterface.cpp135
-rw-r--r--PluginCommandInterfaceDbus/DbusInterface.h12
-rw-r--r--PluginCommandInterfaceDbus/DbusSend.cpp26
-rw-r--r--PluginCommandInterfaceDbus/headers.h11
13 files changed, 379 insertions, 656 deletions
diff --git a/PluginCommandInterfaceDbus/CMakeLists.txt b/PluginCommandInterfaceDbus/CMakeLists.txt
index a5f447c..a1d7209 100644
--- a/PluginCommandInterfaceDbus/CMakeLists.txt
+++ b/PluginCommandInterfaceDbus/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.6)
-PROJECT(PluginRoutingInterfaceDbus)
+PROJECT(PluginCommandInterfaceDbus)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xlinker -export-dynamic")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
@@ -11,8 +11,8 @@ 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(LIBRARY_OUTPUT_PATH ../plugins/command)
+set(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../doc/CommandDBusPlugin)
find_package (Threads)
FIND_PACKAGE(DBUS REQUIRED)
@@ -35,16 +35,16 @@ INCLUDE_DIRECTORIES(
# all source files go here
SET(PLUGINDBUS_SRCS_CXX
+ CommandDbusReceive.cpp
DbusInterface.cpp
DBUSIntrospection.cpp
DBUSMessageHandler.cpp
- CommandReceive.cpp
DbusSend.cpp
)
-add_library(PluginRoutingInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX})
+add_library(PluginCommandInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX})
-TARGET_LINK_LIBRARIES(PluginRoutingInterfaceDbus
+TARGET_LINK_LIBRARIES(PluginCommandInterfaceDbus
${DLT_LIBRARIES}
${DBUS_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
diff --git a/PluginCommandInterfaceDbus/CommandDbusReceive.cpp b/PluginCommandInterfaceDbus/CommandDbusReceive.cpp
new file mode 100644
index 0000000..4269bbe
--- /dev/null
+++ b/PluginCommandInterfaceDbus/CommandDbusReceive.cpp
@@ -0,0 +1,226 @@
+/**
+ *
+ * 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <errno.h>
+
+DLT_IMPORT_CONTEXT(DBusCommandPlugin);
+
+class CommandDbusReceive;
+
+
+CommandDbusReceive* CommandDbusReceive::m_reference = NULL;
+
+static DBUSMessageHandler* g_pDbusMessage;
+
+static MethodTable manager_methods[] =
+{
+ { "connect", "uu", "u", &CommandDbusReceive::connect },
+ { "disconnect", "uu", "u", &CommandDbusReceive::disconnect },
+ { "getListConnections", "", "a{ii}", &CommandDbusReceive::getListConnections },
+ { "getListSinks", "", "a{si}", &CommandDbusReceive::getListSinks },
+ { "getListSources", "", "a{si}", &CommandDbusReceive::getListSources },
+ { "interruptRequest", "ss", "u", &CommandDbusReceive::interruptRequest },
+ { "interruptResume", "s", "u", &CommandDbusReceive::interruptResume },
+ { "setVolume", "ss", "u", &CommandDbusReceive::setVolume },
+ { "", "", "", NULL }
+};
+
+static SignalTable manager_signals[] = {
+ { "signal_connectionChanged", ""},
+ { "signal_numberOfSinksChanged", ""},
+ { "signal_numberOfSourcesChanged", ""},
+ { "", ""}
+};
+
+
+CommandDbusReceive::CommandDbusReceive(CommandReceiveInterface* r_interface): m_audioman(r_interface),m_running(false) {
+}
+
+bool CommandDbusReceive::startup_interface() {
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Starting up dbus connector"));
+
+ g_pDbusMessage = new DBUSMessageHandler();
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("create thread"));
+ this->m_running = true;
+ pthread_create(&m_currentThread, NULL, CommandDbusReceive::run, this);
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Started dbus connector"));
+ return true;
+}
+
+void CommandDbusReceive::stop() {
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Stopped dbus communication"));
+ this->m_running = false;
+ pthread_join(m_currentThread, NULL);
+ delete g_pDbusMessage;
+}
+
+void CommandDbusReceive::connect(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ source_t source = g_pDbusMessage->getUInt();
+ sink_t sink = g_pDbusMessage->getUInt();
+ connection_t connect=m_audioman->connect(source, sink);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append((unsigned int)connect);
+ g_pDbusMessage->closeReply();
+
+}
+void CommandDbusReceive::disconnect(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ source_t source = g_pDbusMessage->getUInt();
+ sink_t sink = g_pDbusMessage->getUInt();
+ connection_t connect=m_audioman->disconnect(source, sink);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append((unsigned int)connect);
+ g_pDbusMessage->closeReply();
+}
+
+void CommandDbusReceive::getListConnections(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ std::list<ConnectionType> list=m_audioman->getListConnections();
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append(list);
+ g_pDbusMessage->closeReply();
+
+}
+
+void CommandDbusReceive::getListSinks(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ std::list<SinkType> list=m_audioman->getListSinks();
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append(list);
+ g_pDbusMessage->closeReply();
+
+}
+
+void CommandDbusReceive::getListSources(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ std::list<SourceType> list=m_audioman->getListSources();
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append(list);
+ g_pDbusMessage->closeReply();
+
+}
+
+void CommandDbusReceive::interruptRequest(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ char* source = g_pDbusMessage->getString();
+ char* sink = g_pDbusMessage->getString();
+ genInt_t interrupt=m_audioman->interruptRequest(source, sink);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append((unsigned int)interrupt);
+ g_pDbusMessage->closeReply();
+}
+
+void CommandDbusReceive::interruptResume(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ interrupt_t interrupt = g_pDbusMessage->getUInt();
+ interrupt_t returnVal=m_audioman->interruptResume(interrupt);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append((unsigned int)returnVal);
+ g_pDbusMessage->closeReply();
+}
+
+void CommandDbusReceive::setVolume(DBusConnection* conn, DBusMessage* msg) {
+ (void)conn; // TODO: remove, only prevents warning
+ g_pDbusMessage->initReceive(msg);
+ sink_t sink = g_pDbusMessage->getUInt();
+ volume_t volume = g_pDbusMessage->getUInt();
+ volume_t returnVolume=m_audioman->setVolume(sink,volume);
+ g_pDbusMessage->initReply(msg);
+ g_pDbusMessage->append((unsigned int)returnVolume);
+ g_pDbusMessage->closeReply();
+}
+
+void CommandDbusReceive::emitSignalConnectionsChanged() {
+ g_pDbusMessage->sendSignal(SIG_CONNECTION_CHANGED);
+}
+
+void CommandDbusReceive::emitSignalNumberofSinksChanged() {
+ g_pDbusMessage->sendSignal(SIG_NUM_SINKS_CHANGED);
+}
+
+void CommandDbusReceive::emitSignalNumberofSourcesChanged() {
+ g_pDbusMessage->sendSignal(SIG_NUM_SOURCES_CHANGED);
+}
+
+DBusHandlerResult CommandDbusReceive::receive_callback (DBusConnection *conn,DBusMessage *msg,void *user_data) {
+ (void) user_data;
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("message received"));
+
+ const char *member = dbus_message_get_member(msg);
+ const char *iface = dbus_message_get_interface(msg);
+ bool found=false;
+ int i = 0;
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
+ DBUSIntrospection introspectionString(manager_methods,manager_signals);
+ introspectionString.process(conn, msg); 'a'
+ g_pDbusMessage->setConnection(conn);
+ dbus_connection_pop_message(conn);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ } else if (strcmp(DBUS_SERVICE_PREFIX,iface)==0) {
+
+ while (!found && strcmp(manager_methods[i].name, "") != 0) {
+ if (strcmp(manager_methods[i].name, member) == 0)
+ {
+ MethodTable entry = manager_methods[i];
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("got call for method:"),DLT_STRING(entry.name));
+ CallBackMethod m = entry.function;
+ (m_reference->*m)(conn, msg);
+ found = true;
+ }
+ i++;
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+ } else {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+}
+
+void* CommandDbusReceive::run(void * arg)
+{
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Main loop running"));
+ m_reference = (CommandDbusReceive*) arg;
+ DBusConnection* conn = g_pDbusMessage->getConnection();
+ if (!dbus_connection_add_filter(conn, (DBusHandleMessageFunction)&m_reference->receive_callback, NULL,NULL)) {
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("failing filter thread"));
+ }
+ while (m_reference->m_running && dbus_connection_read_write_dispatch(conn, -1))
+ {
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Dispatching Most message..."));
+ }
+
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread"));
+}
+
diff --git a/PluginCommandInterfaceDbus/CommandReceive.h b/PluginCommandInterfaceDbus/CommandDbusReceive.h
index 5dc213b..f8daa7e 100644
--- a/PluginCommandInterfaceDbus/CommandReceive.h
+++ b/PluginCommandInterfaceDbus/CommandDbusReceive.h
@@ -27,11 +27,15 @@
#include "headers.h"
-class CommandReceive {
+class CommandDbusReceive {
public:
- CommandReceive(CommandReceiveInterface* r_interface);
+ CommandDbusReceive(CommandReceiveInterface* r_interface);
+ bool startup_interface();
+ void stop();
+
+ static DBusHandlerResult receive_callback (DBusConnection *connection,DBusMessage *message,void *user_data);
void connect(DBusConnection* conn, DBusMessage* msg);
void disconnect(DBusConnection* conn, DBusMessage* msg);
void getListConnections(DBusConnection* conn, DBusMessage* msg);
@@ -41,10 +45,14 @@ public:
void interruptResume(DBusConnection* conn, DBusMessage* msg);
void setVolume(DBusConnection* conn, DBusMessage* msg);
+ void emitSignalConnectionsChanged();
+ void emitSignalNumberofSinksChanged();
+ void emitSignalNumberofSourcesChanged();
+
private:
static void* run(void * threadid);
pthread_t m_currentThread;
- static CommandReceive* m_reference;
+ static CommandDbusReceive* m_reference;
CommandReceiveInterface* m_audioman;
bool m_running;
};
diff --git a/PluginCommandInterfaceDbus/CommandReceive.cpp b/PluginCommandInterfaceDbus/CommandReceive.cpp
deleted file mode 100644
index e0f0524..0000000
--- a/PluginCommandInterfaceDbus/CommandReceive.cpp
+++ /dev/null
@@ -1,179 +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 "headers.h"
-#include <iostream>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <errno.h>
-
-class CommandReceive;
-
-
-CommandReceive* CommandReceive::m_reference = NULL;
-
-static DBUSMessageHandler* g_pDbusMessage;
-
-static MethodTable manager_methods[] =
-{
- { "connect", "uu", "u", &CommandReceive::connect },
- { "disconnect", "uu", "u", &CommandReceive::disconnect },
- { "getListConnections", "", "a{ii}", &CommandReceive::getListConnections },
- { "getListSinks", "", "a{si}", &CommandReceive::getListSinks },
- { "getListSources", "", "a{si}", &CommandReceive::getListSources },
- { "interruptRequest", "ss", "u", &CommandReceive::interruptRequest },
- { "interruptResume", "s", "u", &CommandReceive::interruptResume },
- { "setVolume", "ss", "u", &CommandReceive::setVolume },
- { "", "", "", NULL }
-};
-
-static SignalTable manager_signals[] = {
- { "signal_connectionChanged", ""},
- { "signal_numberOfSinksChanged", ""},
- { "signal_numberOfSourcesChanged", ""},
- { "", ""}
-};
-
-
-CommandReceive::CommandReceive(RoutingReceiveInterface* r_interface) : m_audioman(r_interface),m_running(false) {
-}
-
-bool CommandReceive::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, CommandReceive::run, this);
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Started dbus connector"));
- return true;
-}
-
-void CommandReceive::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 CommandReceive::connect(DBusConnection* conn, DBusMessage* msg) {
- (void)conn; // TODO: remove, only prevents warning
- g_pDbusMessage->initReceive(msg);
- source_t source = g_pDbusMessage->getUInt();
- sink_t sink = g_pDbusMessage->getUInt();
- connection_t connect=m_audioman->connect(source, sink);
- g_pDbusMessage->initReply(msg);
- g_pDbusMessage->appendUInt(connect);
- g_pDbusMessage->closeReply();
-
-}
-void CommandReceive::disconnect(DBusConnection* conn, DBusMessage* msg) {
- (void)conn; // TODO: remove, only prevents warning
- g_pDbusMessage->initReceive(msg);
- source_t source = g_pDbusMessage->getUInt();
- sink_t sink = g_pDbusMessage->getUInt();
- connection_t connect=m_audioman->disconnect(source, sink);
- g_pDbusMessage->initReply(msg);
- g_pDbusMessage->appendUInt(connect);
- g_pDbusMessage->closeReply();
-}
-
-void CommandReceive::getListConnections(DBusConnection* conn, DBusMessage* msg) {
- (void)conn; // TODO: remove, only prevents warning
- std::list<ConnectionType> list=m_audioman->getListConnections();
- g_pDbusMessage->initReply(msg);
- g_pDbusMessage->appendArrayOfStringString()
- g_pDbusMessage->closeReply();
-
-}
-
-void CommandReceive::getListSinks(DBusConnection* conn, DBusMessage* msg) {
-
-}
-
-void CommandReceive::getListSources(DBusConnection* conn, DBusMessage* msg) {
-
-}
-
-void CommandReceive::interruptRequest(DBusConnection* conn, DBusMessage* msg) {
-
-}
-
-void CommandReceive::interruptResume(DBusConnection* conn, DBusMessage* msg) {
-
-}
-
-void CommandReceive::setVolume(DBusConnection* conn, DBusMessage* msg) {
-
-}
-
-void* CommandReceive::run(void * arg)
-{
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Main loop running"));
- m_reference = (CommandReceive*) 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++;
- }
- }
- dbus_connection_flush(conn);
- dbus_message_unref(msg);
- msg = NULL;
- }
-
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread"));
- return 0;
-}
-
diff --git a/PluginCommandInterfaceDbus/DBUSIntrospection.cpp b/PluginCommandInterfaceDbus/DBUSIntrospection.cpp
deleted file mode 100644
index fabd2dd..0000000
--- a/PluginCommandInterfaceDbus/DBUSIntrospection.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/***************************************************************************
- *
- * Copyright 2010,2011 BMW Car IT GmbH
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ****************************************************************************/
-#include "DBUSIntrospection.h"
-#include <string.h>
-#include <sstream>
-using std::stringstream;
-
-
-DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable)
-: m_methodTable(methodTable), m_signalTable(signalTable)
-{
- generateString();
-}
-
-void DBUSIntrospection::generateString()
-{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
-
- addHeader();
- openNode("");
- 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;
- }
-
- index=0;
- if (m_signalTable) {
- while (strcmp(m_signalTable[index].name, "") != 0)
- {
- SignalTable entry = m_signalTable[index];
- addEntry(entry);
- ++index;
- }
- }
- closeInterface();
- closeNode();
-
-}
-
-void DBUSIntrospection::addHeader(void)
-{
- m_introspectionString << "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS"
- << "Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/"
- << "dbus/1.0/introspect.dtd\"> \n";
-}
-
-void DBUSIntrospection::openNode(string nodename)
-{
- m_introspectionString << "<node name=\"" << nodename << "\"> \n";
-}
-
-void DBUSIntrospection::openInterface(string interfacename)
-{
- m_introspectionString << "<interface name=\"" << interfacename << "\"> \n";
-}
-
-void DBUSIntrospection::openMethod(string methodname)
-{
- m_introspectionString << "<method name=\"" << methodname << "\"> \n";
-}
-
-void DBUSIntrospection::addSignal(string signalname) {
- m_introspectionString<<"<signal name=\"" << signalname << "\"> \n";
-}
-
-void DBUSIntrospection::addArgument(string argname, string direction, string type)
-{
- m_introspectionString << "<arg name=\"" << argname << "\" direction=\""
- << direction << "\" type=\"" << type << "\"/> \n";
-}
-
-void DBUSIntrospection::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::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;
- 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/PluginCommandInterfaceDbus/DBUSIntrospection.h b/PluginCommandInterfaceDbus/DBUSIntrospection.h
deleted file mode 100644
index 753dc0e..0000000
--- a/PluginCommandInterfaceDbus/DBUSIntrospection.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/***************************************************************************
- *
- * Copyright 2010,2011 BMW Car IT GmbH
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ****************************************************************************/
-
-#ifndef _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, SignalTable* stable);
- 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 addEntry(SignalTable entry);
-
- void openNode(string nodename);
- void closeNode(void);
-
- void openInterface(string interfacename);
- void closeInterface(void);
-
- void openMethod(string methodname);
- void closeMethod(void);
-
- void addSignal(string signalname);
-
-
-private:
- stringstream m_introspectionString;
- MethodTable* m_methodTable;
- SignalTable* m_signalTable;
-};
-
-
-#endif // _DBUSINTROSPECTION_H_
diff --git a/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp b/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
index 6f335c6..a796f28 100644
--- a/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
+++ b/PluginCommandInterfaceDbus/DBUSMessageHandler.cpp
@@ -15,23 +15,23 @@ DBUSMessageHandler::DBUSMessageHandler()
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"));
+ DLT_LOG(DBusCommandPlugin,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"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Connection is null"));
exit(1);
}
int ret = dbus_bus_request_name(m_pConnection,DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_REPLACE_EXISTING, &m_err);
if (dbus_error_is_set(&m_err))
{
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Name Error"),DLT_STRING(m_err.message));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Name Error"),DLT_STRING(m_err.message));
dbus_error_free(&m_err);
}
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
{
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicatorNot Primary Owner"), DLT_INT(ret));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicatorNot Primary Owner"), DLT_INT(ret));
exit(1);
}
}
@@ -43,13 +43,13 @@ DBUSMessageHandler::~DBUSMessageHandler()
bool errorset = dbus_error_is_set(&err);
if (errorset)
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
+ DLT_LOG(DBusCommandPlugin,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"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
}
dbus_error_init(&err);
dbus_bus_release_name(m_pConnection, DBUS_SERVICE_PREFIX, &err);
@@ -59,7 +59,7 @@ void DBUSMessageHandler::initReceive(DBusMessage* msg)
{
if (!dbus_message_iter_init(msg, &m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS Message has no arguments!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS Message has no arguments!"));
}
}
@@ -75,10 +75,10 @@ void DBUSMessageHandler::closeReply()
// send the reply && flush the connection
if (!dbus_connection_send(m_pConnection, m_pReply, &m_serial))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
exit(1);
}
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply!"));
dbus_connection_flush(m_pConnection);
// free the reply
@@ -92,10 +92,10 @@ void DBUSMessageHandler::ReplyError(DBusMessage* msg, const char* errorname, con
// send the reply && flush the connection
if (!dbus_connection_send(m_pConnection, m_pReply, &m_serial))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
exit(1);
}
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler sending reply with error!"));
dbus_connection_flush(m_pConnection);
// free the reply
@@ -105,10 +105,9 @@ void DBUSMessageHandler::ReplyError(DBusMessage* msg, const char* errorname, con
char* DBUSMessageHandler::getString()
{
char* param;
-
if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
}
else
{
@@ -124,7 +123,7 @@ dbus_bool_t DBUSMessageHandler::getBool()
if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no bool!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no bool!"));
}
else
{
@@ -140,7 +139,7 @@ char DBUSMessageHandler::getByte()
if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no byte!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no byte!"));
}
else
{
@@ -156,7 +155,7 @@ dbus_uint32_t DBUSMessageHandler::getUInt()
if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no uint32_t!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no uint32_t!"));
}
else
{
@@ -172,7 +171,7 @@ double DBUSMessageHandler::getDouble()
if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no double!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no double!"));
}
else
{
@@ -186,7 +185,7 @@ void DBUSMessageHandler::getArrayOfUInt(int* pLength, unsigned int** ppArray)
{
if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
return;
}
@@ -207,7 +206,7 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
{
if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&m_MessageIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no array!"));
return;
}
@@ -218,7 +217,7 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
{
if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&arrayIter))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler argument is no string!"));
}
char* param;
dbus_message_iter_get_basic(&arrayIter, &param);
@@ -236,43 +235,44 @@ void DBUSMessageHandler::getArrayOfString(std::vector<std::string>* stringVector
}
}
-void DBUSMessageHandler::appendBool(dbus_bool_t toAppend)
+void DBUSMessageHandler::append(bool toAppend)
{
- if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BOOLEAN, &toAppend))
+ dbus_bool_t mybool=toAppend;
+ if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BOOLEAN, &mybool))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
exit(1);
}
}
-void DBUSMessageHandler::appendUInt(dbus_uint32_t toAppend)
+void DBUSMessageHandler::append(dbus_uint32_t toAppend)
{
if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_UINT32, &toAppend))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
exit(1);
}
}
-void DBUSMessageHandler::appendDouble(double toAppend)
+void DBUSMessageHandler::append(double toAppend)
{
if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_DOUBLE, &toAppend))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
exit(1);
}
}
-void DBUSMessageHandler::appendByte(char toAppend)
+void DBUSMessageHandler::append(char toAppend)
{
if (!dbus_message_iter_append_basic(&m_MessageIter, DBUS_TYPE_BYTE, &toAppend))
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
exit(1);
}
}
-void DBUSMessageHandler::appendArrayOfUInt(unsigned int length, unsigned int *IDs)
+void DBUSMessageHandler::append(unsigned int length, unsigned int *IDs)
{
DBusMessageIter arrayIter;
dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "u", &arrayIter);
@@ -283,21 +283,20 @@ 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_PREFIX_PATH,DBUS_SERVICE_PREFIX,signalname);
if (NULL == msg)
{
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Message null!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("Message null!"));
this->~DBUSMessageHandler();
}
if (!dbus_connection_send(m_pConnection, msg, &serial)) {
- DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
+ DLT_LOG(DBusCommandPlugin,DLT_LOG_ERROR, DLT_STRING("DBUS handler Out Of Memory!"));
this->~DBUSMessageHandler();
}
@@ -307,37 +306,58 @@ void DBUSMessageHandler::sendSignal(const char* name, const char* signal) {
dbus_message_unref(msg);
}
-void DBUSMessageHandler::appendArrayOfStringUInt(std::list<stringAndUInt> list){
+void DBUSMessageHandler::append(std::list<ConnectionType> list){
DBusMessageIter arrayIter;
- dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "si", &arrayIter);
+ dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "uu", &arrayIter);
- std::list<stringAndUInt>::iterator Ilist;
- std::list<stringAndUInt>::iterator Ibegin=list.begin();
- std::list<stringAndUInt>::iterator Iend=list.end();
+ std::list<ConnectionType>::iterator Ilist;
+ std::list<ConnectionType>::iterator Ibegin=list.begin();
+ std::list<ConnectionType>::iterator Iend=list.end();
for(Ilist=Ibegin;Ilist!=Iend; Ilist++)
{
- dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->string);
- dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->integer);
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->Sink_ID);
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->Source_ID);
}
dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
}
-void DBUSMessageHandler::appendArrayOfStringString(std::list<stringString> list){
+void DBUSMessageHandler::append(std::list<SinkType> list){
DBusMessageIter arrayIter;
- dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "ss", &arrayIter);
+ dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "su", &arrayIter);
- std::list<stringString>::iterator Ilist;
- std::list<stringString>::iterator Ibegin=list.begin();
- std::list<stringString>::iterator Iend=list.end();
+ std::list<SinkType>::iterator Ilist;
+ std::list<SinkType>::iterator Ibegin=list.begin();
+ std::list<SinkType>::iterator Iend=list.end();
for(Ilist=Ibegin;Ilist!=Iend; Ilist++)
{
- dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->string1);
- dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->string2);
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->name);
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->ID);
}
dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
}
+void DBUSMessageHandler::append(std::list<SourceType> list){
+ DBusMessageIter arrayIter;
+ dbus_message_iter_open_container(&m_MessageIter, DBUS_TYPE_ARRAY, "su", &arrayIter);
+
+ std::list<SourceType>::iterator Ilist;
+ std::list<SourceType>::iterator Ibegin=list.begin();
+ std::list<SourceType>::iterator Iend=list.end();
+ for(Ilist=Ibegin;Ilist!=Iend; Ilist++)
+ {
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_STRING, &Ilist->name);
+ dbus_message_iter_append_basic(&arrayIter, DBUS_TYPE_UINT32, &Ilist->ID);
+ }
+ dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
+}
+
+
+
+
+
+
+
diff --git a/PluginCommandInterfaceDbus/DBUSMessageHandler.h b/PluginCommandInterfaceDbus/DBUSMessageHandler.h
index c543caa..0ec6d3a 100644
--- a/PluginCommandInterfaceDbus/DBUSMessageHandler.h
+++ b/PluginCommandInterfaceDbus/DBUSMessageHandler.h
@@ -30,16 +30,6 @@ public:
DBUSMessageHandler();
~DBUSMessageHandler();
- struct stringAndUInt {
- std::string string;
- unsigned int integer;
- };
-
- struct stringString {
- std::string string1;
- std::string string2;
- };
-
void setConnection(DBusConnection* conn);
DBusConnection* getConnection();
@@ -57,14 +47,16 @@ public:
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 appendArrayOfStringUInt(std::list<stringAndUInt> list);
- void appendArrayOfStringString(std::list<stringString> list);
- void sendSignal(const char* name,const char* signal);
+ void append(dbus_uint32_t toAppend);
+ void append(char toAppend);
+ void append(bool toAppend);
+ void append(double toAppend);
+ void append(unsigned int length, unsigned int *IDs);
+ void append(std::list<SourceType> list);
+ void append(std::list<ConnectionType> list);
+ void append(std::list<SinkType> list);
+
+ void sendSignal(const char* signalname);
private:
DBusMessageIter m_MessageIter;
diff --git a/PluginCommandInterfaceDbus/DBUSTypes.h b/PluginCommandInterfaceDbus/DBUSTypes.h
index 73dde75..0f8474c 100644
--- a/PluginCommandInterfaceDbus/DBUSTypes.h
+++ b/PluginCommandInterfaceDbus/DBUSTypes.h
@@ -21,9 +21,7 @@
#include "headers.h"
-class CommandReceive;
-
-typedef void (CommandReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
+typedef void (CommandDbusReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
struct MethodTable
{
diff --git a/PluginCommandInterfaceDbus/DbusInterface.cpp b/PluginCommandInterfaceDbus/DbusInterface.cpp
index 8bfef1f..a83a549 100644
--- a/PluginCommandInterfaceDbus/DbusInterface.cpp
+++ b/PluginCommandInterfaceDbus/DbusInterface.cpp
@@ -33,22 +33,22 @@
#include <string>
#include <sstream>
-DLT_DECLARE_CONTEXT(DBusPlugin)
+DLT_DECLARE_CONTEXT(DBusCommandPlugin)
-DbusInterface::DbusInterface(): m_busname(DBUS_BUSNAME), m_path(DBUS_PATH) {
+DbusCommandInterface::DbusCommandInterface() : 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"));
+ DLT_REGISTER_APP("DBusCommandPlugin", "DBusCommandPlugin");
+ DLT_REGISTER_CONTEXT(DBusCommandPlugin, "PluginCommand", "DBusCommandPlugin");
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("The DBusCommandPluginis started"));
}
-DbusInterface::~DbusInterface() {
+DbusCommandInterface::~DbusCommandInterface() {
delete m_DbusInterface;
}
-void DbusInterface::startup_interface(RoutingReceiveInterface* audioman) {
- m_audioman = audioman;
- m_DbusInterface = new CommandReceive(audioman);
+void DbusCommandInterface::startupInterface(CommandReceiveInterface* iface) {
+ m_audioman = iface;
+ m_DbusInterface = new CommandDbusReceive(iface);
m_DbusInterface->startup_interface();
DBusError err;
@@ -56,134 +56,47 @@ void DbusInterface::startup_interface(RoutingReceiveInterface* audioman) {
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));
+ DLT_LOG(DBusCommandPlugin, 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 "));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("DBus Interface started "));
}
-void DbusInterface::return_BusName(char* BusName) {
- strcpy(BusName, BUS_NAME);
-}
-genError_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 GEN_OK;
- /**
- * \todo always OK...
- */
-}
-void DbusInterface::system_ready() {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Plugin got ready"));
- m_DbusInterface->emit_systemReady();
+void DbusCommandInterface::stop(){
}
-genError_t 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 GEN_OK;
- /**
- * \todo always OK...
- */
-}
-genError_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 GEN_OK;
- /**
- * \todo always OK...
- */
-}
-genError_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 GEN_OK;
- /**
- * \todo always OK...
- */
+void DbusCommandInterface::cbConnectionChanged(){
+ m_DbusInterface->emitSignalConnectionsChanged();
}
-genError_t 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 GEN_OK;
- /**
- * \todo always OK...
- */
-}
-genError_t 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 GEN_OK;
- /**
- * \todo always OK...
- */
-}
-genError_t 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 GEN_OK;
- /**
- * \todo always OK...
- */
+void DbusCommandInterface::cbNumberOfSinksChanged(){
+ m_DbusInterface->emitSignalNumberofSinksChanged();
}
-genError_t 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 GEN_OK;
- /**
- * \todo always OK...
- */
-}
-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
- */
+void DbusCommandInterface::cbNumberOfSourcesChanged(){
+ m_DbusInterface->emitSignalNumberofSourcesChanged();
}
+
//That is the actual implementation of the Factory Class returning the real sendInterface
-extern "C" RoutingSendInterface* PluginRoutingInterfaceDbusFactory() {
- return new DbusInterface();
+extern "C" CommandSendInterface* PluginCommandInterfaceDbusFactory() {
+ return new DbusCommandInterface();
}
-extern "C" void destroyRoutingPluginInterfaceDbus(RoutingSendInterface* iface) {
+extern "C" void destroyRoutingPluginInterfaceDbus(DbusCommandInterface* iface) {
delete iface;
}
+
+
diff --git a/PluginCommandInterfaceDbus/DbusInterface.h b/PluginCommandInterfaceDbus/DbusInterface.h
index 739bb26..83a04b8 100644
--- a/PluginCommandInterfaceDbus/DbusInterface.h
+++ b/PluginCommandInterfaceDbus/DbusInterface.h
@@ -28,6 +28,11 @@
#include "headers.h"
#include "commandInterface.h"
+#define SIG_CONNECTION_CHANGED "signal_connectionChanged"
+#define SIG_NUM_SINKS_CHANGED "signal_numberOfSinksChanged"
+#define SIG_NUM_SOURCES_CHANGED "signal_numberOfSourcesChanged"
+
+
/**Implementation of the interface
*
*/
@@ -39,8 +44,15 @@ public:
void cbConnectionChanged();
void cbNumberOfSinksChanged();
void cbNumberOfSourcesChanged();
+ void startupInterface(CommandReceiveInterface* iface);
+ void stop();
private:
+ CommandReceiveInterface *m_audioman;
+ CommandDbusReceive* m_DbusInterface;
+ DBusConnection* m_conn;
+ char* m_busname;
+ char* m_path;
};
diff --git a/PluginCommandInterfaceDbus/DbusSend.cpp b/PluginCommandInterfaceDbus/DbusSend.cpp
index 7183a95..0fa1e19 100644
--- a/PluginCommandInterfaceDbus/DbusSend.cpp
+++ b/PluginCommandInterfaceDbus/DbusSend.cpp
@@ -10,7 +10,7 @@
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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Error while creating DBus message"));
this->~DbusSend();
}
}
@@ -22,7 +22,7 @@ DbusSend::~DbusSend() {
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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
this->~DbusSend();
}
}
@@ -30,7 +30,7 @@ void DbusSend::appendString(char* string) {
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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
this->~DbusSend();
}
@@ -41,12 +41,12 @@ 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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
this->~DbusSend();
}
if (NULL == pending) {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Pending Call Null"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Pending Call Null"));
this->~DbusSend();
}
dbus_connection_flush(m_conn);
@@ -56,16 +56,16 @@ void DbusSend::sendReply(bool* reply) {
DBusMessage* msg=dbus_pending_call_steal_reply(pending);
if (NULL == msg) {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBUS reply NULL"));
+ DLT_LOG(DBusCommandPlugin, 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"));
+ DLT_LOG(DBusCommandPlugin, 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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Argument not boolean"));
} else {
dbus_message_iter_get_basic(&args, reply);
}
@@ -78,12 +78,12 @@ 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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Out of memory"));
this->~DbusSend();
}
if (NULL == pending) {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Pending Call Null"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Pending Call Null"));
this->~DbusSend();
}
dbus_connection_flush(m_conn);
@@ -93,16 +93,16 @@ void DbusSend::sendReply(int* reply) {
DBusMessage* msg=dbus_pending_call_steal_reply(pending);
if (NULL == msg) {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBUS reply NULL"));
+ DLT_LOG(DBusCommandPlugin, 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"));
+ DLT_LOG(DBusCommandPlugin, 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"));
+ DLT_LOG(DBusCommandPlugin, DLT_LOG_INFO, DLT_STRING("Argument not integer"));
} else {
dbus_message_iter_get_basic(&args, reply);
}
diff --git a/PluginCommandInterfaceDbus/headers.h b/PluginCommandInterfaceDbus/headers.h
index 7152165..062675f 100644
--- a/PluginCommandInterfaceDbus/headers.h
+++ b/PluginCommandInterfaceDbus/headers.h
@@ -10,20 +10,23 @@
#include <dbus/dbus.h>
#include <dlt/dlt.h>
-#include "routinginterface.h"
-#include "AudiomanagerInterface.h"
+#include "CommandReceive.h"
+#include "CommandDbusReceive.h"
+#include "commandInterface.h"
#include "DbusSend.h"
#include "DBUSMessageHandler.h"
#include "DBUSIntrospection.h"
#include "DbusInterface.h"
+#include "DBUSTypes.h"
#define BUS_NAME "DBUS"
#define DBUS_BUSNAME "org.genivi.pulse"
#define DBUS_PATH "/pulse"
-const char DBUS_SERVICE_PREFIX[] = "org.genivi.audiomanagerRouting\0";
+const char DBUS_SERVICE_PREFIX[] = "org.bla.audiomanagerCommand\0";
+const char DBUS_SERVICE_PREFIX_PATH[] = "/org/bla/audiomanagerCommand\0";
-DLT_IMPORT_CONTEXT(DBusPlugin);
+DLT_IMPORT_CONTEXT(DBusCommandPlugin);
#endif /* HEADERS_H_ */