summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon
diff options
context:
space:
mode:
authorChristian Mueller <christian@lmuc329619u.(none)>2011-07-21 20:54:37 +0200
committerChristian Mueller <christian@lmuc329619u.(none)>2011-07-21 20:54:37 +0200
commita34ffa9cf03c0685ee4751efb16eca8267e533c3 (patch)
tree5543bdbf865a8747ff57037b5ee6288a9d924f5a /AudioManagerDaemon
parent4bcad418c039cad5690e62ed63e2b4260c12a517 (diff)
downloadaudiomanager-a34ffa9cf03c0685ee4751efb16eca8267e533c3.tar.gz
- next part of getting rid of QT
- plugin handling for routing plugins work - dbus communication works but nof finalized
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r--AudioManagerDaemon/CMakeLists.txt31
-rw-r--r--AudioManagerDaemon/DataBaseHandler.cpp30
-rw-r--r--AudioManagerDaemon/DataBaseHandler.h2
-rw-r--r--AudioManagerDaemon/HookEngine.cpp14
-rw-r--r--AudioManagerDaemon/HookEngine.h5
-rw-r--r--AudioManagerDaemon/Router.cpp127
-rw-r--r--AudioManagerDaemon/Router.h4
-rw-r--r--AudioManagerDaemon/main.cpp9
-rw-r--r--AudioManagerDaemon/routinginterface.cpp12
-rw-r--r--AudioManagerDaemon/routinginterface.h24
10 files changed, 161 insertions, 97 deletions
diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt
index 60d9216..a0ba7c7 100644
--- a/AudioManagerDaemon/CMakeLists.txt
+++ b/AudioManagerDaemon/CMakeLists.txt
@@ -13,6 +13,8 @@ cmake_minimum_required(VERSION 2.6)
PROJECT(AudioManagerDeamon)
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xlinker -export-dynamic")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "-g -pipe -g -Wall -W -D_REENTRANT")
set(STD_INCLUDE_DIRS "/usr/include")
@@ -27,8 +29,6 @@ file(MAKE_DIRECTORY ${DOC_OUTPUT_PATH})
FIND_PACKAGE(PkgConfig)
pkg_check_modules(SQLITE REQUIRED sqlite3)
pkg_check_modules(DLT REQUIRED automotive-dlt)
-pkg_check_modules(JACK REQUIRED jack)
-
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${STD_INCLUDE_DIRS})
#all source files go here
@@ -40,25 +40,19 @@ SET(AUDIOMAN_SRCS_CXX
main.cpp
DBusCommandInterface.cpp
HookEngine.cpp
+ routinginterface.cpp
)
INCLUDE_DIRECTORIES(
include
${CMAKE_SOURCE_DIR}
${STD_INCLUDE_DIRS}
- ${JACK_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
- ${DBUS_FOLDER}
${DLT_INCLUDE_DIRS}
+ ${DBUS_INCLUDE_DIR}
+ ${DBUS_ARCH_INCLUDE_DIR}
)
-LINK_DIRECTORIES(
- ${LINK_DIRECTORIES}
- ${PULSE_LIBRARY_DIRS}
- ${JACK_LIBRARY_DIRS}
- ${DBUS_FOLDER}
- ${PROJECT_BINARY_DIR}/../plugins
-)
ADD_EXECUTABLE(AudioManager ${AUDIOMAN_SRCS_CXX})
@@ -67,21 +61,6 @@ TARGET_LINK_LIBRARIES(AudioManager
${DLT_LIBRARIES}
)
-add_custom_command(
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DBusCommand_.h ${CMAKE_CURRENT_BINARY_DIR}/DBusCommand.cpp
- COMMAND qdbusxml2cpp ARGS -c DBusCommand -a DBusCommand.h:DBusCommand.cpp ${DBUS_FOLDER}/DBusAudioManager.xml
- MAIN_DEPENDENCY ${DBUS_FOLDER}/DBusAudioManager.xml
-)
-
-
-add_custom_command(
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DBusCommand.h
- COMMAND sed ARGS -i '1i \#include \"../../dbusInterfaces/DBusTypes.h\"' DBusCommand.h
- MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/DBusCommand_.h
-)
-
#add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
diff --git a/AudioManagerDaemon/DataBaseHandler.cpp b/AudioManagerDaemon/DataBaseHandler.cpp
index f72d7a8..c1b1a7a 100644
--- a/AudioManagerDaemon/DataBaseHandler.cpp
+++ b/AudioManagerDaemon/DataBaseHandler.cpp
@@ -169,7 +169,7 @@ sourceClass_t DataBaseHandler::insert_into_Source_Class_table(std::string ClassN
std::string command = "SELECT ID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE ClassName='" + ClassName + "';";
if (SQexecute(command)) {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
return sqlite3_column_int(query,0);
}
}
@@ -214,14 +214,14 @@ source_t DataBaseHandler::insert_into_Source_table(std::string Name, sourceClass
std::string command = "SELECT ID FROM " + std::string(SOURCE_TABLE) + " WHERE Name='" + Name + "';";
if (SQexecute(command)) {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
return sqlite3_column_int(query,0);
}
}
command = "INSERT INTO " + std::string(SOURCE_TABLE) + " (Name, Class_ID, Domain_ID, IsGateway) VALUES ('" + Name + "'," + int2string(Class_ID) + ",'" + int2string(Domain_ID) + "','" + _IsGateway + "')";
- if (sqlite3_step(query)) {
+ if (this->pQuery(command)!=true) {
return -1;
} else {
//emit signal_numberOfSourcesChanged();
@@ -240,7 +240,7 @@ sink_t DataBaseHandler::insert_into_Sink_table(std::string Name, sinkClass_t Cla
std::string command = "SELECT ID FROM " + std::string(SINK_TABLE) + " WHERE Name='" + Name + "';";
if (SQexecute(command)) {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
return sqlite3_column_int(query,0);
}
}
@@ -259,7 +259,7 @@ gateway_t DataBaseHandler::insert_into_Gatway_table(std::string Name, sink_t Sin
std::string command = "SELECT ID FROM " + std::string(GATEWAY_TABLE) + " WHERE Name='" + Name + "';";
if (SQexecute(command)) {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
return sqlite3_column_int(query,0);
}
}
@@ -320,7 +320,7 @@ genError_t DataBaseHandler::getInterruptDatafromID(const genInt_t intID, connect
if (SQexecute(command)!=true) {
return GEN_DATABASE_ERROR;
} else {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
*return_connID = sqlite3_column_int(query,0);
*return_Sink_ID = sqlite3_column_int(query,1);
*return_Source_ID = sqlite3_column_int(query,2);
@@ -339,7 +339,7 @@ genError_t DataBaseHandler::removeInterrupt(const genInt_t intID) {
if (SQexecute(command) != true) {
return GEN_DATABASE_ERROR;
} else {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
delete reinterpret_cast<std::list<source_t>*>(sqlite3_column_int(query,0));
command = "DELETE FROM " + std::string(INTERRUPT_TABLE) + " WHERE ID='" + int2string(intID) + "';";
if (!this->pQuery(command)) {
@@ -358,7 +358,7 @@ domain_t DataBaseHandler::peek_Domain_ID(std::string DomainName) {
std::string command = "SELECT ID FROM " + std::string(DOMAIN_TABLE) + " WHERE DomainName='" + DomainName + "';";
if (SQexecute(command)) {
- if (sqlite3_step(query)) {
+ if (sqlite3_step(query)==SQLITE_ROW) {
return sqlite3_column_int(query,0);
} else {
command = "INSERT INTO " + std::string(DOMAIN_TABLE) + " (DomainName) VALUES ('" + DomainName + "')";
@@ -411,12 +411,16 @@ source_t DataBaseHandler::get_Source_ID_from_Name(std::string name) {
sourceClass_t DataBaseHandler::get_Source_Class_ID_from_Name(std::string name) {
sqlite3_stmt* query;
std::string command = "SELECT ID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE ClassName='" + name + "';";
-
- if (SQexecute(command)) {
+ int p=0;
+ if (SQexecute(command)!=true) {
return -1;
} else {
- sqlite3_step(query);
- return sqlite3_column_int(query,0);
+ p=sqlite3_step(query);
+ if (p==SQLITE_ROW) {
+ return sqlite3_column_int(query,0);
+ } else {
+ p=p+1;
+ }
}
}
@@ -424,7 +428,7 @@ domain_t DataBaseHandler::get_Domain_ID_from_Name(std::string name) {
sqlite3_stmt* query;
std::string command = "SELECT ID FROM " + std::string(DOMAIN_TABLE) + " WHERE DomainName='" + name + "';";
- if (SQexecute(command)) {
+ if (SQexecute(command)!=true) {
return -1;
} else {
sqlite3_step(query);
diff --git a/AudioManagerDaemon/DataBaseHandler.h b/AudioManagerDaemon/DataBaseHandler.h
index 5f3b516..99ac5c5 100644
--- a/AudioManagerDaemon/DataBaseHandler.h
+++ b/AudioManagerDaemon/DataBaseHandler.h
@@ -41,7 +41,7 @@
#define INTERRUPT_TABLE "Interrupts"
#define MAIN_TABLE "MainTable"
-#define SQexecute(command) sqlite3_exec(m_database,command.c_str(),NULL,&query,NULL)!= SQLITE_OK
+#define SQexecute(command) sqlite3_prepare_v2(m_database,command.c_str(),-1,&query,NULL)== SQLITE_OK
#include "audioManagerIncludes.h"
diff --git a/AudioManagerDaemon/HookEngine.cpp b/AudioManagerDaemon/HookEngine.cpp
index 90e52b8..e400de2 100644
--- a/AudioManagerDaemon/HookEngine.cpp
+++ b/AudioManagerDaemon/HookEngine.cpp
@@ -24,18 +24,13 @@
*/
#include "HookEngine.h"
-
-/**
- * this path needs to be adjusted to whatever is suitable on the system
- */
-const char* hookPluginDirectories[] = { "/home/blacky/new_workspace/AudioManager/build/plugins"};
-uint hookPluginDirectoriesCount = sizeof(hookPluginDirectories) / sizeof(hookPluginDirectories[0]);
-
#include <dirent.h>
#include <dlfcn.h>
#include <libgen.h>
#include <unistd.h>
+DLT_DECLARE_CONTEXT(AudioManager);
+
template<class T>T* getCreateFunction(std::string libname) {
// cut off directories
@@ -83,6 +78,11 @@ template<class T>T* getCreateFunction(std::string libname) {
return createFunction;
}
+/**
+ * this path needs to be adjusted to whatever is suitable on the system
+ */
+const char* hookPluginDirectories[] = { "/home/christian/workspace/gitserver/build/plugins/hook"};
+uint hookPluginDirectoriesCount = sizeof(hookPluginDirectories) / sizeof(hookPluginDirectories[0]);
BaseHook::BaseHook() {
}
diff --git a/AudioManagerDaemon/HookEngine.h b/AudioManagerDaemon/HookEngine.h
index 33cd667..9a297db 100644
--- a/AudioManagerDaemon/HookEngine.h
+++ b/AudioManagerDaemon/HookEngine.h
@@ -74,6 +74,9 @@ class BaseHook {
public:
BaseHook();
virtual ~BaseHook();
+
+ void registerAudioManagerCore(AudioManagerCore* core);
+
/**This function is used to register the HookHandler in the plugin.
*
* @param engine pointer to the instance of the HookHandler
@@ -101,8 +104,6 @@ public:
*/
virtual genError_t returnPluginName(char* PluginName)=0;
- void registerAudioManagerCore(AudioManagerCore* core);
-
virtual genHookResult_t hookDomainRegister(char* Name, domain_t ID) {
(void) Name;
(void) ID;
diff --git a/AudioManagerDaemon/Router.cpp b/AudioManagerDaemon/Router.cpp
index b507301..7f1c234 100644
--- a/AudioManagerDaemon/Router.cpp
+++ b/AudioManagerDaemon/Router.cpp
@@ -25,9 +25,16 @@
#include <iostream>
#include <stdio.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <libgen.h>
+#include <unistd.h>
+#include <string>
-#include "DataBaseHandler.h"
-#include "Router.h"
+#include "audioManagerIncludes.h"
+
+const char* routingPluginDirectories[] = { "/home/christian/workspace/gitserver/build/plugins/routing"};
+uint routingPluginDirectoriesCount = sizeof(routingPluginDirectories) / sizeof(routingPluginDirectories[0]);
Router::Router() {
}
@@ -181,27 +188,99 @@ RoutingTreeItem* RoutingTree::returnRootItem() {
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() {
- RoutingSendInterface *b = NULL;
- char BusName[40];
- Bus newBus;
-// foreach (QObject *plugin, QPluginLoader::staticInstances())
-// {
-// strcpy(BusName, "");
-// RoutingInterfaceFactory* busInterfaceFactory = qobject_cast<
-// RoutingInterfaceFactory *> (plugin);
-// if (busInterfaceFactory) {
-// b = busInterfaceFactory->returnInstance();
-// b->return_BusName(BusName);
-// newBus.Name = QString(BusName);
-// newBus.sendInterface = b;
-// Busses.append(newBus);
-// QObject::connect((const QObject*) this,
-// SIGNAL (signal_system_ready(void)), (const QObject*) b,
-// SLOT(slot_system_ready(void)));
-// DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Bushandler:Found new bus interface"), DLT_STRING(newBus.Name.toAscii()));
-// }
-// }
+ std::list<std::string> sharedLibraryNameList;
+
+ for (uint dirIndex = 0; dirIndex < routingPluginDirectoriesCount; ++dirIndex) {
+ const char* directoryName = routingPluginDirectories[dirIndex];
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Searching for Routing 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 Routing plugin"),DLT_STRING(iter->c_str()));
+
+ RoutingSendInterface* (*createFunc)();
+ createFunc = getCreateFunction<RoutingSendInterface*()>(*iter);
+
+ if (!createFunc) {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Entry point of Communicator not found"));
+ continue;
+ }
+
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Hello"));
+ RoutingSendInterface* RoutingPlugin = createFunc();
+
+
+ if (!RoutingPlugin) {
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("RoutingPlugin initialization failed. Entry Function not callable"));
+ continue;
+ }
+
+ Bus newBus;
+ char BusName[40];
+ RoutingPlugin->return_BusName(BusName);
+ newBus.Name=std::string(BusName);
+ newBus.sendInterface=RoutingPlugin;
+ RoutingPlugin->startup_interface(m_receiver);
+ DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Routing Plugin:"), DLT_STRING(BusName));
+ Busses.push_back(newBus);
+ }
}
void Bushandler::StartupInterfaces() {
@@ -217,6 +296,10 @@ void Bushandler::registerReceiver(RoutingReceiver * receiver) {
m_receiver = receiver;
}
+void Bushandler::registerCore (AudioManagerCore* core) {
+ m_core=core;
+}
+
RoutingSendInterface* Bushandler::getInterfaceforBus(std::string bus) {
// foreach (Bus b, Busses)
// {
diff --git a/AudioManagerDaemon/Router.h b/AudioManagerDaemon/Router.h
index 05d2d88..44d379e 100644
--- a/AudioManagerDaemon/Router.h
+++ b/AudioManagerDaemon/Router.h
@@ -30,6 +30,7 @@
class DataBaseHandler;
class RoutingReceiver;
+class AudioManagerCore;
/**calculates routes from sinks to sources
* navigation for audio
@@ -188,6 +189,8 @@ public:
*/
void registerReceiver(RoutingReceiver* Receiver);
+ void registerCore (AudioManagerCore* core);
+
/**By calling this function the plugins are called to startup.
* Init functions etc are done by the plugins in this phase
*/
@@ -216,6 +219,7 @@ private:
std::list<Bus> Busses; //!< list of all busses
RoutingReceiver* m_receiver; //!< pointer to the routing receiver
+ AudioManagerCore* m_core;
};
#endif /* ROUTER_H_ */
diff --git a/AudioManagerDaemon/main.cpp b/AudioManagerDaemon/main.cpp
index 43efaea..342c13d 100644
--- a/AudioManagerDaemon/main.cpp
+++ b/AudioManagerDaemon/main.cpp
@@ -28,12 +28,6 @@
* \todo: write some documentation about Plugin mechanism
*
*/
-//put here all plugins you want to use with the Routing Interface
-//Q_IMPORT_PLUGIN(RoutingPlugin)
-//Q_IMPORT_PLUGIN(RoutingJackPlugin)
-//put here all plugins that you want to use with the hooks. No more modification needed (besides adoption of the CMakeList) !
-//Q_IMPORT_PLUGIN(TestPlugin)
-DLT_DECLARE_CONTEXT(AudioManager);
int main(int argc, char *argv[]) {
@@ -69,7 +63,8 @@ int main(int argc, char *argv[]) {
/**
* \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("create tables for database"));
+ */
+ DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("create tables for database"));
dhandler.create_tables();
/**
diff --git a/AudioManagerDaemon/routinginterface.cpp b/AudioManagerDaemon/routinginterface.cpp
new file mode 100644
index 0000000..cd9645b
--- /dev/null
+++ b/AudioManagerDaemon/routinginterface.cpp
@@ -0,0 +1,12 @@
+/*
+ * routinginterface.cpp
+ *
+ * Created on: Jul 21, 2011
+ * Author: christian
+ */
+
+
+#include "routinginterface.h"
+
+RoutingSendInterface::RoutingSendInterface() {}
+RoutingSendInterface::~RoutingSendInterface() {}
diff --git a/AudioManagerDaemon/routinginterface.h b/AudioManagerDaemon/routinginterface.h
index d4323c1..5460acf 100644
--- a/AudioManagerDaemon/routinginterface.h
+++ b/AudioManagerDaemon/routinginterface.h
@@ -92,9 +92,11 @@ public:
*/
class RoutingSendInterface {
public:
+
+ RoutingSendInterface();
+
/** destructor*/
- virtual ~RoutingSendInterface() {
- }
+ virtual ~RoutingSendInterface();
/** starts up the interface. In the implementations, here is the best place for
* init routines.
@@ -171,23 +173,7 @@ public:
)=0;
/** signal that tells the plugin that the system is ready. Is used to trigger a registration of Domains, etc..*/
- void slot_system_ready();
+ virtual void system_ready()=0;
};
-/** Routing sendInterface Factory.
- * This is used for the Qt Plugin mechanism. The factory creates and returns a pointer to the
- * RoutingSendInterface.
- */
-class RoutingInterfaceFactory {
-public:
- virtual ~RoutingInterfaceFactory() {
- }
-
- /** returns an Instance of RoutingSendInterface.
- * \return pointer to the instance.
- */
- virtual RoutingSendInterface* returnInstance()=0;
-};
-
-
#endif /* ROUTINGINTERFACE_H_ */