}
AudioManagerCore::AudioManagerCore() :
- m_queueList(std::list<Queue*> ()) {
+ m_queueList(std::list<Queue*> ()),m_dbusHandler(0) {
}
AudioManagerCore::~AudioManagerCore() {
return fileList;
}
+void AudioManagerCore::registerDbusRootHandler(dbusRoothandler* handler){
+ m_dbusHandler=handler;
+}
+
+dbusRoothandler* AudioManagerCore::returnDbusHandler(){
+ return m_dbusHandler;
+}
+
+
+
+
+
DataBaseHandler* returnDatabaseHandler();
RoutingReceiver* returnReceiver();
CommandInterface* returnCommandInterface();
+ dbusRoothandler* returnDbusHandler();
void registerDatabasehandler(DataBaseHandler * handler);
void registerRouter(Router* router);
void registerHookEngine(HookHandler* handler);
void registerReceiver(RoutingReceiver* receiver);
void registerCommandInterface(CommandInterface* command);
+ void registerDbusRootHandler(dbusRoothandler* handler);
void addQueue(Queue* queue);
genError_t removeQueue(Queue* queue);
Bushandler* m_busHandler; //!< pointer to the Bushandler Class
HookHandler* m_hookHandler; //!< pointer to the HookHandler CLass
RoutingReceiver* m_receiver; //!< pointer to the Routing receiver Class
+ dbusRoothandler* m_dbusHandler;
CommandInterface* m_command; //!< pointer to the command Interface Class
std::list<Queue*> m_queueList; //!< List of pointers to all running queues
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "-g -pipe -g -Wall -W -D_REENTRANT")
+##todo only when dbus needed!
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}")
+
set(STD_INCLUDE_DIRS "/usr/include")
set(EXECUTABLE_OUTPUT_PATH ../../bin/)
set(DOC_OUTPUT_PATH ../../doc/)
FIND_PACKAGE(PkgConfig)
pkg_check_modules(SQLITE REQUIRED sqlite3)
pkg_check_modules(DLT REQUIRED automotive-dlt)
+
+##todo: only when dbus is reuqired !
+find_package (Threads)
+FIND_PACKAGE(DBUS REQUIRED)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${STD_INCLUDE_DIRS})
#all source files go here
SET(AUDIOMAN_SRCS_CXX
+ main.cpp
AudioManagerCore.cpp
- RoutingReceive.cpp
+ CommandHandler.cpp
CommandReceive.cpp
- Router.cpp
DataBaseHandler.cpp
- main.cpp
HookEngine.cpp
+ Router.cpp
+ RoutingReceive.cpp
+ dbusRoothandler.cpp
)
INCLUDE_DIRECTORIES(
ADD_EXECUTABLE(AudioManager ${AUDIOMAN_SRCS_CXX})
+##todo only when dbus is required
TARGET_LINK_LIBRARIES(AudioManager
${SQLITE_LIBRARIES}
${DLT_LIBRARIES}
+ ${DBUS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
)
#add a target to generate API documentation with Doxygen
--- /dev/null
+/*
+ * CommandHandler.cpp
+ *
+ * Created on: Jul 27, 2011
+ * Author: christian
+ */
+
+#include "CommandHandler.h"
+#include "audioManagerIncludes.h"
+
+const char* commandPluginDirectories[] = { "/home/christian/workspace/gitserver/build/plugins/command"};
+uint commandPluginDirectoriesCount = sizeof(commandPluginDirectories) / sizeof(commandPluginDirectories[0]);
+
+CommandHandler::CommandHandler(AudioManagerCore* core) :m_core(core) {
+ // TODO Auto-generated constructor stub
+
+}
+
+CommandHandler::~CommandHandler() {
+ // TODO Auto-generated destructor stub
+}
+
+void CommandHandler::registerReceiver(CommandReceiveInterface *iface) {
+ m_receiver=iface;
+}
+
+void CommandHandler::loadPlugins(){
+ std::list<std::string> sharedLibraryNameList;
+
+ for (uint dirIndex = 0; dirIndex < commandPluginDirectoriesCount; ++dirIndex) {
+ const char* directoryName = commandPluginDirectories[dirIndex];
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Searching for Command in"),DLT_STRING(directoryName));
+ std::list<std::string> newList=m_core->getSharedLibrariesFromDirectory(directoryName);
+ sharedLibraryNameList.insert(sharedLibraryNameList.end(),newList.begin(),newList.end());
+ }
+
+
+ // iterate all communicator plugins and start them
+ std::list<std::string>::iterator iter = sharedLibraryNameList.begin();
+ std::list<std::string>::iterator iterEnd = sharedLibraryNameList.end();
+
+ for (; iter != iterEnd; ++iter)
+ {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Loading Command plugin"),DLT_STRING(iter->c_str()));
+
+ CommandSendInterface* (*createFunc)();
+ createFunc = getCreateFunction<CommandSendInterface*()>(*iter);
+
+ if (!createFunc) {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Entry point of Communicator not found"));
+ continue;
+ }
+
+ CommandSendInterface* CommandPlugin = createFunc();
+
+
+ if (!CommandPlugin) {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("RoutingPlugin initialization failed. Entry Function not callable"));
+ continue;
+ }
+
+
+ CommandPlugin->startupInterface(m_receiver);
+ DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Routing Plugin"));
+ m_interfaceList.push_back(CommandPlugin);
+ }
+}
+
+
+
--- /dev/null
+/*
+ * CommandHandler.h
+ *
+ * Created on: Jul 27, 2011
+ * Author: christian
+ */
+
+#ifndef COMMANDHANDLER_H_
+#define COMMANDHANDLER_H_
+
+#include "audioManagerIncludes.h"
+#include "commandInterface.h"
+
+class CommandReceiveInterface;
+class CommandSendInterface;
+
+
+class CommandHandler {
+public:
+ CommandHandler(AudioManagerCore* core);
+ void registerReceiver(CommandReceiveInterface* iface);
+ virtual ~CommandHandler();
+ void loadPlugins();
+private:
+ AudioManagerCore* m_core;
+ CommandReceiveInterface* m_receiver;
+ std::list<CommandSendInterface*> m_interfaceList;
+};
+
+#endif /* COMMANDHANDLER_H_ */
#include "CommandReceive.h"
-CommandReceive::CommandReceive(AudioManagerCore* core) : m_core(core) {
+CommandReceive::CommandReceive(){
}
CommandReceive::~CommandReceive() {
}
+void CommandReceive::registerAudiomanagerCore(AudioManagerCore *core){
+ m_core=core;
+}
+
+
connection_t CommandReceive::connect(source_t source, sink_t sink) {
- DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Connect"));
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("Connect"));
if (m_core->UserConnect(source, sink) == GEN_OK) {
return 1;
}
*/
}
-
-
-connection_t CommandReceive::disconnect(source_t source, source_t sink){
+connection_t CommandReceive::disconnect(source_t source, source_t sink) {
genRoute_t ReturnRoute;
if (int value=m_core->returnDatabaseHandler()->returnMainconnectionIDforSinkSourceID(sink,source)>0) {
*/
}
-
-
-std::list<ConnectionType> CommandReceive::getListConnections(){
+std::list<ConnectionType> CommandReceive::getListConnections() {
return m_core->getListConnections();
}
-
-
-std::list<SinkType> CommandReceive::getListSinks(){
+std::list<SinkType> CommandReceive::getListSinks() {
return m_core->getListSinks();
}
-
-
std::list<SourceType> CommandReceive::getListSources() {
return m_core->getListSources();
}
-
-
-genInt_t CommandReceive::interruptRequest(const std::string & SourceName, const std::string & SinkName) {
+genInt_t CommandReceive::interruptRequest(const std::string & SourceName,
+ const std::string & SinkName) {
source_t sourceID = m_core->returnSourceIDfromName(SourceName);
sink_t sinkID = m_core->returnSinkIDfromName(SinkName);
genInt_t intID = -1;
- if (m_core->interruptRequest(sourceID, sinkID, &intID)==GEN_OK) {
+ if (m_core->interruptRequest(sourceID, sinkID, &intID) == GEN_OK) {
return intID;
}
*/
}
-
-
-interrupt_t CommandReceive::interruptResume(interrupt_t interrupt){
+interrupt_t CommandReceive::interruptResume(interrupt_t interrupt) {
/**
* \todo here a callback mechanism needs to be installed....
*/
return 1;
}
-
-
volume_t CommandReceive::setVolume(sink_t sink, volume_t volume) {
if (m_core->UserSetVolume(sink, volume) == GEN_OK) {
return 1;
+
#include "commandInterface.h"
#include "audioManagerIncludes.h"
-class CommandReceive : CommandReceiveInterface {
+class CommandReceiveInterface;
+
+class CommandReceive : public CommandReceiveInterface {
public:
- CommandReceive(AudioManagerCore* core);
+ CommandReceive();
virtual ~CommandReceive();
+
+ void registerAudiomanagerCore(AudioManagerCore* core);
+
+ void startupInterface();
+ void stop();
connection_t connect(source_t source, sink_t sink);
connection_t disconnect(source_t source, source_t sink);
std::list<ConnectionType> getListConnections();
+++ /dev/null
-/**
- * Copyright (C) 2011, BMW AG
- *
- * AudioManangerDeamon
- *
- * \file DBusCommandInterface.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 "DBusCommandInterface.h"
-
-CommandInterface::CommandInterface() {
-}
-
-void CommandInterface::startupInterface() {
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Startup of DBUS Command interface"));
-
-// new DBusCommand(this);
-// QDBusConnection connection = QDBusConnection::sessionBus();
-// connection.registerService(QString(SERVICEINTERFACE));
-// if (connection.isConnected()) {
-// if (connection.registerObject(
-// "/Control",
-// this,
-// (QDBusConnection::ExportAdaptors
-// | QDBusConnection::ExportAllSignals))) {
-// DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Registered DBUS Command interface succsessfully"));
-// } else {
-// DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Failed to register DBUS Command interface succsessfully"));
-// }
-// }
-//
-}
-
-int CommandInterface::connect(int Source_ID, int Sink_ID) {
-
-}
-
-int CommandInterface::disconnect(int Source_ID, int Sink_ID) {
-
-}
-
-int CommandInterface::interruptRequest(const std::string &SourceName,
-
-}
-
-int CommandInterface::interruptResume(int InterruptID) {
-// emit signal_interruptResume(InterruptID);
- return 1;
-}
-
-void CommandInterface::registerAudioManagerCore(AudioManagerCore* core) {
- m_core = core;
-// QObject::connect((const QObject*) m_core,
-// SIGNAL(signal_connectionChanged()), (const QObject*) this,
-// SLOT(slot_connectionChanged()));
-// QObject::connect((const QObject*) m_core,
-// SIGNAL(signal_numberOfSinksChanged()), (const QObject*) this,
-// SLOT(slot_numberOfSinksChanged()));
-// QObject::connect((const QObject*) m_core,
-// SIGNAL(signal_numberOfSourcesChanged()), (const QObject*) this,
-// SLOT(slot_numberOfSourcesChanged()));
-}
-
-void CommandInterface::slot_connectionChanged() {
-// emit signal_connectionChanged();
-}
-void CommandInterface::slot_numberOfSinksChanged() {
-// emit signal_numberOfSinksChanged();
-}
-void CommandInterface::slot_numberOfSourcesChanged() {
-// emit signal_numberOfSourcesChanged();
-}
-
-int CommandInterface::setVolume(int SinkID, int Volume) {
-
-}
-
-std::list<SourceType> CommandInterface::getListSources() {
-
-}
-
-std::list<SinkType> CommandInterface::getListSinks() {
- return m_core->getListSinks();
-}
-
-std::list<ConnectionType> CommandInterface::getListConnections() {
- return m_core->getListConnections();
-}
--- /dev/null
+############################################################################
+#
+# 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
+)
DLT_DECLARE_CONTEXT(AudioManager);
-template<class T>T* getCreateFunction(std::string libname) {
-
- // cut off directories
- char* fileWithPath = const_cast<char*>(libname.c_str());
- std::string libFileName = basename(fileWithPath);
-
- // cut off "lib" in front and cut off .so end"
- std::string createFunctionName = libFileName.substr(3, libFileName.length() - 6) + "Factory";
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Lib entry point name "),DLT_STRING(createFunctionName.c_str()));
-
- // open library#include <unistd.h>
- void *libraryHandle;
- dlerror(); // Clear any existing error
- libraryHandle = dlopen(libname.c_str(), RTLD_NOW /*LAZY*/);
- const char* dlopen_error = dlerror();
- if (!libraryHandle || dlopen_error)
- {
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("dlopen failed"),DLT_STRING(dlopen_error));
- return 0;
- }
-
- // get entry point from shared lib
- dlerror(); // Clear any existing error
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("loading external function with name"),DLT_STRING(createFunctionName.c_str()));
-
- union
- {
- void* voidPointer;
- T* typedPointer;
- } functionPointer;
-
- // Note: direct cast is not allowed by ISO C++. e.g.
- // T* createFunction = reinterpret_cast<T*>(dlsym(libraryHandle, createFunctionName.c_str()));
- // compiler warning: "forbids casting between pointer-to-function and pointer-to-object"
-
- functionPointer.voidPointer = dlsym(libraryHandle, createFunctionName.c_str());
- T* createFunction = functionPointer.typedPointer;
-
- const char* dlsym_error = dlerror();
- if (!createFunction || dlsym_error)
- {
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Failed to load shared lib entry point"),DLT_STRING(dlsym_error));
- }
-
- return createFunction;
-}
-
/**
* this path needs to be adjusted to whatever is suitable on the system
*/
return &m_rootItem;
}
-template<class T>T* getCreateFunction(std::string libname) {
-
- // cut off directories
- char* fileWithPath = const_cast<char*>(libname.c_str());
- std::string libFileName = basename(fileWithPath);
-
- // cut off "lib" in front and cut off .so end"
- std::string createFunctionName = libFileName.substr(3, libFileName.length() - 6) + "Factory";
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Lib entry point name "),DLT_STRING(createFunctionName.c_str()));
-
- // open library
- void *libraryHandle;
- dlerror(); // Clear any existing error
- libraryHandle = dlopen(libname.c_str(), RTLD_NOW /*LAZY*/);
- const char* dlopen_error = dlerror();
- if (!libraryHandle || dlopen_error)
- {
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("dlopen failed"),DLT_STRING(dlopen_error));
- return 0;
- }
-
- // get entry point from shared lib
- dlerror(); // Clear any existing error
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("loading external function with name"),DLT_STRING(createFunctionName.c_str()));
-
- union
- {
- void* voidPointer;
- T* typedPointer;
- } functionPointer;
-
- // Note: direct cast is not allowed by ISO C++. e.g.
- // T* createFunction = reinterpret_cast<T*>(dlsym(libraryHandle, createFunctionName.c_str()));
- // compiler warning: "forbids casting between pointer-to-function and pointer-to-object"
-
- functionPointer.voidPointer = dlsym(libraryHandle, createFunctionName.c_str());
- T* createFunction = functionPointer.typedPointer;
-
- const char* dlsym_error = dlerror();
- if (!createFunction || dlsym_error)
- {
- DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Failed to load shared lib entry point"),DLT_STRING(dlsym_error));
- }
-
- return createFunction;
-}
-
void Bushandler::load_Bus_plugins() {
std::list<std::string> sharedLibraryNameList;
RoutingPlugin->return_BusName(BusName);
newBus.Name=std::string(BusName);
newBus.sendInterface=RoutingPlugin;
- RoutingPlugin->startup_interface(m_receiver);
+ RoutingPlugin->startup_interface(m_receiver,m_core->returnDbusHandler());
DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Routing Plugin:"), DLT_STRING(BusName));
Busses.push_back(newBus);
}
class Bushandler {
public:
- Bushandler() {
- }
- ;
- virtual ~Bushandler() {
- }
- ;
+ Bushandler() {};
+ virtual ~Bushandler() {};
/**by calling this, all bus plugins are loaded
*
void RoutingReceiver::ackConnect(genHandle_t handle, genError_t error) {
//emit signal_ackConnect(handle, error);
}
+
+RoutingReceiver::RoutingReceiver()
+{
+}
+
+void RoutingReceiver::ackDisconnect(genHandle_t handle, genError_t error)
+{
+}
+
+
+
+void RoutingReceiver::signal_ackConnect(genHandle_t handle, genError_t error)
+{
+}
+
+
+
+
class RoutingReceiver: public RoutingReceiveInterface {
public:
+ RoutingReceiver();
virtual ~RoutingReceiver() {}
void register_Databasehandler(DataBaseHandler* handler_); //is used to register the Database handler
int registerSource(char* name, char* audioclass, char* domain);
int peekDomain(char* name);
void ackConnect(genHandle_t handle, genError_t error);
+ void ackDisconnect(genHandle_t handle, genError_t error);
void signal_ackConnect(genHandle_t handle, genError_t error);
#ifndef AUDIOMANAGERINCLUDES_H_
#define AUDIOMANAGERINCLUDES_H_
+#define WITH_DBUS 1
+
#include "dlt/dlt.h"
+DLT_IMPORT_CONTEXT(AudioManager)
+
#include "dataTypes.h"
#include "routinginterface.h"
+#include "commandInterface.h"
#include "DataBaseHandler.h"
#include "RoutingReceive.h"
#include "Router.h"
#include "HookEngine.h"
#include "AudioManagerCore.h"
-//#include "DBusCommandInterface.h"
-
-DLT_IMPORT_CONTEXT(AudioManager)
+#include "pluginTemplate.h"
+#include "CommandHandler.h"
+#include "CommandReceive.h"
#endif /* AUDIOMANAGERINCLUDES_H_ */
class CommandReceiveInterface {\r
\r
public:\r
- virtual void startupInterface()=0;\r
virtual connection_t connect(source_t source, sink_t sink)=0;\r
virtual connection_t disconnect(source_t source, source_t sink)=0;\r
virtual std::list<ConnectionType> getListConnections()=0;\r
\r
class CommandSendInterface {\r
public:\r
-\r
+ virtual void startupInterface(CommandReceiveInterface * action)=0;\r
+ virtual void stop()=0;\r
/**\r
* Callback that is called when the number of connections change\r
*/\r
--- /dev/null
+/*
+ * dbusRoothandler.cpp
+ *
+ * Created on: Aug 1, 2011
+ * Author: christian
+ */
+
+#include "audioManagerIncludes.h"
+#ifdef WITH_DBUS
+
+#include "dbusRoothandler.h"
+
+#define ROOT_INTROSPECT_XML \
+DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
+"<node>" \
+"<interface name='org.freedesktop.DBus.Introspectable'>" \
+"<method name='Introspect'>" \
+" <arg name='xml_data' type='s' direction='out'/>" \
+"</method>" \
+"</interface>" \
+
+
+dbusRoothandler* dbusRoothandler::m_reference = NULL;
+
+static DBusObjectPathVTable vtable =
+{
+ NULL,dbusRoothandler::cbRootIntrospection,NULL, NULL, NULL, NULL
+};
+
+
+DBusHandlerResult dbusRoothandler::cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference) {
+ m_reference=(dbusRoothandler*)reference;
+ std::list<std::string>nodesList=m_reference->m_nodesList;
+ DBusMessage * reply;
+ DBusMessageIter args;
+ dbus_uint32_t serial = 0;
+ DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("Root Callback called"));
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
+ std::list<std::string>::iterator nodeIter;
+ std::list<std::string>::iterator nodeIterStart=nodesList.begin();
+ std::list<std::string>::iterator nodeIterEnd=nodesList.end();
+ const char *xml=ROOT_INTROSPECT_XML;
+ std::stringstream introspect;
+ introspect << std::string(xml);
+ for(nodeIter=nodeIterStart;nodeIter!=nodeIterEnd;nodeIter++) {
+ introspect<<"<node name='"<<nodeIter->c_str()<<"'/>";
+ }
+ introspect<<"</node>";
+
+ reply = dbus_message_new_method_return(msg);
+ std::string s = introspect.str();
+ const char* string=s.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(AudioManager,DLT_LOG_ERROR, DLT_STRING("DBUS Out Of Memory!"));
+ }
+
+ // send the reply && flush the connection
+ if (!dbus_connection_send(conn, reply, &serial))
+ {
+ DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("DBUS Out Of Memory!"));
+ }
+ dbus_connection_flush(conn);
+ // free the reply
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ } else {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+}
+
+dbusRoothandler::dbusRoothandler() : m_pConnection(0),m_err(),m_nodesList() {
+ 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(AudioManager,DLT_LOG_INFO, DLT_STRING("Error while getting the DBus"));
+ dbus_error_free(&m_err);
+ }
+ if (NULL == m_pConnection)
+ {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("DBus Connection is null"));
+ }
+
+ dbus_connection_register_object_path(m_pConnection, DBUS_SERVICE_ROOT, &vtable, this);
+ int ret = dbus_bus_request_name(m_pConnection,DBUS_SERVICE_SERVICE,DBUS_NAME_FLAG_DO_NOT_QUEUE, &m_err);
+ if (dbus_error_is_set(&m_err))
+ {
+ DLT_LOG(AudioManager,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(AudioManager,DLT_LOG_INFO, DLT_STRING("DBUSCommunicatorNot Primary Owner"), DLT_INT(ret));
+ }
+
+ // TODO Auto-generated constructor stub
+
+}
+
+dbusRoothandler::~dbusRoothandler() {
+ // TODO Auto-generated destructor stub
+}
+
+
+DBusConnection *dbusRoothandler::returnConnection(){
+ return m_pConnection;
+}
+
+void dbusRoothandler::registerNode(std::string node){
+ m_nodesList.push_back(node);
+}
+
+#endif
+
+
+
+
--- /dev/null
+/*
+ * dbusRoothandler.h
+ *
+ * Created on: Aug 1, 2011
+ * Author: christian
+ */
+
+#ifndef DBUSROOTHANDLER_H_
+#define DBUSROOTHANDLER_H_
+
+#include "audioManagerIncludes.h"
+#ifdef WITH_DBUS
+#include <dbus/dbus.h>
+#include <string.h>
+#include <list>
+#include <sstream>
+
+const char DBUS_SERVICE_SERVICE[]="org.genivi.audiomanager\0";
+const char DBUS_SERVICE_ROOT[]="/org/genivi/audiomanager\0";
+
+class dbusRoothandler {
+public:
+ dbusRoothandler();
+ virtual ~dbusRoothandler();
+ DBusConnection* returnConnection();
+ static DBusHandlerResult cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference);
+ void registerNode(std::string node);
+private:
+ static dbusRoothandler* m_reference;
+ DBusConnection* m_pConnection;
+ DBusError m_err;
+ std::list<std::string> m_nodesList;
+};
+
+#endif
+#endif /* DBUSROOTHANDLER_H_ */
*/
#include "audioManagerIncludes.h"
+
+#ifdef WITH_DBUS
+#include "dbusRoothandler.h"
+#endif
/**
* \todo: write some documentation about Plugin mechanism
*
//Here are our Main Classes
+ AudioManagerCore core;
DataBaseHandler dhandler;
RoutingReceiver breceiver;
+ CommandReceive creceiver;
Bushandler bushandler;
Router router;
HookHandler hookhandler;
- AudioManagerCore core;
- //DBusCommandInterface commandIface;
+ CommandHandler chandler(&core);
+ dbusRoothandler dbushandler;
//meet and greet: register all the classes @ each other
hookhandler.registerAudioManagerCore(&core);
+ creceiver.registerAudiomanagerCore(&core);
core.registerBushandler(&bushandler);
core.registerDatabasehandler(&dhandler);
core.registerRouter(&router);
core.registerHookEngine(&hookhandler);
core.registerReceiver(&breceiver);
- //core.registerCommandInterface(&commandIface);
+ core.registerDbusRootHandler(&dbushandler);
+ //core.registerCommandInterfa email whenever you are availce(&commandIface);
router.registerDatabasehandler(&dhandler);
//commandIface.registerDatabasehandler(&dhandler);
- //commandIface.registerAudioManagerCore(&core);
+ chandler.registerReceiver(&creceiver);
breceiver.register_Databasehandler(&dhandler);
bushandler.registerReceiver(&breceiver);
+ bushandler.registerCore(&core);
/**
* \todo: we do not have to knock down the database whole the time - this can be done different
DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("load bus plugins"));
bushandler.load_Bus_plugins();
bushandler.StartupInterfaces();
- //commandIface.startupInterface();
+// chandler.loadPlugins();
DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Init phase is over, everything up and running"));
- while (1) {
- sleep(2000);
- }
+ DBusConnection* con=dbushandler.returnConnection();
+
+ while (dbus_connection_read_write_dispatch(con, -1))
+ {
+ DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("Dispatching Dbus message..."));
+ }
}
--- /dev/null
+/*
+ * pluginTemplate.h
+ *
+ * Created on: Jul 27, 2011
+ * Author: christian
+ */
+
+#ifndef PLUGINTEMPLATE_H_
+#define PLUGINTEMPLATE_H_
+
+#include <iostream>
+#include <stdio.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <libgen.h>
+#include <unistd.h>
+#include <string>
+
+#include "audioManagerIncludes.h"
+
+template<class T>T* getCreateFunction(std::string libname) {
+
+ // cut off directories
+ char* fileWithPath = const_cast<char*>(libname.c_str());
+ std::string libFileName = basename(fileWithPath);
+
+ // cut off "lib" in front and cut off .so end"
+ std::string createFunctionName = libFileName.substr(3, libFileName.length() - 6) + "Factory";
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Lib entry point name "),DLT_STRING(createFunctionName.c_str()));
+
+ // open library
+ void *libraryHandle;
+ dlerror(); // Clear any existing error
+ libraryHandle = dlopen(libname.c_str(), RTLD_NOW /*LAZY*/);
+ const char* dlopen_error = dlerror();
+ if (!libraryHandle || dlopen_error)
+ {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("dlopen failed"),DLT_STRING(dlopen_error));
+ return 0;
+ }
+
+ // get entry point from shared lib
+ dlerror(); // Clear any existing error
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("loading external function with name"),DLT_STRING(createFunctionName.c_str()));
+
+ union
+ {
+ void* voidPointer;
+ T* typedPointer;
+ } functionPointer;
+
+ // Note: direct cast is not allowed by ISO C++. e.g.
+ // T* createFunction = reinterpret_cast<T*>(dlsym(libraryHandle, createFunctionName.c_str()));
+ // compiler warning: "forbids casting between pointer-to-function and pointer-to-object"
+
+ functionPointer.voidPointer = dlsym(libraryHandle, createFunctionName.c_str());
+ T* createFunction = functionPointer.typedPointer;
+
+ const char* dlsym_error = dlerror();
+ if (!createFunction || dlsym_error)
+ {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Failed to load shared lib entry point"),DLT_STRING(dlsym_error));
+ }
+
+ return createFunction;
+}
+
+
+#endif /* PLUGINTEMPLATE_H_ */
#include "dataTypes.h"\r
\r
class RoutingSendInterface;\r
+class dbusRoothandler;\r
\r
/** Routing Receive sendInterface description.\r
* This class implements everything from RoutingAdapter -> Audiomanager\r
*/\r
class RoutingReceiveInterface {\r
public:\r
+\r
/**\r
* What happens now?\r
*/\r
/**\r
* Just check me out I am the comment\r
*/\r
- virtual void ackDisconnect(genHandle_t handle, genError_t error);\r
+ virtual void ackDisconnect(genHandle_t handle, genError_t error)=0;\r
\r
};\r
\r
class RoutingSendInterface {\r
public:\r
\r
- /** destructor*/\r
- virtual ~RoutingSendInterface();\r
-\r
/** starts up the interface. In the implementations, here is the best place for\r
* init routines.\r
*/\r
- virtual void startup_interface(RoutingReceiveInterface * action /**< hands over the handle to the receive object. */\r
+ virtual void startup_interface(RoutingReceiveInterface * action, dbusRoothandler* dbushandler\r
)=0;\r
\r
/** connect a source to a sink\r
*/\r
virtual genError_t unmuteSink(sink_t sinkID) =0;\r
\r
- /** signal that tells the plugin that the system is ready. Is used to trigger a registration of Domains, etc..*/\r
- virtual void system_ready()=0;\r
/**\r
* connect a source to a sink \return the unique ID of the connection.\r
*/\r
- virtual genError_t asyncConnect(source_t source, sink_t sink, connection_t con_ID) =0;\r
+// virtual genError_t asyncConnect(source_t source, sink_t sink, connection_t con_ID) =0;\r
/**\r
* disconnect a connection \return true on success\r
*/\r
- virtual genError_t asyncDisconnect(connection_t connection_ID) =0;\r
+// virtual genError_t asyncDisconnect(connection_t connection_ID) =0;\r
+ /** signal that tells the plugin that the system is ready. Is used to trigger a registration of Domains, etc..*/\r
+ virtual void system_ready()=0;\r
};\r
\r
#endif /* ROUTINGINTERFACE_H_ */\r
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")
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)
# 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}
--- /dev/null
+/**
+ *
+ * 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"));
+}
+
#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);
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;
};
+++ /dev/null
-/**
- *
- * 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;
-}
-
+++ /dev/null
-/***************************************************************************
- *
- * 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);
-}
-
+++ /dev/null
-/***************************************************************************
- *
- * 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_
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);
}
}
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);
{
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!"));
}
}
// 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
// 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
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
{
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
{
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
{
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
{
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
{
{
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;
}
{
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;
}
{
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, ¶m);
}
}
-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);
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();
}
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);
+}
+
+
+
+
+
+
+
DBUSMessageHandler();
~DBUSMessageHandler();
- struct stringAndUInt {
- std::string string;
- unsigned int integer;
- };
-
- struct stringString {
- std::string string1;
- std::string string2;
- };
-
void setConnection(DBusConnection* conn);
DBusConnection* getConnection();
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;
#include "headers.h"
-class CommandReceive;
-
-typedef void (CommandReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
+typedef void (CommandDbusReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
struct MethodTable
{
#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;
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;
}
+
+
#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
*
*/
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;
};
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();
}
}
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();
}
}
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();
}
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);
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);
}
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);
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);
}
#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_ */
{ "", ""}
};
+static DBusObjectPathVTable _vtable =
+{
+ NULL,AudioManagerInterface::receive_callback,NULL, NULL, NULL, NULL
+};
+
+
-AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interface) : m_audioman(r_interface),m_running(false) {
+AudioManagerInterface::AudioManagerInterface(RoutingReceiveInterface* r_interface, dbusRoothandler* roothandler) : m_audioman(r_interface),m_Introspection(new DBUSIntrospection(manager_methods, manager_signals,std::string(MY_NODE))),m_roothandler(roothandler) {
}
bool AudioManagerInterface::startup_interface()
{
DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Starting up dbus connector"));
- g_pDbusMessage = new DBUSMessageHandler();
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("create thread"));
- this->m_running = true;
- pthread_create(&m_currentThread, NULL, AudioManagerInterface::run, this);
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Started dbus connector"));
+ g_pDbusMessage = new DBUSMessageHandler(&_vtable,m_roothandler->returnConnection(),this);
+
return true;
}
{
DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopped dbus connector"));
- this->m_running = false;
- pthread_join(m_currentThread, NULL);
delete g_pDbusMessage;
}
char* name = g_pDbusMessage->getString();
char* node = g_pDbusMessage->getString();
bool earlymode = g_pDbusMessage->getString();
- domain_t domain=m_audioman->registerDomain(name, busname, node, earlymode);
+ domain_t domain=m_reference->m_audioman->registerDomain(name, busname, node, earlymode);
g_pDbusMessage->initReply(msg);
g_pDbusMessage->appendUInt(domain);
g_pDbusMessage->closeReply();
emit_systemReady();
}
void AudioManagerInterface::emit_systemReady() {
- DBusMessage* msg;
- DBusConnection* conn = g_pDbusMessage->getConnection();
- dbus_uint32_t serial = 0;
- msg =dbus_message_new_signal("/org/genivi/audiomanager/RoutingInterface",DBUS_SERVICE_PREFIX,"signal_systemReady");
- if (!dbus_connection_send(conn, msg, &serial)) {
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("error while sending signal system ready on dbus"));
- }
- dbus_connection_flush(conn);
+ g_pDbusMessage->sendSignal("signal_systemReady");
}
-void* AudioManagerInterface::run(void * arg)
-{
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Main loop running"));
- m_reference = (AudioManagerInterface*) arg;
- DBusMessage* msg = 0;
- DBusConnection* conn = g_pDbusMessage->getConnection();
- while (m_reference->m_running && dbus_connection_read_write_dispatch(conn, -1))
- {
- msg = dbus_connection_pop_message(conn);
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("message received"));
-
- const char *member = dbus_message_get_member(msg);
- const char *iface = dbus_message_get_interface(msg);
- bool found=false;
- int i = 0;
-
- if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
- DBUSIntrospection introspectionString(manager_methods,manager_signals);
- introspectionString.process(conn, msg);
- g_pDbusMessage->setConnection(conn);
- } else if (strcmp(DBUS_SERVICE_PREFIX,iface)==0) {
-
- while (!found && strcmp(manager_methods[i].name, "") != 0)
- {
- if (strcmp(manager_methods[i].name, member) == 0)
- {
- MethodTable entry = manager_methods[i];
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("got call for method:"),DLT_STRING(entry.name));
- CallBackMethod m = entry.function;
- (m_reference->*m)(conn, msg);
- found = true;
- }
- i++;
- }
+DBusHandlerResult AudioManagerInterface::receive_callback(DBusConnection *conn, DBusMessage *msg, void *user_data){
+ m_reference=(AudioManagerInterface*) user_data;
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("message received"));
+
+ string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
+
+ if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
+ m_reference->m_Introspection->process(conn,msg);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ bool found=false;
+ int i = 0;
+
+ while (!found && strcmp(manager_methods[i].name, "") != 0) {
+ if (dbus_message_is_method_call(msg,DBUS_SERVICE_SERVICE,manager_methods[i].name)) {
+ MethodTable entry = manager_methods[i];
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("got call for method:"),DLT_STRING(entry.name));
+ CallBackMethod m = entry.function;
+ (m_reference->*m)(conn, msg);
+ found=true;
+ return DBUS_HANDLER_RESULT_HANDLED;
}
- dbus_connection_flush(conn);
- dbus_message_unref(msg);
- msg = NULL;
- }
+ i++;
+ }
- DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Stopping thread"));
- return 0;
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+
+
#define DBUSINTERFACE_H_
#include "headers.h"
+#include "DBUSIntrospection.h"
+
+class DBUSIntrospection;
class AudioManagerInterface {
public:
- AudioManagerInterface(RoutingReceiveInterface* r_interface);
+ AudioManagerInterface(RoutingReceiveInterface* r_interface,dbusRoothandler* roothandler);
bool startup_interface();
void stop();
+ static DBusHandlerResult receive_callback (DBusConnection *,DBusMessage *,void *);
void peekDomain(DBusConnection* conn, DBusMessage* msg);
void registerDomain(DBusConnection* conn, DBusMessage* msg);
void emit_systemReady();
private:
- static void* run(void * threadid);
- pthread_t m_currentThread;
static AudioManagerInterface* m_reference;
RoutingReceiveInterface* m_audioman;
- bool m_running;
+ DBUSIntrospection* m_Introspection;
+ dbusRoothandler* m_roothandler;
};
#endif /* DBUSINTERFACE_H_ */
cmake_minimum_required(VERSION 2.6)
-PROJECT(PluginCommandInterfaceDbus)
+PROJECT(PluginRoutingInterfaceDbus)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xlinker -export-dynamic")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(STD_INCLUDE_DIRS "/usr/include")
set(EXECUTABLE_OUTPUT_PATH ../../bin/)
set(LIBRARY_OUTPUT_PATH ../plugins/routing)
-set(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../doc/DBusPlugin)
+set(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../doc/RoutingDBusPlugin)
find_package (Threads)
FIND_PACKAGE(DBUS REQUIRED)
# all source files go here
SET(PLUGINDBUS_SRCS_CXX
+ AudiomanagerInterface.cpp
DbusInterface.cpp
DBUSIntrospection.cpp
DBUSMessageHandler.cpp
- AudiomanagerInterface.cpp
DbusSend.cpp
)
-add_library(PluginCommandInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX})
+add_library(PluginRoutingInterfaceDbus SHARED ${PLUGINDBUS_SRCS_CXX})
-TARGET_LINK_LIBRARIES(PluginCommandInterfaceDbus
+TARGET_LINK_LIBRARIES(PluginRoutingInterfaceDbus
${DLT_LIBRARIES}
${DBUS_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
#include "DBUSIntrospection.h"
#include <string.h>
#include <sstream>
+
+DLT_IMPORT_CONTEXT(DBusCommandPlugin);
+
using std::stringstream;
-DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable)
-: m_methodTable(methodTable), m_signalTable(signalTable)
+DBUSIntrospection::DBUSIntrospection(MethodTable* methodTable, SignalTable* signalTable,std::string nodename)
+: m_methodTable(methodTable), m_signalTable(signalTable), m_nodename(nodename)
{
generateString();
}
DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("Generating instrospection data!"));
addHeader();
- openNode("");
+ openNode(m_nodename);
openInterface("org.freedesktop.DBus.Introspectable");
openMethod("Introspect");
addArgument("data", "out", "s");
closeMethod();
closeInterface();
- openInterface(DBUS_SERVICE_PREFIX);
+ openInterface(DBUS_SERVICE_SERVICE);
int index = 0;
}
void DBUSIntrospection::addSignal(string signalname) {
- m_introspectionString<<"<signal name=\"" << signalname << "\"> \n";
+ m_introspectionString<<"<signal name=\"" << signalname << "\"/> \n";
}
void DBUSIntrospection::addArgument(string argname, string direction, string type)
class DBUSIntrospection
{
public:
- DBUSIntrospection(MethodTable* table, SignalTable* stable);
+ DBUSIntrospection(MethodTable* table, SignalTable* stable,std::string nodename);
void process(DBusConnection* conn, DBusMessage* msg);
private:
stringstream m_introspectionString;
MethodTable* m_methodTable;
SignalTable* m_signalTable;
+ std::string m_nodename;
};
#include "headers.h"
#include <stdlib.h>
-DBUSMessageHandler::DBUSMessageHandler()
+DBUSMessageHandler::DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference)
: m_MessageIter()
, m_pReply(0)
, m_serial(0)
-, m_pConnection(0)
+, m_pConnection(conn)
{
dbus_error_init(&m_err);
- // connect to the bus and check for errors
- m_pConnection = dbus_bus_get(DBUS_BUS_SESSION, &m_err);
- if (dbus_error_is_set(&m_err))
- {
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Connection error"));
- dbus_error_free(&m_err);
- }
- if (NULL == m_pConnection)
- {
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Connection is null"));
- exit(1);
- }
- int ret = dbus_bus_request_name(m_pConnection,DBUS_SERVICE_PREFIX, DBUS_NAME_FLAG_REPLACE_EXISTING, &m_err);
- if (dbus_error_is_set(&m_err))
- {
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicator Name Error"),DLT_STRING(m_err.message));
- dbus_error_free(&m_err);
- }
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
- {
- DLT_LOG(DBusPlugin,DLT_LOG_INFO, DLT_STRING("DBUSCommunicatorNot Primary Owner"), DLT_INT(ret));
- exit(1);
- }
+ string nodeString =std::string(DBUS_SERVICE_ROOT)+"/"+std::string(MY_NODE);
+ dbus_bool_t b=dbus_connection_register_object_path(m_pConnection, nodeString.c_str(), vtable, reference);
+ if(!b) {
+ DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Registering of node"), DLT_STRING(MY_NODE),DLT_STRING("failed"));
+ }
}
DBUSMessageHandler::~DBUSMessageHandler()
{
DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
}
- dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_PREFIX, &err);
+ dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_SERVICE, &err);
errorset = dbus_error_is_set(&err);
if (errorset)
{
DLT_LOG(DBusPlugin,DLT_LOG_ERROR, DLT_STRING("there was an dbus error"));
}
dbus_error_init(&err);
- dbus_bus_release_name(m_pConnection, DBUS_SERVICE_PREFIX, &err);
+ dbus_bus_release_name(m_pConnection, DBUS_SERVICE_SERVICE, &err);
}
void DBUSMessageHandler::initReceive(DBusMessage* msg)
dbus_message_iter_close_container(&m_MessageIter, &arrayIter);
}
-void DBUSMessageHandler::sendSignal(const char* name, const char* signal) {
+void DBUSMessageHandler::sendSignal(const char* signalname) {
dbus_uint32_t serial = 0;
DBusMessage* msg;
- DBusMessageIter args;
- msg = dbus_message_new_signal(DBUS_SERVICE_PREFIX, signal, name);
+ msg =dbus_message_new_signal(DBUS_SERVICE_ROOT,DBUS_SERVICE_SERVICE,signalname);
if (NULL == msg)
{
class DBUSMessageHandler
{
public:
- DBUSMessageHandler();
+ DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference);
~DBUSMessageHandler();
void setConnection(DBusConnection* conn);
void appendDouble(double toAppend);
void appendArrayOfUInt(unsigned int length, unsigned int *IDs);
- void sendSignal(const char* name,const char* signal);
+ void sendSignal(const char* signalname);
private:
DBusMessageIter m_MessageIter;
return m_pConnection;
}
-void DBUSMessageHandler::appendArrayOfStringString(std::list<stringString> list)
-{
-}
-
#endif // _DBUSMESSAGEWRAPPER_H_
DbusInterface::DbusInterface(): m_busname(DBUS_BUSNAME), m_path(DBUS_PATH) {
DLT_REGISTER_APP("DBusPlugin", "DBusPlugin");
- DLT_REGISTER_CONTEXT(DBusPlugin, "Plugin", "Dbus Plugin");
+ DLT_REGISTER_CONTEXT(DBusPlugin, "DPlugin", "Dbus Plugin");
DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("The DBus Plugin is started"));
}
delete m_DbusInterface;
}
-void DbusInterface::startup_interface(RoutingReceiveInterface* audioman) {
+void DbusInterface::startup_interface(RoutingReceiveInterface* audioman,dbusRoothandler* dbushandler) {
m_audioman = audioman;
- m_DbusInterface = new AudioManagerInterface(audioman);
+ m_rootHandler = dbushandler;
+ m_DbusInterface = new AudioManagerInterface(audioman,dbushandler);
m_DbusInterface->startup_interface();
-
+ m_rootHandler->registerNode(MY_NODE);
DBusError err;
dbus_error_init(&err);
*/
}
-genError_t DbusInterface::asyncConnect(source_t source, sink_t sink, connection_t con_ID) {
- /**
- * \todo implement
- */
-}
-
-genError_t DbusInterface::asyncDisconnect(connection_t connection_ID){
- /**
- * \todo implement
- */
-}
+//genError_t DbusInterface::asyncConnect(source_t source, sink_t sink, connection_t con_ID) {
+// /**
+// * \todo implement
+// */
+// return GEN_OK;
+//}
+//
+//genError_t DbusInterface::asyncDisconnect(connection_t connection_ID){
+// /**
+// * \todo implement
+// */
+// return GEN_OK;
+//}
//That is the actual implementation of the Factory Class returning the real sendInterface
#include "headers.h"
#include "routinginterface.h"
+class RoutingSendInterface;
+
/**Implementation of the interface
*
*/
DbusInterface();
virtual ~DbusInterface();
- void startup_interface(RoutingReceiveInterface * audioman);
+ void startup_interface(RoutingReceiveInterface * audioman, dbusRoothandler* dbushandler);
void return_BusName(char * BusName);
genError_t connect(source_t source, sink_t sink, connection_t connID);
genError_t disconnect(connection_t connectionID);
genError_t muteSink(sink_t sinkID);
genError_t unmuteSource(source_t sourceID);
genError_t unmuteSink(sink_t sinkID);
- genError_t asyncConnect(source_t source, sink_t sink, connection_t con_ID);
- virtual genError_t asyncDisconnect(connection_t connection_ID);
+// genError_t asyncConnect(source_t source, sink_t sink, connection_t con_ID);
+// genError_t asyncDisconnect(connection_t connection_ID);
void system_ready();
private:
RoutingReceiveInterface *m_audioman;
AudioManagerInterface* m_DbusInterface;
DBusConnection* m_conn;
+ dbusRoothandler* m_rootHandler;
char* m_busname;
char* m_path;
#include <dbus/dbus.h>
#include <dlt/dlt.h>
#include "routinginterface.h"
+#include "dbusRoothandler.h"
#include "AudiomanagerInterface.h"
#include "DbusSend.h"
#include "DBUSMessageHandler.h"
#define DBUS_BUSNAME "org.genivi.command"
#define DBUS_PATH "/pulse"
-const char DBUS_SERVICE_PREFIX[] = "org.genivi.audiomanagerCommand\0";
+
+const char MY_NODE[]="routinginterface\0";
DLT_IMPORT_CONTEXT(DBusPlugin);